Ejemplo n.º 1
0
  @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;
  }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 @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;
 }
Ejemplo n.º 5
0
 private void updateParkingUser(UserDto user) {
   ParkingUserDto currentParkingUser = parkingUserBusinessLogic.findByUserId(user.getId());
   currentParkingUser.setAllowedParkingArea(user.getSelectedParkingArea());
   parkingUserBusinessLogic.update(currentParkingUser);
 }
Ejemplo n.º 6
0
 private void createParkingUser(UserDto dbUser, UserDto user) {
   ParkingUserDto parkingUser = new ParkingUserDto(dbUser.getId());
   parkingUser.setAllowedParkingArea(user.getSelectedParkingArea());
   parkingUserBusinessLogic.create(parkingUser);
 }