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 int getUserPostCount(JCUser user) { int count = 0; for (Post post : getPosts()) { if (post.getUserCreated().equals(user)) { count ++; } } return count; }
public static Branch getDefaultBranchWithTopic(Long id, Topic topic) { Branch branch = getDefaultBranch(id); branch.addTopic(topic); topic.setBranch(branch); return branch; }
public static TopicDraft getDefaultTopicDraft() { JCUser user = persist(ObjectsFactory.getDefaultUser()); Branch branch = persist(ObjectsFactory.getDefaultBranch()); TopicDraft newTopicDraft = new TopicDraft(user, RandomStringUtils.random(5), RandomStringUtils.random(15)); newTopicDraft.setTopicType(TopicTypeName.DISCUSSION.getName()); newTopicDraft.setBranchId(branch.getId()); persist(newTopicDraft); return newTopicDraft; }
/** * Returns first unread post for current user. If no unread post * information has been set explicitly this method will return * first topic's post id, considering all topic as unread. * * @return returns first unread post id for the current user */ public Long getFirstUnreadPostId() { if (isHasUpdates()) { return getFirstNewerPost(lastReadPostDate).getId(); } return getFirstPost().getId(); }
/** * {@inheritDoc} * * <p> * The target URL has the next format http://{forum root}/posts/{id} */ @Override public String getUrlSuffix() { return URL_SUFFIX + getLastPost().getId(); }
/** * {@inheritDoc} */ @Override public Set<JCUser> getSubscribers() { return getTopic().getSubscribers(); }
public static Post getPostWithComments() { Post post = new Post(getDefaultUser(), "test"); post.addComment(new PostComment()); post.addComment(new PostComment()); return post; } }
/** * @return content of the first post of the topic */ public String getBodyText() { Post firstPost = getFirstPost(); return firstPost.getPostContent(); }
/** * {@inheritDoc} */ @Override public <T extends SubscriptionAwareEntity> String getUnsubscribeLinkForSubscribersOf(Class<T> clazz) { return getTopic().getUnsubscribeLinkForSubscribersOf(clazz); }
public static UserContact getDefaultUserContact() { UserContactType type = new UserContactType(); UserContact contact = new UserContact("value", type); contact.setOwner(ObjectsFactory.getDefaultUser()); return contact; }
/** * Check - sending notification is allow * * @param user User for which we check allow sending pm notification * @return flag with value (send or not) */ private boolean isSendNotificationMessage(JCUser user) { return (sendingNotificationsEnabledProperty.booleanValue() && user.isSendPmNotification()); }
/** * Create the PrivateMessage with filled required fields. * * @return ready to save instance */ public static PrivateMessage getDefaultPrivateMessage() { JCUser userTo = persist(ObjectsFactory.getUser("UserTo", "mail2@mail.com")); JCUser userFrom = persist(ObjectsFactory.getUser("UserFrom", "mail1@mail.com")); return new PrivateMessage(userTo, userFrom, "Message title", "Private message body"); }
public static PollItem createDefaultVotingOption() { Poll voting = createDefaultVoting(); persist(voting); PollItem option = new PollItem("First voting option"); voting.addPollOptions(option); return option; }
public static JCUser getDefaultUserWithGroups() { List<Group> groups = ObjectsFactory.getDefaultGroupList(); for (Group group : groups) { persist(group); } JCUser user = ObjectsFactory.getDefaultUser(); user.setGroups(groups); persist(user); return user; }
public static Branch getDefaultBranch() { Branch branch = ObjectsFactory.getDefaultBranch(); return persist(branch); }
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(); }
/** * Checks if this topic contains only posts added by topic Owner. * * @return <code>true</code> if condition is followed, otherwise <code>false</code> */ public boolean isContainsOwnerPostsOnly() { for (Post post : getPosts()) { if (!post.getUserCreated().equals(topicStarter)) { return false; } } return true; }