use of gov.nih.nci.ctd2.dashboard.model.ECOTerm 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);
}
use of gov.nih.nci.ctd2.dashboard.model.ECOTerm in project nci-ctd2-dashboard by CBIIT.
the class ECOTermAPI method getECOTermFromCode.
@Transactional
@RequestMapping(value = "{ecocode}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getECOTermFromCode(@PathVariable String ecocode) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
ECOTerm ecoterm = dashboardDao.getEcoTerm(ecocode);
if (ecoterm == null) {
return new ResponseEntity<String>("{\"name\":\"(not available)\"}", headers, HttpStatus.OK);
}
log.debug("ECO term name: " + ecoterm);
// CTD2Serializer.createJSONSerializer();
JSONSerializer jsonSerializer = new JSONSerializer().transform(new FieldNameTransformer("name"), "displayName");
String json = jsonSerializer.deepSerialize(ecoterm);
return new ResponseEntity<String>(json, headers, HttpStatus.OK);
}
use of gov.nih.nci.ctd2.dashboard.model.ECOTerm in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method findECOTerms.
@SuppressWarnings("unchecked")
private List<ECOTerm> findECOTerms(String queryString) {
// search ECO codes first
Pattern ECOCodePattern = Pattern.compile("(eco[:_])?(\\d{7})");
Matcher matcher = ECOCodePattern.matcher(queryString);
List<String> codes = new ArrayList<String>();
while (matcher.find()) {
codes.add("ECO:" + matcher.group(2));
}
org.hibernate.query.Query<?> query = null;
List<ECOTerm> list = null;
Session session = getSession();
if (codes.size() > 0) {
query = session.createQuery("FROM ECOTermImpl WHERE code in (:codes)");
query.setParameterList("codes", codes);
list = (List<ECOTerm>) query.list();
} else {
String[] words = queryString.trim().split(" (?=([^\"]*\"[^\"]*\")*[^\"]*$)");
Set<ECOTerm> set = new HashSet<ECOTerm>();
for (String w : words) {
String x = w.replaceAll("^\"|\"$", "");
if (x.length() == 0) {
continue;
}
query = session.createQuery("FROM ECOTermImpl WHERE displayName LIKE :name OR synonyms LIKE :synonym");
query.setParameter("name", x);
query.setParameter("synonym", x);
set.addAll((List<ECOTerm>) query.list());
}
list = new ArrayList<ECOTerm>(set);
}
log.debug("eco term number " + list.size());
session.close();
return list;
}
use of gov.nih.nci.ctd2.dashboard.model.ECOTerm in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method ontologySearchExperimentalEvidence.
private List<Integer> ontologySearchExperimentalEvidence(final List<ECOTerm> ecoterms) {
List<Integer> list = new ArrayList<Integer>();
for (ECOTerm t : ecoterms) {
int code = Integer.parseInt(t.getCode().substring(4));
log.debug("eco code:" + code);
list.addAll(searchEEChildren(code));
}
return list;
}
use of gov.nih.nci.ctd2.dashboard.model.ECOTerm in project nci-ctd2-dashboard by CBIIT.
the class EcoController method term.
@Transactional
@RequestMapping(value = "term/{id}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> term(@PathVariable final String id) {
log.debug("request received by EcoController for " + id);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
final ECOTerm ecoterm = dashboardDao.getEntityByStableURL("eco", "eco/" + id);
log.debug(ecoterm);
final JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
return new ResponseEntity<String>(jsonSerializer.deepSerialize(ecoterm), headers, HttpStatus.OK);
}
Aggregations