Search in sources :

Example 16 with ImplTransformer

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

the class FindProteinFromGeneController method browseByCharacter.

@Transactional
@RequestMapping(value = "{id}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> browseByCharacter(@PathVariable Integer id) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    Gene gene = dashboardDao.getEntityById(Gene.class, id);
    List<Protein> proteinByGene = dashboardDao.findProteinByGene(gene);
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.deepSerialize(proteinByGene), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) Gene(gov.nih.nci.ctd2.dashboard.model.Gene) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) Protein(gov.nih.nci.ctd2.dashboard.model.Protein) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with ImplTransformer

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

the class ListController method getSimilarSubmissionsInJson.

@Transactional
@RequestMapping(value = "similar/{submissionId}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getSimilarSubmissionsInJson(@PathVariable Integer submissionId) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    List<Submission> submissions = webServiceUtil.getSimilarSubmissions(submissionId);
    return new ResponseEntity<String>(jsonSerializer.serialize(submissions), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) 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 18 with ImplTransformer

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

the class ExploreController method browseByKeyword.

@Transactional
@RequestMapping(value = "{roles}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> browseByKeyword(@PathVariable String roles) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    List<SubjectWithSummaries> entities = new ArrayList<SubjectWithSummaries>();
    for (String s : roles.split(",")) {
        String role = s.trim().toLowerCase();
        entities.addAll(getWebServiceUtil().exploreSubjects(role));
    }
    Collections.sort(entities, new Comparator<SubjectWithSummaries>() {

        @Override
        public int compare(SubjectWithSummaries o1, SubjectWithSummaries o2) {
            int i = o2.getScore() - o1.getScore();
            if (i == 0) {
                int j = o2.getMaxTier() - o1.getMaxTier();
                if (j == 0) {
                    return o2.getNumberOfObservations() - o1.getNumberOfObservations();
                } else {
                    return j;
                }
            } else {
                return i;
            }
        }
    });
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.deepSerialize(entities), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) SubjectWithSummaries(gov.nih.nci.ctd2.dashboard.util.SubjectWithSummaries) ResponseEntity(org.springframework.http.ResponseEntity) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) 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 19 with ImplTransformer

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

the class JSONController method getGeneInJson.

/*
     * gene needs a separate method because it asks for different number of
     * parameters
     */
@Transactional
@RequestMapping(value = "{type}/{species}/{symbol}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getGeneInJson(@PathVariable String type, @PathVariable String species, @PathVariable String symbol) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    if (!type.equalsIgnoreCase("gene")) {
        log.info("query with wrong type");
        return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
    }
    List<Gene> genes = dashboardDao.findGenesBySymbol(symbol);
    Gene gene = null;
    for (Gene g : genes) {
        if (g.getOrganism().getDisplayName().toLowerCase().startsWith(species)) {
            gene = g;
            break;
        }
    }
    if (gene == null) {
        return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
    } else {
        JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
        return new ResponseEntity<String>(jsonSerializer.deepSerialize(gene), 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 20 with ImplTransformer

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

the class ObservationController method getOneObservationsPerSubmission.

@Transactional
@RequestMapping(value = "onePerSubmissionBySubject", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getOneObservationsPerSubmission(@RequestParam("subjectId") Integer subjectId, @RequestParam(value = "role", required = false, defaultValue = "") String role, @RequestParam(value = "tier", required = false, defaultValue = "0") Integer tier) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    List<ObservationWithCount> list = null;
    if (tier > 0 || role.trim().length() > 0) {
        list = onePerSubmissionBySubjectId(subjectId, role, tier);
    } else {
        Map<Observation, BigInteger> observationAndCount = dashboardDao.getOneObservationPerSubmission(subjectId);
        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) 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