Пример #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
  /**
   * Makes the current user to unwatch a specific topic
   *
   * @param topicId the id of the topic to unwatch
   */
  @SecurityConstraint(value = AuthenticatedRule.class, displayLogin = true)
  public void unwatch(long topicId) {
    Topic topic = new Topic();
    topic.setId(topicId);

    this.watchService.unwatch(topic, userSession.getUser());
    this.result.redirectTo(this).list(topicId);
  }
Пример #3
0
  /**
   * Makes the current logged user watch a specific topic.
   *
   * @param topicId the id of the topic to watch
   */
  @SecurityConstraint(value = AuthenticatedRule.class, displayLogin = true)
  public void watch(long topicId) {
    Topic topic = new Topic();
    topic.setId(topicId);

    UserSession userSession = this.userSession;

    this.watchService.watch(topic, userSession.getUser());
    this.result.redirectTo(Actions.LIST + "/" + topicId);
  }
  @Test
  public void deleted() {
    final Topic topic = new Topic();
    topic.setId(2);

    context.checking(
        new Expectations() {
          {
            one(repository).removeSubscription(topic);
          }
        });

    event.deleted(topic);
    context.assertIsSatisfied();
  }
Пример #5
0
  private void performAddValidations(Topic topic) {
    if (topic.getUser() == null) {
      throw new IllegalStateException("Cannot save a topic without an user");
    }

    if (StringUtils.isEmpty(topic.getSubject())) {
      throw new IllegalStateException("Cannot save a topic without a subject");
    }

    if (topic.getForum().getId() == 0) {
      throw new IllegalStateException("Cannot save a Topic without a forum");
    }

    this.performCommonPostValidations(topic.getFirstPost());
  }
Пример #6
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);
    }
  }