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; }
@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); } }
@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); } } }
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); }