use of org.obiba.mica.access.event.DataAccessAmendmentUpdatedEvent in project mica2 by obiba.
the class DataAccessAmendmentService method save.
@Override
public DataAccessAmendment save(@NotNull DataAccessAmendment amendment) {
DataAccessAmendment saved = amendment;
DataAccessEntityStatus from = null;
if (amendment.isNew()) {
setAndLogStatus(saved, DataAccessEntityStatus.OPENED);
int count = findByParentId(saved.getParentId()).size();
saved.setId(saved.getParentId() + "-A" + (count + 1));
} else {
saved = dataAmendmentRequestRepository.findOne(amendment.getId());
if (saved != null) {
from = saved.getStatus();
// validate the status
dataAccessRequestUtilService.checkStatusTransition(saved, amendment.getStatus());
saved.setStatus(amendment.getStatus());
if (amendment.hasStatusChangeHistory())
saved.setStatusChangeHistory(amendment.getStatusChangeHistory());
// merge beans
BeanUtils.copyProperties(amendment, saved, "id", "version", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate", "statusChangeHistory");
} else {
saved = amendment;
setAndLogStatus(saved, DataAccessEntityStatus.OPENED);
}
}
ensureProjectTitle(saved);
schemaFormContentFileService.save(saved, dataAmendmentRequestRepository.findOne(amendment.getId()), String.format("/data-access-request/%s/amendment/%s", saved.getParentId(), amendment.getId()));
saved.setLastModifiedDate(DateTime.now());
dataAmendmentRequestRepository.save(saved);
eventBus.post(new DataAccessAmendmentUpdatedEvent(saved));
sendNotificationEmails(saved, from);
return saved;
}
Aggregations