Exemplo n.º 1
0
 private Topic createCodeReviewWithLockHandling(Topic topic, TopicDto topicDto)
     throws NotFoundException {
   for (int i = 0; i < UserController.LOGIN_TRIES_AFTER_LOCK; i++) {
     try {
       return topicModificationService.createTopic(topic, topicDto.getBodyText());
     } catch (HibernateOptimisticLockingFailureException e) {
     }
   }
   try {
     return topicModificationService.createTopic(topic, topicDto.getBodyText());
   } catch (HibernateOptimisticLockingFailureException e) {
     LOGGER.error(
         "User has been optimistically locked and can't be reread {} times. Username: {}",
         UserController.LOGIN_TRIES_AFTER_LOCK,
         userService.getCurrentUser().getUsername());
     throw e;
   }
 }
Exemplo n.º 2
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());
  }