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);
}
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);
}
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);
}
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>();
}
}
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;
}
Aggregations