/** * {@inheritDoc} * * <p> * The target URL has the next format http://{forum root}/branches/{id} */ @Override public String getUrlSuffix() { return URL_SUFFIX + getId(); }
/** * {@inheritDoc} */ @Override public Branch deleteAllTopics(long branchId) throws NotFoundException { Branch branch = get(branchId); // Create tmp list to avoid ConcurrentModificationException List<Topic> loopList = new ArrayList<>(branch.getTopics()); for (Topic topic : loopList) { topicService.deleteTopicSilent(topic.getId()); } logger.info("All topics for branch \"{}\" were deleted. " + "Branch id: {}", branch.getName(), branch.getId()); return branch; }
/** * Fill the branch breadcrumb. * * @param branch {@link org.jtalks.jcommune.model.entity.Branch} of the breadcrumbed topic. * @return {@link Breadcrumb} the filled breadcrumb for the Topic location. */ private Breadcrumb prepareTopicBreadcrumb(Branch branch) { return new Breadcrumb( branch.getId(), BreadcrumbLocation.BRANCH, branch.getName()); }
topic.addPost(first); topic.setBranch(branch); branch.setLastPost(first); topicDraftService.deleteDraft(); logger.debug("Created new topic id={}, branch id={}, author={}", new Object[]{topic.getId(), topic.getBranch().getId(), currentUser.getUsername()}); return topic;
/** * Displays last messages for the branch. * * @return {@code ModelAndView} with post list and vars for pagination */ @RequestMapping("/branches/{branchId}/recent") public ModelAndView recentBranchPostsPage(@PathVariable("branchId") long branchId) throws NotFoundException { branchService.checkIfBranchExists(branchId); Branch branch = branchService.get(branchId); List<Post> posts = postService.getLastPostsFor(branch, RECENT_POST_COUNT); return new ModelAndView("posts/recent") .addObject("feedTitle", branch.getName()) .addObject("feedDescription", branch.getDescription()) .addObject("urlSuffix", branch.getUrlSuffix()) .addObject("posts", posts); }
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(); }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#componentId, 'COMPONENT', 'GeneralPermission.ADMIN')") public void createNewBranch(long componentId, long sectionId, String title, String description) { Section section = sectionDao.get(sectionId); Branch branch = new Branch(title, description); branch.setSection(section); section.addOrUpdateBranch(branch); sectionDao.saveOrUpdate(section); //add default permission to view topics (for group Registered users) Group registeredUsersGroup = groupDao.getGroupByName(AdministrationGroup.USER.getName()); Collection<Group> groups = Arrays.asList(registeredUsersGroup); PermissionChanges permissionChanges = new PermissionChanges(BranchPermission.VIEW_TOPICS, groups, Collections.<Group>emptyList()); permissionService.changeGrants(branch, permissionChanges); }
/** * {@inheritDoc} */ @Override public void toggleBranchSubscription(Branch branch) { JCUser current = userService.getCurrentUser(); if (branch.getSubscribers().contains(current)) { branch.getSubscribers().remove(current); } else { branch.getSubscribers().add(current); } branchDao.saveOrUpdate(branch); }
/** * @param entity entity like "Branch/Topics" * @return title for Topic/Branch or "" if entity is not instanceof Topic/Branch */ private String getTitleName(Entity entity) { if (entity instanceof Topic) { Topic topic = (Topic) entity; return ": " + topic.getTitle(); } else if (entity instanceof Branch) { Branch branch = (Branch) entity; return ": " + branch.getName(); } else if (entity instanceof Post) { Post post = (Post) entity; return ": " + post.getTopic().getTitle(); } else { return ""; } }
/** * {@inheritDoc} */ @PreAuthorize("hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.MOVE_TOPICS')") @Override public void moveTopic(Topic topic, Long branchId) throws NotFoundException { Branch sourceBranch = topic.getBranch(); Branch targetBranch = branchDao.get(branchId); if (targetBranch == null) { throw new NotFoundException("Target branch not exist"); } targetBranch.addTopic(topic); branchDao.saveOrUpdate(targetBranch); List<Post> topicPosts = topic.getPosts(); if (topicPosts.contains(sourceBranch.getLastPost())) { branchLastPostService.refreshLastPostInBranch(sourceBranch); } branchLastPostService.refreshLastPostInBranch(targetBranch); notificationService.sendNotificationAboutTopicMoved(topic); logger.info("Moved topic \"{}\". Topic id: {}", topic.getTitle(), topic.getId()); }
/** * {@inheritDoc} */ @Override public <T extends SubscriptionAwareEntity> String getUnsubscribeLinkForSubscribersOf(Class<T> clazz) { if (Branch.class.isAssignableFrom(clazz)) { return getBranch().getUnsubscribeLinkForSubscribersOf(clazz); } else { //In case of post unsubscribe from topic too return String.format("/topics/%s/unsubscribe", getId()); } }
public static Branch getDefaultBranchWithTopic(Long id, Topic topic) { Branch branch = getDefaultBranch(id); branch.addTopic(topic); topic.setBranch(branch); return branch; }
public static Branch getDefaultBranch() { return new Branch("branch name", "branch description"); }
public static Section getDefaultSectionWithBranch(Branch branch) { Section section = getDefaultSection(); branch.setSection(section); section.addOrUpdateBranch(branch); return section; }
/** * Converts branch list into branch dto array. * * @param branches branch list * @return branch dto array */ private BranchDto[] convertBranchesListToBranchDtoArray(List<Branch> branches) { List<BranchDto> dtos = project(branches, BranchDto.class, on(Branch.class).getId(), on(Branch.class).getName()); return dtos.toArray(new BranchDto[dtos.size()]); }
/** * 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 public void unsubscribeFromBranch(Branch branch) { JCUser current = userService.getCurrentUser(); if (branch.getSubscribers().contains(current)) { branch.getSubscribers().remove(current); } branchDao.saveOrUpdate(branch); }
/** * Send email about new topic in the subscribed branch. * * @param subscriber recipient * @param topic newly created topic */ void sendTopicCreationMail(JCUser subscriber, Topic topic) { try { String urlSuffix = getTopicUrlSuffix(topic); String url = this.getDeploymentRootUrl() + urlSuffix; Locale locale = subscriber.getLanguage().getLocale(); Map<String, Object> model = new HashMap<>(); model.put(LINK, url); model.put(LINK_UNSUBSCRIBE, this.getDeploymentRootUrl() + topic.getBranch().getUnsubscribeLinkForSubscribersOf(Branch.class)); model.put(LINK_LABEL, getDeploymentRootUrlWithoutPort() + urlSuffix); sendEmailOnForumUpdates(subscriber, model, locale, topic.getBranch(), "subscriptionNotification.subject", "branchSubscriptionNotification.vm"); } catch (MailingFailedException e) { LOGGER.error("Failed to sent mail about creation topic for user: " + subscriber.getUsername()); } }
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; }