Search in sources :

Example 1 with Comment

use of org.obiba.mica.core.domain.Comment in project mica2 by obiba.

the class DataAccessRequestResource method changeApplicant.

@PUT
@Path("/_applicant")
public Response changeApplicant(@PathParam("id") String id, @QueryParam("username") String applicant) {
    if (!SecurityUtils.getSubject().hasRole(Roles.MICA_DAO) && !SecurityUtils.getSubject().hasRole(Roles.MICA_ADMIN)) {
        throw new AuthorizationException();
    }
    if (Strings.isNullOrEmpty(applicant))
        throw new IllegalArgumentException("An applicant name is required");
    DataAccessRequest request = dataAccessRequestService.findById(id);
    String originalApplicant = request.getApplicant();
    dataAccessRequestService.changeApplicantAndSave(request, applicant);
    commentsService.findPublicComments("/data-access-request", id).stream().filter(comment -> comment.getCreatedBy().equals(originalApplicant)).map(comment -> Comment.newBuilder(comment).createdBy(applicant).build()).forEach(comment -> commentsService.save(comment, null));
    return Response.noContent().build();
}
Also used : DataAccessForm(org.obiba.mica.micaConfig.domain.DataAccessForm) AbstractDataAccessEntityForm(org.obiba.mica.micaConfig.domain.AbstractDataAccessEntityForm) DataAccessRequestTimeline(org.obiba.mica.access.domain.DataAccessRequestTimeline) Date(java.util.Date) Roles(org.obiba.mica.security.Roles) FileStoreService(org.obiba.mica.file.FileStoreService) TempFile(org.obiba.mica.file.TempFile) Mica(org.obiba.mica.web.model.Mica) Map(java.util.Map) TempFileService(org.obiba.mica.file.service.TempFileService) DataAccessRequestCommentMailNotification(org.obiba.mica.access.notification.DataAccessRequestCommentMailNotification) ParseException(java.text.ParseException) Dtos(org.obiba.mica.web.model.Dtos) CommentsService(org.obiba.mica.core.service.CommentsService) ActionLog(org.obiba.mica.access.domain.ActionLog) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) VariableSetService(org.obiba.mica.dataset.service.VariableSetService) NoSuchCommentException(org.obiba.mica.core.domain.NoSuchCommentException) DataAccessRequestReportNotificationService(org.obiba.mica.access.notification.DataAccessRequestReportNotificationService) Collectors(java.util.stream.Collectors) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) Timed(com.codahale.metrics.annotation.Timed) AuthorizationException(org.apache.shiro.authz.AuthorizationException) NoSuchDataAccessRequestException(org.obiba.mica.access.NoSuchDataAccessRequestException) List(java.util.List) DataAccessEntityStatus(org.obiba.mica.access.domain.DataAccessEntityStatus) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) SecurityUtils(org.apache.shiro.SecurityUtils) Comment(org.obiba.mica.core.domain.Comment) UnauthorizedCommentException(org.obiba.mica.core.domain.UnauthorizedCommentException) DataAccessRequestService(org.obiba.mica.access.service.DataAccessRequestService) DataAccessEntityService(org.obiba.mica.access.service.DataAccessEntityService) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) DataAccessRequestUtilService(org.obiba.mica.access.service.DataAccessRequestUtilService) ResourceDeletedEvent(org.obiba.mica.security.event.ResourceDeletedEvent) LanguageTag(sun.util.locale.LanguageTag) DataAccessFormService(org.obiba.mica.micaConfig.service.DataAccessFormService) JSONUtils(org.obiba.mica.JSONUtils) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) Attachment(org.obiba.mica.file.Attachment) Logger(org.slf4j.Logger) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) ApplicationContext(org.springframework.context.ApplicationContext) Component(org.springframework.stereotype.Component) DataAccessFeasibilityNotEnabled(org.obiba.mica.micaConfig.DataAccessFeasibilityNotEnabled) DataAccessConfigService(org.obiba.mica.micaConfig.service.DataAccessConfigService) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) DataAccessAmendmentsNotEnabled(org.obiba.mica.micaConfig.DataAccessAmendmentsNotEnabled) AuthorizationException(org.apache.shiro.authz.AuthorizationException) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest)

Example 2 with Comment

use of org.obiba.mica.core.domain.Comment in project mica2 by obiba.

the class DataAccessController method getComments.

@GetMapping("/data-access-comments/{id:.+}")
public ModelAndView getComments(@PathVariable String id) {
    Subject subject = SecurityUtils.getSubject();
    if (subject.isAuthenticated()) {
        Map<String, Object> params = newParameters(id);
        addDataAccessConfiguration(params);
        List<Comment> comments = commentsService.findPublicComments("/data-access-request", id);
        params.put("comments", comments);
        params.put("authors", comments.stream().map(AbstractAuditableDocument::getCreatedBy).distinct().collect(Collectors.toMap(u -> u, u -> userProfileService.getProfileMap(u, true))));
        return new ModelAndView("data-access-comments", params);
    } else {
        return new ModelAndView("redirect:../signin?redirect=" + micaConfigService.getContextPath() + "/data-access-comments%2F" + id);
    }
}
Also used : Comment(org.obiba.mica.core.domain.Comment) ModelAndView(org.springframework.web.servlet.ModelAndView) Subject(org.apache.shiro.subject.Subject)

Example 3 with Comment

use of org.obiba.mica.core.domain.Comment in project mica2 by obiba.

the class DataAccessRequestResource method createComment.

@POST
@Path("/comments")
public Response createComment(@PathParam("id") String id, String message) {
    subjectAclService.checkPermission("/data-access-request", "VIEW", id);
    dataAccessRequestService.findById(id);
    Comment comment = // 
    commentsService.save(// 
    Comment.newBuilder().createdBy(// 
    SecurityUtils.getSubject().getPrincipal().toString()).message(// 
    message).resourceId(// 
    "/data-access-request").instanceId(// 
    id).build(), // 
    commentMailNotification);
    subjectAclService.addPermission("/data-access-request/" + id + "/comment", "VIEW,EDIT,DELETE", comment.getId());
    subjectAclService.addGroupPermission(Roles.MICA_DAO, "/data-access-request/" + id + "/comment", "DELETE", comment.getId());
    return Response.noContent().build();
}
Also used : Comment(org.obiba.mica.core.domain.Comment) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 4 with Comment

use of org.obiba.mica.core.domain.Comment in project mica2 by obiba.

the class DataAccessRequestResource method createComment.

@POST
@Path("/comments")
public Response createComment(@PathParam("id") String id, String message, @QueryParam("admin") @DefaultValue("false") boolean admin) {
    subjectAclService.checkPermission("/data-access-request", "VIEW", id);
    DataAccessRequest request = dataAccessRequestService.findById(id);
    if (request.isArchived())
        throw new BadRequestException("Data access request is archived");
    Comment.Builder buildComment = // 
    Comment.newBuilder().createdBy(// 
    SecurityUtils.getSubject().getPrincipal().toString()).message(// 
    message).resourceId(// 
    "/data-access-request").instanceId(id);
    if (admin) {
        if (!subjectAclService.isPermitted("/data-access-request/private-comment", "VIEW"))
            subjectAclService.checkPermission("/private-comment/data-access-request", "ADD");
        buildComment.admin(admin);
    }
    // 
    Comment comment = commentsService.save(buildComment.build(), commentMailNotification);
    subjectAclService.addPermission("/data-access-request/" + id + "/comment", "VIEW,EDIT,DELETE", comment.getId());
    subjectAclService.addGroupPermission(Roles.MICA_DAO, "/data-access-request/" + id + "/comment", "DELETE", comment.getId());
    return Response.noContent().build();
}
Also used : Comment(org.obiba.mica.core.domain.Comment) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest)

Example 5 with Comment

use of org.obiba.mica.core.domain.Comment in project mica2 by obiba.

the class CommentsResource method createComment.

@POST
public Response createComment(@PathParam("id") String id, String message) {
    subjectAclService.checkPermission(String.format("/draft/%s", service.getTypeName()), "VIEW", id);
    Comment comment = // 
    commentsService.save(// 
    Comment.newBuilder().createdBy(// 
    SecurityUtils.getSubject().getPrincipal().toString()).message(// 
    message).resourceId(// 
    String.format("/draft/%s", service.getTypeName())).instanceId(// 
    id).build(), commentMailNotification);
    subjectAclService.addPermission(String.format("/draft/%s/%s/comment", service.getTypeName(), id), "VIEW,EDIT,DELETE", comment.getId());
    return Response.noContent().build();
}
Also used : Comment(org.obiba.mica.core.domain.Comment) POST(javax.ws.rs.POST)

Aggregations

Comment (org.obiba.mica.core.domain.Comment)8 POST (javax.ws.rs.POST)2 Subject (org.apache.shiro.subject.Subject)2 DataAccessRequest (org.obiba.mica.access.domain.DataAccessRequest)2 Timed (com.codahale.metrics.annotation.Timed)1 Strings (com.google.common.base.Strings)1 EventBus (com.google.common.eventbus.EventBus)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 NotNull (javax.validation.constraints.NotNull)1 javax.ws.rs (javax.ws.rs)1 Path (javax.ws.rs.Path)1 Response (javax.ws.rs.core.Response)1 SecurityUtils (org.apache.shiro.SecurityUtils)1