Search in sources :

Example 6 with Subject

use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.

the class DashboardDaoImpl method batchMerge.

@Override
public void batchMerge(Collection<? extends Subject> subjects) {
    if (subjects == null || subjects.isEmpty())
        return;
    Session session = getSessionFactory().openSession();
    session.beginTransaction();
    for (Subject subject : subjects) {
        session.merge(subject);
    }
    session.getTransaction().commit();
    session.close();
}
Also used : 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)

Example 7 with Subject

use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.

the class DashboardDaoImpl method getSubmissionsForSubjectName.

/*
     * get submissions if subject name is in some of four fields of its
     * **Observation Template**: (1) DashboardEntityImpl.FIELD_DISPLAYNAME, (2)
     * ObservationTemplateImpl.FIELD_DESCRIPTION, (3)
     * ObservationTemplateImpl.FIELD_SUBMISSIONDESC, (4)
     * ObservationTemplateImpl.FIELD_SUBMISSIONNAME
     */
@Override
public List<Submission> getSubmissionsForSubjectName(String subjectName) {
    String sql = "SELECT submission.id from submission JOIN observation_template ON submission.observationTemplate_id=observation_template.id" + " JOIN dashboard_entity ON submission.id=dashboard_entity.id WHERE displayName LIKE :subjectName" + " OR description LIKE :subjectName OR submissionDescription LIKE :subjectName" + " OR submissionName LIKE :subjectName";
    Session session = getSession();
    @SuppressWarnings("unchecked") org.hibernate.query.Query<Integer> query = session.createNativeQuery(sql);
    query.setParameter("subjectName", "%" + subjectName + "%");
    List<Submission> list = new ArrayList<Submission>();
    for (Integer id : query.getResultList()) {
        Submission submission = getEntityById(Submission.class, id);
        list.add(submission);
    }
    session.close();
    return list;
}
Also used : BigInteger(java.math.BigInteger) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) ArrayList(java.util.ArrayList) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 8 with Subject

use of gov.nih.nci.ctd2.dashboard.model.Subject 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 9 with Subject

use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.

the class ControlledVocabularyPerColumnFieldSetMapper method mapFieldSet.

public ControlledVocabulary mapFieldSet(FieldSet fieldSet) throws BindException {
    String templateName = fieldSet.readString(TEMPLATE_NAME);
    ObservationTemplate observationTemplate = observationTemplateNameMap.get(templateName);
    if (observationTemplate == null)
        return new ControlledVocabulary(null, null, null);
    if (subjectRoleCache == null)
        subjectRoleCache = new HashMap<String, SubjectRole>();
    if (evidenceRoleCache == null)
        evidenceRoleCache = new HashMap<String, EvidenceRole>();
    String subject = fieldSet.readString(SUBJECT);
    String evidence = fieldSet.readString(EVIDENCE);
    if (subject.length() > 0) {
        String subjectRoleStr = fieldSet.readString(ROLE);
        SubjectRole subjectRole = subjectRoleCache.get(subjectRoleStr);
        if (subjectRole == null) {
            subjectRole = dashboardFactory.create(SubjectRole.class);
            subjectRole.setDisplayName(subjectRoleStr);
            subjectRoleCache.put(subjectRoleStr, subjectRole);
        }
        ObservedSubjectRole observedSubjectRole = dashboardFactory.create(ObservedSubjectRole.class);
        observedSubjectRole.setSubjectRole(subjectRole);
        observedSubjectRole.setColumnName(fieldSet.readString(COLUMN_NAME));
        observedSubjectRole.setDisplayText(fieldSet.readString(DISPLAY_TEXT));
        observedSubjectRole.setObservationTemplate(observationTemplate);
        return new ControlledVocabulary(observationTemplate, subjectRole, observedSubjectRole);
    } else if (evidence.length() > 0) {
        String evidenceRoleStr = fieldSet.readString(ROLE);
        EvidenceRole evidenceRole = evidenceRoleCache.get(evidenceRoleStr);
        if (evidenceRole == null) {
            evidenceRole = dashboardFactory.create(EvidenceRole.class);
            evidenceRole.setDisplayName(evidenceRoleStr);
            evidenceRoleCache.put(evidenceRoleStr, evidenceRole);
        }
        ObservedEvidenceRole observedEvidenceRole = dashboardFactory.create(ObservedEvidenceRole.class);
        observedEvidenceRole.setEvidenceRole(evidenceRole);
        observedEvidenceRole.setColumnName(fieldSet.readString(COLUMN_NAME));
        observedEvidenceRole.setDisplayText(fieldSet.readString(DISPLAY_TEXT));
        observedEvidenceRole.setObservationTemplate(observationTemplate);
        observedEvidenceRole.setAttribute(getObservedEvidenceRoleAttribute(fieldSet.readString(MIME_TYPE), fieldSet.readString(NUMERIC_UNITS)));
        return new ControlledVocabulary(observationTemplate, evidenceRole, observedEvidenceRole);
    }
    return new ControlledVocabulary(null, null, null);
}
Also used : HashMap(java.util.HashMap) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) SubjectRole(gov.nih.nci.ctd2.dashboard.model.SubjectRole) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) ObservedEvidenceRole(gov.nih.nci.ctd2.dashboard.model.ObservedEvidenceRole) ObservedEvidenceRole(gov.nih.nci.ctd2.dashboard.model.ObservedEvidenceRole) EvidenceRole(gov.nih.nci.ctd2.dashboard.model.EvidenceRole)

Example 10 with Subject

use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.

the class XrefDataWriter method write.

public void write(List<? extends XrefData> items) throws Exception {
    Map<Integer, Subject> all = new HashMap<Integer, Subject>();
    for (XrefData item : items) {
        List<? extends Subject> subjects = item.subjects;
        if (subjects == null || subjects.size() == 0) {
            continue;
        }
        Xref xref = item.xref;
        for (Subject subject : subjects) {
            Integer subjectId = subject.getId();
            Subject x = all.get(subjectId);
            if (x == null) {
                x = subject;
                all.put(subjectId, x);
            }
            x.getXrefs().add(xref);
        }
    }
    dashboardDao.batchMerge(all.values());
}
Also used : Xref(gov.nih.nci.ctd2.dashboard.model.Xref) HashMap(java.util.HashMap) Subject(gov.nih.nci.ctd2.dashboard.model.Subject)

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