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; }