Search in sources :

Example 1 with WordCloudEntry

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]);
}
Also used : BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) WordCloudEntry(gov.nih.nci.ctd2.dashboard.util.WordCloudEntry) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 2 with WordCloudEntry

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) WordCloudEntry(gov.nih.nci.ctd2.dashboard.util.WordCloudEntry) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with WordCloudEntry

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) WordCloudEntry(gov.nih.nci.ctd2.dashboard.util.WordCloudEntry) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with WordCloudEntry

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) WordCloudEntry(gov.nih.nci.ctd2.dashboard.util.WordCloudEntry) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with WordCloudEntry

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]);
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) WordCloudEntry(gov.nih.nci.ctd2.dashboard.util.WordCloudEntry) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Aggregations

WordCloudEntry (gov.nih.nci.ctd2.dashboard.util.WordCloudEntry)6 JSONSerializer (flexjson.JSONSerializer)3 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 Session (org.hibernate.Session)3 FullTextSession (org.hibernate.search.FullTextSession)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ResponseEntity (org.springframework.http.ResponseEntity)3 Transactional (org.springframework.transaction.annotation.Transactional)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3