Search in sources :

Example 6 with Comment

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

the class CommentDtos method fromDto.

@NotNull
Comment fromDto(@NotNull Mica.CommentDtoOrBuilder dto) {
    Comment.Builder commentBuilder = // 
    Comment.newBuilder().id(// 
    dto.getId()).message(// 
    dto.getMessage()).resourceId(// 
    dto.getResourceId()).instanceId(dto.getInstanceId());
    if (dto.hasAdmin())
        commentBuilder.admin(dto.getAdmin());
    Comment comment = commentBuilder.build();
    if (dto.hasModifiedBy())
        comment.setLastModifiedBy(dto.getModifiedBy());
    TimestampsDtos.fromDto(dto.getTimestamps(), comment);
    return comment;
}
Also used : Comment(org.obiba.mica.core.domain.Comment) NotNull(javax.validation.constraints.NotNull)

Example 7 with Comment

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

the class CommentsService method save.

public Comment save(Comment comment, MailNotification<Comment> mailNotification) {
    if (comment.getMessage().isEmpty())
        throw new IllegalArgumentException("Comment message cannot be empty");
    Comment saved = comment;
    if (!comment.isNew()) {
        saved = commentsRepository.findOne(comment.getId());
        if (saved == null) {
            saved = comment;
        } else {
            BeanUtils.copyProperties(comment, saved, "id", "classId", "createdDate");
        }
        saved.setLastModifiedDate(DateTime.now());
    }
    if (mailNotification != null)
        mailNotification.send(saved);
    commentsRepository.save(saved);
    eventBus.post(new CommentUpdatedEvent(comment));
    return saved;
}
Also used : Comment(org.obiba.mica.core.domain.Comment) CommentUpdatedEvent(org.obiba.mica.core.event.CommentUpdatedEvent)

Example 8 with Comment

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

the class DataAccessController method getPrivateComments.

@GetMapping("/data-access-private-comments/{id:.+}")
public ModelAndView getPrivateComments(@PathVariable String id) {
    Subject subject = SecurityUtils.getSubject();
    if (subject.isAuthenticated()) {
        Map<String, Object> params = newParameters(id);
        addDataAccessConfiguration(params);
        if (!isPermitted("/data-access-request/private-comment", "VIEW"))
            checkPermission("/private-comment/data-access-request", "VIEW", null);
        List<Comment> comments = commentsService.findPrivateComments("/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-private-comments", params);
    } else {
        return new ModelAndView("redirect:../signin?redirect=" + micaConfigService.getContextPath() + "/data-access-private-comments%2F" + id);
    }
}
Also used : Comment(org.obiba.mica.core.domain.Comment) ModelAndView(org.springframework.web.servlet.ModelAndView) Subject(org.apache.shiro.subject.Subject)

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