Search in sources :

Example 16 with Subject

use of gov.nih.nci.ctd2.dashboard.model.Subject 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 17 with Subject

use of gov.nih.nci.ctd2.dashboard.model.Subject 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 18 with Subject

use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.

the class BrowseAPI method getSubmission.

@Transactional
@RequestMapping(value = "{subjectClass}/{subjectName}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getSubmission(@PathVariable String subjectClass, @PathVariable String subjectName, @RequestParam(value = "center", required = false, defaultValue = "") String center, @RequestParam(value = "role", required = false, defaultValue = "") String role, @RequestParam(value = "tier", required = false, defaultValue = "") String tiers, @RequestParam(value = "maximum", required = false, defaultValue = "") String maximum) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    SubjectResponse.Filter filter = SubjectResponse.createFilter(center, role, tiers, maximum);
    DashboardEntity subject = null;
    if (subjectClass.equalsIgnoreCase("evidence") || subjectClass.equalsIgnoreCase("eco")) {
        /* API spec asks for Evidence but stable URL uses eco */
        var obj = dashboardDao.getEntityByStableURL("eco", "eco/" + subjectName);
        if (obj instanceof ECOTerm) {
            subject = (ECOTerm) obj;
        } else {
            log.error("unexpected subject type:" + obj.getClass().getName());
        }
    } else if (subjectClass.equalsIgnoreCase("gene")) {
        List<Gene> genes = dashboardDao.findGenesBySymbol(subjectName);
        if (genes.size() > 0) {
            Gene gene = genes.get(0);
            List<Protein> p = dashboardDao.findProteinByGene(gene);
            Xref xref = new XrefImpl();
            xref.setDatabaseId(p.get(0).getUniprotId());
            xref.setDatabaseName("UniProt");
            gene.getXrefs().add(xref);
            subject = gene;
        }
    } else {
        var obj = dashboardDao.getEntityByStableURL(subjectClass, subjectClass + "/" + subjectName);
        if (obj instanceof Subject) {
            subject = (Subject) obj;
        } else {
            log.error("unexpected subject type: " + (obj == null ? null : obj.getClass().getName()));
        }
    }
    if (subject == null) {
        return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
    }
    SubjectResponse subjectResponse = SubjectResponse.createInstance(subject, filter, dashboardDao);
    log.debug("ready to serialize");
    JSONSerializer jsonSerializer = CTD2Serializer.createJSONSerializer();
    String json = "{}";
    try {
        json = jsonSerializer.deepSerialize(subjectResponse);
    } 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) SubjectResponse(gov.nih.nci.ctd2.dashboard.api.SubjectResponse) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) Xref(gov.nih.nci.ctd2.dashboard.model.Xref) ResponseEntity(org.springframework.http.ResponseEntity) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) Gene(gov.nih.nci.ctd2.dashboard.model.Gene) List(java.util.List) XrefImpl(gov.nih.nci.ctd2.dashboard.impl.XrefImpl) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with Subject

use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.

the class ObservationController method getBySubjectId.

private List<Observation> getBySubjectId(Integer subjectId, String role, Integer tier) {
    Subject subject = dashboardDao.getEntityById(Subject.class, subjectId);
    if (subject != null) {
        Set<Observation> observations = new HashSet<Observation>();
        for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
            ObservedSubjectRole observedSubjectRole = observedSubject.getObservedSubjectRole();
            String subjectRole = observedSubjectRole.getSubjectRole().getDisplayName();
            Integer observationTier = observedSubject.getObservation().getSubmission().getObservationTemplate().getTier();
            if ((role.equals("") || role.equals(subjectRole)) && (tier == 0 || tier == observationTier)) {
                observations.add(observedSubject.getObservation());
            }
        }
        List<Observation> list = new ArrayList<Observation>(observations);
        Collections.sort(list, new Comparator<Observation>() {

            @Override
            public int compare(Observation o1, Observation o2) {
                Integer tier2 = o2.getSubmission().getObservationTemplate().getTier();
                Integer tier1 = o1.getSubmission().getObservationTemplate().getTier();
                return tier2 - tier1;
            }
        });
        return list;
    } else {
        return new ArrayList<Observation>();
    }
}
Also used : BigInteger(java.math.BigInteger) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) ArrayList(java.util.ArrayList) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) HashSet(java.util.HashSet)

Example 20 with Subject

use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.

the class SubjectResponse method createInstance.

private static SubjectResponse createInstance(final Subject subject, final Filter filter, DashboardDao dashboardDao) {
    int[] tierCount = new int[3];
    Set<Integer> set = new HashSet<Integer>();
    for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
        ObservedSubjectRole observedSubjectRole = observedSubject.getObservedSubjectRole();
        String subjectRole = observedSubjectRole.getSubjectRole().getDisplayName();
        if (filter.rolesIncluded.size() > 0 && !filter.rolesIncluded.contains(subjectRole))
            continue;
        ObservationTemplate observatinoTemplate = observedSubject.getObservation().getSubmission().getObservationTemplate();
        Integer observationTier = observatinoTemplate.getTier();
        String centerNameBrief = observatinoTemplate.getSubmissionCenter().getStableURL().substring(7);
        if (filter.centerIncluded.size() > 0 && !filter.centerIncluded.contains(centerNameBrief))
            continue;
        if ((Arrays.asList(filter.tiersIncluded).contains(observationTier))) {
            set.add(observedSubject.getObservation().getId());
            tierCount[observationTier.intValue() - 1]++;
            if (filter.limit > 0 && set.size() >= filter.limit) {
                break;
            }
        }
    }
    List<ObservationItem> observations = dashboardDao.findObservationInfo(new ArrayList<Integer>(set));
    Set<String> roles = new TreeSet<String>();
    for (int i = 0; i < observations.size(); i++) {
        for (SubjectItem sub : observations.get(i).subject_list) {
            if (sub.getName().equals(subject.getDisplayName())) {
                roles.add(sub.getRole());
                break;
            }
        }
    }
    String[] uris = observations.stream().map(x -> x.uri).toArray(String[]::new);
    SubjectResponse subjectResponse = new SubjectResponse(subject, uris, roles.toArray(new String[0]), tierCount);
    return subjectResponse;
}
Also used : Arrays(java.util.Arrays) DashboardDao(gov.nih.nci.ctd2.dashboard.dao.DashboardDao) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservationURIsAndTiers(gov.nih.nci.ctd2.dashboard.util.ObservationURIsAndTiers) Set(java.util.Set) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Xref(gov.nih.nci.ctd2.dashboard.model.Xref) Synonym(gov.nih.nci.ctd2.dashboard.model.Synonym) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) TreeSet(java.util.TreeSet) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) HashSet(java.util.HashSet)

Aggregations

Subject (gov.nih.nci.ctd2.dashboard.model.Subject)15 ArrayList (java.util.ArrayList)14 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)12 BigInteger (java.math.BigInteger)12 FullTextSession (org.hibernate.search.FullTextSession)11 Session (org.hibernate.Session)10 HashSet (java.util.HashSet)9 JSONSerializer (flexjson.JSONSerializer)8 ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)8 HashMap (java.util.HashMap)8 HttpHeaders (org.springframework.http.HttpHeaders)8 ResponseEntity (org.springframework.http.ResponseEntity)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Xref (gov.nih.nci.ctd2.dashboard.model.Xref)7 Transactional (org.springframework.transaction.annotation.Transactional)7 Submission (gov.nih.nci.ctd2.dashboard.model.Submission)6 WordCloudEntry (gov.nih.nci.ctd2.dashboard.util.WordCloudEntry)6 DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)5 Observation (gov.nih.nci.ctd2.dashboard.model.Observation)5 ObservedSubjectRole (gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole)5