Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RequestMapping(value = "/edit/{id}", method = RequestMethod.POST)
- public ModelAndView edditingUser(Model model, @ModelAttribute User user,
- BindingResult result, @PathVariable Long id) {
- ModelAndView modelAndView = null;
- try { // tymczasowe, TODO: ustawienie avatara podczas edycji usera
- user.setAvatar(userService.getUser(user.getId()).getAvatar());
- } catch (BusinessException e) {
- log.error("setting old avatar", e);
- }
- UsersValidator userValidator = new UsersValidator();
- userValidator.validate(user, result);
- if (result.hasErrors()) {
- modelAndView = editUserPage(model, id);
- return modelAndView;
- }
- User temp = new User();
- temp.setId(user.getId());
- temp.setBossUser(user.getBossUser());
- try {
- if (userService.getUser(id).getId() == user.getBossUser().getId())
- throw new Exception("new boss, same as the user");
- //TODO: Aktualnie wyszukujemy po wszystkich userach, trzeba to zmienic, najlepiej utworzyc relacje dwustronna
- while(temp.getBossUser() != null)
- {
- if(temp.getId() == userService.getUser(id).getId())
- throw new Exception("hierarchy error");
- temp = temp.getBossUser();
- }
- userService.updateUser(user);
- modelAndView = new ModelAndView("redirect:/user/list");
- String message = "User was successfully edited.";
- modelAndView.addObject("message", message);
- } catch (BusinessException e) {
- log.error("edditingUser", e);
- String message = "We were unable to update user id:" + id
- + " due to: " + e.getLocalizedMessage();
- modelAndView = editUserPage(model, id);
- modelAndView.addObject("message", message);
- } catch (Exception e) {
- String message = "We were unable to update user id:" + id
- + " due to: " + e.getLocalizedMessage();
- modelAndView = editUserPage(model, id);
- modelAndView.addObject("message", message);
- }
- return modelAndView;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement