Search in sources :

Example 6 with DashboardEntity

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

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

Example 8 with DashboardEntity

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

the class SearchAPI method getSubmission.

@Transactional
@RequestMapping(value = "{term}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getSubmission(@PathVariable String term, @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);
    List<SubjectResponse> allSubjects = new ArrayList<SubjectResponse>();
    List<SubjectResult> results = dashboardDao.search(term.toLowerCase()).subject_result;
    for (SubjectResult subjectResult : results) {
        try {
            Class<? extends DashboardEntity> clazz = Class.forName("gov.nih.nci.ctd2.dashboard.model." + subjectResult.className).asSubclass(DashboardEntity.class);
            ;
            DashboardEntity result = dashboardDao.getEntityById(clazz, subjectResult.id);
            SubjectResponse subjectResponse = SubjectResponse.createInstance(result, filter, dashboardDao);
            if (subjectResponse == null) {
                continue;
            }
            allSubjects.add(subjectResponse);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            continue;
        }
    }
    log.debug("ready to serialize");
    JSONSerializer jsonSerializer = CTD2Serializer.createJSONSerializer();
    String json = "{}";
    try {
        json = jsonSerializer.deepSerialize(allSubjects);
    } 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) ArrayList(java.util.ArrayList) ResponseEntity(org.springframework.http.ResponseEntity) SubjectResult(gov.nih.nci.ctd2.dashboard.util.SubjectResult) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with DashboardEntity

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

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

the class RssController method searchRSS.

@Transactional
@RequestMapping(value = "search/{keyword}", method = { RequestMethod.GET, RequestMethod.POST })
public ResponseEntity<String> searchRSS(@PathVariable String keyword) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/rss+xml");
    // This is to prevent unnecessary server loads
    if (keyword.length() < 2)
        return new ResponseEntity<String>(headers, HttpStatus.BAD_REQUEST);
    try {
        keyword = URLDecoder.decode(keyword, Charset.defaultCharset().displayName());
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    // Search and find the entity hits
    SearchResults entitiesWithCounts = dashboardDao.search(keyword);
    List<DashboardEntity> searchEntities = new ArrayList<DashboardEntity>();
    for (SubjectResult subjectResult : entitiesWithCounts.subject_result) {
        try {
            Class<? extends DashboardEntity> clazz = Class.forName("gov.nih.nci.ctd2.dashboard.model." + subjectResult.className).asSubclass(DashboardEntity.class);
            DashboardEntity entity = dashboardDao.getEntityById(clazz, subjectResult.id);
            searchEntities.add(entity);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            continue;
        }
    }
    String titlePostfix = keyword;
    String rssDescription = "Latest observations and submission related to '" + keyword + "'";
    String dashboardUrl = context.getScheme() + "://" + context.getServerName() + context.getContextPath() + "/";
    String rssLink = dashboardUrl + "#search/" + keyword;
    String feedStr = generateFeed(searchEntities, titlePostfix, rssDescription, rssLink);
    return new ResponseEntity<String>(feedStr, headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) SubjectResult(gov.nih.nci.ctd2.dashboard.util.SubjectResult) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SearchResults(gov.nih.nci.ctd2.dashboard.util.SearchResults) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)8 ArrayList (java.util.ArrayList)7 HttpHeaders (org.springframework.http.HttpHeaders)7 ResponseEntity (org.springframework.http.ResponseEntity)7 Transactional (org.springframework.transaction.annotation.Transactional)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 JSONSerializer (flexjson.JSONSerializer)6 DateTransformer (gov.nih.nci.ctd2.dashboard.util.DateTransformer)4 ImplTransformer (gov.nih.nci.ctd2.dashboard.util.ImplTransformer)4 StableURL (gov.nih.nci.ctd2.dashboard.util.StableURL)4 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)3 Subject (gov.nih.nci.ctd2.dashboard.model.Subject)3 SubjectResponse (gov.nih.nci.ctd2.dashboard.api.SubjectResponse)2 ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)2 Submission (gov.nih.nci.ctd2.dashboard.model.Submission)2 Xref (gov.nih.nci.ctd2.dashboard.model.Xref)2 SubjectResult (gov.nih.nci.ctd2.dashboard.util.SubjectResult)2 HashSet (java.util.HashSet)2 SyndCategory (com.rometools.rome.feed.synd.SyndCategory)1 SyndCategoryImpl (com.rometools.rome.feed.synd.SyndCategoryImpl)1