Esempio n. 1
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";
  }
Esempio n. 2
0
  /**
   * This method will show create user form.
   *
   * @param model
   * @param request
   * @return createUserPage page
   */
  @RequestMapping(value = "/createUser", method = RequestMethod.GET)
  public String createUser(ModelMap model, HttpServletRequest request) {
    try {
      Users user = new Users();
      user.setStatus(false);

      UserSessionInfo userSessionInfo = null;
      if (request.getSession().getAttribute(ApplicationConstants.USER_SESSION_KEY) != null) {
        userSessionInfo =
            (UserSessionInfo)
                request.getSession().getAttribute(ApplicationConstants.USER_SESSION_KEY);
      }

      List<Roles> roleInfoList = userService.getRoleInfo();
      model.addAttribute("roleInfoList", roleInfoList);

      model.addAttribute("user", user);
      model.addAttribute("headers", "Create User");
      model.addAttribute("Save", "Save");
    } catch (Exception e) {
      log.error("Exception in createUser::" + ExceptionUtils.getStackTrace(e));
    }
    return "createUserPage";
  }
Esempio n. 3
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));
    }
  }
Esempio n. 4
0
  /**
   * This Method used to save the newly created user
   *
   * @param user
   * @param result
   * @param model
   * @param session
   * @param locale
   * @return
   */
  @RequestMapping(value = "/saveNewUser", method = RequestMethod.POST)
  public String saveUser(
      @ModelAttribute("user") Users user,
      BindingResult result,
      ModelMap model,
      HttpSession session,
      Locale locale) {

    UserSessionInfo userSessionInfo =
        (UserSessionInfo) session.getAttribute(ApplicationConstants.USER_SESSION_KEY);
    List<Roles> roleInfoList = null;
    try {
      createUserValidator.userValidate(user, result, userSessionInfo);

      if (!result.hasErrors()) {
        // Save
        int UserId = userService.saveUser(user);

        if (UserId == 0) {
          log.info("User " + user.getUserName() + " save failed.");
          model.addAttribute(
              "Error",
              messageSource.getMessage(
                  "user.save.failure", new String[] {user.getUserName()}, locale));
          model.addAttribute("user", user);
          model.addAttribute("roleInfoList", roleInfoList);
          model.addAttribute("headers", "Create User");
          if (user.getUserId() != 0) {
            model.addAttribute("Save", "Modify");
          } else {
            model.addAttribute("Save", "Save");
          }

          return "createUserPage";

        } else {
          log.info("User " + user.getUserName() + " saved successfully.");
          model.addAttribute("response", "User \"" + user.getUserName() + "\" saved successfully");
          model.addAttribute("errorresponse", "");
          model.addAttribute("searchUserName", "");
          model.addAttribute("headers", "Users");
          return "usersList";
        }

      } else {

        roleInfoList = userService.getRoleInfo();
        model.addAttribute("roleInfoList", roleInfoList);
        model.addAttribute("headers", "Create User");
        if (user.getUserId() != 0) {
          model.addAttribute("Save", "Modify");
        } else {
          model.addAttribute("Save", "Save");
        }
        return "createUserPage";
      }

    } catch (Exception e) {
      model.addAttribute("user", user);
      model.addAttribute("response", "");
      model.addAttribute("errorresponse", "Failed to save user!");
      model.addAttribute("roleInfoList", roleInfoList);
      model.addAttribute("headers", "Create User");
      model.addAttribute("Save", "Save");
      log.error("Exception in saveUser::" + ExceptionUtils.getStackTrace(e));
    }
    model.addAttribute(
        "Error",
        messageSource.getMessage("user.save.failure", new String[] {user.getUserName()}, locale));
    return "createUserPage";
  }