use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class WordCloudController method getCountsForSubject.
@Transactional
@RequestMapping(value = "subject/{subject_id}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getCountsForSubject(@PathVariable Integer subject_id) {
log.debug("request received for subject id: " + subject_id);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
WordCloudEntry[] words = dashboardDao.getSubjectCounts(subject_id);
JSONSerializer jsonSerializer = new JSONSerializer().exclude("class");
String json = "{}";
try {
json = jsonSerializer.deepSerialize(words);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
return new ResponseEntity<String>(json, headers, HttpStatus.OK);
}
use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class ObservationController method getObservationsBySubmissionIdAndSubjuectId.
/*
* For a given submission, tier is decided so there is point of further
* specifiying tier.
*/
@Transactional
@RequestMapping(value = "bySubmissionAndSubject", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getObservationsBySubmissionIdAndSubjuectId(@RequestParam("submissionId") Integer submissionId, @RequestParam("subjectId") Integer subjectId, @RequestParam(value = "role", required = false, defaultValue = "") String role) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
String summaryTemplate = null;
Set<Observation> observations = new HashSet<Observation>();
Subject subject = dashboardDao.getEntityById(Subject.class, subjectId);
for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
Observation observation = observedSubject.getObservation();
Submission submission = observation.getSubmission();
if (!submission.getId().equals(submissionId)) {
continue;
} else if (summaryTemplate == null) {
summaryTemplate = submission.getObservationTemplate().getObservationSummary();
}
String subjectRole = observedSubject.getObservedSubjectRole().getSubjectRole().getDisplayName();
if ((role.equals("") || role.equals(subjectRole))) {
observations.add(observation);
}
}
List<ObservationWithSummary> list = new ArrayList<ObservationWithSummary>();
for (Observation observation : observations) {
String expanded = dashboardDao.expandSummary(observation.getId(), summaryTemplate) + " (<a class='button-link' href='#" + observation.getStableURL() + "'>details »</a>)";
list.add(new ObservationWithSummary(observation, expanded));
}
JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
return new ResponseEntity<String>(jsonSerializer.serialize(list), headers, HttpStatus.OK);
}
use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method getSubjectCountsForRoles.
/* this query is to emulate the explore pages */
@Override
public WordCloudEntry[] getSubjectCountsForRoles(String[] roles) {
if (roles == null || roles.length == 0)
return new WordCloudEntry[0];
StringBuffer role_list = new StringBuffer("(");
role_list.append("'" + roles[0] + "'");
for (int i = 1; i < roles.length; i++) {
role_list.append(",'" + roles[1] + "'");
}
role_list.append(")");
List<WordCloudEntry> list = new ArrayList<WordCloudEntry>();
String sql = "SELECT displayName, numberOfObservations, stableURL FROM subject_with_summaries" + " JOIN subject ON subject_with_summaries.subject_id=subject.id" + " JOIN dashboard_entity ON subject.id=dashboard_entity.id" + " WHERE score>1 AND role IN " + role_list.toString() + " ORDER BY numberOfObservations DESC LIMIT 250";
log.debug(sql);
Session session = getSession();
@SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> query = session.createNativeQuery(sql);
for (Object[] obj : query.getResultList()) {
String subject = (String) obj[0];
String fullname = null;
if (subject.length() > ABBREVIATION_LENGTH_LIMIT) {
fullname = subject;
subject = shorternSubjectName(subject);
}
Integer count = (Integer) obj[1];
String url = (String) obj[2];
list.add(new WordCloudEntry(subject, count, url, fullname));
}
session.close();
return list.toArray(new WordCloudEntry[0]);
}
use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method findSubjectsByXref.
@Override
public List<Subject> findSubjectsByXref(String databaseName, String databaseId) {
Set<Subject> subjects = new HashSet<Subject>();
List<Xref> list = query2ParamsWithClass("from XrefImpl where databaseName = :dname and databaseId = :did", "dname", databaseName, "did", databaseId);
for (Xref o : list) {
subjects.addAll(findSubjectsByXref(o));
}
return new ArrayList<Subject>(subjects);
}
use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method batchSave.
@Override
public void batchSave(Collection<? extends DashboardEntity> entities, int batchSize) {
if (entities == null || entities.isEmpty())
return;
Session session = getSessionFactory().openSession();
session.beginTransaction();
int i = 0;
for (DashboardEntity entity : entities) {
if (entity instanceof Subject) {
Subject subject = (Subject) entity;
for (Xref x : subject.getXrefs()) {
session.save(x);
}
for (Synonym x : subject.getSynonyms()) {
session.save(x);
}
}
session.save(entity);
i++;
if (batchSize != 0 && i % batchSize == 0) {
session.flush();
session.clear();
}
}
session.flush();
session.clear();
session.getTransaction().commit();
session.close();
}
Aggregations