Esempio n. 1
0
  private Object getTopic(Long topicId, String siteId, String userId) {

    if (LOG.isDebugEnabled()) {
      LOG.debug("getTopic(" + topicId + "," + siteId + "," + userId + ")");
    }

    // This call gets the attachments for the messages but not the topic. Unexpected, yes. Cool,
    // not.
    DiscussionTopic fatTopic =
        (DiscussionTopic) forumManager.getTopicByIdWithMessagesAndAttachments(topicId);

    if (!uiPermissionsManager.isRead(
        topicId,
        fatTopic.getDraft(),
        false,
        userId,
        forumManager.getContextForTopicById(topicId))) {
      LOG.error("'" + userId + "' is not authorised to read topic '" + topicId + "'.");
      throw new EntityException(
          "You are not authorised to read this topic.", "", HttpServletResponse.SC_UNAUTHORIZED);
    }

    SparseTopic sparseTopic = new SparseTopic(fatTopic);

    // Setup the total and read message counts on the topic
    List<Long> topicIds = new ArrayList<Long>();
    topicIds.add(fatTopic.getId());

    List<Object[]> totalCounts = forumManager.getMessageCountsForMainPage(topicIds);
    if (totalCounts.size() > 0) {
      sparseTopic.setTotalMessages((Integer) totalCounts.get(0)[1]);
    } else {
      sparseTopic.setTotalMessages(0);
    }

    List<Object[]> readCounts = forumManager.getReadMessageCountsForMainPage(topicIds);
    if (readCounts.size() > 0) {
      sparseTopic.setReadMessages((Integer) readCounts.get(0)[1]);
    } else {
      sparseTopic.setReadMessages(0);
    }

    List<SparseMessage> messages = new ArrayList<SparseMessage>();
    for (Message fatMessage : (List<Message>) fatTopic.getMessages()) {
      SparseMessage sparseMessage =
          new SparseMessage(
              fatMessage,
              /* readStatus = */ false,
              /* addAttachments = */ true,
              developerHelperService.getServerURL());
      messages.add(sparseMessage);
    }

    List<SparseThread> threads =
        new MessageUtils().getThreadsWithCounts(messages, forumManager, userId);

    sparseTopic.setThreads(threads);

    return sparseTopic;
  }
Esempio n. 2
0
  private Object getMessage(Long messageId, String siteId, String userId) {

    if (LOG.isDebugEnabled()) {
      LOG.debug("getMessage(" + messageId + "," + siteId + "," + userId + ")");
    }

    Message fatMessage = forumManager.getMessageById(messageId);

    Topic fatTopic =
        forumManager.getTopicByIdWithMessagesAndAttachments(fatMessage.getTopic().getId());

    // This sets the attachments on the message.We have to do this as
    // getMessageById doesn't populate the attachments.
    setAttachments(fatMessage, fatTopic.getMessages());

    if (!uiPermissionsManager.isRead(
        fatTopic.getId(),
        ((DiscussionTopic) fatTopic).getDraft(),
        false,
        userId,
        forumManager.getContextForTopicById(fatTopic.getId()))) {
      LOG.error("'" + userId + "' is not authorised to read message '" + messageId + "'.");
      throw new EntityException(
          "You are not authorised to read this message.", "", HttpServletResponse.SC_UNAUTHORIZED);
    }

    List<SparseMessage> messages = new ArrayList<SparseMessage>();

    for (Message fm : (List<Message>) fatTopic.getMessages()) {
      messages.add(
          new SparseMessage(
              fm,
              /* readStatus =*/ false,
              /* addAttachments =*/ true,
              developerHelperService.getServerURL()));
    }

    SparseMessage sparseThread =
        new SparseMessage(
            fatMessage, false, /* readStatus =*/ true, developerHelperService.getServerURL());

    new MessageUtils().attachReplies(sparseThread, messages, forumManager, userId);

    return sparseThread;
  }