Search in sources :

Example 1 with DateTransformer

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

the class StoriesController method getSearchResultsInJson.

@Transactional
@RequestMapping(method = { RequestMethod.POST, RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getSearchResultsInJson(@RequestParam("limit") Integer limit) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    ArrayList<Observation> entities = new ArrayList<Observation>();
    // If no limit, then show everything
    if (limit == -1)
        limit = Integer.MAX_VALUE;
    for (Submission submission : dashboardDao.findSubmissionByIsStory(true, true)) {
        List<Observation> observationsBySubmission = dashboardDao.findObservationsBySubmission(submission);
        // Story submissions have a single observation in them
        assert observationsBySubmission.size() == 1;
        entities.addAll(observationsBySubmission);
    }
    Collections.sort(entities, new Comparator<Observation>() {

        @Override
        public int compare(Observation o1, Observation o2) {
            Integer rank1 = o1.getSubmission().getObservationTemplate().getSubmissionStoryRank();
            Integer rank2 = o2.getSubmission().getObservationTemplate().getSubmissionStoryRank();
            return rank1 - rank2;
        }
    });
    /*
        entities.sort(new Comparator<Observation>() {
            @Override
            public int compare(Observation o1, Observation o2) {
                Integer rank1 = o1.getSubmission().getObservationTemplate().getSubmissionStoryRank();
                Integer rank2 = o2.getSubmission().getObservationTemplate().getSubmissionStoryRank();
                return rank1-rank2;
            }
        });
        */
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.serialize(entities.subList(0, Math.min(limit, entities.size()))), 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) ResponseEntity(org.springframework.http.ResponseEntity) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with DateTransformer

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

the class JSONController method getEntityInJson.

@Transactional
@RequestMapping(value = "{type}/{id}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getEntityInJson(@PathVariable String type, @PathVariable String id) {
    DashboardEntity entityById = null;
    Class<? extends DashboardEntity> clazz = Subject.class;
    if (type.equalsIgnoreCase("subject")) {
        clazz = Subject.class;
    } else if (type.equals("observedsubject")) {
        clazz = ObservedSubject.class;
    }
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    log.debug("JSONController " + type + " " + id);
    if (typesWithStableURL.contains(type)) {
        String stableURL = type + "/" + id;
        if (type.equals("observedevidence"))
            stableURL = "mra/" + id;
        entityById = dashboardDao.getEntityByStableURL(type, stableURL);
    } else {
        entityById = dashboardDao.getEntityById(clazz, Integer.parseInt(id));
    }
    if (entityById == null) {
        return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
    }
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.deepSerialize(entityById), 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 3 with DateTransformer

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

the class ListController method getSearchResultsInJson.

@Transactional
@RequestMapping(value = "{type}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getSearchResultsInJson(@PathVariable String type, @RequestParam(value = "filterBy", required = false) Integer filterBy, @RequestParam(value = "getAll", required = false, defaultValue = "false") Boolean getAll) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    List<? extends DashboardEntity> entities = webServiceUtil.getDashboardEntities(type, filterBy);
    if (!getAll && entities.size() > getMaxNumberOfEntities()) {
        entities = entities.subList(0, getMaxNumberOfEntities());
    }
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.serialize(entities), 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 4 with DateTransformer

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

the class OntologySearchController method searchExtraSubmissions.

@RequestMapping(value = "extra-submissions", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> searchExtraSubmissions(@RequestParam("subject-name") String subjectName) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    try {
        List<SubmissionResult> submission_result = dashboardDao.getSubmissionsForSubjectName(subjectName).stream().map(submission -> {
            ObservationTemplate template = submission.getObservationTemplate();
            return new SearchResults.SubmissionResult(submission.getStableURL(), submission.getSubmissionDate(), template.getDescription(), template.getTier(), template.getSubmissionCenter().getDisplayName(), submission.getId(), dashboardDao.findObservationsBySubmission(submission).size(), template.getIsSubmissionStory());
        }).collect(Collectors.toList());
        JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
        return new ResponseEntity<String>(jsonSerializer.deepSerialize(submission_result), headers, HttpStatus.OK);
    } catch (Exception e) {
        e.printStackTrace();
        return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
    }
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) DashboardDao(gov.nih.nci.ctd2.dashboard.dao.DashboardDao) URLDecoder(java.net.URLDecoder) SubmissionResult(gov.nih.nci.ctd2.dashboard.util.SearchResults.SubmissionResult) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) SearchResults(gov.nih.nci.ctd2.dashboard.util.SearchResults) Date(java.util.Date) HttpHeaders(org.springframework.http.HttpHeaders) 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) Collectors(java.util.stream.Collectors) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) Charset(java.nio.charset.Charset) JSONSerializer(flexjson.JSONSerializer) Log(org.apache.commons.logging.Log) ResponseEntity(org.springframework.http.ResponseEntity) LogFactory(org.apache.commons.logging.LogFactory) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) HttpHeaders(org.springframework.http.HttpHeaders) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) SubmissionResult(gov.nih.nci.ctd2.dashboard.util.SearchResults.SubmissionResult) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) SearchResults(gov.nih.nci.ctd2.dashboard.util.SearchResults) ResponseEntity(org.springframework.http.ResponseEntity) SubmissionResult(gov.nih.nci.ctd2.dashboard.util.SearchResults.SubmissionResult) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) JSONSerializer(flexjson.JSONSerializer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with DateTransformer

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

the class OntologySearchController method ontologySearch.

@RequestMapping(method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> ontologySearch(@RequestParam("terms") String terms) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    SearchResults ontologyResult = dashboardDao.ontologySearch(terms.replaceAll("`", "'"));
    log.debug("number of subject results from ontology search " + ontologyResult.numberOfSubjects());
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.deepSerialize(ontologyResult), 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) SearchResults(gov.nih.nci.ctd2.dashboard.util.SearchResults) JSONSerializer(flexjson.JSONSerializer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JSONSerializer (flexjson.JSONSerializer)18 DateTransformer (gov.nih.nci.ctd2.dashboard.util.DateTransformer)18 ImplTransformer (gov.nih.nci.ctd2.dashboard.util.ImplTransformer)18 HttpHeaders (org.springframework.http.HttpHeaders)18 ResponseEntity (org.springframework.http.ResponseEntity)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 Transactional (org.springframework.transaction.annotation.Transactional)16 Observation (gov.nih.nci.ctd2.dashboard.model.Observation)5 ArrayList (java.util.ArrayList)5 Submission (gov.nih.nci.ctd2.dashboard.model.Submission)3 SearchResults (gov.nih.nci.ctd2.dashboard.util.SearchResults)3 BigInteger (java.math.BigInteger)2 DashboardDao (gov.nih.nci.ctd2.dashboard.dao.DashboardDao)1 ECOTerm (gov.nih.nci.ctd2.dashboard.model.ECOTerm)1 Gene (gov.nih.nci.ctd2.dashboard.model.Gene)1 ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)1 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)1 Protein (gov.nih.nci.ctd2.dashboard.model.Protein)1 Subject (gov.nih.nci.ctd2.dashboard.model.Subject)1 EcoBrowse (gov.nih.nci.ctd2.dashboard.util.EcoBrowse)1