public static List<Post> createAndSavePostList(int size) { List<Post> posts = new ArrayList<>(); Topic topic = PersistedObjectsFactory.getDefaultTopic(); JCUser author = topic.getTopicStarter(); for (int i = 0; i < size - 1; i++) { Post newPost = new Post(author, "content " + i); topic.addPost(newPost); posts.add(newPost); session.save(newPost); } session.save(topic); return posts; }
public static Topic getTopic(JCUser author, int numberOfPosts) { Topic topic = new Topic(author, "some topic"); for (int i = 0; i < numberOfPosts; i++) { topic.addPost(new Post(author, "post #" + (i + 1))); } return topic; }
public static List<Topic> topics(JCUser author, int topicCount) { List<Topic> topics = new ArrayList<>(); for (int i = 0; i < topicCount; i++) { Topic topic = new Topic(author, "title", "Discussion"); topic.setBranch(getDefaultBranch()); topic.addPost(new Post(author, "post-content")); topics.add(topic); } return topics; }
public static Post getDefaultPost() { return persist(new Post(persist(ObjectsFactory.getRandomUser()), "post content")); }
public static Post getPostWithComments() { Post post = new Post(getDefaultUser(), "test"); post.addComment(new PostComment()); post.addComment(new PostComment()); return post; } }
public static Topic getDefaultTopic() { JCUser user = persist(ObjectsFactory.getDefaultUser()); Branch branch = ObjectsFactory.getDefaultBranch(); Topic newTopic = new Topic(user, "topic title", "Discussion"); Post post = new Post(user, "post content"); newTopic.addPost(post); branch.addTopic(newTopic); persist(branch); return newTopic; }
public static List<Topic> createAndSaveTopicList(int size) { org.jtalks.jcommune.model.entity.Branch branch = ObjectsFactory.getDefaultBranch(); JCUser user = persist(ObjectsFactory.getDefaultUser()); for (int i = 0; i < size; i++) { Topic topic = new Topic(user, "title" + i, "Discussion"); topic.addPost(new Post(user, "post_context" + i)); branch.addTopic(topic); } persist(branch); return branch.getTopics(); }
/** * Create the Topics with posts. * * @return saved topics */ public static List<Topic> createAndSaveTopicListWithPosts(int size) { org.jtalks.jcommune.model.entity.Branch branch = ObjectsFactory.getDefaultBranch(); JCUser user = persist(ObjectsFactory.getRandomUser()); for (int i = 0; i < size; i++) { Topic topic = new Topic(user, "title" + i, "Discussion"); topic.addPost(new Post(topic.getTopicStarter(), "content")); branch.addTopic(topic); } persist(branch); return branch.getTopics(); }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#branchId, 'BRANCH', 'BranchPermission.CREATE_POSTS')") public Post replyToTopic(long topicId, String answerBody, long branchId) throws NotFoundException { Topic topic = topicFetchService.getTopicSilently(topicId); this.assertPostingIsAllowed(topic); JCUser currentUser = userService.getCurrentUser(); currentUser.setPostCount(currentUser.getPostCount() + 1); Post answer = new Post(currentUser, answerBody); topic.addPost(answer); topic.removeDraftOfUser(currentUser); if (currentUser.isAutosubscribe()){ subscriptionService.subscribe(topic); } postDao.saveOrUpdate(answer); Branch branch = topic.getBranch(); branch.setLastPost(answer); branchDao.saveOrUpdate(branch); dao.saveOrUpdate(topic); securityService.createAclBuilder().grant(GeneralPermission.WRITE).to(currentUser).on(answer).flush(); notificationService.subscribedEntityChanged(topic); userService.notifyAndMarkNewlyMentionedUsers(answer); logger.debug("New post in topic. Topic id={}, Post id={}, Post author={}", new Object[]{topicId, answer.getId(), currentUser.getUsername()}); return answer; }
bodyText = wrapWithCodeTag(bodyText); Post first = new Post(currentUser, bodyText); topic.setType(topicDto.getType()); topic.addPost(first);