Search in sources :

Example 1 with EvidenceItem

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

the class DashboardDaoImpl method createObservedEvidenceInfo.

private List<EvidenceItem> createObservedEvidenceInfo(Integer observationId) {
    Session session = getSession();
    @SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> query = session.createNativeQuery("SELECT d2.displayName AS type, observed_evidence_role.displayText AS description, evidence.id, columnName" + " FROM observed_evidence join evidence on observed_evidence.evidence_id=evidence.id" + " JOIN observed_evidence_role ON observed_evidence.observedEvidenceRole_id=observed_evidence_role.id" + " JOIN evidence_role ON observed_evidence_role.evidenceRole_id=evidence_role.id" + " JOIN dashboard_entity AS d2 ON evidence_role.id=d2.id WHERE observation_id=" + observationId);
    List<EvidenceItem> list = new ArrayList<EvidenceItem>();
    List<Object[]> evidences = query.list();
    for (Object[] obj : evidences) {
        String type = (String) obj[0];
        String description = (String) obj[1];
        Integer evidenceId = (Integer) obj[2];
        Evidence evidence = getEntityById(Evidence.class, evidenceId);
        String evidenceName = evidence.getDisplayName();
        String columnName = (String) obj[3];
        EvidenceItem evidenceItem = new EvidenceItem(evidence, type, description, evidenceName, columnName);
        list.add(evidenceItem);
    }
    session.close();
    return list;
}
Also used : EvidenceItem(gov.nih.nci.ctd2.dashboard.api.EvidenceItem) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) Evidence(gov.nih.nci.ctd2.dashboard.model.Evidence) ObservedEvidence(gov.nih.nci.ctd2.dashboard.model.ObservedEvidence) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 2 with EvidenceItem

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

EvidenceItem (gov.nih.nci.ctd2.dashboard.api.EvidenceItem)2 BigInteger (java.math.BigInteger)2 Session (org.hibernate.Session)2 FullTextSession (org.hibernate.search.FullTextSession)2 ObservationItem (gov.nih.nci.ctd2.dashboard.api.ObservationItem)1 SubjectItem (gov.nih.nci.ctd2.dashboard.api.SubjectItem)1 Evidence (gov.nih.nci.ctd2.dashboard.model.Evidence)1 ObservedEvidence (gov.nih.nci.ctd2.dashboard.model.ObservedEvidence)1 ArrayList (java.util.ArrayList)1