/** * @param entity entity like "Branch/Topics" * @return title for Topic/Branch or "" if entity is not instanceof Topic/Branch */ private String getTitleName(Entity entity) { if (entity instanceof Topic) { Topic topic = (Topic) entity; return ": " + topic.getTitle(); } else if (entity instanceof Branch) { Branch branch = (Branch) entity; return ": " + branch.getName(); } else if (entity instanceof Post) { Post post = (Post) entity; return ": " + post.getTopic().getTitle(); } else { return ""; } }
/** * {@inheritDoc} */ @PreAuthorize("(hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.DELETE_OWN_POSTS') and " + "#topic.containsOwnerPostsOnly and #topic.topicStarter.id == principal.id) or " + "(hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.DELETE_OTHERS_POSTS') and " + "hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.DELETE_OWN_POSTS'))") @Override public void deleteTopic(Topic topic) throws NotFoundException { deleteTopicSilent(topic); notificationService.sendNotificationAboutRemovingTopic(topic); logger.info("Deleted topic \"{}\". Topic id: {}", topic.getTitle(), topic.getId()); }
/** * Edit post page filled with data from post with given id * * @param postId post id * @return redirect to post form page * @throws NotFoundException when topic or post not found */ @RequestMapping(value = "/posts/{postId}/edit", method = RequestMethod.GET) public ModelAndView editPage(@PathVariable(POST_ID) Long postId) throws NotFoundException { Post post = postService.get(postId); return new ModelAndView("topic/editPost") .addObject(POST_DTO, PostDto.getDtoFor(post)) .addObject(TOPIC_ID, post.getTopic().getId()) .addObject(POST_ID, postId) .addObject(TOPIC_TITLE, post.getTopic().getTitle()) .addObject("breadcrumbList", breadcrumbBuilder.getForumBreadcrumb(post.getTopic())); }
/** * Show edit answer page * * @param request HttpServletRequest * @param model model for transferring to jsp * @param id id of answer to edit * * @return plugin view name * @throws NotFoundException if answer with specified id not found */ @RequestMapping(value = "post/{id}/edit", method = RequestMethod.GET) public String editAnswerPage(HttpServletRequest request, Model model, @PathVariable("id") Long id) throws NotFoundException{ Post answer = getPluginPostService().get(id); PostDto answerDto = PostDto.getDtoFor(answer); VelocityEngine engine = new VelocityEngine(getProperties()); engine.init(); Map<String, Object> data = getDefaultModel(request); data.put(QEUSTION_TITLE, answer.getTopic().getTitle()); data.put(POST_DTO, answerDto); data.put(HTML_ESCAPER, htmlEscaper); model.addAttribute(CONTENT, getMergedTemplate(engine, ANSWER_FORM_TEMPLATE_PATH, "UTF-8", data)); return PLUGIN_VIEW_NAME; }
/** * Fill the post breadcrumb. * * @param post {@link org.jtalks.jcommune.model.entity.Post} the breadcrumbed post. * @return {@link Breadcrumb} the filled breadcrumb for the Post location. */ private Breadcrumb preparePostBreadcrumb(Post post) { Topic topic = post.getTopic(); return new Breadcrumb( topic.getId(), BreadcrumbLocation.TOPIC, topic.getTitle()); } }
VelocityEngine engine = new VelocityEngine(getProperties()); engine.init(); data.put(QEUSTION_TITLE, answer.getTopic().getTitle()); data.put(POST_DTO, postDto); data.put(RESULT, result);
/** * {@inheritDoc} */ @PreAuthorize("hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.MOVE_TOPICS')") @Override public void moveTopic(Topic topic, Long branchId) throws NotFoundException { Branch sourceBranch = topic.getBranch(); Branch targetBranch = branchDao.get(branchId); if (targetBranch == null) { throw new NotFoundException("Target branch not exist"); } targetBranch.addTopic(topic); branchDao.saveOrUpdate(targetBranch); List<Post> topicPosts = topic.getPosts(); if (topicPosts.contains(sourceBranch.getLastPost())) { branchLastPostService.refreshLastPostInBranch(sourceBranch); } branchLastPostService.refreshLastPostInBranch(targetBranch); notificationService.sendNotificationAboutTopicMoved(topic); logger.info("Moved topic \"{}\". Topic id: {}", topic.getTitle(), 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; } }
/** * 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; }
/** * 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; }
Topic topic = new Topic(currentUser, topicDto.getTitle()); topic.setAnnouncement(topicDto.isAnnouncement()); topic.setSticked(topicDto.isSticked());