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;
}
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();
}
Aggregations