Esempio n. 1
0
  @Override
  public boolean hasSomeContent(User author, JiveContentObject newObject) {

    ModerationHelper moderationHelper = JiveApplication.getContext().getModerationHelper();

    // Note: hasSomeContent expects its interceptor to be TYPE_POST (called
    // AFTER creating a content),
    // thus a number of existing content on time of creating a first content
    // is always one.

    // check for Messages and Threads (root discussions and questions):
    int messagesCount = forumManager.getUserMessageCount(author);
    log.info("hasSomeContent Messages size: " + messagesCount);

    // moderation-safe message addition:
    // for each user-added message check whether the message is moderated
    // if all found messages are moderated, send a new content to moderation
    if (messagesCount > 0) {
      for (ForumMessage m : forumManager.getUserMessages(author)) {

        // forumManager.getUserMessages() also returns message being
        // inserted when triggering interceptor
        if (!moderationHelper.isInModeration(m) && !m.equals(newObject)) {
          if (log.isDebugEnabled()) {
            log.debug(
                "message "
                    + m.getPlainSubject()
                    + " does not equal to the message to be inserted and is not moderated: returns true");
          }
          return true;
        }
      }
    }

    // check for documents
    int documentsCount = documentManager.getUserDocumentCount(author, documentStates);
    log.info("hasSomeContent: Documents size: " + documentsCount);

    // moderation-safe edition: similar to messages
    if (documentsCount >= 1) {
      for (Document d : documentManager.getUserDocuments(author, documentStates)) {
        if (!moderationHelper.isInModeration(d) && d.getID() != newObject.getID()) {
          if (log.isDebugEnabled()) {
            log.debug(
                "document: "
                    + d.getPlainSubject()
                    + "is not the document to be inserted and is not moderated: hasSomeContent returns true");
          }
          return true;
        }
      }
    }

    // check for blogposts:
    // Note: Blogpost edit does not trigger interceptor
    for (Blog b : blogManager.getExplicitlyEntitledBlogs(author)) {
      if (b.getContributors().contains(author)) {

        Iterator<BlogPost> blogIterator = blogManager.getBlogPosts(b);
        while (blogIterator.hasNext()) {
          BlogPost existingPost = blogIterator.next();

          if (existingPost.getID() != newObject.getID()
              && !moderationHelper.isInModeration(existingPost)) {
            if (log.isDebugEnabled()) {
              log.debug(
                  "hasSomeContent: Blog size > 0: "
                      + existingPost.getSubject()
                      + " is not moderated and is not the one being inserted: hasSomeContent returns true");
            }
            return true;
          }
        }
      }
    }
    log.debug("hasSomeContent: Blog size: 0");

    // Types not triggering interceptor, thus not considered:
    // Poll, File, Task, Bookmark, Status update

    return false;
  }