Search in sources :

Example 1 with SubjectItem

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

the class DashboardDaoImpl method createObservedSubjectInfo.

private List<SubjectItem> createObservedSubjectInfo(Integer observationId) {
    Session session1 = getSession();
    @SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> query1 = session1.createNativeQuery("SELECT d2.displayName AS role, observed_subject_role.displayText AS description, d1.displayName AS name, subject.id, columnName, stableURL" + " FROM observed_subject join subject on observed_subject.subject_id=subject.id" + " JOIN dashboard_entity d1 ON subject.id=d1.id" + " JOIN observed_subject_role ON observed_subject.observedSubjectRole_id = observed_subject_role.id" + " JOIN subject_role ON observed_subject_role.subjectRole_id=subject_role.id" + " JOIN dashboard_entity AS d2 ON subject_role.id=d2.id" + " where observation_id=" + observationId);
    List<Object[]> subjects = query1.list();
    List<SubjectItem> list = new ArrayList<SubjectItem>();
    for (Object[] obj : subjects) {
        String role = (String) obj[0];
        String description = (String) obj[1];
        String name = (String) obj[2];
        Integer subjectId = (Integer) obj[3];
        String columnName = (String) obj[4];
        String stableURL = (String) obj[5];
        @SuppressWarnings("unchecked") org.hibernate.query.Query<String> query2 = session1.createNativeQuery("SELECT displayName FROM subject_synonym_map " + " JOIN synonym ON subject_synonym_map.synonyms_id=synonym.id " + " JOIN dashboard_entity ON synonym.id = dashboard_entity.id" + " WHERE SubjectImpl_id=" + subjectId);
        List<String> synonyms = query2.list();
        @SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> query3 = session1.createNativeQuery("SELECT databaseId, databaseName FROM subject_xref_map" + " JOIN xref ON subject_xref_map.xrefs_id=xref.id " + " WHERE SubjectImpl_id=" + subjectId);
        List<Object[]> xrefs = query3.list();
        List<XRefItem> xrefItems = new ArrayList<XRefItem>();
        for (Object[] x : xrefs) {
            xrefItems.add(new XRefItem((String) x[1], (String) x[0]));
        }
        SubjectItem subjectItem = new SubjectItem(stableURL, role, description, name, synonyms.toArray(new String[0]), xrefItems.toArray(new XRefItem[0]), columnName);
        list.add(subjectItem);
    }
    session1.close();
    return list;
}
Also used : ArrayList(java.util.ArrayList) XRefItem(gov.nih.nci.ctd2.dashboard.api.XRefItem) SubjectItem(gov.nih.nci.ctd2.dashboard.api.SubjectItem) BigInteger(java.math.BigInteger) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 2 with SubjectItem

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

the class SubjectResponse method createInstance.

private static SubjectResponse createInstance(final Subject subject, final Filter filter, DashboardDao dashboardDao) {
    int[] tierCount = new int[3];
    Set<Integer> set = new HashSet<Integer>();
    for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
        ObservedSubjectRole observedSubjectRole = observedSubject.getObservedSubjectRole();
        String subjectRole = observedSubjectRole.getSubjectRole().getDisplayName();
        if (filter.rolesIncluded.size() > 0 && !filter.rolesIncluded.contains(subjectRole))
            continue;
        ObservationTemplate observatinoTemplate = observedSubject.getObservation().getSubmission().getObservationTemplate();
        Integer observationTier = observatinoTemplate.getTier();
        String centerNameBrief = observatinoTemplate.getSubmissionCenter().getStableURL().substring(7);
        if (filter.centerIncluded.size() > 0 && !filter.centerIncluded.contains(centerNameBrief))
            continue;
        if ((Arrays.asList(filter.tiersIncluded).contains(observationTier))) {
            set.add(observedSubject.getObservation().getId());
            tierCount[observationTier.intValue() - 1]++;
            if (filter.limit > 0 && set.size() >= filter.limit) {
                break;
            }
        }
    }
    List<ObservationItem> observations = dashboardDao.findObservationInfo(new ArrayList<Integer>(set));
    Set<String> roles = new TreeSet<String>();
    for (int i = 0; i < observations.size(); i++) {
        for (SubjectItem sub : observations.get(i).subject_list) {
            if (sub.getName().equals(subject.getDisplayName())) {
                roles.add(sub.getRole());
                break;
            }
        }
    }
    String[] uris = observations.stream().map(x -> x.uri).toArray(String[]::new);
    SubjectResponse subjectResponse = new SubjectResponse(subject, uris, roles.toArray(new String[0]), tierCount);
    return subjectResponse;
}
Also used : Arrays(java.util.Arrays) DashboardDao(gov.nih.nci.ctd2.dashboard.dao.DashboardDao) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservationURIsAndTiers(gov.nih.nci.ctd2.dashboard.util.ObservationURIsAndTiers) Set(java.util.Set) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Xref(gov.nih.nci.ctd2.dashboard.model.Xref) Synonym(gov.nih.nci.ctd2.dashboard.model.Synonym) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) TreeSet(java.util.TreeSet) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) HashSet(java.util.HashSet)

Example 3 with SubjectItem

use of gov.nih.nci.ctd2.dashboard.api.SubjectItem 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

SubjectItem (gov.nih.nci.ctd2.dashboard.api.SubjectItem)2 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 Session (org.hibernate.Session)2 FullTextSession (org.hibernate.search.FullTextSession)2 EvidenceItem (gov.nih.nci.ctd2.dashboard.api.EvidenceItem)1 ObservationItem (gov.nih.nci.ctd2.dashboard.api.ObservationItem)1 XRefItem (gov.nih.nci.ctd2.dashboard.api.XRefItem)1 DashboardDao (gov.nih.nci.ctd2.dashboard.dao.DashboardDao)1 DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)1 ECOTerm (gov.nih.nci.ctd2.dashboard.model.ECOTerm)1 ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)1 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)1 ObservedSubjectRole (gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole)1 Subject (gov.nih.nci.ctd2.dashboard.model.Subject)1 Synonym (gov.nih.nci.ctd2.dashboard.model.Synonym)1 Xref (gov.nih.nci.ctd2.dashboard.model.Xref)1 ObservationURIsAndTiers (gov.nih.nci.ctd2.dashboard.util.ObservationURIsAndTiers)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1