use of org.obiba.mica.access.domain.DataAccessRequest in project mica2 by obiba.
the class DataAccessRequestService method save.
public DataAccessRequest save(@NotNull DataAccessRequest request) {
DataAccessRequest saved = request;
DataAccessRequest.Status from = null;
Iterable<Attachment> attachmentsToDelete = null;
Iterable<Attachment> attachmentsToSave = null;
if (request.isNew()) {
setAndLogStatus(saved, DataAccessRequest.Status.OPENED);
saved.setId(generateId());
attachmentsToSave = saved.getAttachments();
} else {
saved = dataAccessRequestRepository.findOne(request.getId());
if (saved != null) {
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, DataAccessRequest.Status.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);
});
saved.setLastModifiedDate(DateTime.now());
dataAccessRequestRepository.saveWithReferences(saved);
if (attachmentsToDelete != null)
attachmentsToDelete.forEach(a -> fileStoreService.delete(a.getId()));
eventBus.post(new DataAccessRequestUpdatedEvent(saved));
sendNotificationEmails(saved, from);
return saved;
}
use of org.obiba.mica.access.domain.DataAccessRequest in project mica2 by obiba.
the class DataAccessRequestService method updateStatus.
/**
* Update the status of the {@link DataAccessRequest} matching the identifier.
*
* @param id
* @param status
* @throws NoSuchDataAccessRequestException
*/
public DataAccessRequest updateStatus(@NotNull String id, @NotNull DataAccessRequest.Status status) throws NoSuchDataAccessRequestException {
DataAccessRequest request = findById(id);
setAndLogStatus(request, status);
save(request);
return request;
}
use of org.obiba.mica.access.domain.DataAccessRequest in project mica2 by obiba.
the class DataAccessRequestService method saveAttachments.
public DataAccessRequest saveAttachments(@NotNull DataAccessRequest request) {
DataAccessRequest saved = findById(request.getId());
saved.setAttachments(request.getAttachments());
save(saved);
sendAttachmentsUpdatedNotificationEmail(request);
return saved;
}
use of org.obiba.mica.access.domain.DataAccessRequest in project mica2 by obiba.
the class DataAccessRequestDtos method fromDto.
@NotNull
public DataAccessRequest fromDto(@NotNull Mica.DataAccessRequestDto dto) {
DataAccessRequest.Builder builder = DataAccessRequest.newBuilder();
builder.applicant(dto.getApplicant()).status(dto.getStatus());
if (dto.hasContent())
builder.content(dto.getContent());
DataAccessRequest request = builder.build();
if (dto.hasId())
request.setId(dto.getId());
if (dto.getAttachmentsCount() > 0) {
request.setAttachments(dto.getAttachmentsList().stream().map(attachmentDtos::fromDto).collect(Collectors.toList()));
}
TimestampsDtos.fromDto(dto.getTimestamps(), request);
return request;
}
use of org.obiba.mica.access.domain.DataAccessRequest in project mica2 by obiba.
the class ProjectDtos method asDto.
@NotNull
public Mica.ProjectDto asDto(@NotNull Project project, boolean asDraft) {
Mica.ProjectDto.Builder builder = Mica.ProjectDto.newBuilder().addAllTitle(//
localizedStringDtos.asDto(project.getTitle())).addAllSummary(localizedStringDtos.asDto(project.getSummary()));
if (project.hasModel())
builder.setContent(JSONUtils.toJSON(project.getModel()));
if (project.hasDataAccessRequestId()) {
try {
DataAccessRequest request = dataAccessRequestService.findById(project.getDataAccessRequestId());
Mica.DataAccessRequestSummaryDto.Builder darBuilder = Mica.DataAccessRequestSummaryDto.newBuilder();
darBuilder.setId(project.getDataAccessRequestId());
darBuilder.setStatus(request.getStatus().name());
darBuilder.setApplicant(request.getApplicant());
darBuilder.setViewable(subjectAclService.isPermitted("/data-access-request", "VIEW", request.getId()));
builder.setRequest(darBuilder);
} catch (NoSuchElementException e) {
// ignore
}
}
if (!project.isNew())
builder.setId(project.getId());
Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(project);
if (asDraft) {
ProjectState projectState = projectService.getEntityState(project.getId());
//
builder.setTimestamps(TimestampsDtos.asDto(project)).setPublished(//
projectState.isPublished()).setExtension(Mica.EntityStateDto.projectState, entityStateDtos.asDto(projectState).setPermissions(permissionsDto).build());
}
builder.setPermissions(permissionsDto);
builder.setTimestamps(TimestampsDtos.asDto(project));
return builder.build();
}
Aggregations