@RequestMapping("/edit") public String editPage( @RequestParam String action, @RequestParam(required = false) Long id, Model model) { model.addAttribute("authority", loggedinUserRole()); model.addAttribute("action", action); // ParkingJ user related. // Set allowed parking if (id == null) { model.addAttribute("allowedParkingArea", allowedParkingArea(id)); model.addAttribute("user", new UserDto()); model.addAttribute("updateMode", false); } else { UserDto dbUser = userBusinessLogic.findOneById(id); // ParkingJ user related. // Set allowed parking model.addAttribute("allowedParkingArea", allowedParkingArea(dbUser.getAccountId())); // Set first allowed parking before setting to model List<Long> selectedParkingArea = parkingUserBusinessLogic.findByUserId(dbUser.getId()).getAllowedParkingArea(); dbUser.setSelectedParkingArea(selectedParkingArea); ; // End. model.addAttribute("user", dbUser); model.addAttribute("updateMode", true); } return EDIT_PAGE; }
@RequestMapping("/changepassword") public String changePasswordPage(@RequestParam Long id, Model model) { model.addAttribute("authority", loggedinUserRole()); UserDto user = userBusinessLogic.findOneById(id); user.setConfirmPassword(""); user.setPassword(""); model.addAttribute("user", user); return USER_CHANGE_PASS_PAGE; }
private Collection<UserDto> removedLoggedInUserInList(long userID, final List<UserDto> users) { Collection<UserDto> filtered = null; if (null != users && !users.isEmpty()) { filtered = new ArrayList<>(users); for (Iterator<UserDto> iterator = filtered.iterator(); iterator.hasNext(); ) { UserDto userDto = iterator.next(); if (userDto.getId() == userID) { iterator.remove(); } } } return filtered; }
private String update(UserDto user, RedirectAttributes redir, Model model) { try { userBusinessLogic.update(user); redir.addFlashAttribute( "message", String.format("Successfully updated user \"%s\". ", user.getFullName())); updateParkingUser(user); } catch (Exception e) { model.addAttribute("message", e.getMessage()); model.addAttribute("user", userBusinessLogic.findOneById(user.getId())); model.addAttribute("action", "UPDATE"); return EDIT_PAGE; } return REDIRECT_MAIN_PAGE; }
@RequestMapping(value = "/changepassword", method = RequestMethod.POST) public String changePassword( @ModelAttribute UserDto user, RedirectAttributes redir, Model model) { model.addAttribute("authority", loggedinUserRole()); try { userBusinessLogic.updatePassword(user); redir.addFlashAttribute( "message", String.format("Successfully updated password of user \"%s\". ", user.getFullName())); } catch (Exception e) { model.addAttribute("message", e.getMessage()); model.addAttribute("user", userBusinessLogic.findOneById(user.getId())); return USER_CHANGE_PASS_PAGE; } return REDIRECT_MAIN_PAGE; }
private String create(UserDto user, RedirectAttributes redir, Model model) { try { UserDto dbUser = userBusinessLogic.create(user); redir.addFlashAttribute( "message", String.format("Successfully created user \"%s\". ", user.getFullName())); createParkingUser(dbUser, user); } catch (Exception e) { model.addAttribute("message", e.getMessage()); model.addAttribute("user", new UserDto()); model.addAttribute("action", "CREATE"); return EDIT_PAGE; } return REDIRECT_MAIN_PAGE; }
private void updateParkingUser(UserDto user) { ParkingUserDto currentParkingUser = parkingUserBusinessLogic.findByUserId(user.getId()); currentParkingUser.setAllowedParkingArea(user.getSelectedParkingArea()); parkingUserBusinessLogic.update(currentParkingUser); }
private void createParkingUser(UserDto dbUser, UserDto user) { ParkingUserDto parkingUser = new ParkingUserDto(dbUser.getId()); parkingUser.setAllowedParkingArea(user.getSelectedParkingArea()); parkingUserBusinessLogic.create(parkingUser); }