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