use of org.obiba.mica.access.domain.DataAccessEntityStatus in project mica2 by obiba.
the class DataAccessRequestService method save.
private DataAccessRequest save(@NotNull DataAccessRequest request, DateTime lastModifiedDate) {
DataAccessRequest saved = request;
DataAccessEntityStatus from = null;
Iterable<Attachment> attachmentsToDelete = null;
Iterable<Attachment> attachmentsToSave = null;
if (request.isNew()) {
setAndLogStatus(saved, DataAccessEntityStatus.OPENED);
saved.setId(generateId());
attachmentsToSave = saved.getAttachments();
} else {
saved = dataAccessRequestRepository.findOne(request.getId());
if (saved != null) {
if (!SecurityUtils.getSubject().hasRole(Roles.MICA_DAO) && !SecurityUtils.getSubject().hasRole(Roles.MICA_ADMIN)) {
// preserve current actionLogs as no other user role can add or remove them
request.setActionLogHistory(saved.getActionLogHistory());
}
attachmentsToDelete = Sets.difference(Sets.newHashSet(saved.getAttachments()), Sets.newHashSet(request.getAttachments()));
attachmentsToSave = Sets.difference(Sets.newHashSet(request.getAttachments()), Sets.newHashSet(saved.getAttachments()));
from = saved.getStatus();
// validate the status
dataAccessRequestUtilService.checkStatusTransition(saved, request.getStatus());
saved.setStatus(request.getStatus());
if (request.hasStatusChangeHistory())
saved.setStatusChangeHistory(request.getStatusChangeHistory());
// merge beans
BeanUtils.copyProperties(request, saved, "id", "version", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate", "statusChangeHistory");
} else {
saved = request;
setAndLogStatus(saved, DataAccessEntityStatus.OPENED);
}
}
schemaFormContentFileService.save(saved, dataAccessRequestRepository.findOne(request.getId()), String.format("/data-access-request/%s", saved.getId()));
if (attachmentsToSave != null)
attachmentsToSave.forEach(a -> {
fileStoreService.save(a.getId());
a.setJustUploaded(false);
attachmentRepository.save(a);
});
if (lastModifiedDate != null)
saved.setLastModifiedDate(lastModifiedDate);
dataAccessRequestRepository.saveWithReferences(saved);
if (attachmentsToDelete != null)
attachmentsToDelete.forEach(a -> fileStoreService.delete(a.getId()));
if (saved.hasVariablesSet() && DataAccessEntityStatus.OPENED.equals(saved.getStatus())) {
variableSetService.setLock(saved.getVariablesSet(), false);
}
eventBus.post(new DataAccessRequestUpdatedEvent(saved));
sendNotificationEmails(saved, from);
return saved;
}
use of org.obiba.mica.access.domain.DataAccessEntityStatus 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;
}
use of org.obiba.mica.access.domain.DataAccessEntityStatus 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