Search in sources :

Example 1 with XRefItem

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

Aggregations

SubjectItem (gov.nih.nci.ctd2.dashboard.api.SubjectItem)1 XRefItem (gov.nih.nci.ctd2.dashboard.api.XRefItem)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Session (org.hibernate.Session)1 FullTextSession (org.hibernate.search.FullTextSession)1