Search in sources :

Example 1 with XrefImpl

use of gov.nih.nci.ctd2.dashboard.impl.XrefImpl 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 2 with XrefImpl

use of gov.nih.nci.ctd2.dashboard.impl.XrefImpl in project nci-ctd2-dashboard by CBIIT.

the class DashboardDaoImpl method findSubjectsByXref.

@Override
public List<Subject> findSubjectsByXref(String databaseName, String databaseId) {
    Set<Subject> subjects = new HashSet<Subject>();
    List<Xref> list = query2ParamsWithClass("from XrefImpl where databaseName = :dname and databaseId = :did", "dname", databaseName, "did", databaseId);
    for (Xref o : list) {
        subjects.addAll(findSubjectsByXref(o));
    }
    return new ArrayList<Subject>(subjects);
}
Also used : Xref(gov.nih.nci.ctd2.dashboard.model.Xref) ArrayList(java.util.ArrayList) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) HashSet(java.util.HashSet)

Aggregations

Subject (gov.nih.nci.ctd2.dashboard.model.Subject)2 Xref (gov.nih.nci.ctd2.dashboard.model.Xref)2 JSONSerializer (flexjson.JSONSerializer)1 SubjectResponse (gov.nih.nci.ctd2.dashboard.api.SubjectResponse)1 XrefImpl (gov.nih.nci.ctd2.dashboard.impl.XrefImpl)1 DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)1 ECOTerm (gov.nih.nci.ctd2.dashboard.model.ECOTerm)1 Gene (gov.nih.nci.ctd2.dashboard.model.Gene)1 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1