Search in sources :

Example 6 with Project

use of org.obiba.mica.project.domain.Project in project mica2 by obiba.

the class ProjectService method index.

/**
 * Index a specific {@link Project} without updating it.
 *
 * @param id
 * @throws NoSuchProjectException
 */
public void index(@NotNull String id) throws NoSuchProjectException {
    ProjectState projectState = getEntityState(id);
    Project project = findById(id);
    eventBus.post(new ProjectUpdatedEvent(project));
    if (projectState.isPublished())
        eventBus.post(new ProjectPublishedEvent(project, getCurrentUsername()));
    else
        eventBus.post(new ProjectUpdatedEvent(project));
}
Also used : Project(org.obiba.mica.project.domain.Project) ProjectPublishedEvent(org.obiba.mica.project.event.ProjectPublishedEvent) ProjectState(org.obiba.mica.project.domain.ProjectState) ProjectUpdatedEvent(org.obiba.mica.project.event.ProjectUpdatedEvent)

Example 7 with Project

use of org.obiba.mica.project.domain.Project in project mica2 by obiba.

the class ProjectService method delete.

/**
 * Delete a {@link Project}.
 *
 * @param id
 * @throws NoSuchProjectException
 */
public void delete(@NotNull String id) throws NoSuchProjectException {
    Project project = findById(id);
    fileSystemService.delete(FileUtils.getEntityPath(project));
    projectStateRepository.delete(id);
    projectRepository.delete(id);
    gitService.deleteGitRepository(project);
    eventBus.post(new ProjectDeletedEvent(project));
}
Also used : Project(org.obiba.mica.project.domain.Project) ProjectDeletedEvent(org.obiba.mica.project.event.ProjectDeletedEvent)

Example 8 with Project

use of org.obiba.mica.project.domain.Project 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)

Example 9 with Project

use of org.obiba.mica.project.domain.Project in project mica2 by obiba.

the class DraftProjectsResource method create.

@POST
@Path("/projects")
@Timed
@RequiresPermissions("/draft/project:ADD")
public Response create(Mica.ProjectDto projectDto, @Context UriInfo uriInfo, @Nullable @QueryParam("comment") String comment) {
    Project project = dtos.fromDto(projectDto);
    projectService.save(project, comment);
    return Response.created(uriInfo.getBaseUriBuilder().segment("draft", "project", project.getId()).build()).build();
}
Also used : Project(org.obiba.mica.project.domain.Project) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Project (org.obiba.mica.project.domain.Project)9 NotNull (javax.validation.constraints.NotNull)2 ProjectState (org.obiba.mica.project.domain.ProjectState)2 ProjectPublishedEvent (org.obiba.mica.project.event.ProjectPublishedEvent)2 ProjectUpdatedEvent (org.obiba.mica.project.event.ProjectUpdatedEvent)2 Timed (com.codahale.metrics.annotation.Timed)1 Subscribe (com.google.common.eventbus.Subscribe)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 DataAccessRequest (org.obiba.mica.access.domain.DataAccessRequest)1 LocalizedString (org.obiba.mica.core.domain.LocalizedString)1 ProjectDeletedEvent (org.obiba.mica.project.event.ProjectDeletedEvent)1 ProjectUnpublishedEvent (org.obiba.mica.project.event.ProjectUnpublishedEvent)1 NoSuchProjectException (org.obiba.mica.project.service.NoSuchProjectException)1 ObibaRealm (org.obiba.shiro.realm.ObibaRealm)1 Caching (org.springframework.cache.annotation.Caching)1 Async (org.springframework.scheduling.annotation.Async)1