Search in sources :

Example 1 with DataAccessFeasibilityUpdatedEvent

use of org.obiba.mica.access.event.DataAccessFeasibilityUpdatedEvent in project mica2 by obiba.

the class DataAccessFeasibilityService method save.

@Override
public DataAccessFeasibility save(@NotNull DataAccessFeasibility feasibility) {
    DataAccessFeasibility saved = feasibility;
    DataAccessEntityStatus from = null;
    if (feasibility.isNew()) {
        setAndLogStatus(saved, DataAccessEntityStatus.OPENED);
        int count = findByParentId(saved.getParentId()).size();
        saved.setId(saved.getParentId() + "-F" + (count + 1));
    } else {
        saved = dataFeasibilityRequestRepository.findOne(feasibility.getId());
        if (saved != null) {
            from = saved.getStatus();
            // validate the status
            dataAccessRequestUtilService.checkStatusTransition(saved, feasibility.getStatus());
            saved.setStatus(feasibility.getStatus());
            if (feasibility.hasStatusChangeHistory())
                saved.setStatusChangeHistory(feasibility.getStatusChangeHistory());
            // merge beans
            BeanUtils.copyProperties(feasibility, saved, "id", "version", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate", "statusChangeHistory");
        } else {
            saved = feasibility;
            setAndLogStatus(saved, DataAccessEntityStatus.OPENED);
        }
    }
    schemaFormContentFileService.save(saved, dataFeasibilityRequestRepository.findOne(feasibility.getId()), String.format("/data-access-request/%s/feasibility/%s", saved.getParentId(), feasibility.getId()));
    saved.setLastModifiedDate(DateTime.now());
    dataFeasibilityRequestRepository.save(saved);
    eventBus.post(new DataAccessFeasibilityUpdatedEvent(saved));
    sendNotificationEmails(saved, from);
    return saved;
}
Also used : DataAccessFeasibility(org.obiba.mica.access.domain.DataAccessFeasibility) DataAccessFeasibilityUpdatedEvent(org.obiba.mica.access.event.DataAccessFeasibilityUpdatedEvent) DataAccessEntityStatus(org.obiba.mica.access.domain.DataAccessEntityStatus)

Aggregations

DataAccessEntityStatus (org.obiba.mica.access.domain.DataAccessEntityStatus)1 DataAccessFeasibility (org.obiba.mica.access.domain.DataAccessFeasibility)1 DataAccessFeasibilityUpdatedEvent (org.obiba.mica.access.event.DataAccessFeasibilityUpdatedEvent)1