Search in sources :

Example 21 with Subject

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);
}
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 22 with Subject

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 &raquo;</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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) ArrayList(java.util.ArrayList) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) ResponseEntity(org.springframework.http.ResponseEntity) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) HashSet(java.util.HashSet) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with Subject

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]);
}
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)

Example 24 with Subject

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);
}
Also used : Xref(gov.nih.nci.ctd2.dashboard.model.Xref) ArrayList(java.util.ArrayList) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) HashSet(java.util.HashSet)

Example 25 with Subject

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();
}
Also used : Xref(gov.nih.nci.ctd2.dashboard.model.Xref) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) Synonym(gov.nih.nci.ctd2.dashboard.model.Synonym) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Aggregations

Subject (gov.nih.nci.ctd2.dashboard.model.Subject)15 ArrayList (java.util.ArrayList)14 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)12 BigInteger (java.math.BigInteger)12 FullTextSession (org.hibernate.search.FullTextSession)11 Session (org.hibernate.Session)10 HashSet (java.util.HashSet)9 JSONSerializer (flexjson.JSONSerializer)8 ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)8 HashMap (java.util.HashMap)8 HttpHeaders (org.springframework.http.HttpHeaders)8 ResponseEntity (org.springframework.http.ResponseEntity)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Xref (gov.nih.nci.ctd2.dashboard.model.Xref)7 Transactional (org.springframework.transaction.annotation.Transactional)7 Submission (gov.nih.nci.ctd2.dashboard.model.Submission)6 WordCloudEntry (gov.nih.nci.ctd2.dashboard.util.WordCloudEntry)6 DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)5 Observation (gov.nih.nci.ctd2.dashboard.model.Observation)5 ObservedSubjectRole (gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole)5