public void testTag() throws Exception { // set Data setData(); Tag tag = createTag("Tag1"); Tag tag2 = createTag("Tag2"); Tag tag3 = createTag("Tag3"); // add tag List<Tag> tags = new ArrayList<Tag>(); tags.add(tag); tags.add(tag2); tags.add(tag3); Topic topic = forumService_.getTopic(categoryId, forumId, topicId, ""); forumService_.addTag(tags, USER_ROOT, topic.getPath()); // get Tags name in topic by root. // List<String> list = forumService_.getTagNameInTopic(USER_ROOT+","+topicId); // Test get tag String id = Utils.TAG + tag.getName(); tag = forumService_.getTag(id); assertNotNull(tag); // Get all tag // assertEquals("All tags size is not 3", 3, forumService_.getAllTags().size()); }
@Override public void updateTopics(List<Topic> topics, boolean isLock) { for (Topic topic : topics) { topic.setIsLock(isLock); ForumActivityContext ctx = ForumActivityContext.makeContextForAddTopic(topic); TopicActivityTask task = TopicActivityTask.UPDATE_FORUM_TOPIC; ActivityExecutor.execute(task, ctx); } }
private void setData() throws Exception { killData(); Category cat = createCategory(getId(Utils.CATEGORY)); this.categoryId = cat.getId(); forumService_.saveCategory(cat, true); Forum forum = createdForum(); this.forumId = forum.getId(); forumService_.saveForum(categoryId, forum, true); Topic topic = createdTopic("root"); forumService_.saveTopic(categoryId, forumId, topic, true, false, new MessageBuilder()); this.topicId = topic.getId(); }
private void updateProperties(Topic topic, ForumActivityContext ctx) { PropertyChangeSupport newPcs = new PropertyChangeSupport(topic); PropertyChangeSupport pcs = topic.getPcs(); // Topic.TOPIC_NAME if (pcs.hasPropertyName(Topic.TOPIC_NAME)) { newPcs.addPropertyChange(pcs.getPropertyChange(Topic.TOPIC_NAME)); } // Topic.TOPIC_CONTENT if (pcs.hasPropertyName(Topic.TOPIC_CONTENT)) { newPcs.addPropertyChange(pcs.getPropertyChange(Topic.TOPIC_CONTENT)); } if (newPcs.getChangeEvents().length > 1) { ctx.setPcs(newPcs); // 1. executes task TopicActivityTask task = TopicActivityTask.UPDATE_TOPIC_PROPERTIES; ctx = ForumActivityUtils.processBBCode(ctx); ActivityExecutor.execute(task, ctx); // 2. remove events pcs.removePropertyChange(Topic.TOPIC_NAME); pcs.removePropertyChange(Topic.TOPIC_CONTENT); } }
public void updatePost(String postId, boolean isQuote, boolean isPP, Post post) throws Exception { if (post != null) this.post_ = post; this.postId = postId; this.isQuote = isQuote; this.isMP = isPP; UIForumInputWithActions threadContent = this.getChildById(FIELD_THREADCONTEN_TAB); UIFormStringInput editReason = threadContent.getUIStringInput(FIELD_EDITREASON_INPUT); editReason.setRendered(false); if (!ForumUtils.isEmpty(this.postId) && post != null) { String message = CommonUtils.decodeSpecialCharToHTMLnumberIgnore(post.getMessage()); if (isQuote) { // quote threadContent .getUIStringInput(FIELD_POSTTITLE_INPUT) .setValue(CommonUtils.decodeSpecialCharToHTMLnumber(getTitle(post.getName()))); String value = "[QUOTE=" + getForumService().getScreenName(post.getOwner()) + "]" + message + "[/QUOTE]"; threadContent.getChild(UIFormWYSIWYGInput.class).setValue(value); } else if (isPP) { threadContent .getUIStringInput(FIELD_POSTTITLE_INPUT) .setValue(CommonUtils.decodeSpecialCharToHTMLnumber(getTitle(topic.getTopicName()))); } else { // edit this.attachments_.clear(); editReason.setRendered(true); threadContent .getUIStringInput(FIELD_POSTTITLE_INPUT) .setValue(CommonUtils.decodeSpecialCharToHTMLnumber(post.getName())); if (post.getAttachments() != null && post.getAttachments().size() > 0) { this.attachments_.addAll(post.getAttachments()); this.refreshUploadFileList(); } threadContent.getChild(UIFormWYSIWYGInput.class).setValue(message); } } else { if (!isQuote) { // reply threadContent .getUIStringInput(FIELD_POSTTITLE_INPUT) .setValue(CommonUtils.decodeSpecialCharToHTMLnumber(getTitle(topic.getTopicName()))); } } }
private void injectTopic() throws Exception { // String topicName = topicBase + toType; Topic topic = getTopicByName(topicName); if (topic == null) { getLog() .info( "topic name is '" + topicName + "' is wrong. Please set it exactly. Aborting injection ..."); return; } Forum forum = getForumByTopicName(topicName); Category cat = getCategoryByForumName(forum.getForumName()); // String[] userNames = getUserNames(); if (userNames == null | userNames.length <= 0) { getLog() .info( "Don't assign permission any user to '" + topicName + "' topic. Please set it exactly. Aborting injection ..."); return; } // topic = forumService.getTopic(cat.getId(), forum.getId(), topic.getId(), null); topic.setCanPost(userNames); topic.setCanView(userNames); topic.setEmailNotification(userNames); forumService.saveTopic(cat.getId(), forum.getId(), topic, false, false, new MessageBuilder()); getLog() .info( "Assign permission '" + Arrays.toString(userNames) + "' user(s) into '" + topicName + "' topic in '" + forum.getForumName() + "' forum."); }
@Override public void updateTopic(Topic topic) { TopicActivityTask task = null; ForumActivityContext ctx = ForumActivityContext.makeContextForUpdateTopic(topic); updateProperties(topic, ctx); PropertyChangeEvent[] events = topic.getChangeEvent(); for (int i = 0; i < events.length; i++) { task = getTaskFromUpdateTopic(events[i], ctx); ActivityExecutor.execute(task, ctx); } }
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 }
@Override public void inject(HashMap<String, String> params) throws Exception { // int number = param(params, NUMBER); String topicPrefix = params.get(TOPIC_PREFIX); // int fromUser = param(params, FROM_USER); int toUser = param(params, TO_USER); String userPrefix = params.get(USER_PREFIX); // int toForum = param(params, TO_FORUM); String forumPrefix = params.get(FORUM_PREFIX); init(userPrefix, null, forumPrefix, topicPrefix, null, 0); String forumName = forumBase + toForum; Forum forum = getForumByName(forumName); if (forum == null) { getLog() .info( "forum name is '" + forumName + "' wrong. Please set it exactly. Aborting injection ..."); return; } Category cat = getCategoryByForumName(forumName); // for (int i = fromUser; i <= toUser; ++i) { String owner = userBase + i; // for (int j = 0; j < number; ++j) { String topicName = topicName(); Topic topicNew = new Topic(); topicNew.setOwner(owner); topicNew.setTopicName(topicName); topicNew.setCreatedDate(new Date()); topicNew.setModifiedBy(owner); topicNew.setModifiedDate(new Date()); topicNew.setLastPostBy(owner); topicNew.setLastPostDate(new Date()); topicNew.setDescription(lorem.getParagraphs()); topicNew.setPostCount(0); topicNew.setViewCount(0); topicNew.setIsNotifyWhenAddPost(""); topicNew.setIsModeratePost(false); topicNew.setIsClosed(false); topicNew.setIsLock(false); topicNew.setIsWaiting(false); topicNew.setIsActive(true); topicNew.setIcon("classNameIcon"); topicNew.setIsApproved(true); topicNew.setCanView(new String[] {}); topicNew.setCanPost(new String[] {}); // forumService.saveTopic( cat.getId(), forum.getId(), topicNew, true, false, new MessageBuilder()); ++topicNumber; // getLog().info("Topic '" + topicName + "' in forum '" + forumName + "' created by " + owner); } } }
private Topic createdTopic(String owner) { Topic topicNew = new Topic(); topicNew.setOwner(owner); topicNew.setTopicName("TestTopic"); topicNew.setCreatedDate(new Date()); topicNew.setModifiedBy("root"); topicNew.setModifiedDate(new Date()); topicNew.setLastPostBy("root"); topicNew.setLastPostDate(new Date()); topicNew.setDescription("Topic description"); topicNew.setPostCount(0); topicNew.setViewCount(0); topicNew.setIsNotifyWhenAddPost(""); topicNew.setIsModeratePost(false); topicNew.setIsClosed(false); topicNew.setIsLock(false); topicNew.setIsWaiting(false); topicNew.setIsActive(true); topicNew.setIcon("classNameIcon"); topicNew.setIsApproved(true); topicNew.setCanView(new String[] {}); topicNew.setCanPost(new String[] {}); return topicNew; }
public void testTopic() throws Exception { Category cat = createCategory(getId(Utils.CATEGORY)); forumService_.saveCategory(cat, true); Forum forum = createdForum(); forumService_.saveForum(cat.getId(), forum, true); List<String> listTopicId = new ArrayList<String>(); // add 10 Topics List<Topic> list = new ArrayList<Topic>(); Topic topic; for (int i = 0; i < 10; i++) { topic = createdTopic("Owner"); list.add(topic); listTopicId.add(topic.getId()); forumService_.saveTopic(cat.getId(), forum.getId(), topic, true, false, new MessageBuilder()); } topic = list.get(8); // get Topic - topic in position 8 Topic topica = forumService_.getTopic(cat.getId(), forum.getId(), topic.getId(), ""); assertNotNull(topica); // get Topic by path topica = forumService_.getTopicByPath( cat.getId() + "/" + forum.getId() + "/" + topic.getId(), false); assertNotNull(topica); // update Topic topica.setIsSticky(true); topica.setTopicName("topic 8"); forumService_.saveTopic(cat.getId(), forum.getId(), topica, false, false, new MessageBuilder()); assertEquals( "This topic name not is 'topic 8'", "topic 8", forumService_.getTopic(cat.getId(), forum.getId(), topic.getId(), "").getTopicName()); // modifyTopic topica.setIsLock(true); list.clear(); list.add(topica); forumService_.modifyTopic(list, 2); topica = forumService_.getTopic(cat.getId(), forum.getId(), topic.getId(), ""); assertEquals("This topic is open.", topica.getIsLock(), true); // get PageList Topic JCRPageList pagelist = forumService_.getPageTopic(cat.getId(), forum.getId(), "", ""); assertEquals("Available all topics not equals 10.", pagelist.getAvailable(), 10); pagelist.setPageSize(5); List<Topic> listTopic = pagelist.getPage(1); assertEquals("Available page not equals 5", listTopic.size(), 5); assertEquals(pagelist.getAvailablePage(), 2); // get Topic By User topic = createdTopic("demo"); forumService_.saveTopic(cat.getId(), forum.getId(), topic, true, false, new MessageBuilder()); // We have 11 topic: 10 by Owner and 1 by demo pagelist = forumService_.getPageTopicByUser("Owner", true, ""); assertEquals(pagelist.getAvailable(), 10); // auto prune // set 5 topics for old Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(cal.getTimeInMillis() - 2 * 86400000); Node topicNode; for (Topic topic2 : listTopic) { topicNode = root_.getNode(topic2.getPath().replaceFirst("/", "")); topicNode.setProperty(ForumNodeTypes.EXO_LAST_POST_DATE, cal); topicNode.save(); } listTopic = forumService_.getAllTopicsOld(1, forum.getPath()); assertEquals( "Failed to run auto prune. List topic has size not equals 5.", listTopic.size(), 5); // move Topic // move topic from forum to forum 1 Forum forum1 = createdForum(); forumService_.saveForum(cat.getId(), forum1, true); forum1 = forumService_.getForum(cat.getId(), forum1.getId()); List<Topic> topics = new ArrayList<Topic>(); topics.add(topica); forumService_.moveTopic(topics, forum1.getPath(), "", ""); assertNotNull( "Failed to moved topic, topic is null.", forumService_.getTopic(cat.getId(), forum1.getId(), topica.getId(), "")); // test remove Topic return Topic // remove id topic moved in list topicIds. if (listTopicId.contains(topica.getId())) listTopicId.remove(topica.getId()); for (String topicId : listTopicId) { forumService_.removeTopic(cat.getId(), forum.getId(), topicId); } List<Topic> topics2 = forumService_.getTopics(cat.getId(), forum.getId()); assertEquals( "Topics in forum failed to remove. List topic has size more than 1.", topics2.size(), 1); }
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); }