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