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