Ejemplo n.º 1
0
 /**
  * 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 {
   Branch branch = branchService.get(branchId);
   Topic topic = new Topic();
   topic.setBranch(branch);
   TopicDto dto = new TopicDto(topic);
   return new ModelAndView(CODE_REVIEW_VIEW)
       .addObject(TOPIC_DTO, dto)
       .addObject(BRANCH_ID, branchId)
       .addObject(SUBMIT_URL, "/reviews/new?branchId=" + branchId)
       .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getNewTopicBreadcrumb(branch));
 }
 /**
  * Deactivates branch updates subscription for the current user
  *
  * @param id identifies branch to unsubscribe from
  * @throws NotFoundException if no object is found for id given
  */
 @RequestMapping("branches/{id}/unsubscribe")
 @ResponseBody
 public ModelAndView unsubscribeFromBranch(
     @PathVariable Long id,
     @RequestHeader(value = "X-Requested-With", defaultValue = "NotAjax") String header)
     throws NotFoundException {
   Branch branch = branchService.get(id);
   subscriptionService.toggleBranchSubscription(branch);
   if (header.equals("NotAjax")) {
     // redirect to new page
     return new ModelAndView("redirect:/branches/" + id);
   } else {
     // no redirecting, perform AJAX request
     return null;
   }
 }
Ejemplo n.º 3
0
  /**
   * Create code review from data entered in form
   *
   * @param topicDto object with data from form
   * @param result {@link BindingResult} validation result
   * @param branchId branch, where topic will be created
   * @return {@code ModelAndView} object which will be redirect to forum.html
   * @throws NotFoundException when branch not found
   */
  @RequestMapping(value = "/reviews/new", method = RequestMethod.POST)
  public ModelAndView createCodeReview(
      @Valid @ModelAttribute TopicDto topicDto,
      BindingResult result,
      @RequestParam(BRANCH_ID) Long branchId)
      throws NotFoundException {
    Branch branch = branchService.get(branchId);
    if (result.hasErrors()) {
      return new ModelAndView(CODE_REVIEW_VIEW)
          .addObject(TOPIC_DTO, topicDto)
          .addObject(BRANCH_ID, branchId)
          .addObject(SUBMIT_URL, "/reviews/new?branchId=" + branchId)
          .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getForumBreadcrumb(branch));
    }
    Topic topic = topicDto.getTopic();
    topic.setBranch(branch);
    Topic createdTopic = topicModificationService.createCodeReview(topic, topicDto.getBodyText());

    return new ModelAndView(REDIRECT_URL + createdTopic.getId());
  }