/** * {@inheritDoc} */ @Override public String getUrlSuffix() { return URL_SUFFIX + getId(); }
/** * {@inheritDoc} * * <p> * The target URL has the next format http://{forum root}/posts/{id} */ @Override public String getUrlSuffix() { return URL_SUFFIX + getLastPost().getId(); }
/** * Returns first unread post for current user. If no unread post * information has been set explicitly this method will return * first topic's post id, considering all topic as unread. * * @return returns first unread post id for the current user */ public Long getFirstUnreadPostId() { if (isHasUpdates()) { return getFirstNewerPost(lastReadPostDate).getId(); } return getFirstPost().getId(); }
public CodeReviewDto(Post post) { this.postId = post.getId(); for (PostComment comment : post.getComments()) { this.comments.add(new CodeReviewCommentDto(comment)); } }
/** * Delete post by given id * * @param postId post * @return redirect to post next to deleted one. Redirects to previous post in case if it's last post in topic. * @throws NotFoundException when post was not found */ @RequestMapping(method = RequestMethod.DELETE, value = "/posts/{postId}") public ModelAndView delete(@PathVariable(POST_ID) final Long postId) throws NotFoundException { final Post post = this.postService.get(postId); Post nextPost = post.getTopic().getNeighborPost(post); retryTemplate.execute(new RetryCallback<Object, NotFoundException>() { @Override public Object doWithRetry(RetryContext context) throws NotFoundException { Post post = postService.get(postId); postService.deletePost(post); return null; } }); return new ModelAndView("redirect:/posts/" + nextPost.getId()); }
/** * Performs update with security checking. * * @param post an instance of post, that will be updated * @param postContent new content of the post * @throws AccessDeniedException if user tries to update the first post of code review which should be impossible, * see <a href="http://jtalks.org/display/jcommune/1.1+Larks">Requirements</a> * for details */ @PreAuthorize("(hasPermission(#post.id, 'POST', 'GeneralPermission.WRITE') and " + "hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.EDIT_OWN_POSTS')) or " + "(not hasPermission(#post.id, 'POST', 'GeneralPermission.WRITE') and " + "hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.EDIT_OTHERS_POSTS'))") @Override public void updatePost(Post post, String postContent) { Topic postTopic = post.getTopic(); if (postTopic.isCodeReview() && postTopic.getPosts().get(0).getId() == post.getId()) { throw new AccessDeniedException("It is impossible to edit code review!"); } post.setPostContent(postContent); post.updateModificationDate(); this.getDao().saveOrUpdate(post); userService.notifyAndMarkNewlyMentionedUsers(post); logger.debug("Post id={} updated.", post.getId()); }
return new ModelAndView(this.redirectToPageWithPost(newbie.getId()));
/** * {@inheritDoc} */ @Override public void notifyAndMarkNewlyMentionedUsers(Post post) { MentionedUsers mentionedUsers = MentionedUsers.parse(post); List<JCUser> usersToNotify = mentionedUsers.getNewUsersToNotify(getDao()); for (JCUser user : usersToNotify) { mailService.sendUserMentionedNotification(user, post.getId()); } mentionedUsers.markUsersAsAlreadyNotified(postDao); }
/** * Deletes answer by given id * * @param answerId id of the answer * @return redirect to question page * @throws NotFoundException when answer was not found */ @RequestMapping(method = RequestMethod.DELETE, value = "post/{answerId}") public String deleteAnswer(@PathVariable Long answerId) throws NotFoundException { Post answer = getPluginPostService().get(answerId); Post neighborAnswer = answer.getTopic().getNeighborPost(answer); getPluginPostService().deletePost(answer); return "redirect:" + QuestionsAndAnswersPlugin.CONTEXT + "/" + answer.getTopic().getId() + "#" + neighborAnswer.getId(); }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.CREATE_POSTS') " + "and #post.userCreated.username != principal.username") public Post vote(Post post, PostVote vote) { JCUser currentUser = userService.getCurrentUser(); if (!post.canBeVotedBy(currentUser, vote.isVotedUp())) { logger.info("User [{}] tries to vote for post with id={} in same direction more than one time", currentUser.getUsername(), post.getId()); throw new AccessDeniedException("User can't vote in same direction more than one time"); } vote.setUser(currentUser); int ratingChanges = post.calculateRatingChanges(vote); post.putVote(vote); getDao().saveOrUpdate(post); getDao().changeRating(post.getId(), ratingChanges); return post; }
postDto.getBodyText(), topic.getBranch().getId()); getPluginLastReadPostService().markTopicAsRead(newbie.getTopic()); return "redirect:" + QuestionsAndAnswersPlugin.CONTEXT + "/" + questionId + "#" + newbie.getId();
/** * {@inheritDoc} */ @Override @PreAuthorize("(hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.DELETE_OWN_POSTS') and " + "#post.userCreated.username == principal.username) or " + "(hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.DELETE_OTHERS_POSTS') and " + "#post.userCreated.username != principal.username)") public void deletePost(Post post) { JCUser postCreator = post.getUserCreated(); postCreator.setPostCount(postCreator.getPostCount() - 1); Topic topic = post.getTopic(); topic.removePost(post); Branch branch = topic.getBranch(); boolean deletedPostIsLastPostInBranch = branch.isLastPost(post); if (deletedPostIsLastPostInBranch) { branch.clearLastPost(); } // todo: event API? topicDao.saveOrUpdate(topic); securityService.deleteFromAcl(post); /* only the creator of the post should be notified when it's removed. */ notificationService.subscribedEntityChanged(post); if (deletedPostIsLastPostInBranch) { branchLastPostService.refreshLastPostInBranch(branch); } logger.debug("Deleted post id={}", post.getId()); }
/** * Create dto * * @param post post for conversion * @return dto for post */ public static PostDto getDtoFor(Post post) { PostDto dto = new PostDto(); dto.setBodyText(post.getPostContent()); dto.setId(post.getId()); dto.setTopicId(post.getTopic().getId()); dto.setCreationDate(post.getCreationDate()); dto.setModificationDate(post.getModificationDate()); return dto; }
/** * Creates feed item with information about the post * * @param post post to add to the feed * @param componentUrl base url of the forum component * @return item for the RSS feed */ private Item createFeedItem(Post post, String componentUrl) { Item item = new Item(); Content content = new Content(); content.setType(Content.TEXT); content.setValue(post.getPostContent()); item.setContent(content); item.setTitle(post.getTopic().getTitle()); item.setAuthor(post.getUserCreated().getUsername()); item.setLink(componentUrl + "/posts/" + post.getId()); item.setPubDate(post.getCreationDate().toDate()); return item; }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#branchId, 'BRANCH', 'BranchPermission.CREATE_POSTS')") public Post replyToTopic(long topicId, String answerBody, long branchId) throws NotFoundException { Topic topic = topicFetchService.getTopicSilently(topicId); this.assertPostingIsAllowed(topic); JCUser currentUser = userService.getCurrentUser(); currentUser.setPostCount(currentUser.getPostCount() + 1); Post answer = new Post(currentUser, answerBody); topic.addPost(answer); topic.removeDraftOfUser(currentUser); if (currentUser.isAutosubscribe()){ subscriptionService.subscribe(topic); } postDao.saveOrUpdate(answer); Branch branch = topic.getBranch(); branch.setLastPost(answer); branchDao.saveOrUpdate(branch); dao.saveOrUpdate(topic); securityService.createAclBuilder().grant(GeneralPermission.WRITE).to(currentUser).on(answer).flush(); notificationService.subscribedEntityChanged(topic); userService.notifyAndMarkNewlyMentionedUsers(answer); logger.debug("New post in topic. Topic id={}, Post id={}, Post author={}", new Object[]{topicId, answer.getId(), currentUser.getUsername()}); return answer; }
/** * Create news item * * @param topic news topic * @param url building URL * @return item for news feed */ private Item createFeedItem(Topic topic, String url) { Item item = new Item(); Description description = new Description(); description.setType("text"); String postContent = topic.getLastPost().getPostContent(); postContent = RssUtils.skipInValidXMLChars(postContent); description.setValue(postContent); Content content = new Content(); item.setContent(content); item.setTitle(topic.getTitle()); item.setAuthor(topic.getLastPost().getUserCreated().getUsername()); item.setLink(url + "/posts/" + topic.getLastPost().getId()); item.setComments(topic.getTopicStarter().getSignature()); item.setDescription(description); item.setPubDate(topic.getModificationDate().toDate()); return item; }