/** * @return content of the first post of the topic */ public String getBodyText() { Post firstPost = getFirstPost(); return firstPost.getPostContent(); }
/** * Get next post to given post in topic. Following basic cases are possible: * <ol> * <li>In case of one post in topic it returns it back (not valid case from * end-user point of view).</li> * <li>In case if we pass post in the middle of the topic it returns next * post.</li> * <li>In case if we pass last post in the topic it returns previous one.</li> * </ol> * Used to find closest post which is good to be displayed after deletion of * post we pass as a parameter. * * @param post post to search next * @return Neighbor post */ public Post getNeighborPost(Post post) { for (int i = posts.size() - 1; i > 0; i--) { if (posts.get(i).equals(post)) { return (i == posts.size() - 1) ? posts.get(i - 1) : posts .get(i + 1); } } return getFirstPost(); }
/** * Returns first post that is newer then give time * @param time time to looking for newer post * @return first post that is newer then give time or first post if there is no post that is newer */ private Post getFirstNewerPost(DateTime time) { for (Post post : getPosts()) { if (post.getCreationDate().isAfter(time)) { return post; } } return getFirstPost(); }
/** * Get the date of the last modification of posts in the current topic. */ public DateTime getLastModificationPostDate() { DateTime newTopicModificationDate = getFirstPost().getLastTouchedDate(); for (Post post : getPosts()) { if (post.getLastTouchedDate().isAfter(newTopicModificationDate.toInstant())) { newTopicModificationDate = post.getLastTouchedDate(); } } return newTopicModificationDate; }
/** * Calculates modification date of topic taking it as last post in topic creation date. * Used after deletion of the post. It is necessary to save the sort order of topics in the future. */ public void recalculateModificationDate() { DateTime newTopicModificationDate = getFirstPost().getCreationDate(); for (Post post : getPosts()) { if (post.getCreationDate().isAfter(newTopicModificationDate.toInstant())) { newTopicModificationDate = post.getCreationDate(); } } modificationDate = newTopicModificationDate; }
/** * 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(); }
/** * {@inheritDoc} * * @throws AccessDeniedException besides other reasons, always throws this when Code Review is edited because it * shouldn't be possible to edit it. More details on requirements can be found here * <a href="http://jtalks.org/display/jcommune/1.1+Larks">here</a>. */ @Override @PreAuthorize("(hasPermission(#topic.id, 'TOPIC', 'GeneralPermission.WRITE') and " + "hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.EDIT_OWN_POSTS')) or " + "(not hasPermission(#topic.id, 'TOPIC', 'GeneralPermission.WRITE') and " + "hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.EDIT_OTHERS_POSTS'))") public void updateTopic(Topic topic, Poll poll) { if (topic.isCodeReview()) { throw new AccessDeniedException("It is not allowed to edit Code Review!"); } Post post = topic.getFirstPost(); post.updateModificationDate(); if (poll != null && poll.getEndingDate() != null) { topic.getPoll().setEndingDate(poll.getEndingDate()); } dao.saveOrUpdate(topic); logger.debug("Topic id={} updated", topic.getId()); }
/** * Fills persistent topic object with data from the current dto * * @param persistentTopic persistent topic * @return the same topic with fields set from dto */ public Topic fillTopic(Topic persistentTopic) { persistentTopic.setTitle(topic.getTitle()); persistentTopic.getFirstPost().setPostContent(bodyText); persistentTopic.setAnnouncement(topic.isAnnouncement()); persistentTopic.setSticked(topic.isSticked()); return topic; } }
userService.notifyAndMarkNewlyMentionedUsers(topic.getFirstPost()); lastReadPostService.markTopicAsRead(topic); topicDraftService.deleteDraft();