Пример #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
  private void performCommonPostValidations(Post post) {
    if (StringUtils.isEmpty(post.getSubject())) {
      throw new IllegalStateException("Cannot save a post without a subject");
    }

    if (StringUtils.isEmpty(post.getText())) {
      throw new IllegalStateException("Cannot save a post without a message");
    }
  }
Пример #3
0
  protected void addNewPostText(Post post) throws Exception {
    PreparedStatement p = null;
    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.addNewPostText"));
      int cIndex = 1;
      p.setInt(cIndex++, post.getId());
      p.setString(cIndex++, post.getText());
      p.setString(cIndex++, post.getSubject());

      p.executeUpdate();
    } finally {
      DbUtils.close(p);
    }
  }
Пример #4
0
  protected void updatePostsTextTable(Post post) {
    PreparedStatement p = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.updatePostText"));
      p.setString(1, post.getText());
      p.setString(2, post.getSubject());
      p.setInt(3, post.getId());

      p.executeUpdate();
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(p);
    }
  }