예제 #1
0
  /**
   * Posts a reply to a topic
   *
   * @param topic the topic which will receive the reply
   * @param post the reply itself
   * @param attachments
   */
  @Override
  public void reply(Topic topic, Post post, List<AttachedFile> attachments) {
    Topic current = this.topicRepository.get(topic.getId());

    if (StringUtils.isEmpty(post.getSubject())) {
      post.setSubject(current.getSubject());
    }

    this.performReplyValidations(post);
    this.attachmentService.insertAttachments(attachments, post);

    if (attachments.size() > 0) {
      current.setHasAttachment(true);
    }

    topic.setForum(current.getForum());

    post.setTopic(current);
    post.setDate(new Date());
    post.setForum(current.getForum());

    this.postRepository.add(post);

    if (!post.isWaitingModeration()) {
      current.setLastPost(post);
      current.getForum().setLastPost(post);
      current.incrementTotalReplies();
      post.getUser().incrementTotalPosts();
    }
  }
예제 #2
0
  /**
   * Create a new topic. Saves a topic, as well the related first post. Date, user and subject of
   * the associated post are forced to be the same value used by the topic.
   *
   * @param topic the topic to save
   * @param pollOptions
   * @param attachments
   */
  @Override
  public void addTopic(Topic topic, List<PollOption> pollOptions, List<AttachedFile> attachments) {
    this.performAddValidations(topic);

    if (topic.getDate() == null) {
      topic.setDate(new Date());
    }

    Post post = topic.getFirstPost();
    topic.setFirstPost(null);

    this.pollService.associatePoll(topic, pollOptions);

    topic.setHasAttachment(attachments.size() > 0);
    this.topicRepository.add(topic);

    post.setForum(topic.getForum());
    post.setTopic(topic);
    post.setDate(topic.getDate());
    post.setUser(topic.getUser());
    post.setSubject(topic.getSubject());

    this.attachmentService.insertAttachments(attachments, post);
    this.postRepository.add(post);

    topic.setFirstPost(post);
    topic.setLastPost(post);

    if (!topic.isWaitingModeration()) {
      Forum forum = this.forumRepository.get(topic.getForum().getId());
      forum.setLastPost(post);

      int userTotalPosts = this.userRepository.getTotalPosts(post.getUser());
      topic.getUser().setTotalPosts(userTotalPosts);
    }
  }