Search in sources :

Example 11 with ImplTransformer

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

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

Example 13 with ImplTransformer

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

the class CountController method getSearchResultsInJson.

@Transactional
@RequestMapping(value = "{type}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getSearchResultsInJson(@PathVariable String type, @RequestParam("filterBy") Integer filterBy) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    List<? extends DashboardEntity> entities = webServiceUtil.getDashboardEntities(type, filterBy);
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.serialize(entities.size()), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with ImplTransformer

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

the class EcoController method browse.

@Transactional
@RequestMapping(value = "browse", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> browse() {
    final HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    final List<EcoBrowse> list = dashboardDao.getEcoBrowse();
    log.debug("number of ECO terms " + list.size());
    Collections.sort(list, new Comparator<EcoBrowse>() {

        @Override
        public int compare(final EcoBrowse o1, final EcoBrowse o2) {
            return o2.getNumberOfSubmissions() - o1.getNumberOfSubmissions();
        }
    });
    final JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.deepSerialize(list), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) EcoBrowse(gov.nih.nci.ctd2.dashboard.util.EcoBrowse) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with ImplTransformer

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

the class EcoController method term.

@Transactional
@RequestMapping(value = "term/{id}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> term(@PathVariable final String id) {
    log.debug("request received by EcoController for " + id);
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    final ECOTerm ecoterm = dashboardDao.getEntityByStableURL("eco", "eco/" + id);
    log.debug(ecoterm);
    final JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.deepSerialize(ecoterm), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm) 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