use of gov.nih.nci.ctd2.dashboard.api.FieldNameTransformer in project nci-ctd2-dashboard by CBIIT.
the class ObservationsAPI method getObservations.
@Transactional
@RequestMapping(value = "{submissionId}/{indexRanges}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getObservations(@PathVariable String submissionId, @PathVariable String indexRanges) {
/* submissionId is not internal ID as other parts of code. it is the identifier as part of stableURL */
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
Set<Integer> indexes = new HashSet<Integer>();
try {
for (String range : indexRanges.split(",")) {
String[] x = range.split("-");
if (x.length == 1) {
int index = Integer.parseInt(x[0]);
indexes.add(index);
} else if (x.length == 2) {
int index1 = Integer.parseInt(x[0]);
int index2 = Integer.parseInt(x[1]);
if (index2 <= index1) {
log.warn("incorrect ranges syntax:" + indexRanges);
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
for (int i = index1; i <= index2; i++) {
indexes.add(i);
}
} else {
log.warn("incorrect ranges syntax:" + indexRanges);
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
}
} catch (NumberFormatException ex) {
log.warn(ex.getMessage());
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
try {
ObservationItem[] observations = dashboardDao.getObservations(submissionId, indexes);
log.debug("ready to serialize");
JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new SimpleDateTransformer(), Date.class).transform(new FieldNameTransformer("class"), "clazz").transform(new FieldNameTransformer("class"), "subject_list.clazz").transform(new FieldNameTransformer("class"), "evidence_list.clazz").transform(new FieldNameTransformer("subject_uri"), "subject_list.uri").transform(new ExcludeTransformer(), void.class).exclude("class").exclude("evidence_list.evidenceName").exclude("evidence_list.columnName").exclude("subject_list.columnName").exclude("subject_list.synonyms").exclude("subject_list.xref").exclude("uri").exclude("id");
String json = "{}";
try {
json = jsonSerializer.deepSerialize(observations);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
return new ResponseEntity<String>(json, headers, HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
}
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
use of gov.nih.nci.ctd2.dashboard.api.FieldNameTransformer 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.api.FieldNameTransformer in project nci-ctd2-dashboard by CBIIT.
the class ObservationAPI method getObservation.
@Transactional
@RequestMapping(value = "{id}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getObservation(@PathVariable String id) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
ObservationItem observation = dashboardDao.getObservationInfo("observation/" + id);
if (observation == null) {
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
log.debug("ready to serialize");
JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new SimpleDateTransformer(), Date.class).transform(new FieldNameTransformer("class"), "clazz").transform(new FieldNameTransformer("class"), "subject_list.clazz").transform(new FieldNameTransformer("class"), "evidence_list.clazz").transform(new FieldNameTransformer("subject_uri"), "subject_list.uri").transform(new ExcludeTransformer(), void.class).exclude("class").exclude("evidence_list.evidenceName").exclude("evidence_list.columnName").exclude("subject_list.columnName").exclude("subject_list.synonyms").exclude("subject_list.xref").exclude("uri").exclude("id");
String json = "{}";
try {
json = jsonSerializer.deepSerialize(observation);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
return new ResponseEntity<String>(json, headers, HttpStatus.OK);
}
Aggregations