Search in sources :

Example 6 with ObservationItem

use of gov.nih.nci.ctd2.dashboard.api.ObservationItem in project nci-ctd2-dashboard by CBIIT.

the class DashboardDaoImpl method getObservations.

@Override
public ObservationItem[] getObservations(String submissionId, Set<Integer> indexes) {
    // this works because observation URIs are totally based on submission URI
    List<String> uris = indexes.stream().map(i -> "observation/" + submissionId + "-" + i).collect(Collectors.toList());
    // uris.forEach(System.out::println);
    Session session = getSession();
    List<ObservationItem> list = new ArrayList<ObservationItem>();
    @SuppressWarnings("unchecked") org.hibernate.query.Query<ObservationItem> query = session.createQuery("FROM ObservationItem WHERE uri IN (:uris)");
    query.setParameterList("uris", uris);
    try {
        list = query.getResultList();
    } catch (NoResultException e) {
        log.info("ObservationItem not available for submission ID " + submissionId);
    }
    ObservationItem[] x = list.stream().toArray(ObservationItem[]::new);
    log.debug("count of observations:" + x.length);
    session.close();
    return x;
}
Also used : Query(org.apache.lucene.search.Query) ObservedEvidenceRole(gov.nih.nci.ctd2.dashboard.model.ObservedEvidenceRole) Transcript(gov.nih.nci.ctd2.dashboard.model.Transcript) Arrays(java.util.Arrays) DashboardDao(gov.nih.nci.ctd2.dashboard.dao.DashboardDao) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) Cacheable(org.springframework.cache.annotation.Cacheable) NoResultException(javax.persistence.NoResultException) XRefItem(gov.nih.nci.ctd2.dashboard.api.XRefItem) SubmissionCenter(gov.nih.nci.ctd2.dashboard.model.SubmissionCenter) Matcher(java.util.regex.Matcher) MultiFieldQueryParser(org.apache.lucene.queryparser.classic.MultiFieldQueryParser) Map(java.util.Map) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BigInteger(java.math.BigInteger) TissueSample(gov.nih.nci.ctd2.dashboard.model.TissueSample) ZipEntry(java.util.zip.ZipEntry) PrintWriter(java.io.PrintWriter) Organism(gov.nih.nci.ctd2.dashboard.model.Organism) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ScrollableResults(org.hibernate.ScrollableResults) SearchResults(gov.nih.nci.ctd2.dashboard.util.SearchResults) SubjectResult(gov.nih.nci.ctd2.dashboard.util.SubjectResult) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) SessionFactory(org.hibernate.SessionFactory) Set(java.util.Set) FullTextQuery(org.hibernate.search.FullTextQuery) CellSample(gov.nih.nci.ctd2.dashboard.model.CellSample) Compound(gov.nih.nci.ctd2.dashboard.model.Compound) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm) SubjectWithOrganism(gov.nih.nci.ctd2.dashboard.model.SubjectWithOrganism) Collectors(java.util.stream.Collectors) ObservationItem(gov.nih.nci.ctd2.dashboard.api.ObservationItem) List(java.util.List) Xref(gov.nih.nci.ctd2.dashboard.model.Xref) EcoBrowse(gov.nih.nci.ctd2.dashboard.util.EcoBrowse) ScrollMode(org.hibernate.ScrollMode) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) DashboardEntityImpl(gov.nih.nci.ctd2.dashboard.impl.DashboardEntityImpl) Gene(gov.nih.nci.ctd2.dashboard.model.Gene) Pattern(java.util.regex.Pattern) LogFactory(org.apache.commons.logging.LogFactory) ShRna(gov.nih.nci.ctd2.dashboard.model.ShRna) ZipOutputStream(java.util.zip.ZipOutputStream) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) ParseException(org.apache.lucene.queryparser.classic.ParseException) FullTextSession(org.hibernate.search.FullTextSession) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) SimpleDateFormat(java.text.SimpleDateFormat) Session(org.hibernate.Session) HashMap(java.util.HashMap) EvidenceItem(gov.nih.nci.ctd2.dashboard.api.EvidenceItem) Evidence(gov.nih.nci.ctd2.dashboard.model.Evidence) WhitespaceAnalyzer(org.apache.lucene.analysis.core.WhitespaceAnalyzer) TypedQuery(javax.persistence.TypedQuery) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) SubjectWithSummaries(gov.nih.nci.ctd2.dashboard.util.SubjectWithSummaries) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Search(org.hibernate.search.Search) Summary(gov.nih.nci.ctd2.dashboard.util.Summary) SubjectImpl(gov.nih.nci.ctd2.dashboard.impl.SubjectImpl) AnimalModel(gov.nih.nci.ctd2.dashboard.model.AnimalModel) ObservedEvidence(gov.nih.nci.ctd2.dashboard.model.ObservedEvidence) WordCloudEntry(gov.nih.nci.ctd2.dashboard.util.WordCloudEntry) Files(java.nio.file.Files) ObservationURIsAndTiers(gov.nih.nci.ctd2.dashboard.util.ObservationURIsAndTiers) FileWriter(java.io.FileWriter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FlushMode(org.hibernate.FlushMode) SubjectItem(gov.nih.nci.ctd2.dashboard.api.SubjectItem) File(java.io.File) Hierarchy(gov.nih.nci.ctd2.dashboard.util.Hierarchy) Annotation(gov.nih.nci.ctd2.dashboard.model.Annotation) ObservationTemplateImpl(gov.nih.nci.ctd2.dashboard.impl.ObservationTemplateImpl) Paths(java.nio.file.Paths) Synonym(gov.nih.nci.ctd2.dashboard.model.Synonym) Protein(gov.nih.nci.ctd2.dashboard.model.Protein) Log(org.apache.commons.logging.Log) DashboardFactory(gov.nih.nci.ctd2.dashboard.model.DashboardFactory) ArrayList(java.util.ArrayList) NoResultException(javax.persistence.NoResultException) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session) ObservationItem(gov.nih.nci.ctd2.dashboard.api.ObservationItem)

Example 7 with ObservationItem

use of gov.nih.nci.ctd2.dashboard.api.ObservationItem in project nci-ctd2-dashboard by CBIIT.

the class DashboardDaoImpl method prepareAPIData.

/*
     * This is still necessary for API 2.0 because we need to access roles from
     * subject.
     */
@SuppressWarnings("unchecked")
@Override
public void prepareAPIData() {
    Session session = getSession();
    session.beginTransaction();
    session.createQuery("DELETE FROM EvidenceItem").executeUpdate();
    session.createQuery("DELETE FROM SubjectItem").executeUpdate();
    session.createQuery("DELETE FROM ObservationItem").executeUpdate();
    org.hibernate.query.Query<Object[]> query0 = session.createNativeQuery("SELECT submission.id, observationSummary FROM observation_template JOIN  submission ON observation_template.id=submission.observationTemplate_id");
    List<Object[]> submissions = query0.list();
    for (Object[] objs : submissions) {
        Integer submission_id = (Integer) (objs[0]);
        String observationSummary = (String) (objs[1]);
        org.hibernate.query.Query<Object[]> query = session.createNativeQuery("SELECT id, stableURL FROM observation WHERE submission_id=" + submission_id);
        List<Object[]> result = query.list();
        for (Object[] obj : result) {
            Integer id = (Integer) obj[0];
            String uri = (String) obj[1];
            List<EvidenceItem> evidences = createObservedEvidenceInfo(id);
            List<SubjectItem> subjects = createObservedSubjectInfo(id);
            ObservationItem obsv = new ObservationItem();
            obsv.setId(id);
            obsv.setSubmission_id(submission_id);
            obsv.observation_summary = replaceValues(observationSummary, subjects, evidences);
            obsv.evidence_list = evidences.toArray(new EvidenceItem[0]);
            obsv.subject_list = subjects.toArray(new SubjectItem[0]);
            session.save(obsv);
            obsv.uri = uri;
        }
    }
    session.getTransaction().commit();
    session.close();
}
Also used : EvidenceItem(gov.nih.nci.ctd2.dashboard.api.EvidenceItem) SubjectItem(gov.nih.nci.ctd2.dashboard.api.SubjectItem) BigInteger(java.math.BigInteger) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session) ObservationItem(gov.nih.nci.ctd2.dashboard.api.ObservationItem)

Aggregations

ObservationItem (gov.nih.nci.ctd2.dashboard.api.ObservationItem)6 Session (org.hibernate.Session)4 FullTextSession (org.hibernate.search.FullTextSession)4 BigInteger (java.math.BigInteger)3 JSONSerializer (flexjson.JSONSerializer)2 EvidenceItem (gov.nih.nci.ctd2.dashboard.api.EvidenceItem)2 ExcludeTransformer (gov.nih.nci.ctd2.dashboard.api.ExcludeTransformer)2 FieldNameTransformer (gov.nih.nci.ctd2.dashboard.api.FieldNameTransformer)2 SimpleDateTransformer (gov.nih.nci.ctd2.dashboard.api.SimpleDateTransformer)2 SubjectItem (gov.nih.nci.ctd2.dashboard.api.SubjectItem)2 DashboardDao (gov.nih.nci.ctd2.dashboard.dao.DashboardDao)2 DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)2 ECOTerm (gov.nih.nci.ctd2.dashboard.model.ECOTerm)2 ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)2 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)2 ObservedSubjectRole (gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole)2 Subject (gov.nih.nci.ctd2.dashboard.model.Subject)2 Synonym (gov.nih.nci.ctd2.dashboard.model.Synonym)2 Xref (gov.nih.nci.ctd2.dashboard.model.Xref)2 ImplTransformer (gov.nih.nci.ctd2.dashboard.util.ImplTransformer)2