Search in sources :

Example 1 with ObservedEvidence

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);
}
Also used : ObservedEvidence(gov.nih.nci.ctd2.dashboard.model.ObservedEvidence) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) StableURL(gov.nih.nci.ctd2.dashboard.util.StableURL) ArrayList(java.util.ArrayList) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) Evidence(gov.nih.nci.ctd2.dashboard.model.Evidence) ObservedEvidence(gov.nih.nci.ctd2.dashboard.model.ObservedEvidence) SimpleDateFormat(java.text.SimpleDateFormat) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject)

Example 2 with ObservedEvidence

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ObservedEvidence

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;
}
Also used : StableURL(gov.nih.nci.ctd2.dashboard.util.StableURL) File(java.io.File)

Aggregations

StableURL (gov.nih.nci.ctd2.dashboard.util.StableURL)2 JSONSerializer (flexjson.JSONSerializer)1 DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)1 Evidence (gov.nih.nci.ctd2.dashboard.model.Evidence)1 Observation (gov.nih.nci.ctd2.dashboard.model.Observation)1 ObservedEvidence (gov.nih.nci.ctd2.dashboard.model.ObservedEvidence)1 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)1 Submission (gov.nih.nci.ctd2.dashboard.model.Submission)1 DateTransformer (gov.nih.nci.ctd2.dashboard.util.DateTransformer)1 ImplTransformer (gov.nih.nci.ctd2.dashboard.util.ImplTransformer)1 File (java.io.File)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1