@Override
 public void updatePost(Post post, int type) {
   switch (type) {
     case HIDDEN:
       if (post.getIsHidden() == true) {
         ForumActivityContext ctx = ForumActivityContext.makeContextForUpdatePost(post);
         PostActivityTask task = PostActivityTask.HIDE_POST;
         ActivityExecutor.execute(task, ctx);
       } else {
         ForumActivityContext ctx = ForumActivityContext.makeContextForUpdatePost(post);
         PostActivityTask task = PostActivityTask.UNHIDE_POST;
         ActivityExecutor.execute(task, ctx);
       }
       break;
     case WAITING:
       if (post.getIsWaiting() == true) {
         ForumActivityContext ctx = ForumActivityContext.makeContextForUpdatePost(post);
         PostActivityTask task = PostActivityTask.HIDE_POST;
         ActivityExecutor.execute(task, ctx);
       } else {
         ForumActivityContext ctx = ForumActivityContext.makeContextForUpdatePost(post);
         PostActivityTask task = PostActivityTask.UNHIDE_POST;
         ActivityExecutor.execute(task, ctx);
       }
       break;
     default:
       return;
   }
 }
Example #2
0
  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
  }
Example #3
0
  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())));
      }
    }
  }
Example #4
0
 private Post createdPost() {
   Post post = new Post();
   post.setOwner("root");
   post.setCreatedDate(new Date());
   post.setModifiedBy("root");
   post.setModifiedDate(new Date());
   post.setName("SubJect");
   post.setMessage("content description");
   post.setRemoteAddr("192.168.1.11");
   post.setIcon("classNameIcon");
   post.setIsApproved(true);
   post.setIsActiveByTopic(true);
   post.setIsHidden(false);
   return post;
 }
Example #5
0
    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);
    }
Example #6
0
    public void onEvent(Event<UIPostForm> event, UIPostForm uiForm, String id) throws Exception {
      if (uiForm.isDoubleClickSubmit) return;
      uiForm.isDoubleClickSubmit = true;
      UIForumPortlet forumPortlet = uiForm.getAncestorOfType(UIForumPortlet.class);
      UserProfile userProfile = forumPortlet.getUserProfile();
      try {
        if (forumPortlet.checkForumHasAddPost(uiForm.categoryId, uiForm.forumId, uiForm.topicId)) {
          UIForumInputWithActions threadContent = uiForm.getChildById(FIELD_THREADCONTEN_TAB);
          int t = 0, k = 1;
          String postTitle = threadContent.getUIStringInput(FIELD_POSTTITLE_INPUT).getValue();
          boolean isAddRe = false;
          int maxText = ForumUtils.MAXTITLE;
          if (!ForumUtils.isEmpty(postTitle)) {
            while (postTitle.indexOf(uiForm.getTitle("").trim()) == 0) {
              postTitle = postTitle.replaceFirst(STR_RE.trim(), ForumUtils.EMPTY_STR).trim();
              isAddRe = true;
            }
            if (postTitle.length() > maxText) {
              warning(
                  "NameValidator.msg.warning-long-text",
                  new String[] {uiForm.getLabel(FIELD_POSTTITLE_INPUT), String.valueOf(maxText)});
              uiForm.isDoubleClickSubmit = false;
              return;
            }
          }
          String message = threadContent.getChild(UIFormWYSIWYGInput.class).getValue();
          String checksms =
              TransformHTML.cleanHtmlCode(
                  message,
                  new ArrayList<String>((new ExtendedBBCodeProvider()).getSupportedBBCodes()));
          checksms = checksms.replaceAll("&nbsp;", " ");
          t = checksms.length();
          if (ForumUtils.isEmpty(postTitle)) {
            k = 0;
          }
          if (t > 0 && k != 0 && !checksms.equals("null")) {
            String editReason = threadContent.getUIStringInput(FIELD_EDITREASON_INPUT).getValue();
            if (!ForumUtils.isEmpty(editReason) && editReason.length() > maxText) {
              warning(
                  "NameValidator.msg.warning-long-text",
                  new String[] {uiForm.getLabel(FIELD_EDITREASON_INPUT), String.valueOf(maxText)});
              uiForm.isDoubleClickSubmit = false;
              return;
            }
            String userName = userProfile.getUserId();
            editReason = CommonUtils.encodeSpecialCharInTitle(editReason);
            message = TransformHTML.fixAddBBcodeAction(message);
            message = CommonUtils.encodeSpecialCharInSearchTerm(message);
            postTitle = CommonUtils.encodeSpecialCharInTitle(postTitle);
            Post post = uiForm.post_;
            boolean isPP = false;
            boolean isOffend = false;
            boolean hasTopicMod = false;
            if (!uiForm.isMod()) {
              String[] censoredKeyword = ForumUtils.getCensoredKeyword(uiForm.getForumService());
              checksms = checksms.toLowerCase().trim();
              for (String string : censoredKeyword) {
                if (checksms.indexOf(string.trim()) >= 0) {
                  isOffend = true;
                  break;
                }
                if (postTitle.toLowerCase().indexOf(string.trim()) >= 0) {
                  isOffend = true;
                  break;
                }
              }
              if (post.getUserPrivate() != null && post.getUserPrivate().length == 2) isPP = true;
              if ((!uiForm.isMP || !isPP) && uiForm.topic != null)
                hasTopicMod = uiForm.topic.getIsModeratePost();
            }
            if (isOffend && (uiForm.isMP || isPP)) {
              uiForm.warning("UIPostForm.msg.PrivateCensor");
              uiForm.isDoubleClickSubmit = false;
              return;
            }
            // set link
            String link = ForumUtils.createdForumLink(ForumUtils.TOPIC, uiForm.topicId, false);
            //
            if (uiForm.isQuote || uiForm.isMP) post = new Post();
            post.setName((isAddRe) ? uiForm.getTitle(postTitle) : postTitle);
            post.setMessage(message);
            post.setOwner(userName);
            post.setCreatedDate(new Date());
            post.setIcon("uiIconForumTopic uiIconForumLightGray");
            post.setAttachments(uiForm.getAttachFileList());
            post.setIsWaiting(isOffend);
            post.setLink(link);
            String[] userPrivate = new String[] {"exoUserPri"};
            if (uiForm.isMP) {
              userPrivate = new String[] {userName, uiForm.post_.getOwner()};
              hasTopicMod = false;
            }
            post.setUserPrivate(userPrivate);
            post.setIsApproved(!hasTopicMod);

            UITopicDetailContainer topicDetailContainer =
                forumPortlet.findFirstComponentOfType(UITopicDetailContainer.class);
            UITopicDetail topicDetail = topicDetailContainer.getChild(UITopicDetail.class);
            boolean isParentDelete = false;
            boolean isNew = false;
            try {
              if (!ForumUtils.isEmpty(uiForm.postId)) {
                if (uiForm.isQuote || uiForm.isMP) {
                  post.setRemoteAddr(WebUIUtils.getRemoteIP());
                  try {
                    uiForm
                        .getForumService()
                        .savePost(
                            uiForm.categoryId,
                            uiForm.forumId,
                            uiForm.topicId,
                            post,
                            true,
                            ForumUtils.getDefaultMail());
                    isNew = true;
                  } catch (PathNotFoundException e) {
                    isParentDelete = true;
                  }
                  topicDetail.setIdPostView("lastpost");
                } else {
                  // post.setId(uiForm.postId) ;
                  post.setModifiedBy(userName);
                  post.setModifiedDate(new Date());
                  post.setEditReason(editReason);
                  MessageBuilder messageBuilder = ForumUtils.getDefaultMail();
                  messageBuilder.setLink(link + ForumUtils.SLASH + post.getId());
                  try {
                    uiForm
                        .getForumService()
                        .savePost(
                            uiForm.categoryId,
                            uiForm.forumId,
                            uiForm.topicId,
                            post,
                            false,
                            messageBuilder);
                  } catch (PathNotFoundException e) {
                    isParentDelete = true;
                  }
                  topicDetail.setIdPostView(uiForm.postId);
                }
              } else {
                post.setRemoteAddr(WebUIUtils.getRemoteIP());
                try {
                  uiForm
                      .getForumService()
                      .savePost(
                          uiForm.categoryId,
                          uiForm.forumId,
                          uiForm.topicId,
                          post,
                          true,
                          ForumUtils.getDefaultMail());
                  isNew = true;
                } catch (PathNotFoundException e) {
                  isParentDelete = true;
                } catch (Exception ex) {
                  uiForm.log.warn(String.format("Failed to save post %s", post.getName()), ex);
                }
                topicDetail.setIdPostView("lastpost");
              }
              if (isNew) {
                if (userProfile.getIsAutoWatchTopicIPost()) {
                  List<String> values = new ArrayList<String>();
                  values.add(userProfile.getEmail());
                  String path =
                      uiForm.categoryId
                          + ForumUtils.SLASH
                          + uiForm.forumId
                          + ForumUtils.SLASH
                          + uiForm.topicId;
                  uiForm.getForumService().addWatch(1, path, values, userProfile.getUserId());
                }
              }
              uiForm
                  .getForumService()
                  .updateTopicAccess(forumPortlet.getUserProfile().getUserId(), uiForm.topicId);
              forumPortlet
                  .getUserProfile()
                  .setLastTimeAccessTopic(
                      uiForm.topicId, CommonUtils.getGreenwichMeanTime().getTimeInMillis());
            } catch (Exception e) {
              uiForm.log.warn("Failed to save topic", e);
            }
            uiForm.isMP = uiForm.isQuote = false;
            if (isParentDelete) {
              forumPortlet.cancelAction();
              uiForm.warning("UIPostForm.msg.isParentDelete");
              return;
            }
            forumPortlet.cancelAction();
            if (isOffend || hasTopicMod) {
              topicDetail.setIdPostView("normal");
              if (isOffend) uiForm.warning("MessagePost.msg.isOffend", false);
              else {
                uiForm.warning("MessagePost.msg.isModerate", false);
              }
            }
            event.getRequestContext().addUIComponentToUpdateByAjax(topicDetailContainer);
          } else {
            String[] args = {ForumUtils.EMPTY_STR};
            if (k == 0) {
              args = new String[] {uiForm.getLabel(FIELD_POSTTITLE_INPUT)};
              if (t == 0)
                args =
                    new String[] {
                      uiForm.getLabel(FIELD_POSTTITLE_INPUT)
                          + ", "
                          + uiForm.getLabel(FIELD_MESSAGECONTENT)
                    };
              uiForm.isDoubleClickSubmit = false;
              uiForm.warning("NameValidator.msg.ShortMessage", args);
            } else if (t == 0) {
              args = new String[] {uiForm.getLabel(FIELD_MESSAGECONTENT)};
              uiForm.isDoubleClickSubmit = false;
              uiForm.warning("NameValidator.msg.ShortMessage", args);
            }
          }
        } else {
          forumPortlet.cancelAction();
          forumPortlet.removeCacheUserProfile();
          UITopicDetail topicDetail = forumPortlet.findFirstComponentOfType(UITopicDetail.class);
          topicDetail.initInfoTopic(uiForm.categoryId, uiForm.forumId, uiForm.topic, 0);
          uiForm.warning("UIPostForm.msg.no-permission", false);
          event.getRequestContext().addUIComponentToUpdateByAjax(forumPortlet);
        }
      } catch (Exception e) {
        uiForm.log.error("Can not save post into this topic, exception: " + e.getMessage(), e);
        uiForm.warning("UIPostForm.msg.isParentDelete", false);
        forumPortlet.cancelAction();
      }
    }
Example #7
0
 public void onEvent(Event<UIPostForm> event, UIPostForm uiForm, String id) throws Exception {
   UIForumInputWithActions threadContent = uiForm.getChildById(FIELD_THREADCONTEN_TAB);
   int t = 0, k = 1;
   String postTitle = threadContent.getUIStringInput(FIELD_POSTTITLE_INPUT).getValue();
   String userName = UserHelper.getCurrentUser();
   String message = threadContent.getChild(UIFormWYSIWYGInput.class).getValue();
   String checksms =
       TransformHTML.cleanHtmlCode(
           message, new ArrayList<String>((new ExtendedBBCodeProvider()).getSupportedBBCodes()));
   checksms = checksms.replaceAll("&nbsp;", " ");
   t = checksms.trim().length();
   if (ForumUtils.isEmpty(postTitle)) {
     k = 0;
   }
   if (t > 0 && k != 0 && !checksms.equals("null")) {
     postTitle = CommonUtils.encodeSpecialCharInTitle(postTitle);
     Post post = uiForm.post_;
     post.setName(postTitle);
     post.setMessage(message);
     post.setOwner(userName);
     if (ForumUtils.isEmpty(uiForm.postId)) {
       post.setCreatedDate(CommonUtils.getGreenwichMeanTime().getTime());
       post.setModifiedDate(CommonUtils.getGreenwichMeanTime().getTime());
     }
     post.setModifiedBy(userName);
     post.setRemoteAddr(ForumUtils.EMPTY_STR);
     post.setIcon("uiIconForumTopic uiIconForumLightGray");
     post.setIsApproved(false);
     post.setAttachments(uiForm.getAttachFileList());
     UIPopupContainer popupContainer = uiForm.getAncestorOfType(UIPopupContainer.class);
     UIViewPost viewPost = uiForm.openPopup(popupContainer, UIViewPost.class, 670, 0);
     viewPost.setId("viewPost");
     viewPost.setPostView(post);
     viewPost.setActionForm(new String[] {"Close"});
   } else {
     String[] args = {ForumUtils.EMPTY_STR};
     if (k == 0) {
       args = new String[] {uiForm.getLabel(FIELD_POSTTITLE_INPUT)};
       if (t <= 0)
         args =
             new String[] {
               uiForm.getLabel(FIELD_POSTTITLE_INPUT)
                   + ", "
                   + uiForm.getLabel(FIELD_MESSAGECONTENT)
             };
       uiForm.warning("NameValidator.msg.ShortText", args);
     } else if (t <= 0) {
       args = new String[] {uiForm.getLabel(FIELD_MESSAGECONTENT)};
       uiForm.warning("NameValidator.msg.ShortMessage", args);
     }
   }
 }