Example #1
0
  /** {@inheritDoc} */
  public final void update() {
    clearErrors();
    // do custom update
    doUpdate();

    // update binder
    binder.update();

    if (errors != null
        && binder.getBindingResult() != null
        && errors.getObjectName().equals(binder.getBindingResult().getObjectName()))
      errors.addAllErrors(binder.getBindingResult());

    // update subviews
    for (View<T> v : subViews) {
      v.update();
      if (errors != null
          && v.getBindingResult() != null
          && errors.getObjectName().equals(v.getBindingResult().getObjectName()))
        errors.addAllErrors(v.getBindingResult());
    }

    // allow subclasses to do something after the update
    afterUpdate();
  }
  @RequestMapping(value = "/shift/{shiftId}/edit", method = RequestMethod.POST)
  public ModelAndView editShift(
      @PathVariable("shiftId") final Integer shiftId,
      @Valid @ModelAttribute("shift") Shift shift,
      BindingResult result) {
    ModelAndView mav = new ModelAndView();

    if (result.hasErrors()) {
      return new ModelAndView("shift/create", "shift", shift);
    }

    Event event = eventService.get(shift.getEvent().getId());

    // Set Dates to today
    shift.setStartTime(convertDateToToday(shift.getStartTime(), event.getDate()));
    shift.setEndTime(convertDateToToday(shift.getEndTime(), event.getDate()));

    try {
      shiftService.edit(shift);
    } catch (NotValidException e) {
      LOGGER.warn(e);
      result.addAllErrors(e.getErrors());
      return new ModelAndView("shift/create", "shift", shift);
    }

    return new ModelAndView("redirect:/event/" + shift.getEvent().getId() + "/edit");
  }
Example #3
0
  @CacheEvict(value = "users", allEntries = true)
  @Transactional(propagation = Propagation.NOT_SUPPORTED)
  public List<User> bulkDeleteUser(UserBulkDeleteRequest bulkDeleteForm, BindingResult result) {
    List<User> users = new ArrayList<>();
    for (long id : bulkDeleteForm.getIds()) {
      final UserDeleteRequest deleteRequest = new UserDeleteRequest.Builder().id(id).build();

      final BeanPropertyBindingResult r = new BeanPropertyBindingResult(deleteRequest, "request");
      r.setMessageCodesResolver(messageCodesResolver);

      TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
      transactionTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW);
      User user = null;
      try {
        user =
            transactionTemplate.execute(
                new TransactionCallback<User>() {
                  public User doInTransaction(TransactionStatus status) {
                    try {
                      return deleteUser(deleteRequest, r);
                    } catch (BindException e) {
                      throw new RuntimeException(e);
                    }
                  }
                });
        users.add(user);
      } catch (Exception e) {
        logger.debug("Errors: {}", r);
        result.addAllErrors(r);
      }
    }
    return users;
  }