/** * Gets the current (ThreadLocal) instance of {@code IntactContext}. If no such instance exist, * IntAct Core will be automatically initialized using JPA configurations in the classpath, configured * DataConfigs and, if these are not found, using a temporary database. * * @return the IntactContext instance */ public static IntactContext getCurrentInstance() { if (!currentInstanceExists()) { log.warn("Current instance of IntactContext is null. Initializing a context in memory."); initStandaloneContextInMemory(); } return instance; }
/** * Gets the current (ThreadLocal) instance of {@code IntactContext}. If no such instance exist, * IntAct Core will be automatically initialized using JPA configurations in the classpath, configured * DataConfigs and, if these are not found, using a temporary database. * * @return the IntactContext instance */ public static IntactContext getCurrentInstance() { if (!currentInstanceExists()) { log.warn("Current instance of IntactContext is null. Initializing a context in memory."); initStandaloneContextInMemory(); } return instance; }
protected CvUpdater() throws IOException, OBOParseException { if (!IntactContext.currentInstanceExists()) { throw new IllegalStateException("To instantiate a CvUpdated using no arguments, an instance of IntactContext must exist"); } this.processed = new HashMap<String, CvObject>(); this.stats = new CvUpdaterStatistics(); this.intactContext = IntactContext.getCurrentInstance(); this.persisterHelper = intactContext.getPersisterHelper(); }
/** * Update the shortlabel based on the data available in the database. */ public void synchronizeShortLabel() { if( IntactContext.currentInstanceExists() ) { if( IntactContext.getCurrentInstance().getConfig().isAutoUpdateInteractionLabel() ) { String shortLabel = getShortLabel(); String newShortLabel = InteractionUtils.syncShortLabelWithDb(shortLabel); if (!shortLabel.equals(newShortLabel)) { if (log.isDebugEnabled()) log.debug("Interaction with label '"+shortLabel+"' renamed '"+newShortLabel+"'" ); setShortLabel(newShortLabel); } } } else { log.warn( "There is no IntAct Context initialized, skipping interaction shortlabel synchronization." ); } }
/** * Update the shortlabel based on the data available in the database. */ public void synchronizeShortLabel() { if( IntactContext.currentInstanceExists() ) { if( IntactContext.getCurrentInstance().getConfig().isAutoUpdateInteractionLabel() ) { String shortLabel = getShortLabel(); String newShortLabel = InteractionUtils.syncShortLabelWithDb(shortLabel); if (!shortLabel.equals(newShortLabel)) { if (log.isDebugEnabled()) log.debug("Interaction with label '"+shortLabel+"' renamed '"+newShortLabel+"'" ); setShortLabel(newShortLabel); } } } else { log.warn( "There is no IntAct Context initialized, skipping interaction shortlabel synchronization." ); } }
@PrePersist public void synchronizeShortLabel() { if( IntactContext.currentInstanceExists() ) { if( IntactContext.getCurrentInstance().getConfig().isAutoUpdateExperimentLabel() ) { String shortLabel = getShortLabel(); String newShortLabel = shortLabel; try { newShortLabel = ExperimentUtils.syncShortLabelWithDb(shortLabel, ExperimentUtils.getPubmedId( this )); } catch (Exception e) { log.error("Exception synchronizing the label, probably due to an invalid format: "+newShortLabel, e); } if (!shortLabel.equals(newShortLabel)) { if (log.isDebugEnabled()) log.debug("Experiment with label '"+shortLabel+"' renamed '"+newShortLabel+"'" ); setShortLabel(newShortLabel); } } } else { log.warn( "There is no IntAct Context initialized, skipping experiment shortlabel synchronization." ); } }
@PrePersist public void synchronizeShortLabel() { if( IntactContext.currentInstanceExists() ) { if( IntactContext.getCurrentInstance().getConfig().isAutoUpdateExperimentLabel() ) { String shortLabel = getShortLabel(); String newShortLabel = shortLabel; try { newShortLabel = ExperimentUtils.syncShortLabelWithDb(shortLabel, ExperimentUtils.getPubmedId( this )); } catch (Exception e) { log.error("Exception synchronizing the label, probably due to an invalid format: "+newShortLabel, e); } if (!shortLabel.equals(newShortLabel)) { if (log.isDebugEnabled()) log.debug("Experiment with label '"+shortLabel+"' renamed '"+newShortLabel+"'" ); setShortLabel(newShortLabel); } } } else { log.warn( "There is no IntAct Context initialized, skipping experiment shortlabel synchronization." ); } }
public Institution getDefaultInstitutionForAcs() { if (defaultInstitutionForAcs == null && IntactContext.currentInstanceExists()) { defaultInstitutionForAcs = IntactContext.getCurrentInstance().getInstitution(); if (defaultInstitutionForAcs != null) { InstitutionXref xref = XrefUtils.getPsiMiIdentityXref(defaultInstitutionForAcs); if (xref != null) { defaultInstitutionPrimaryIdForAcs = xref.getPrimaryId(); } } } return defaultInstitutionForAcs; }
/** * The ID is the concatenation of the prefix and a sequence provided by the database, separated * by a dash. * * @param sessionImplementor a hibernate session implementor * @param object the object being persisted * * @return the new generated ID * * @throws HibernateException if something goes wrong */ @Override public Serializable generate( SessionImplementor sessionImplementor, Object object ) throws HibernateException { String prefix; if (IntactContext.currentInstanceExists()) { prefix = IntactContext.getCurrentInstance().getConfig().getAcPrefix(); } else { prefix = "UNK"; } String id = prefix + "-" + super.generate( sessionImplementor, object ); log.trace( "Assigning Id: " + id ); return id; }
/** * The ID is the concatenation of the prefix and a sequence provided by the database, separated * by a dash. * * @param sessionImplementor a hibernate session implementor * @param object the object being persisted * * @return the new generated ID * * @throws HibernateException if something goes wrong */ @Override public Serializable generate( SessionImplementor sessionImplementor, Object object ) throws HibernateException { String prefix; if (IntactContext.currentInstanceExists()) { prefix = IntactContext.getCurrentInstance().getConfig().getAcPrefix(); } else { prefix = "UNK"; } String id = prefix + "-" + super.generate( sessionImplementor, object ); log.trace( "Assigning Id: " + id ); return id; }
if (IntactContext.currentInstanceExists() && IntactContext.getCurrentInstance().getSpringContext().containsBean("userContext")) { UserContext userContext = (UserContext) IntactContext.getCurrentInstance().getSpringContext().getBean("userContext");
if (IntactContext.currentInstanceExists() && IntactContext.getCurrentInstance().getSpringContext().containsBean("userContext")) { UserContext userContext = (UserContext) IntactContext.getCurrentInstance().getSpringContext().getBean("userContext");
/** * Check if the object state is "new" or "managed". This check is useful in those * cases where we need to check if the collections (annotations, aliases and xrefs) are * accessible and won't throw a LazyInitializationException if accessed. * * @param annotatedObject The AnnotatedObject to check * @return True if is new or managed */ public static boolean isNewOrManaged(AnnotatedObject annotatedObject) { // is it new? if (annotatedObject.getAc() == null) return true; // is it transient? (as in opposition to managed) if (IntactContext.currentInstanceExists() && IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getBaseDao().isTransient(annotatedObject)) { return false; } return true; }
/** * Check if the object state is "new" or "managed". This check is useful in those * cases where we need to check if the collections (annotations, aliases and xrefs) are * accessible and won't throw a LazyInitializationException if accessed. * * @param annotatedObject The AnnotatedObject to check * @return True if is new or managed */ public static boolean isNewOrManaged(AnnotatedObject annotatedObject) { // is it new? if (annotatedObject.getAc() == null) return true; // is it transient? (as in opposition to managed) if (IntactContext.currentInstanceExists() && IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getBaseDao().isTransient(annotatedObject)) { return false; } return true; }
public static <X extends Xref> Collection<X> getIdentityXrefs(AnnotatedObject<X, ?> annotatedObject) { Collection<X> xrefs = new ArrayList<X>(); Collection<X> allXrefs = annotatedObject.getXrefs(); if (!IntactCore.isInitialized(annotatedObject.getXrefs()) && IntactContext.currentInstanceExists()) { EntityManager entityManager = IntactContext.getCurrentInstance().getDaoFactory().getEntityManager(); // set the flush mode to manual to avoid hibernate trying to flush the session when querying the xrefs FlushModeType originalFlushMode = entityManager.getFlushMode(); entityManager.setFlushMode(FlushModeType.COMMIT); Class xrefClass = AnnotatedObjectUtils.getXrefClassType(annotatedObject.getClass()); allXrefs = IntactContext.getCurrentInstance().getDaoFactory().getXrefDao(xrefClass).getByParentAc(annotatedObject.getAc()); entityManager.setFlushMode(originalFlushMode); } for (X xref : allXrefs) { CvXrefQualifier qualifier = xref.getCvXrefQualifier(); String qualifierMi = null; if (qualifier != null && ((qualifierMi = qualifier.getIdentifier()) != null && qualifierMi.equals(CvXrefQualifier.IDENTITY_MI_REF))) { xrefs.add(xref); } } return xrefs; }
public static <X extends Xref> Collection<X> getIdentityXrefs(AnnotatedObject<X, ?> annotatedObject) { Collection<X> xrefs = new ArrayList<X>(); Collection<X> allXrefs = annotatedObject.getXrefs(); if (!IntactCore.isInitialized(annotatedObject.getXrefs()) && IntactContext.currentInstanceExists()) { EntityManager entityManager = IntactContext.getCurrentInstance().getDaoFactory().getEntityManager(); // set the flush mode to manual to avoid hibernate trying to flush the session when querying the xrefs FlushModeType originalFlushMode = entityManager.getFlushMode(); entityManager.setFlushMode(FlushModeType.COMMIT); Class xrefClass = AnnotatedObjectUtils.getXrefClassType(annotatedObject.getClass()); allXrefs = IntactContext.getCurrentInstance().getDaoFactory().getXrefDao(xrefClass).getByParentAc(annotatedObject.getAc()); entityManager.setFlushMode(originalFlushMode); } for (X xref : allXrefs) { CvXrefQualifier qualifier = xref.getCvXrefQualifier(); String qualifierMi = null; if (qualifier != null && ((qualifierMi = qualifier.getIdentifier()) != null && qualifierMi.equals(CvXrefQualifier.IDENTITY_MI_REF))) { xrefs.add(xref); } } return xrefs; }