private Category createCategory(String id) { Category cat = new Category(id); cat.setOwner("root"); cat.setCategoryName("testCategory"); cat.setCategoryOrder(1); cat.setCreatedDate(new Date()); cat.setDescription("desciption"); cat.setModifiedBy("root"); cat.setModifiedDate(new Date()); return cat; }
@Override public void inject(HashMap<String, String> params) throws Exception { // int number = param(params, NUMBER); int from = param(params, FROM_USER); int to = param(params, TO_USER); String userPrefix = params.get(USER_PREFIX); String categoryPrefix = params.get(CATEGORY_PREFIX); init(userPrefix, categoryPrefix, null, null, null, 0); // for (int i = from; i <= to; ++i) { for (int j = 0; j < number; ++j) { // String owner = userBase + i; String categoryName = categoryName(); Category cat = new Category(); cat.setOwner(owner); cat.setCategoryName(categoryName); cat.setCategoryOrder(i); cat.setCreatedDate(new Date()); cat.setDescription(categoryName + " desciption"); cat.setModifiedBy(owner); cat.setModifiedDate(new Date()); forumService.saveCategory(cat, true); ++categoryNumber; // getLog().info("Category '" + categoryName + "' created by " + owner); } } }
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); }