コード例 #1
0
  /**
   * Displays a Discussion Thread page
   *
   * <p>- Requires a cookie for the session user - Requires a threadId request parameter for the
   * HTTP GET
   *
   * @param req The HTTP Request
   * @param res The HTTP Response
   */
  public void discussionAction(HttpServletRequest req, HttpServletResponse res) {
    // Ensure there is a cookie for the session user
    if (AccountController.redirectIfNoCookie(req, res)) return;

    Map<String, Object> viewData = new HashMap<>();

    if (req.getMethod() == HttpMethod.Get) {

      // Get the thread
      GroupManager gm = new GroupManager();
      int threadId = Integer.parseInt(req.getParameter("threadId"));
      DiscussionManager discussionManager = new DiscussionManager();
      DiscussionThread thread = discussionManager.getThread(threadId);
      thread.setGroup(gm.get(thread.getGroupId()));
      thread.setPosts(discussionManager.getPosts(threadId));

      // get documents for the thread
      DocumentManager docMan = new DocumentManager();
      viewData.put("documents", docMan.getDocumentsForThread(threadId));

      viewData.put("thread", thread);
      viewData.put("title", "Discussion: " + thread.getThreadName());
      view(req, res, "/views/group/DiscussionThread.jsp", viewData);
    } else {
      httpNotFound(req, res);
    }
  }
コード例 #2
0
  public void summaryAction(HttpServletRequest req, HttpServletResponse res) {
    if (AccountController.redirectIfNoCookie(req, res)) return;

    Map<String, Object> viewData = new HashMap<String, Object>();
    DocumentManager docMan = new DocumentManager();

    try {

      if (req.getParameter("documentId") != null) {
        // Get the document ID
        int docId = Integer.parseInt(req.getParameter("documentId"));
        // Get the document using document id
        Document document = docMan.get(docId);
        // Set title to name of the document
        viewData.put("title", document.getDocumentName());
        // Create List of access records
        List<AccessRecord> accessRecords = new LinkedList<AccessRecord>();
        // Add access records for document to the list
        accessRecords = docMan.getAccessRecords(docId);

        viewData.put("accessRecords", accessRecords);
      } else {
        // Go back to thread page.
      }

    } catch (Exception e) {
      Logger.getLogger("").log(Level.SEVERE, "An error occurred when getting profile user", e);
    }

    view(req, res, "/views/group/Document.jsp", viewData);
  }
コード例 #3
0
ファイル: DbSpamManager.java プロジェクト: jbossorg/sbs-spam
  @Audit
  @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
  @Override
  public void reportSpammersContent(User spammer, User reporter, String comment) {
    if (log.isInfoEnabled()) {
      log.info(
          "Reporting SPAM Abuse on all content of of this spammer: "
              + spammer.getUsername()
              + ". Reporter is: "
              + reporter.getUsername());
    }

    final Date reportDate = new Date();

    Iterable<Document> docs = documentManager.getUserDocuments(spammer, documentStates);
    for (Document document : docs) {
      if (log.isTraceEnabled()) {
        log.trace("Report spam of document: " + document.getDocumentID());
      }
      reportSpam(document, reporter, comment, reportDate);
    }

    Iterable<ForumMessage> messages = forumManager.getUserMessages(spammer);
    for (ForumMessage message : messages) {
      if (log.isTraceEnabled()) {
        log.trace(
            "Report spam of message: "
                + message.getID()
                + ", threadId: "
                + message.getForumThreadID());
      }
      // TODO: Check how works root messages (threads)
      reportSpam(message, reporter, comment, reportDate);
    }

    List<Blog> blogs = blogManager.getExplicitlyEntitledBlogs(spammer);
    for (Blog blog : blogs) {
      if (blog.isUserBlog()) {
        Iterator<BlogPost> blogPosts = blogManager.getBlogPosts(blog);
        while (blogPosts.hasNext()) {
          BlogPost blogPost = blogPosts.next();
          if (log.isTraceEnabled()) {
            log.trace("Report spam for Blog post, id: " + blogPost.getID());
          }
          reportSpam(blogPost, reporter, comment, reportDate);
        }
      }
    }
    Iterator<Favorite> favorites =
        favoriteManager.getUserFavorites(spammer, Sets.newHashSet(externalUrlObjectType));
    while (favorites.hasNext()) {
      Favorite favorite = favorites.next();
      JiveObject favoritedObject = favorite.getObjectFavorite().getFavoritedObject();
      if (log.isTraceEnabled()) {
        log.trace("Report spam Favorite (Bookmark) to external URL: " + favorite.getID());
        log.trace("Favorited object: " + favoritedObject);
      }
      reportSpam(favoritedObject, reporter, comment, reportDate);
    }
  }
コード例 #4
0
  /**
   * Displays a given Research Group page for a HTTP Get, or creates a new Group for a HTTP Post
   *
   * <p>- Requires a cookie for the session user - Requires a groupId request parameter for a GET -
   * Requires a groupName, description, createdByUserId request parameters for a POST
   *
   * @param req The HTTP Request
   * @param res The HTTP Response
   */
  public void researchgroupAction(HttpServletRequest req, HttpServletResponse res) {
    // Ensure there is a cookie for the session user
    if (AccountController.redirectIfNoCookie(req, res)) return;

    Map<String, Object> viewData = new HashMap<String, Object>();
    viewData.put("title", "Research Group");

    if (req.getMethod() == HttpMethod.Get) {
      // Load group data into Map
      GroupManager gm = new GroupManager();
      int groupId = Integer.parseInt(req.getParameter("groupId"));
      Group group = gm.get(groupId);

      if (group != null) {
        // Load Group into map
        viewData.put("group", group);

        // Load group members into Map
        List<String> groupMembers = gm.getGroupMembers(groupId);
        viewData.put("groupMembers", groupMembers);

        // Load meetings into map
        MeetingManager meetMan = new MeetingManager();
        List<Meeting> groupMeetings = meetMan.getGroupMeetings(groupId);
        viewData.put("groupMeetings", groupMeetings);

        // Load Document Data into Map
        DocumentManager docMan = new DocumentManager();
        List<Document> groupDocuments = docMan.getGroupDocuments(groupId);
        viewData.put("groupDocuments", groupDocuments);

        // Load discussion threads
        DiscussionManager dm = new DiscussionManager();
        viewData.put("groupDiscussions", dm.getThreads(groupId));

        // Check if the user is a member
        boolean isMember = false;
        HttpSession session = req.getSession();
        Session userSession = (Session) session.getAttribute("userSession");
        User user = userSession.getUser();

        for (Group g : gm.getAllGroups(user.getId())) {
          if (g.getId() == group.getId()) {
            isMember = true;
            break;
          }
        }

        viewData.put("notMember", !isMember);

        // View group page.
        view(req, res, "/views/group/ResearchGroup.jsp", viewData);

      } else {
        httpNotFound(req, res);
      }

    } else if (req.getMethod() == HttpMethod.Post) {
      // Create Group

      // Get data from parameters
      String groupName = req.getParameter("groupName");
      String description = req.getParameter("description");
      int adminId = Integer.parseInt(req.getParameter("createdByUserId"));

      // Create the Group
      GroupManager groupMan = new GroupManager();
      Group group = new Group();
      group.setGroupName(groupName);
      group.setDescription(description);
      group.setCoordinatorId(adminId);
      // Create the mapping
      groupMan.createGroup(group);
      int groupId = groupMan.getIdFor(group);
      groupMan.createMapping(groupId, adminId);

      group.setId(groupId);

      // Update the User Session to show new group
      HttpSession session = req.getSession();
      Session userSession = (Session) session.getAttribute("userSession");
      User admin = userSession.getUser();
      admin.getGroups().add(group);

      // Show the Group Page
      viewData.put("groupName", group.getGroupName());
      List<String> groupMembers = groupMan.getGroupMembers(groupId);
      viewData.put("groupMembers", groupMembers);

      view(req, res, "/views/group/ResearchGroup.jsp", viewData);
    }
  }
コード例 #5
0
  /**
   * Displays the Create Discussion page for a HTTP Get, or creates a Discussion Thread for a HTTP
   * Post
   *
   * <p>- Requires a cookie for the session user - Requires a groupId request parameter for a GET -
   * Requires a groupId and threadName request parameter for a POST - Requires a document request
   * part for a POST
   *
   * @param req The HTTP Request
   * @param res The HTTP Response
   */
  public void createDiscussionAction(HttpServletRequest req, HttpServletResponse res) {
    // Ensure there is a cookie for the session user
    if (AccountController.redirectIfNoCookie(req, res)) return;

    Map<String, Object> viewData = new HashMap<>();

    if (req.getMethod() == HttpMethod.Get) {
      viewData.put("title", "Create Discussion");
      viewData.put("groupId", req.getParameter("groupId"));

      view(req, res, "/views/group/CreateDiscussion.jsp", viewData);
      return;
    } else if (req.getMethod() == HttpMethod.Post) {
      // save discussion
      GroupManager groupMan = new GroupManager();
      DiscussionThread thread = new DiscussionThread();
      int groupId = Integer.parseInt(req.getParameter("groupId"));
      thread.setGroupId(groupId);
      thread.setGroup(groupMan.get(groupId));
      thread.setThreadName(req.getParameter("threadName"));

      DiscussionManager dm = new DiscussionManager();
      dm.createDiscussion(thread);

      try {
        Part documentPart = req.getPart("document");

        // if we have a document to upload
        if (documentPart.getSize() > 0) {
          String uuid = DocumentController.saveDocument(this.getServletContext(), documentPart);
          Document doc = new Document();
          doc.setDocumentName(getFileName(documentPart));
          doc.setDocumentPath(uuid);
          doc.setVersionNumber(1);
          doc.setThreadId(thread.getId());
          doc.setGroupId(thread.getGroupId());

          DocumentManager docMan = new DocumentManager();
          docMan.createDocument(doc);

          // Get uploading User
          HttpSession session = req.getSession();
          Session userSession = (Session) session.getAttribute("userSession");
          User uploader = userSession.getUser();

          // Create a notification to all in the group
          NotificationManager notificationMan = new NotificationManager();
          groupMan = new GroupManager();
          List<User> groupUsers = groupMan.getGroupUsers(groupId);

          for (User u : groupUsers) {
            Notification notification =
                new Notification(
                    u.getId(),
                    u,
                    groupId,
                    null,
                    "User " + uploader.getFullName() + " has uploaded a document",
                    "/document/document?documentId=" + doc.getId());

            notificationMan.createNotification(notification);
          }
        }
      } catch (Exception e) {
        logger.log(Level.SEVERE, "Document save error", e);
      }

      redirectToLocal(req, res, "/group/discussion/?threadId=" + thread.getId());
      return;
    }
    httpNotFound(req, res);
  }
コード例 #6
0
ファイル: DbSpamManager.java プロジェクト: jbossorg/sbs-spam
  @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;
  }
コード例 #7
0
ファイル: DbSpamManager.java プロジェクト: jbossorg/sbs-spam
  @Audit
  @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
  @Override
  public void resolveContentAsSpam(User spammer, User moderator) {
    if (log.isInfoEnabled()) {
      log.info("Resolve SPAM reports on all content of of this user: "******"Resolve Documents");
    Iterable<Document> docs = documentManager.getUserDocuments(spammer, documentStatesToResolve);
    for (Document document : docs) {
      if (log.isTraceEnabled()) {
        log.trace("Resolve Report spam of document: " + document.getDocumentID());
      }
      resolveSpamReport(document, moderator);
    }

    log.debug("Resolve Threads");
    ThreadResultFilter moderationFilter = ThreadResultFilter.createDefaultUserMessagesFilter();
    moderationFilter.setStatus(JiveContentObject.Status.ABUSE_HIDDEN);

    Iterable<ForumMessage> messages = forumManager.getUserMessages(spammer, moderationFilter);
    List<Long> resolvedThreads = new ArrayList<Long>();

    for (ForumMessage message : messages) {
      if (log.isTraceEnabled()) {
        log.trace(
            "Resolve Report spam of message: "
                + message.getID()
                + ", threadId: "
                + message.getForumThreadID());
      }
      ForumThread thread = message.getForumThread();
      if (!resolvedThreads.contains(thread.getID())) {
        resolvedThreads.add(thread.getID());
        if (thread.getUser().getUsername().equals(spammer.getUsername())) {
          if (log.isTraceEnabled()) {
            log.trace("Resolve Report spam of thread: " + thread.getID());
          }
          resolveSpamReport(thread, moderator);
        }
      }
      resolveSpamReport(message, moderator);
    }

    log.debug("Resolve Blogs");
    Iterable<Blog> blogs = blogManager.getExplicitlyEntitledBlogs(spammer);
    for (Blog blog : blogs) {
      if (log.isTraceEnabled()) {
        log.trace("Processing blog: " + blog.getName());
      }
      if (blog.isUserBlog()) {
        Iterator<BlogPost> blogPosts = getBlogPosts(blog, JiveContentObject.Status.ABUSE_HIDDEN);
        while (blogPosts.hasNext()) {
          BlogPost blogPost = blogPosts.next();
          if (log.isTraceEnabled()) {
            log.trace("Resolve Report spam Blog post: " + blogPost.getID());
          }
          resolveSpamReport(blogPost, moderator);
        }
      }
    }

    log.trace("Resolve Bookmarks");
    Iterator<Favorite> favorites =
        favoriteManager.getUserFavorites(spammer, Sets.newHashSet(externalUrlObjectType));
    while (favorites.hasNext()) {
      Favorite favorite = favorites.next();
      JiveObject favoritedObject = favorite.getObjectFavorite().getFavoritedObject();
      if (log.isTraceEnabled()) {
        log.trace("Resolve Report spam Favorite (Bookmark) to external URL: " + favorite.getID());
        log.trace(
            "Favorited object, id: "
                + favoritedObject.getID()
                + ", type: "
                + favoritedObject.getObjectType());
      }
      resolveSpamReport(favoritedObject, moderator);
    }
  }