Search in sources :

Example 6 with ImplTransformer

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

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

Example 8 with ImplTransformer

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

the class SearchController method getSearchResultsInJson.

@Transactional
@RequestMapping(value = "{keyword}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getSearchResultsInJson(@PathVariable String keyword) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    // This is to prevent unnecessary server loads
    if (keyword.length() < 2)
        return new ResponseEntity<String>(headers, HttpStatus.BAD_REQUEST);
    keyword = keyword.replaceAll("`", "'");
    SearchResults results = dashboardDao.search(keyword);
    log.debug("number of subject results from search " + results.numberOfSubjects());
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.deepSerialize(results), 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) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with ImplTransformer

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

the class ObservationController method getObservationsBySubmissionIdAndEcoTerm.

@Transactional
@RequestMapping(value = "bySubmissionAndEcoTerm", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getObservationsBySubmissionIdAndEcoTerm(@RequestParam("submissionId") Integer submissionId, @RequestParam("ecocode") String ecocode) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    String summaryTemplate = dashboardDao.getEntityById(Submission.class, submissionId).getObservationTemplate().getObservationSummary();
    List<Observation> observations = dashboardDao.getObservationsForSubmissionAndEcoCode(submissionId, ecocode);
    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) 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) 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 10 with ImplTransformer

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

the class ObservationController method getObservationsBySubmissionId.

@Transactional
@RequestMapping(value = "bySubmission", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getObservationsBySubmissionId(@RequestParam("submissionId") Integer submissionId, @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 = getBySubmissionId(submissionId);
    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)

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