Search in sources :

Example 1 with DataAccessAmendmentUpdatedEvent

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;
}
Also used : DataAccessAmendment(org.obiba.mica.access.domain.DataAccessAmendment) DataAccessAmendmentUpdatedEvent(org.obiba.mica.access.event.DataAccessAmendmentUpdatedEvent) DataAccessEntityStatus(org.obiba.mica.access.domain.DataAccessEntityStatus)

Aggregations

DataAccessAmendment (org.obiba.mica.access.domain.DataAccessAmendment)1 DataAccessEntityStatus (org.obiba.mica.access.domain.DataAccessEntityStatus)1 DataAccessAmendmentUpdatedEvent (org.obiba.mica.access.event.DataAccessAmendmentUpdatedEvent)1