Search in sources :

Example 21 with ImplTransformer

use of gov.nih.nci.ctd2.dashboard.util.ImplTransformer 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 22 with ImplTransformer

use of gov.nih.nci.ctd2.dashboard.util.ImplTransformer in project nci-ctd2-dashboard by CBIIT.

the class ObservationController method getOneObservationsPerSubmissionByECOTerm.

@Transactional
@RequestMapping(value = "onePerSubmissionByEcoTerm", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getOneObservationsPerSubmissionByECOTerm(@RequestParam("ecocode") String ecocode, @RequestParam(value = "tier", required = false, defaultValue = "0") Integer tier) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    Map<Observation, BigInteger> observationAndCount = dashboardDao.getOneObservationPerSubmissionByEcoCode(ecocode, tier);
    List<ObservationWithCount> list = new ArrayList<ObservationWithCount>();
    for (Observation observation : observationAndCount.keySet()) {
        list.add(new ObservationWithCount(observation, observationAndCount.get(observation).intValue()));
    }
    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) ResponseEntity(org.springframework.http.ResponseEntity) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JSONSerializer (flexjson.JSONSerializer)22 ImplTransformer (gov.nih.nci.ctd2.dashboard.util.ImplTransformer)22 HttpHeaders (org.springframework.http.HttpHeaders)22 ResponseEntity (org.springframework.http.ResponseEntity)22 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22 Transactional (org.springframework.transaction.annotation.Transactional)20 DateTransformer (gov.nih.nci.ctd2.dashboard.util.DateTransformer)18 Observation (gov.nih.nci.ctd2.dashboard.model.Observation)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 ExcludeTransformer (gov.nih.nci.ctd2.dashboard.api.ExcludeTransformer)4 SimpleDateTransformer (gov.nih.nci.ctd2.dashboard.api.SimpleDateTransformer)4 Submission (gov.nih.nci.ctd2.dashboard.model.Submission)4 SearchResults (gov.nih.nci.ctd2.dashboard.util.SearchResults)3 FieldNameTransformer (gov.nih.nci.ctd2.dashboard.api.FieldNameTransformer)2 ObservationItem (gov.nih.nci.ctd2.dashboard.api.ObservationItem)2 DashboardDao (gov.nih.nci.ctd2.dashboard.dao.DashboardDao)2 BigInteger (java.math.BigInteger)2 HashSet (java.util.HashSet)2 List (java.util.List)2