/** * @param map : holds require attributes * @param request :for getting session * @return: to the specified path * @throws QuestionBankSystemException: handle all system related exceptions * @throws QuestionBankException: handle all runtime exceptions */ @RequestMapping(value = "/profile", method = RequestMethod.GET) public ModelAndView getUserForProfile( Map<String, Object> map, HttpServletRequest request, HttpServletResponse response) throws QuestionBankSystemException, QuestionBankException { userService.doSetupForPage(map, ""); // do setup for page int id = getUserId(request); // get id from session ModelAndView modelAndView = null; if (id == 0) { User userResult = new User(); modelAndView = new ModelAndView("home"); modelAndView.addObject(userResult); return modelAndView; // redirecting to home if unauthorized access } else { modelAndView = new ModelAndView("profile"); // redirecting to profile page modelAndView.addObject(userService.getUser(id)); } User user = userService.getUser((int) request.getSession().getAttribute("id")); map = userService.getUserForProfile(user, map); // calling get user for profile return modelAndView; }
/** * @param map : holds require attributes * @param request :for getting session * @return: to the specified path * @throws QuestionBankSystemException: handle all system related exceptions * @throws QuestionBankException: handle all runtime exceptions */ public Map<String, Object> setUserToMap(Map<String, Object> map, HttpServletRequest request) throws QuestionBankSystemException, QuestionBankException { int id = getUserId(request); if (id == 0) { User userResult = new User(); map.put("user", userResult); } else { map.put("user", userService.getUser(id)); } // setting user to map return map; }