Search in sources :

Example 21 with Submission

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

the class DashboardDaoImpl method getObservationsForSubmissionAndEcoCode.

@Override
public List<Observation> getObservationsForSubmissionAndEcoCode(Integer submissionId, String ecocode) {
    String sql = "SELECT observation.id FROM observation" + " JOIN submission ON observation.submission_id=submission.id" + " JOIN observation_template ON submission.observationTemplate_id=observation_template.id" + " WHERE submission.id=" + submissionId + " AND ecocode LIKE '%" + ecocode + "%'";
    Session session = getSession();
    @SuppressWarnings("unchecked") org.hibernate.query.Query<Integer> query = session.createNativeQuery(sql);
    List<Integer> idList = query.list();
    List<Observation> list = new ArrayList<Observation>();
    for (Integer id : idList) {
        Observation observation = getEntityById(Observation.class, id);
        list.add(observation);
    }
    session.close();
    return list;
}
Also used : BigInteger(java.math.BigInteger) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) ArrayList(java.util.ArrayList) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 22 with Submission

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

the class DashboardDaoImpl method ecoCode2ObservationURIsAndTiers.

@Override
public ObservationURIsAndTiers ecoCode2ObservationURIsAndTiers(String ecoCode) {
    Session session = getSession();
    @SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> ecocodeQuery = session.createNativeQuery("SELECT ecocode, id, tier FROM observation_template WHERE LENGTH(ecocode)>0");
    List<Object[]> ecocodeResult = ecocodeQuery.list();
    List<String> observationURIs = new ArrayList<String>();
    int tier1 = 0, tier2 = 0, tier3 = 0;
    for (Object[] array : ecocodeResult) {
        String allcodes = (String) array[0];
        Integer templateId = (Integer) array[1];
        Integer tier = (Integer) array[2];
        String[] ecocodes = allcodes.split("\\|");
        if (Arrays.asList(ecocodes).contains(ecoCode)) {
            String sql = "SELECT observation.stableURL FROM observation" + " JOIN submission ON observation.submission_id=submission.id" + " WHERE submission.observationTemplate_id=" + templateId;
            @SuppressWarnings("unchecked") org.hibernate.query.Query<String> query = session.createNativeQuery(sql);
            List<String> uris = query.list();
            observationURIs.addAll(uris);
            switch(tier) {
                case 1:
                    tier1++;
                    break;
                case 2:
                    tier2++;
                    break;
                case 3:
                    tier3++;
                    break;
                default:
                    log.error("unknow tier number " + tier);
            }
        }
    }
    session.close();
    return new ObservationURIsAndTiers(observationURIs.toArray(new String[0]), tier1, tier2, tier3);
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) ObservationURIsAndTiers(gov.nih.nci.ctd2.dashboard.util.ObservationURIsAndTiers) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 23 with Submission

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

the class DashboardDaoImpl method findSubmissionByIsStory.

@Override
public List<Submission> findSubmissionByIsStory(boolean isSubmissionStory, boolean sortByPriority) {
    List<ObservationTemplate> tmpList1 = queryWithClass("from ObservationTemplateImpl where isSubmissionStory = :iss order by submissionStoryRank desc", "iss", isSubmissionStory);
    List<ObservationTemplate> tmpList2 = queryWithClass("from ObservationTemplateImpl where isSubmissionStory = :iss", "iss", isSubmissionStory);
    List<ObservationTemplate> tmpList = sortByPriority ? tmpList1 : tmpList2;
    List<Submission> list = new ArrayList<Submission>();
    for (ObservationTemplate o : tmpList) {
        list.addAll(findSubmissionByObservationTemplate(o));
    }
    return list;
}
Also used : Submission(gov.nih.nci.ctd2.dashboard.model.Submission) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) ArrayList(java.util.ArrayList)

Example 24 with Submission

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

the class DashboardDaoImpl method summarizePerSubject.

private Summary summarizePerSubject(Class<? extends Subject> subjectClass, String label) {
    String tableName = "";
    Class<?> implClass = subjectClass.isInterface() ? dashboardFactory.getImplClass(subjectClass) : subjectClass;
    java.lang.annotation.Annotation[] annotation = implClass.getAnnotationsByType(javax.persistence.Table.class);
    if (annotation.length == 1) {
        javax.persistence.Table table = (javax.persistence.Table) annotation[0];
        tableName = table.name();
    } else {
        return new Summary("exception", 0, 0, 0, 0);
    }
    Session session = getSession();
    @SuppressWarnings("unchecked") org.hibernate.query.Query<BigInteger> query = session.createNativeQuery("SELECT count(DISTINCT submission_id) FROM " + tableName + " JOIN observed_subject ON observed_subject.subject_id=" + tableName + ".id" + " JOIN observation ON observation.id=observed_subject.observation_id");
    BigInteger submissions = query.getSingleResult();
    String tierQuery = "SELECT tier, COUNT(DISTINCT observation_id) FROM " + tableName + " JOIN observed_subject ON observed_subject.subject_id=" + tableName + ".id" + " JOIN observation ON observation.id=observed_subject.observation_id" + " JOIN submission ON submission.id=observation.submission_id" + " JOIN observation_template ON observation_template.id=submission.observationTemplate_id" + " GROUP BY tier";
    @SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> query2 = session.createNativeQuery(tierQuery);
    int[] tierCount = new int[3];
    List<Object[]> result = query2.list();
    for (Object[] obj : result) {
        Integer tier = (Integer) obj[0];
        BigInteger count = (BigInteger) obj[1];
        tierCount[tier - 1] = count.intValue();
    }
    session.close();
    return new Summary(label, submissions.intValue(), tierCount[0], tierCount[1], tierCount[2]);
}
Also used : Annotation(gov.nih.nci.ctd2.dashboard.model.Annotation) BigInteger(java.math.BigInteger) Summary(gov.nih.nci.ctd2.dashboard.util.Summary) BigInteger(java.math.BigInteger) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 25 with Submission

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

the class DashboardDaoImpl method prepareAPIData.

/*
     * This is still necessary for API 2.0 because we need to access roles from
     * subject.
     */
@SuppressWarnings("unchecked")
@Override
public void prepareAPIData() {
    Session session = getSession();
    session.beginTransaction();
    session.createQuery("DELETE FROM EvidenceItem").executeUpdate();
    session.createQuery("DELETE FROM SubjectItem").executeUpdate();
    session.createQuery("DELETE FROM ObservationItem").executeUpdate();
    org.hibernate.query.Query<Object[]> query0 = session.createNativeQuery("SELECT submission.id, observationSummary FROM observation_template JOIN  submission ON observation_template.id=submission.observationTemplate_id");
    List<Object[]> submissions = query0.list();
    for (Object[] objs : submissions) {
        Integer submission_id = (Integer) (objs[0]);
        String observationSummary = (String) (objs[1]);
        org.hibernate.query.Query<Object[]> query = session.createNativeQuery("SELECT id, stableURL FROM observation WHERE submission_id=" + submission_id);
        List<Object[]> result = query.list();
        for (Object[] obj : result) {
            Integer id = (Integer) obj[0];
            String uri = (String) obj[1];
            List<EvidenceItem> evidences = createObservedEvidenceInfo(id);
            List<SubjectItem> subjects = createObservedSubjectInfo(id);
            ObservationItem obsv = new ObservationItem();
            obsv.setId(id);
            obsv.setSubmission_id(submission_id);
            obsv.observation_summary = replaceValues(observationSummary, subjects, evidences);
            obsv.evidence_list = evidences.toArray(new EvidenceItem[0]);
            obsv.subject_list = subjects.toArray(new SubjectItem[0]);
            session.save(obsv);
            obsv.uri = uri;
        }
    }
    session.getTransaction().commit();
    session.close();
}
Also used : EvidenceItem(gov.nih.nci.ctd2.dashboard.api.EvidenceItem) SubjectItem(gov.nih.nci.ctd2.dashboard.api.SubjectItem) BigInteger(java.math.BigInteger) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session) ObservationItem(gov.nih.nci.ctd2.dashboard.api.ObservationItem)

Aggregations

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