Ejemplo n.º 1
0
  /**
   * This method used to edit already created user
   *
   * @param userId
   * @param model
   * @return
   */
  @RequestMapping(value = "/editUserPage", method = RequestMethod.GET)
  public String editUser(
      String userId, ModelMap model, HttpServletResponse response, HttpSession session) {

    try {
      Users user = userService.getUserByUserId(Integer.parseInt(userId));
      List<Roles> roleInfoList = userService.getRoleInfo();
      model.addAttribute("roleInfoList", roleInfoList);
      model.addAttribute("user", user);
      model.addAttribute("headers", "Modify User");
      model.addAttribute("Save", "Modify");
    } catch (Exception e) {
      log.error("Exception in editUser::" + ExceptionUtils.getStackTrace(e));
    }
    return "createUserPage";
  }
Ejemplo n.º 2
0
  /**
   * This method used for getting the information of user
   *
   * @param userId
   * @param model
   * @param response
   */
  @RequestMapping(value = "/getUserInfo", method = RequestMethod.POST)
  public void getUserByUserId(
      int userId, ModelMap model, HttpServletResponse response, HttpSession session) {
    UserSessionInfo userSession =
        (UserSessionInfo) session.getAttribute(ApplicationConstants.USER_SESSION_KEY);
    try {
      SimpleDateFormat dobFormat = new SimpleDateFormat("MM/dd/yyyy");
      Users user = new Users();
      if (user.getUserId() != userId) {
        user = userService.getUserByUserId(userId);

        if (user != null && user.getUserId() > 0) {

          JSONObject jsonObject = new JSONObject();
          jsonObject.put("confirmPassword", user.getPassword());
          jsonObject.put("email", user.getEmailId().toString());
          jsonObject.put("extn1", "" + user.getExtn1());
          jsonObject.put("extn2", "" + user.getExtn2());
          jsonObject.put("firstName", user.getFirstName().toString());
          jsonObject.put("lastName", user.getLastName().toString());
          jsonObject.put("role", user.getRoles().getRoleName());
          jsonObject.put("mobileNumber1", user.getMobileNumber1().toString());
          jsonObject.put("mobileNumber2", "" + user.getMobileNumber2());
          jsonObject.put("password", user.getPassword().toString());
          jsonObject.put("active", user.getStatus().toString());
          jsonObject.put("userName", user.getUserName().toString());
          jsonObject.put("workingPhone1", user.getWorkingPhone1().toString());
          jsonObject.put("workingPhone2", "" + user.getWorkingPhone2());
          jsonObject.put("department", "" + user.getDepartment());
          jsonObject.put("employeeId", "" + user.getEmployeeId());

          response.getWriter().write(jsonObject.toString());
        } else {
          log.error("UserId not found::::" + userId);
        }
      }
    } catch (Exception e) {
      log.error("Exception in getUserByUserId::" + ExceptionUtils.getStackTrace(e));
    }
  }
Ejemplo n.º 3
0
  /**
   * This method used to delete the user
   *
   * @param userId
   * @param response
   * @param model
   * @return
   */
  @RequestMapping(value = "/deleteUserInfo", method = RequestMethod.GET)
  public String deleteUser(
      int userId,
      HttpServletResponse response,
      ModelMap model,
      HttpSession session,
      HttpServletRequest request) {
    try {
      boolean result = false;
      Users user = userService.getUserByUserId(userId);
      if (user != null) {
        result = userService.deleteUser(user);
      }

      if (result) {
        model.addAttribute("response", "User \"" + user.getUserName() + "\" deleted successfully");
        model.addAttribute("errorresponse", "");
      } else {
        model.addAttribute("response", "");
        model.addAttribute("errorresponse", "Failed to delete user!");
      }

    } catch (Exception e) {
      log.error("Exception in deleteUser::" + ExceptionUtils.getStackTrace(e));
      model.addAttribute("response", "");
      model.addAttribute("errorresponse", "Failed to delete user!");
    }

    UserSessionInfo user = null;

    if (request.getSession().getAttribute(ApplicationConstants.USER_SESSION_KEY) != null) {
      user =
          (UserSessionInfo)
              request.getSession().getAttribute(ApplicationConstants.USER_SESSION_KEY);
    }
    return "usersList";
  }