use of gov.nih.nci.ctd2.dashboard.model.ObservedEvidence in project nci-ctd2-dashboard by CBIIT.
the class ObservationDataWriter method write.
public void write(List<? extends ObservationData> items) throws Exception {
// calls) (2) there is at least one observation in each call
if (items.size() == 0) {
// this might happen when some suject is rejected
log.debug("no item");
return;
}
final Submission submission = items.get(0).observation.getSubmission();
final String submissionName = submission.getDisplayName();
StableURL stableURL = new StableURL();
synchronized (submission) {
log.debug("[" + ++counter + "]SUBMISSION " + submissionName + ": " + items.size() + " observation(s)");
final String submissionCacheKey = submissionName + new SimpleDateFormat("yyyy.MM.dd").format(submission.getSubmissionDate()) + submission.getObservationTemplate().getDisplayName();
if (!submissionCache.contains(submissionCacheKey)) {
submission.setStableURL(stableURL.createURLWithPrefix("submission", submissionName));
dashboardDao.save(submission);
submissionCache.add(submissionCacheKey);
observationIndex.put(submissionName, 0);
}
}
List<Observation> observations = new ArrayList<Observation>();
List<Evidence> evidences = new ArrayList<Evidence>();
List<ObservedSubject> observedSubjects = new ArrayList<ObservedSubject>();
List<ObservedEvidence> observedEvidences = new ArrayList<ObservedEvidence>();
for (ObservationData observationData : items) {
Observation observation = observationData.observation;
int index = observationIndex.get(submissionName);
observation.setStableURL(stableURL.createURLWithPrefix("observation", submissionName) + "-" + index);
observations.add(observation);
observationIndex.put(submissionName, index + 1);
for (DashboardEntity e : observationData.evidence) {
evidences.add((Evidence) e);
}
for (DashboardEntity e : observationData.observedEntities) {
String className = e.getClass().getName();
switch(className) {
case "gov.nih.nci.ctd2.dashboard.impl.ObservedSubjectImpl":
observedSubjects.add((ObservedSubject) e);
break;
case "gov.nih.nci.ctd2.dashboard.impl.ObservedEvidenceImpl":
observedEvidences.add((ObservedEvidence) e);
break;
default:
log.error("unexpected type " + className);
}
}
}
// use a smaller batch size to prevent 'lock wait timeout'
int batchSize = 100;
log.debug("observations to write " + observations.size());
dashboardDao.batchSave(observations, batchSize);
log.debug("observedSubjects to write " + observedSubjects.size());
dashboardDao.batchSave(observedSubjects, batchSize);
log.debug("evidences to write " + evidences.size());
dashboardDao.batchSave(evidences, batchSize);
log.debug("observedEvidences to write " + observedEvidences.size());
dashboardDao.batchSave(observedEvidences, batchSize);
log.debug("ALL WRITTEN: " + submissionName);
}
use of gov.nih.nci.ctd2.dashboard.model.ObservedEvidence in project nci-ctd2-dashboard by CBIIT.
the class JSONController method getEntityInJson.
@Transactional
@RequestMapping(value = "{type}/{id}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getEntityInJson(@PathVariable String type, @PathVariable String id) {
DashboardEntity entityById = null;
Class<? extends DashboardEntity> clazz = Subject.class;
if (type.equalsIgnoreCase("subject")) {
clazz = Subject.class;
} else if (type.equals("observedsubject")) {
clazz = ObservedSubject.class;
}
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
log.debug("JSONController " + type + " " + id);
if (typesWithStableURL.contains(type)) {
String stableURL = type + "/" + id;
if (type.equals("observedevidence"))
stableURL = "mra/" + id;
entityById = dashboardDao.getEntityByStableURL(type, stableURL);
} else {
entityById = dashboardDao.getEntityById(clazz, Integer.parseInt(id));
}
if (entityById == null) {
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
return new ResponseEntity<String>(jsonSerializer.deepSerialize(entityById), headers, HttpStatus.OK);
}
use of gov.nih.nci.ctd2.dashboard.model.ObservedEvidence in project nci-ctd2-dashboard by CBIIT.
the class ObservationDataFactoryImpl method createObservedFileEvidence.
@Override
public ObservedEvidence createObservedFileEvidence(String evidenceValue, String columnName, String templateName, Observation observation) {
ObservedEvidence observedEvidence = dashboardFactory.create(ObservedEvidence.class);
observedEvidence.setDisplayName(evidenceValue);
observedEvidence.setObservation(observation);
ObservedEvidenceRole observedEvidenceRole = getObservedEvidenceRole(templateName, columnName);
if (observedEvidenceRole != null)
observedEvidence.setObservedEvidenceRole(observedEvidenceRole);
Evidence evidence = dashboardFactory.create(FileEvidence.class);
evidence.setDisplayName(String.valueOf(evidenceValue));
File file = new File(evidenceValue);
((FileEvidence) evidence).setFileName(file.getName());
((FileEvidence) evidence).setFilePath(file.getPath());
/* This may result in unintended behavior on Windows platform.
The string filePath is meant to be part of a remote URL instead of a local path. */
if (observedEvidenceRole != null && observedEvidenceRole.getAttribute().length() > 0) {
((FileEvidence) evidence).setMimeType(observedEvidenceRole.getAttribute());
}
observedEvidence.setEvidence(evidence);
if (file.getName().endsWith(".mra")) {
String stableURL = new StableURL().createURLWithPrefix("mra", file.getName());
observedEvidence.setStableURL(stableURL);
}
return observedEvidence;
}
Aggregations