Example #1
0
  private void injectCategory() throws Exception {
    //
    String categoryName = categoryBase + toType;
    Category cat = getCategoryByName(categoryName);
    if (cat == null) {
      getLog()
          .info(
              "category name is '"
                  + categoryName
                  + "' is wrong. Please set it exactly. Aborting injection ...");
      return;
    }

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

    //
    cat = forumService.getCategory(cat.getId());
    cat.setModerators(userNames);
    cat.setCreateTopicRole(userNames);
    cat.setViewer(userNames);
    cat.setPoster(userNames);

    forumService.saveCategory(cat, false);
    getLog()
        .info(
            "Assign permission '"
                + Arrays.toString(userNames)
                + "' user(s) into '"
                + categoryName
                + "' category.");
  }
Example #2
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);
  }
Example #3
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);
    }