Search in sources :

Example 1 with NoSuchProjectException

use of org.obiba.mica.project.service.NoSuchProjectException in project mica2 by obiba.

the class DataAccessRequestDtos method asDto.

@NotNull
public Mica.DataAccessRequestDto asDto(@NotNull DataAccessRequest request) {
    Mica.DataAccessRequestDto.Builder builder = Mica.DataAccessRequestDto.newBuilder();
    // 
    builder.setApplicant(request.getApplicant()).setStatus(// 
    request.getStatus().name()).setTimestamps(// 
    TimestampsDtos.asDto(request));
    // 
    if (request.hasContent())
        builder.setContent(request.getContent());
    if (!request.isNew())
        builder.setId(request.getId());
    String title = dataAccessRequestUtilService.getRequestTitle(request);
    if (!Strings.isNullOrEmpty(title)) {
        builder.setTitle(title);
    }
    request.getAttachments().forEach(attachment -> builder.addAttachments(attachmentDtos.asDto(attachment)));
    request.getStatusChangeHistory().forEach(statusChange -> builder.addStatusChangeHistory(statusChangeDtos.asDto(statusChange)));
    // possible actions depending on the caller
    if (subjectAclService.isPermitted("/data-access-request", "VIEW", request.getId())) {
        builder.addActions("VIEW");
    }
    if (subjectAclService.isPermitted("/data-access-request", "EDIT", request.getId())) {
        builder.addActions("EDIT");
    }
    if (subjectAclService.isPermitted("/data-access-request", "DELETE", request.getId())) {
        builder.addActions("DELETE");
    }
    if (subjectAclService.isPermitted(Paths.get("/data-access-request", request.getId()).toString(), "EDIT", "_status")) {
        builder.addActions("EDIT_STATUS");
    }
    if (SecurityUtils.getSubject().hasRole(Roles.MICA_DAO) || subjectAclService.isPermitted(Paths.get("/data-access-request", request.getId(), "_attachments").toString(), "EDIT")) {
        builder.addActions("EDIT_ATTACHMENTS");
    }
    try {
        Project project = projectService.findById(request.getId());
        Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(project);
        Mica.ProjectSummaryDto.Builder projectSummaryDtoBuilder = Mica.ProjectSummaryDto.newBuilder();
        projectSummaryDtoBuilder.setId(project.getId());
        projectSummaryDtoBuilder.setPermissions(permissionsDto);
        builder.setProject(projectSummaryDtoBuilder.build());
    } catch (NoSuchProjectException e) {
    // do nothing
    }
    ObibaRealm.Subject profile = userProfileService.getProfile(request.getApplicant());
    if (profile != null) {
        builder.setProfile(userProfileDtos.asDto(profile));
    }
    // possible status transitions
    dataAccessRequestUtilService.nextStatus(request).forEach(status -> builder.addNextStatus(status.toString()));
    return builder.build();
}
Also used : Project(org.obiba.mica.project.domain.Project) NoSuchProjectException(org.obiba.mica.project.service.NoSuchProjectException) ObibaRealm(org.obiba.shiro.realm.ObibaRealm) NotNull(javax.validation.constraints.NotNull)

Aggregations

NotNull (javax.validation.constraints.NotNull)1 Project (org.obiba.mica.project.domain.Project)1 NoSuchProjectException (org.obiba.mica.project.service.NoSuchProjectException)1 ObibaRealm (org.obiba.shiro.realm.ObibaRealm)1