/** * 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)); }
topicDraftService.getDraft(), new TopicDraft());
/** * 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; }
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; }
public static TopicDraft getDefaultTopicDraft() { TopicDraft draft = new TopicDraft(getDefaultUser(), RandomStringUtils.random(5), RandomStringUtils.random(15)); draft.setPollTitle(RandomStringUtils.random(5)); draft.setPollItemsValue(RandomStringUtils.random(5) + "\n" + RandomStringUtils.random(5)); draft.setTopicType(TopicTypeName.DISCUSSION.getName()); draft.setBranchId(1L); return draft; }