/** * 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()); }
/** * 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); }
/** * 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()]); }
/** * {@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; }
/** * @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 ""; } }