public List<String> getInteractionsFromExperimentExportSpecified() { DataContext dataContext = IntactContext.getCurrentInstance().getDataContext(); TransactionStatus transactionStatus = dataContext.beginTransaction(); Query query = IntactContext.getCurrentInstance().getDaoFactory().getEntityManager().createQuery(interactionsFromExperimentExportSpecified); query.setParameter("drExport", CvTopic.UNIPROT_DR_EXPORT); List<String> interactions = query.getResultList(); dataContext.commitTransaction(transactionStatus); return interactions; }
@PostConstruct private void init() { this.nonMiCvDatabase = CvObjectUtils.createCvObject( IntactContext.getCurrentInstance().getInstitution(), CvDatabase.class, CvDatabase.INTACT_MI_REF, CvDatabase.INTACT ); }
public static Annotation hideTerm(CvObject c, String message){ DaoFactory factory = IntactContext.getCurrentInstance().getDaoFactory(); CvTopic topicFromDb = factory.getCvObjectDao(CvTopic.class).getByShortLabel(CvTopic.HIDDEN); if (topicFromDb == null){ topicFromDb = CvObjectUtils.createCvObject(IntactContext.getCurrentInstance().getInstitution(), CvTopic.class, null, CvTopic.HIDDEN); IntactContext.getCurrentInstance().getCorePersister().saveOrUpdate(topicFromDb); } Annotation newAnnotation = new Annotation(topicFromDb, message); c.addAnnotation(newAnnotation); return newAnnotation; }
@Deprecated public CorePersister getCorePersister() { return IntactContext.getCurrentInstance().getCorePersister(); } }
/** * @since 2.4.0 */ public CoreDeleter getCoreDeleter() { return (CoreDeleter) IntactContext.getCurrentInstance().getSpringContext().getBean("coreDeleter"); }
/** * 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; }
public SearchableDao getDao() { if (searchableDao == null) { searchableDao = IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getSearchableDao(); } return searchableDao; }
@Override @Transactional public Institution convertFromString(String str) { if (str == null) return null; return IntactContext.getCurrentInstance().getDaoFactory().getInstitutionDao().getByShortLabel(str); }
/** * Create a BioSource * * @param shortlabel shortlabel of the Biosource. * @param fullname fullname of the Biosource. * @param taxid taxid of the Biosource. * @return a persistent BioSource. */ private BioSource createBioSource(String shortlabel, String fullname, String taxid) throws BioSourceServiceException { if (log.isDebugEnabled()) { log.debug("Persisting BioSource(" + taxid + ", " + shortlabel + ", " + fullname + ")"); } DataContext dataContext = IntactContext.getCurrentInstance().getDataContext(); DaoFactory daoFactory = dataContext.getDaoFactory(); if (institution == null) { institution = IntactContext.getCurrentInstance().getInstitution(); } // Instanciate it BioSource bioSource = new BioSource(institution, shortlabel, taxid); bioSource.setFullName(fullname); return bioSource; }
/** * 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 local identity is created using a sequence. If the sequence does not exist, a new one is created * with initial value calculated using the maximum integer for the existing local CV identifiers. * @return The next value available * @throws SequenceCreationException thrown if the sequence cannot be created. */ protected String nextLocalIdentifier() throws SequenceCreationException { final IntactContext context = IntactContext.getCurrentInstance(); String prefix = context.getConfig().getLocalCvPrefix(); Integer max = context.getDataContext().getDaoFactory() .getCvObjectDao().getLastCvIdentifierWithPrefix(prefix); if (max == null) max = 0; SequenceManager seqManager = (SequenceManager) context.getSpringContext().getBean("sequenceManager"); seqManager.createSequenceIfNotExists(IntactAuxiliaryConfigurator.CV_LOCAL_SEQ, max+1); String nextIntegerAsString = String.valueOf(seqManager.getNextValueForSequence(IntactAuxiliaryConfigurator.CV_LOCAL_SEQ)); return prefix+":" + StringUtils.leftPad(nextIntegerAsString, 4, "0"); }
/** * Create a new InteractorXref for the protein * @param uniprotAc : the uniprot accession * @return the InteractorXref with the uniprot ac and qualifier identity */ private InteractorXref createIdentityInteractorXrefForUniprotAc(String uniprotAc){ IntactContext intactContext = IntactContext.getCurrentInstance(); if (uniprotAc == null){ return null; } final CvDatabase uniprot = intactContext.getDaoFactory().getCvObjectDao(CvDatabase.class).getByPsiMiRef( CvDatabase.UNIPROT_MI_REF ); final CvXrefQualifier identity = intactContext.getDaoFactory().getCvObjectDao(CvXrefQualifier.class).getByPsiMiRef(CvXrefQualifier.IDENTITY_MI_REF); InteractorXref xRef = new InteractorXref(intactContext.getInstitution(), uniprot, uniprotAc, identity); return xRef; }
/** * 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 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; }
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; }
@Transactional(propagation = Propagation.REQUIRED) public void updateChildrenHavingMissingParent(String child, String parent) { CvObjectDao<CvDagObject> cvDao = IntactContext.getCurrentInstance().getDaoFactory().getCvObjectDao(CvDagObject.class); CvDagObject reloadedChild = cvDao.getByAc(child); CvDagObject reloadedParent = cvDao.getByAc(parent); if (reloadedChild != null){ reloadedChild.addParent(reloadedParent); IntactContext.getCurrentInstance().getCorePersister().saveOrUpdate(reloadedChild); } else { log.warn("Cv object " + child + " cannot be updated because does not exist anymore"); } }
private static CvAliasType getOrCreateSynonymType( DaoFactory daoFactory ) { final Institution owner = IntactContext.getCurrentInstance().getInstitution(); IntactContext.getCurrentInstance().getCorePersister().saveOrUpdate( synonymType ); System.out.println( "CvAliasType( 'synonym', 'MI:1041' ) was persisted." );
if (IntactContext.currentInstanceExists() && IntactContext.getCurrentInstance().getSpringContext().containsBean("userContext")) { UserContext userContext = (UserContext) IntactContext.getCurrentInstance().getSpringContext().getBean("userContext");
public GeneratedEntry addInteractionWithAc(String ac) { Interaction interaction = intactContext.getDataContext().getDaoFactory() .getInteractionDao().getByAc(ac); checkResult(interaction, ac, "interaction"); return addInteraction(interaction); }
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(); }