/** * Add topic to branch. * * @param topic topic */ public void addTopic(Topic topic) { topic.setBranch(this); this.topics.add(topic); }
public static Branch getDefaultBranchWithTopic(Long id, Topic topic) { Branch branch = getDefaultBranch(id); branch.addTopic(topic); topic.setBranch(branch); return branch; }
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; }
Branch branch = branchService.get(branchId); final Topic topic = topicDto.getTopic(); topic.setBranch(branch); topic.setType(TopicTypeName.CODE_REVIEW.getName());
/** * Shows page with form for new code review * * @param branchId {@link Branch} branch, where code review will be created * @return {@code ModelAndView} object with "codeReviewForm" view, new {@link TopicDto} and branch id * @throws NotFoundException when branch was not found */ @RequestMapping(value = "/reviews/new", method = RequestMethod.GET) public ModelAndView showNewCodeReviewPage(@RequestParam(BRANCH_ID) Long branchId) throws NotFoundException { TopicDraft draft = ObjectUtils.defaultIfNull( topicDraftService.getDraft(), new TopicDraft()); TopicDto dto = new TopicDto(draft); Branch branch = branchService.get(branchId); dto.getTopic().setBranch(branch); dto.getTopic().setType(TopicTypeName.CODE_REVIEW.getName()); return new ModelAndView(CODE_REVIEW_VIEW) .addObject(TOPIC_DTO, dto) .addObject(TOPIC_DRAFT, draft) .addObject(BRANCH_ID, branchId) .addObject(SUBMIT_URL, "/reviews/new?branchId=" + branchId) .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getNewTopicBreadcrumb(branch)); }
/** * Shows page with form for new topic * * @param branchId {@link Branch} branch, where topic will be created * @return {@code ModelAndView} object with "newTopic" view, new {@link TopicDto} and branch id * @throws NotFoundException when branch was not found */ @RequestMapping(value = "/topics/new", method = RequestMethod.GET) public ModelAndView showNewTopicPage(@RequestParam(BRANCH_ID) Long branchId) throws NotFoundException { TopicDraft topicDraft = ObjectUtils.defaultIfNull( topicDraftService.getDraft(), new TopicDraft()); TopicDto dto = new TopicDto(topicDraft); Branch branch = branchService.get(branchId); dto.getTopic().setBranch(branch); dto.getTopic().setType(TopicTypeName.DISCUSSION.getName()); return new ModelAndView(TOPIC_VIEW) .addObject(TOPIC_DTO, dto) .addObject(TOPIC_DRAFT, topicDraft) .addObject(BRANCH_ID, branchId) .addObject(SUBMIT_URL, "/topics/new?branchId=" + branchId) .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getNewTopicBreadcrumb(branch)); }
topic.setBranch(branch); Topic createdTopic = retryTemplate.execute(new RetryCallback<Topic, NotFoundException>() { @Override
Branch branch = getPluginBranchService().get(branchId); Map<String, Object> data = getDefaultModel(request); topicDto.getTopic().setBranch(branch); topicDto.getTopic().setType(QuestionsAndAnswersPlugin.TOPIC_TYPE); if (result.hasErrors()) {
if (result.hasErrors()) { topicDto.getTopic().setId(topic.getId()); topicDto.getTopic().setBranch(topic.getBranch()); VelocityEngine engine = new VelocityEngine(getProperties()); engine.init();
/** * Shows question creation page * * @param branchId id of the branch in which user want to create question * @param model model for transferring to jsp * @param request HttpServletRequest * * @return plugin view name * @throws NotFoundException if branch with specified id not found */ @RequestMapping(value = "new", method = RequestMethod.GET) public String showNewQuestionPage(@RequestParam(BRANCH_ID) Long branchId, Model model, HttpServletRequest request) throws NotFoundException { VelocityEngine engine = new VelocityEngine(getProperties()); engine.init(); TopicDraft draft = ObjectUtils.defaultIfNull( getPluginTopicDraftService().getDraft(), new TopicDraft()); TopicDto dto = new TopicDto(draft); dto.getTopic().setType(QuestionsAndAnswersPlugin.TOPIC_TYPE); Branch branch = getPluginBranchService().get(branchId); dto.getTopic().setBranch(branch); Map<String, Object> data = getDefaultModel(request); data.put(BREADCRUMB_LIST, breadcrumbBuilder.getForumBreadcrumb(dto.getTopic())); data.put(TOPIC_DTO, dto); data.put(TOPIC_DRAFT, draft); data.put(HTML_ESCAPER, htmlEscaper); data.put(EDIT_MODE, false); model.addAttribute(CONTENT, getMergedTemplate(engine, QUESTION_FORM_TEMPLATE_PATH, "UTF-8", data)); return PLUGIN_VIEW_NAME; }
topic.setAnnouncement(topicDto.isAnnouncement()); topic.setSticked(topicDto.isSticked()); topic.setBranch(topicDto.getBranch()); if (topicDto.isCodeReview()) { bodyText = wrapWithCodeTag(bodyText); topic.setType(topicDto.getType()); topic.addPost(first); topic.setBranch(branch); branch.setLastPost(first);