public void testPost() throws Exception { // set Data setData(); List<Post> posts = new ArrayList<Post>(); for (int i = 0; i < 25; ++i) { Post post = createdPost(); posts.add(post); forumService_.savePost(categoryId, forumId, topicId, post, true, new MessageBuilder()); } // getPost assertNotNull(forumService_.getPost(categoryId, forumId, topicId, posts.get(0).getId())); // get ListPost JCRPageList pagePosts = forumService_.getPosts(categoryId, forumId, topicId, "", "", "", "root"); assertEquals( pagePosts.getAvailable(), posts.size() + 1); // size = 26 (first post and new postList) List page1 = pagePosts.getPage(1); assertEquals(page1.size(), 10); List page3 = pagePosts.getPage(3); assertEquals(page3.size(), 6); // getPost by Ip JCRPageList pageIpPosts = forumService_.getListPostsByIP("192.168.1.11", null); assertEquals(pageIpPosts.getAvailable(), 25); // size = 25 (not content first post) // update Post First Post newPost = (Post) pagePosts.getPage(1).get(1); newPost.setMessage("New message"); forumService_.savePost(categoryId, forumId, topicId, newPost, false, new MessageBuilder()); assertEquals( "New message", forumService_.getPost(categoryId, forumId, topicId, newPost.getId()).getMessage()); // test movePost Topic topicnew = createdTopic("root"); forumService_.saveTopic(categoryId, forumId, topicnew, true, false, new MessageBuilder()); topicnew = forumService_.getTopic(categoryId, forumId, topicnew.getId(), "root"); forumService_.movePost( new String[] {newPost.getPath()}, topicnew.getPath(), false, "test mail content", ""); assertNotNull(forumService_.getPost(categoryId, forumId, topicnew.getId(), newPost.getId())); // test remove Post return post assertNotNull(forumService_.removePost(categoryId, forumId, topicnew.getId(), newPost.getId())); assertNull(forumService_.getPost(categoryId, forumId, topicnew.getId(), newPost.getId())); // getViewPost }
public void onEvent( Event<UICommentForm> event, UICommentForm commentForm, final String objectId) throws Exception { String comment = ((UIFormWYSIWYGInput) commentForm.getChildById(commentForm.COMMENT_CONTENT)).getValue(); if (CommonUtils.isEmpty(comment) || !ValidatorDataInput.fckContentIsNotEmpty(comment)) { warning("UICommentForm.msg.comment-is-null"); return; } if (!commentForm.getFAQService().isExisting(commentForm.question_.getPath())) { warning("UIQuestions.msg.comment-id-deleted"); return; } UIAnswersPortlet portlet = commentForm.getAncestorOfType(UIAnswersPortlet.class); UIAnswersContainer answersContainer = portlet.getChild(UIAnswersContainer.class); UIQuestions questions = answersContainer.getChild(UIQuestions.class); comment = CommonUtils.encodeSpecialCharInContent(comment); try { // Create link by Vu Duy Tu. if (FAQUtils.isFieldEmpty(commentForm.question_.getLink())) { commentForm.question_.setLink( FAQUtils.getQuestionURI(commentForm.question_.getId(), false)); } if (commentForm.comment != null) { commentForm.comment.setNew(false); } else { commentForm.comment = new Comment(); commentForm.comment.setNew(true); } commentForm.comment.setComments(comment); // For discuss in forum String topicId = commentForm.question_.getTopicIdDiscuss(); if (topicId != null && topicId.length() > 0) { ForumService forumService = (ForumService) PortalContainer.getInstance().getComponentInstanceOfType(ForumService.class); Topic topic = (Topic) forumService.getObjectNameById( topicId, org.exoplatform.forum.service.Utils.TOPIC); if (topic != null) { String remoteAddr = WebUIUtils.getRemoteIP(); String[] ids = topic.getPath().split("/"); int t = ids.length; String linkForum = FAQUtils.getLinkDiscuss(topicId); String postId = commentForm.comment.getPostId(); if (postId == null || postId.length() == 0) { Post post = new Post(); post.setOwner(commentForm.currentUser_); post.setIcon("ViewIcon"); post.setName("Re: " + commentForm.question_.getQuestion()); post.setMessage(comment); post.setLink(linkForum + "/" + postId); post.setIsApproved(!topic.getIsModeratePost()); post.setRemoteAddr(remoteAddr); try { forumService.savePost( ids[t - 3], ids[t - 2], topicId, post, true, new MessageBuilder()); } catch (Exception e) { event.getSource().log.debug("Saving post fail: ", e); } commentForm.comment.setPostId(post.getId()); } else { try { Post post = forumService.getPost(ids[t - 3], ids[t - 2], topicId, postId); boolean isNew = false; if (post == null) { post = new Post(); isNew = true; post.setOwner(commentForm.currentUser_); post.setIcon("ViewIcon"); post.setName("Re: " + commentForm.question_.getQuestion()); commentForm.comment.setPostId(post.getId()); post.setLink(linkForum + "/" + postId); post.setRemoteAddr(remoteAddr); } else { post.setModifiedBy(commentForm.currentUser_); } post.setIsApproved(!topic.getIsModeratePost()); post.setMessage(comment); forumService.savePost( ids[t - 3], ids[t - 2], topicId, post, isNew, new MessageBuilder()); } catch (Exception e) { event.getSource().log.debug("Saving post fail: ", e); } } } } String language = ""; if (!commentForm.languageSelected.equals(commentForm.question_.getLanguage())) language = commentForm.languageSelected; String currentUser = FAQUtils.getCurrentUser(); commentForm.comment.setCommentBy(currentUser); commentForm.comment.setFullName(FAQUtils.getFullName(null)); commentForm .getFAQService() .saveComment(commentForm.question_.getPath(), commentForm.comment, language); if (!commentForm.languageSelected.equals(commentForm.question_.getLanguage())) { try { questions.updateCurrentLanguage(); } catch (Exception e) { questions.updateQuestionLanguageByLanguage( commentForm.question_.getPath(), commentForm.languageSelected); } } else { questions.updateQuestionLanguageByLanguage( commentForm.question_.getPath(), commentForm.languageSelected); } } catch (Exception e) { event.getSource().log.error("Fail to save action: ", e); warning("UIQuestions.msg.category-id-deleted", false); } portlet.cancelAction(); event.getRequestContext().addUIComponentToUpdateByAjax(answersContainer); }