/** * Creates and returns new list of comments of the current post which is not marked as removed. We cant use * hibernate "WHERE" clause due caching issue. Additionally we may need to retrieve comments which is marked as * removed in future. To manipulate with list of comments use {@link #getComments()} and * {@link #setComments(java.util.List)} methods. * * @return newly created list of comments which not marked as deleted */ public List<PostComment> getNotRemovedComments() { List<PostComment> notRemovedComments = new ArrayList<>(); for (PostComment comment : getComments()) { if (comment.getDeletionDate() == null) { notRemovedComments.add(comment); } } return notRemovedComments; }
/** * Checks permissions before deleting comment * * {@inheritDoc} */ @PreAuthorize("(hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.DELETE_OWN_POSTS') and " + "#comment.author.username == principal.username) or " + "(hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.DELETE_OTHERS_POSTS') and " + "#comment.author.username != principal.username)") public void deleteComment(Post post, PostComment comment) { post.getComments().remove(comment); getDao().saveOrUpdate(post); }
public CodeReviewDto(Post post) { this.postId = post.getId(); for (PostComment comment : post.getComments()) { this.comments.add(new CodeReviewCommentDto(comment)); } }