Search in sources :

Example 1 with ObservationItem

use of gov.nih.nci.ctd2.dashboard.api.ObservationItem in project nci-ctd2-dashboard by CBIIT.

the class DashboardDaoImpl method getObservationInfo.

@Override
public ObservationItem getObservationInfo(String uri) {
    Session session = getSession();
    @SuppressWarnings("unchecked") org.hibernate.query.Query<ObservationItem> query = session.createQuery("FROM ObservationItem WHERE uri = :uri");
    query.setParameter("uri", uri);
    ObservationItem x = null;
    try {
        x = query.getSingleResult();
    } catch (NoResultException e) {
        e.printStackTrace();
    }
    session.close();
    return x;
}
Also used : NoResultException(javax.persistence.NoResultException) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session) ObservationItem(gov.nih.nci.ctd2.dashboard.api.ObservationItem)

Example 2 with ObservationItem

use of gov.nih.nci.ctd2.dashboard.api.ObservationItem in project nci-ctd2-dashboard by CBIIT.

the class DashboardDaoImpl method findObservationInfo.

@Override
public List<ObservationItem> findObservationInfo(List<Integer> observationIds) {
    Session session = getSession();
    List<ObservationItem> list = new ArrayList<ObservationItem>();
    for (Integer id : observationIds) {
        @SuppressWarnings("unchecked") org.hibernate.query.Query<ObservationItem> query = session.createQuery("from ObservationItem where id = :id");
        query.setParameter("id", id);
        list.add(query.getSingleResult());
    }
    session.close();
    return list;
}
Also used : BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session) ObservationItem(gov.nih.nci.ctd2.dashboard.api.ObservationItem)

Example 3 with ObservationItem

use of gov.nih.nci.ctd2.dashboard.api.ObservationItem in project nci-ctd2-dashboard by CBIIT.

the class ObservationsAPI method getObservations.

@Transactional
@RequestMapping(value = "{submissionId}/{indexRanges}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getObservations(@PathVariable String submissionId, @PathVariable String indexRanges) {
    /* submissionId is not internal ID as other parts of code. it is the identifier as part of stableURL */
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    Set<Integer> indexes = new HashSet<Integer>();
    try {
        for (String range : indexRanges.split(",")) {
            String[] x = range.split("-");
            if (x.length == 1) {
                int index = Integer.parseInt(x[0]);
                indexes.add(index);
            } else if (x.length == 2) {
                int index1 = Integer.parseInt(x[0]);
                int index2 = Integer.parseInt(x[1]);
                if (index2 <= index1) {
                    log.warn("incorrect ranges syntax:" + indexRanges);
                    return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
                }
                for (int i = index1; i <= index2; i++) {
                    indexes.add(i);
                }
            } else {
                log.warn("incorrect ranges syntax:" + indexRanges);
                return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
            }
        }
    } catch (NumberFormatException ex) {
        log.warn(ex.getMessage());
        return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
    }
    try {
        ObservationItem[] observations = dashboardDao.getObservations(submissionId, indexes);
        log.debug("ready to serialize");
        JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new SimpleDateTransformer(), Date.class).transform(new FieldNameTransformer("class"), "clazz").transform(new FieldNameTransformer("class"), "subject_list.clazz").transform(new FieldNameTransformer("class"), "evidence_list.clazz").transform(new FieldNameTransformer("subject_uri"), "subject_list.uri").transform(new ExcludeTransformer(), void.class).exclude("class").exclude("evidence_list.evidenceName").exclude("evidence_list.columnName").exclude("subject_list.columnName").exclude("subject_list.synonyms").exclude("subject_list.xref").exclude("uri").exclude("id");
        String json = "{}";
        try {
            json = jsonSerializer.deepSerialize(observations);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
        }
        return new ResponseEntity<String>(json, headers, HttpStatus.OK);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) FieldNameTransformer(gov.nih.nci.ctd2.dashboard.api.FieldNameTransformer) Date(java.util.Date) ResponseEntity(org.springframework.http.ResponseEntity) SimpleDateTransformer(gov.nih.nci.ctd2.dashboard.api.SimpleDateTransformer) ExcludeTransformer(gov.nih.nci.ctd2.dashboard.api.ExcludeTransformer) HashSet(java.util.HashSet) ObservationItem(gov.nih.nci.ctd2.dashboard.api.ObservationItem) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ObservationItem

use of gov.nih.nci.ctd2.dashboard.api.ObservationItem in project nci-ctd2-dashboard by CBIIT.

the class ObservationAPI method getObservation.

@Transactional
@RequestMapping(value = "{id}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getObservation(@PathVariable String id) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    ObservationItem observation = dashboardDao.getObservationInfo("observation/" + id);
    if (observation == null) {
        return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
    }
    log.debug("ready to serialize");
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new SimpleDateTransformer(), Date.class).transform(new FieldNameTransformer("class"), "clazz").transform(new FieldNameTransformer("class"), "subject_list.clazz").transform(new FieldNameTransformer("class"), "evidence_list.clazz").transform(new FieldNameTransformer("subject_uri"), "subject_list.uri").transform(new ExcludeTransformer(), void.class).exclude("class").exclude("evidence_list.evidenceName").exclude("evidence_list.columnName").exclude("subject_list.columnName").exclude("subject_list.synonyms").exclude("subject_list.xref").exclude("uri").exclude("id");
    String json = "{}";
    try {
        json = jsonSerializer.deepSerialize(observation);
    } 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) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) SimpleDateTransformer(gov.nih.nci.ctd2.dashboard.api.SimpleDateTransformer) FieldNameTransformer(gov.nih.nci.ctd2.dashboard.api.FieldNameTransformer) ExcludeTransformer(gov.nih.nci.ctd2.dashboard.api.ExcludeTransformer) Date(java.util.Date) ObservationItem(gov.nih.nci.ctd2.dashboard.api.ObservationItem) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ObservationItem

use of gov.nih.nci.ctd2.dashboard.api.ObservationItem in project nci-ctd2-dashboard by CBIIT.

the class SubjectResponse method createInstance.

private static SubjectResponse createInstance(final Subject subject, final Filter filter, DashboardDao dashboardDao) {
    int[] tierCount = new int[3];
    Set<Integer> set = new HashSet<Integer>();
    for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
        ObservedSubjectRole observedSubjectRole = observedSubject.getObservedSubjectRole();
        String subjectRole = observedSubjectRole.getSubjectRole().getDisplayName();
        if (filter.rolesIncluded.size() > 0 && !filter.rolesIncluded.contains(subjectRole))
            continue;
        ObservationTemplate observatinoTemplate = observedSubject.getObservation().getSubmission().getObservationTemplate();
        Integer observationTier = observatinoTemplate.getTier();
        String centerNameBrief = observatinoTemplate.getSubmissionCenter().getStableURL().substring(7);
        if (filter.centerIncluded.size() > 0 && !filter.centerIncluded.contains(centerNameBrief))
            continue;
        if ((Arrays.asList(filter.tiersIncluded).contains(observationTier))) {
            set.add(observedSubject.getObservation().getId());
            tierCount[observationTier.intValue() - 1]++;
            if (filter.limit > 0 && set.size() >= filter.limit) {
                break;
            }
        }
    }
    List<ObservationItem> observations = dashboardDao.findObservationInfo(new ArrayList<Integer>(set));
    Set<String> roles = new TreeSet<String>();
    for (int i = 0; i < observations.size(); i++) {
        for (SubjectItem sub : observations.get(i).subject_list) {
            if (sub.getName().equals(subject.getDisplayName())) {
                roles.add(sub.getRole());
                break;
            }
        }
    }
    String[] uris = observations.stream().map(x -> x.uri).toArray(String[]::new);
    SubjectResponse subjectResponse = new SubjectResponse(subject, uris, roles.toArray(new String[0]), tierCount);
    return subjectResponse;
}
Also used : Arrays(java.util.Arrays) DashboardDao(gov.nih.nci.ctd2.dashboard.dao.DashboardDao) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservationURIsAndTiers(gov.nih.nci.ctd2.dashboard.util.ObservationURIsAndTiers) Set(java.util.Set) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Xref(gov.nih.nci.ctd2.dashboard.model.Xref) Synonym(gov.nih.nci.ctd2.dashboard.model.Synonym) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) TreeSet(java.util.TreeSet) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) HashSet(java.util.HashSet)

Aggregations

ObservationItem (gov.nih.nci.ctd2.dashboard.api.ObservationItem)6 Session (org.hibernate.Session)4 FullTextSession (org.hibernate.search.FullTextSession)4 BigInteger (java.math.BigInteger)3 JSONSerializer (flexjson.JSONSerializer)2 EvidenceItem (gov.nih.nci.ctd2.dashboard.api.EvidenceItem)2 ExcludeTransformer (gov.nih.nci.ctd2.dashboard.api.ExcludeTransformer)2 FieldNameTransformer (gov.nih.nci.ctd2.dashboard.api.FieldNameTransformer)2 SimpleDateTransformer (gov.nih.nci.ctd2.dashboard.api.SimpleDateTransformer)2 SubjectItem (gov.nih.nci.ctd2.dashboard.api.SubjectItem)2 DashboardDao (gov.nih.nci.ctd2.dashboard.dao.DashboardDao)2 DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)2 ECOTerm (gov.nih.nci.ctd2.dashboard.model.ECOTerm)2 ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)2 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)2 ObservedSubjectRole (gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole)2 Subject (gov.nih.nci.ctd2.dashboard.model.Subject)2 Synonym (gov.nih.nci.ctd2.dashboard.model.Synonym)2 ImplTransformer (gov.nih.nci.ctd2.dashboard.util.ImplTransformer)2 ArrayList (java.util.ArrayList)2