Search in sources :

Example 1 with ExcludeTransformer

use of gov.nih.nci.ctd2.dashboard.api.ExcludeTransformer 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 2 with ExcludeTransformer

use of gov.nih.nci.ctd2.dashboard.api.ExcludeTransformer 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 3 with ExcludeTransformer

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

the class SummaryController method getSummary.

@Transactional
@RequestMapping(method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getSummary() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    List<Summary> summary = dashboardDao.getOverallSummary();
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new SimpleDateTransformer(), Date.class).transform(new ExcludeTransformer(), void.class);
    String json = "{}";
    try {
        json = jsonSerializer.exclude("class").exclude("submissions.class").deepSerialize(summary.toArray(new Summary[0]));
    } catch (Exception e) {
        e.printStackTrace();
        return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
    }
    log.debug("get summary");
    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) ExcludeTransformer(gov.nih.nci.ctd2.dashboard.api.ExcludeTransformer) Summary(gov.nih.nci.ctd2.dashboard.util.Summary) Date(java.util.Date) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ExcludeTransformer

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

the class CentersAPI method getCenters.

@Transactional
@RequestMapping(method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getCenters() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    List<SubmissionCenter> centers = dashboardDao.findEntities(SubmissionCenter.class);
    APICenter[] apiCenters = new APICenter[centers.size()];
    int centerIndex = 0;
    for (SubmissionCenter center : centers) {
        List<Submission> submissions = dashboardDao.findSubmissionBySubmissionCenter(center);
        String[] ss = submissions.stream().map(x -> x.getStableURL()).toArray(String[]::new);
        // design flaw
        String pi = submissions.get(0).getObservationTemplate().getPrincipalInvestigator();
        apiCenters[centerIndex++] = new APICenter(center, pi, ss);
    }
    log.debug("ready to serialize");
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new SimpleDateTransformer(), Date.class).transform(new ExcludeTransformer(), void.class);
    String json = "{}";
    try {
        json = jsonSerializer.exclude("class").exclude("submissions.class").deepSerialize(apiCenters);
    } catch (Exception e) {
        e.printStackTrace();
        return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
    }
    return new ResponseEntity<String>(json, headers, HttpStatus.OK);
}
Also used : ExcludeTransformer(gov.nih.nci.ctd2.dashboard.api.ExcludeTransformer) DashboardDao(gov.nih.nci.ctd2.dashboard.dao.DashboardDao) Date(java.util.Date) HttpHeaders(org.springframework.http.HttpHeaders) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Controller(org.springframework.stereotype.Controller) SubmissionCenter(gov.nih.nci.ctd2.dashboard.model.SubmissionCenter) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) JSONSerializer(flexjson.JSONSerializer) Log(org.apache.commons.logging.Log) ResponseEntity(org.springframework.http.ResponseEntity) SimpleDateTransformer(gov.nih.nci.ctd2.dashboard.api.SimpleDateTransformer) LogFactory(org.apache.commons.logging.LogFactory) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) Transactional(org.springframework.transaction.annotation.Transactional) HttpHeaders(org.springframework.http.HttpHeaders) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) Date(java.util.Date) SubmissionCenter(gov.nih.nci.ctd2.dashboard.model.SubmissionCenter) ResponseEntity(org.springframework.http.ResponseEntity) SimpleDateTransformer(gov.nih.nci.ctd2.dashboard.api.SimpleDateTransformer) ExcludeTransformer(gov.nih.nci.ctd2.dashboard.api.ExcludeTransformer) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JSONSerializer (flexjson.JSONSerializer)4 ExcludeTransformer (gov.nih.nci.ctd2.dashboard.api.ExcludeTransformer)4 SimpleDateTransformer (gov.nih.nci.ctd2.dashboard.api.SimpleDateTransformer)4 ImplTransformer (gov.nih.nci.ctd2.dashboard.util.ImplTransformer)4 Date (java.util.Date)4 HttpHeaders (org.springframework.http.HttpHeaders)4 ResponseEntity (org.springframework.http.ResponseEntity)4 Transactional (org.springframework.transaction.annotation.Transactional)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 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)1 Submission (gov.nih.nci.ctd2.dashboard.model.Submission)1 SubmissionCenter (gov.nih.nci.ctd2.dashboard.model.SubmissionCenter)1 Summary (gov.nih.nci.ctd2.dashboard.util.Summary)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1