use of gov.nih.nci.ctd2.dashboard.util.WordCloudEntry in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method getSubjectCounts.
@Override
public WordCloudEntry[] getSubjectCounts() {
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 ORDER BY numberOfObservations DESC LIMIT 250";
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.util.WordCloudEntry in project nci-ctd2-dashboard by CBIIT.
the class WordCloudController method getSubjectCounts.
@Transactional
@RequestMapping(method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getSubjectCounts() {
log.debug("request received");
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
WordCloudEntry[] words = dashboardDao.getSubjectCounts();
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);
}
log.debug("get subject counts");
return new ResponseEntity<String>(json, headers, HttpStatus.OK);
}
use of gov.nih.nci.ctd2.dashboard.util.WordCloudEntry in project nci-ctd2-dashboard by CBIIT.
the class WordCloudController method getSubjectCountsForRoles.
@Transactional
@RequestMapping(value = "{roles}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getSubjectCountsForRoles(@PathVariable String roles) {
log.debug("request received for roles: " + roles);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
String[] role_array = roles.split(",");
WordCloudEntry[] words = new WordCloudEntry[0];
if (role_array.length > 0) {
words = dashboardDao.getSubjectCountsForRoles(role_array);
} else {
words = dashboardDao.getSubjectCounts();
}
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.util.WordCloudEntry 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.util.WordCloudEntry 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]);
}
Aggregations