예제 #1
0
 public void testExportXML() throws Exception {
   Category cat = createCategory(getId(Utils.CATEGORY));
   forumService_.saveCategory(cat, true);
   cat = forumService_.getCategory(cat.getId());
   Forum forum = createdForum();
   forumService_.saveForum(cat.getId(), forum, true);
   forum = forumService_.getForum(cat.getId(), forum.getId());
   ByteArrayOutputStream bos = new ByteArrayOutputStream();
   forumService_.exportXML(
       cat.getId(), forum.getId(), new ArrayList<String>(), forum.getPath(), bos, false);
   assertEquals("can't export Forum into XML file", bos.size() > 0, true);
 }
예제 #2
0
 private void killData() throws Exception {
   List<Category> cats = forumService_.getCategories();
   if (cats.size() > 0) {
     for (Category category : cats) {
       forumService_.removeCategory(category.getId());
     }
   }
 }
예제 #3
0
  private void injectForum() throws Exception {
    //
    String forumName = forumBase + toType;
    Forum forum = getForumByName(forumName);
    if (forum == null) {
      getLog()
          .info(
              "forum name is '"
                  + forumName
                  + "' is wrong. Please set it exactly. Aborting injection ...");
      return;
    }
    Category cat = getCategoryByForumName(forumName);

    //
    String[] userNames = getUserNames();
    if (userNames == null | userNames.length <= 0) {
      getLog()
          .info(
              "Don't assign permission any user to '"
                  + forumName
                  + "' forum. Please set it exactly. Aborting injection ...");
      return;
    }

    //
    forum = forumService.getForum(cat.getId(), forum.getId());
    forum.setModerators(userNames);
    forum.setCreateTopicRole(userNames);
    forum.setViewer(userNames);
    forum.setPoster(userNames);
    forumService.saveForum(cat.getId(), forum, false);

    getLog()
        .info(
            "Assign permission '"
                + Arrays.toString(userNames)
                + "' user(s) into '"
                + forumName
                + "' forum in '"
                + cat.getCategoryName()
                + "' category.");
  }
예제 #4
0
  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.");
  }
예제 #5
0
 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();
 }
예제 #6
0
 public void testImportXML() throws Exception {
   Category cat = createCategory(getId(Utils.CATEGORY));
   forumService_.saveCategory(cat, true);
   cat = forumService_.getCategory(cat.getId());
   String pathNode = cat.getPath();
   assertEquals(
       "Before import data, category don't have any forum",
       forumService_.getForums(cat.getId(), "").size(),
       0);
   try {
     File file =
         new File(System.getProperty("user.dir") + "/src/test/resources/conf/portal/Data.xml");
     String content = FileUtils.readFileToString(file, "UTF-8");
     byte currentXMLBytes[] = content.getBytes();
     ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(currentXMLBytes);
     // Import forum into category
     forumService_.importXML(
         pathNode, byteArrayInputStream, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
     assertEquals(
         "Can't import forum into category", forumService_.getForums(cat.getId(), "").size(), 1);
   } catch (IOException e) {
     log.debug("Failed to test importXML", e);
   }
 }
예제 #7
0
  public void setCategoryValue(Category category, boolean isUpdate) throws Exception {
    if (isUpdate) {
      this.categoryId = category.getId();
      getUIStringInput(FIELD_CATEGORYTITLE_INPUT)
          .setValue(CommonUtils.decodeSpecialCharToHTMLnumber(category.getCategoryName()));
      getUIStringInput(FIELD_CATEGORYORDER_INPUT)
          .setValue(Long.toString(category.getCategoryOrder()));
      getUIFormTextAreaInput(FIELD_DESCRIPTION_INPUT)
          .setDefaultValue(CommonUtils.decodeSpecialCharToHTMLnumber(category.getDescription()));
      String userPrivate = ForumUtils.unSplitForForum(category.getUserPrivate());
      getUIFormTextAreaInput(FIELD_USERPRIVATE_MULTIVALUE).setValue(userPrivate);

      UIPermissionPanel permissionTab = getChildById(PERMISSION_TAB);
      permissionTab.addPermissionForOwners(MODERAROR, category.getModerators());
      permissionTab.addPermissionForOwners(TOPICABLE, category.getCreateTopicRole());
      permissionTab.addPermissionForOwners(POSTABLE, category.getPoster());
      permissionTab.addPermissionForOwners(VIEWER, category.getViewer());
    }
  }
예제 #8
0
  @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);
      }
    }
  }
예제 #9
0
  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);
  }
예제 #10
0
  public void testForum() throws Exception {
    String catId = getId(Utils.CATEGORY);
    Category cat = createCategory(catId);
    // create new category
    forumService_.saveCategory(cat, true);

    // create new forum
    Forum forum = createdForum();
    String forumId = forum.getId();

    // add forum
    forumService_.saveForum(catId, forum, true);

    // getForum
    forum = forumService_.getForum(catId, forumId);
    assertNotNull("Forum is null", forum);

    // getList Forum
    // Created 5 new forum, we have total 6 forum.
    List<Forum> forums = new ArrayList<Forum>();
    for (int i = 0; i < 5; i++) {
      forumService_.saveForum(cat.getId(), createdForum(), true);
    }
    forums.addAll(forumService_.getForums(catId, ""));

    // check size of list forum
    assertEquals("List forums size not equals 6", forums.size(), 6);

    // update Forum
    forum.setForumName("Forum update");
    forumService_.saveForum(catId, forum, false);
    assertEquals(forum.getForumName(), forumService_.getForum(catId, forumId).getForumName());

    // modifyForum
    forum.setIsLock(true);
    forumService_.modifyForum(forum, 2);
    forum = forumService_.getForum(catId, forumId);
    assertEquals(forum.getIsLock(), true);

    // saveModerateOfForum
    List<String> list = new ArrayList<String>();
    list.add(catId + "/" + forum.getId());
    forumService_.saveModerateOfForums(list, "demo", false);
    forum = forumService_.getForum(catId, forumId);
    list.clear();
    list.addAll(Arrays.asList(forum.getModerators()));
    assertEquals(list.contains("demo"), true);

    // test moderator of category.
    cat.setModerators(new String[] {"admin", "john"});
    forumService_.saveCategory(cat, false);
    forum = forumService_.getForum(catId, forumId);
    list.clear();
    list.addAll(Arrays.asList(forum.getModerators()));
    // assertEquals("Forum in category can not content moderatort user admin",
    // list.contains("admin"), true);

    // test moveForum, Move list Forum from Category 'cat' to Category 'cate'

    // create new Category
    Category cate = createCategory(getId(Utils.CATEGORY));
    forumService_.saveCategory(cate, true);
    Category cateNew = forumService_.getCategory(cate.getId());

    // move forum
    forumService_.moveForum(forums, cateNew.getPath());

    // get forum in new category
    forum = forumService_.getForum(cate.getId(), forumId);
    assertNotNull(forum);

    // remove Forum and return this Forum
    for (Forum forum2 : forums) {
      forumService_.removeForum(cate.getId(), forum2.getId());
    }

    // check remove
    forums = forumService_.getForumSummaries(catId, "");
    assertEquals("List forums can not equals 0", forums.size(), 0);
  }
예제 #11
0
    public void onEvent(Event<UICategoryForm> event, UICategoryForm uiForm, String objectId)
        throws Exception {
      if (uiForm.isDoubleClickSubmit) return;
      String categoryTitle = uiForm.getUIStringInput(FIELD_CATEGORYTITLE_INPUT).getValue();
      int maxText = ForumUtils.MAXTITLE;
      if (categoryTitle.length() > maxText) {
        warning(
            "NameValidator.msg.warning-long-text",
            new String[] {uiForm.getLabel(FIELD_CATEGORYTITLE_INPUT), String.valueOf(maxText)});
        return;
      }
      categoryTitle = CommonUtils.encodeSpecialCharInTitle(categoryTitle);
      String description = uiForm.getUIFormTextAreaInput(FIELD_DESCRIPTION_INPUT).getValue();
      if (!ForumUtils.isEmpty(description) && description.length() > maxText) {
        warning(
            "NameValidator.msg.warning-long-text",
            new String[] {uiForm.getLabel(FIELD_DESCRIPTION_INPUT), String.valueOf(maxText)});
        return;
      }
      description = CommonUtils.encodeSpecialCharInTitle(description);
      String categoryOrder = uiForm.getUIStringInput(FIELD_CATEGORYORDER_INPUT).getValue();
      if (ForumUtils.isEmpty(categoryOrder)) categoryOrder = "0";
      categoryOrder = ForumUtils.removeZeroFirstNumber(categoryOrder);
      if (categoryOrder.length() > 3) {
        warning(
            "NameValidator.msg.erro-large-number",
            new String[] {uiForm.getLabel(FIELD_CATEGORYORDER_INPUT)});
        return;
      }

      UIPermissionPanel permissionTab = uiForm.getChildById(PERMISSION_TAB);
      String moderator = permissionTab.getOwnersByPermission(MODERAROR);
      moderator = ForumUtils.removeSpaceInString(moderator);
      moderator = ForumUtils.removeStringResemble(moderator);
      String[] moderators = ForumUtils.splitForForum(moderator);
      if (!ForumUtils.isEmpty(moderator)) {
        String erroUser = UserHelper.checkValueUser(moderator);
        if (!ForumUtils.isEmpty(erroUser)) {
          warning(
              "NameValidator.msg.erroUser-input",
              new String[] {uiForm.getLabel(MODERAROR), erroUser});
          return;
        }
      } else {
        moderators = new String[] {""};
      }

      String userPrivate = uiForm.getUIFormTextAreaInput(FIELD_USERPRIVATE_MULTIVALUE).getValue();
      if (!ForumUtils.isEmpty(userPrivate) && !ForumUtils.isEmpty(moderator)) {
        userPrivate = userPrivate + ForumUtils.COMMA + moderator;
      }
      userPrivate = ForumUtils.removeSpaceInString(userPrivate);
      userPrivate = ForumUtils.removeStringResemble(userPrivate);
      String[] userPrivates = ForumUtils.splitForForum(userPrivate);
      if (!ForumUtils.isEmpty(userPrivate)) {
        String erroUser = UserHelper.checkValueUser(userPrivate);
        if (!ForumUtils.isEmpty(erroUser)) {
          warning(
              "NameValidator.msg.erroUser-input",
              new String[] {uiForm.getLabel(FIELD_USERPRIVATE_MULTIVALUE), erroUser});
          return;
        }
      } else {
        userPrivates = new String[] {""};
      }

      String topicable = permissionTab.getOwnersByPermission(TOPICABLE);
      String postable = permissionTab.getOwnersByPermission(POSTABLE);
      String viewer = permissionTab.getOwnersByPermission(VIEWER);

      topicable = ForumUtils.removeSpaceInString(topicable);
      postable = ForumUtils.removeSpaceInString(postable);
      viewer = ForumUtils.removeSpaceInString(viewer);

      String erroUser = UserHelper.checkValueUser(topicable);
      erroUser = UserHelper.checkValueUser(topicable);
      if (!ForumUtils.isEmpty(erroUser)) {
        warning(
            "NameValidator.msg.erroUser-input",
            new String[] {uiForm.getLabel(TOPICABLE), erroUser});
        return;
      }
      erroUser = UserHelper.checkValueUser(postable);
      if (!ForumUtils.isEmpty(erroUser)) {
        warning(
            "NameValidator.msg.erroUser-input", new String[] {uiForm.getLabel(POSTABLE), erroUser});
        return;
      }
      erroUser = UserHelper.checkValueUser(viewer);
      if (!ForumUtils.isEmpty(erroUser)) {
        warning(
            "NameValidator.msg.erroUser-input", new String[] {uiForm.getLabel(VIEWER), erroUser});
        return;
      }

      String[] setTopicable = ForumUtils.splitForForum(topicable);
      String[] setPostable = ForumUtils.splitForForum(postable);
      String[] setViewer = ForumUtils.splitForForum(viewer);

      String userName = uiForm.getUserProfile().getUserId();
      UIForumPortlet forumPortlet = uiForm.getAncestorOfType(UIForumPortlet.class);
      boolean isNew = true;
      Category cat = new Category();
      if (!ForumUtils.isEmpty(uiForm.categoryId)) {
        cat = uiForm.getForumService().getCategory(uiForm.categoryId);
        if (cat == null) {
          warning("UIForumPortlet.msg.catagory-deleted", false);
          forumPortlet.cancelAction();
          forumPortlet.renderForumHome();
          event.getRequestContext().addUIComponentToUpdateByAjax(forumPortlet);
          return;
        }
        isNew = false;
      }
      cat.setOwner(userName);
      cat.setCategoryName(categoryTitle.trim());
      cat.setCategoryOrder(Long.parseLong(categoryOrder));
      cat.setCreatedDate(new Date());
      cat.setDescription(description);
      cat.setModifiedBy(userName);
      cat.setModifiedDate(new Date());
      cat.setUserPrivate(userPrivates);
      cat.setModerators(moderators);
      cat.setCreateTopicRole(setTopicable);
      cat.setPoster(setPostable);
      cat.setViewer(setViewer);

      UICategoryContainer categoryContainer = forumPortlet.getChild(UICategoryContainer.class);
      try {
        uiForm.getForumService().saveCategory(cat, isNew);
        List<String> invisibleCategories = forumPortlet.getInvisibleCategories();
        if (!invisibleCategories.isEmpty()) {
          List<String> invisibleForums = forumPortlet.getInvisibleForums();
          invisibleCategories.add(cat.getId());
          String listForumId = UICategoryForm.listToString(invisibleForums);
          String listCategoryId = UICategoryForm.listToString(invisibleCategories);
          ForumUtils.savePortletPreference(listCategoryId, listForumId);
          forumPortlet.loadPreferences();
        }
        UICategory uiCategory = categoryContainer.getChild(UICategory.class);
        uiCategory.setIsEditForum(true);
        uiCategory.updateByBreadcumbs(cat.getId());
        categoryContainer.updateIsRender(false);
        forumPortlet.updateIsRendered(ForumUtils.CATEGORIES);
        forumPortlet.findFirstComponentOfType(UIBreadcumbs.class).setUpdataPath(cat.getId());
      } catch (Exception e) {
        warning("UIForumPortlet.msg.catagory-deleted", false);
        forumPortlet.renderForumHome();
      }
      forumPortlet.cancelAction();
      uiForm.isDoubleClickSubmit = true;
      event.getRequestContext().addUIComponentToUpdateByAjax(forumPortlet);
    }