Guest User

Untitled

a guest
May 2nd, 2017
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.83 KB | None | 0 0
  1. package com.accenture.adf.businesstier.controller;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import javax.servlet.http.HttpServletRequest;
  7. import javax.servlet.http.HttpServletResponse;
  8. import javax.servlet.http.HttpSession;
  9.  
  10. import org.apache.log4j.Logger;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.servlet.ModelAndView;
  14.  
  15. import com.accenture.adf.businesstier.entity.Event;
  16. import com.accenture.adf.businesstier.entity.Visitor;
  17. import com.accenture.adf.businesstier.service.EventFacade;
  18. import com.accenture.adf.businesstier.service.EventServiceImpl;
  19. import com.accenture.adf.businesstier.service.VisitorFacade;
  20. import com.accenture.adf.businesstier.service.VisitorServiceImpl;
  21. import com.accenture.adf.exceptions.FERSGenericException;
  22.  
  23. /**
  24. * <br/>
  25. * CLASS DESCRIPTION: <br/>
  26. * A controller class for receiving and handling all visitor related transactions from the
  27. * User Interface including visitor account access, visitor account maintenance,
  28. * and visitor event registration requests. <br/>
  29. *
  30. */
  31.  
  32. @Controller
  33. public class VisitorController {
  34.  
  35. private static Logger log = Logger.getLogger(VisitorController.class);
  36.  
  37. /**
  38. * <br/>
  39. * METHOD DESCRIPTION: <br/>
  40. * This method will receive request from Registration.jsp and directs to
  41. * service class to register new Visitor into system
  42. * by accepting details and persist into database <br/>
  43. *
  44. * @param request (type HttpServletRequest)
  45. * @param response (type HttpServletResponse)
  46. *
  47. * @return ModelAndView
  48. *
  49. * @throws FERSGenericException
  50. *
  51. *
  52. */
  53.  
  54.  
  55. @RequestMapping("/newVisitor")
  56. public ModelAndView newVisitor(HttpServletRequest request,
  57. HttpServletResponse response) throws Exception {
  58. if(request==null || response==null)
  59. {
  60. log.info("Request or Response failed for NEWVISITOR METHOD..");
  61. throw new FERSGenericException("Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder", new NullPointerException());
  62. }
  63. String username=request.getParameter("USERNAME");
  64. String password=request.getParameter("PASSWORD");
  65. String firstname=request.getParameter("FIRSTNAME");
  66. String lastname=request.getParameter("LASTNAME");
  67. String email=request.getParameter("EMAIL");
  68. String phoneno=request.getParameter("PHONENO");
  69. String place=request.getParameter("PLACE");
  70. System.out.println("Parameter got successfully!!");
  71. log.info("creating new visitor with UserName :"+username);
  72.  
  73. Visitor visitor=new Visitor();
  74. visitor.setUserName(username);
  75. visitor.setPassword(password);
  76. visitor.setFirstName(firstname);
  77. visitor.setLastName(lastname);
  78. visitor.setEmail(email);
  79. visitor.setPhoneNumber(phoneno);
  80. visitor.setAddress(place);
  81.  
  82. VisitorFacade vServiceImpl=new VisitorServiceImpl();
  83. boolean insertStatus=vServiceImpl.createVisitor(visitor);
  84. System.out.println(" create visitor1 successfully!!");
  85. ModelAndView mv=new ModelAndView();
  86. if(insertStatus==true)
  87. {
  88. mv.addObject("REGISTRATIONSTATUSMESSAGE", "User Registered Succesfully !!!");
  89. log.info("Succesfully created visitor "+ username);
  90. System.out.println("visitor created successfully!");
  91. mv.setViewName("/index");
  92.  
  93. }
  94. else
  95. {
  96. mv.addObject("REGISTRATIONSTATUSMESSAGE", "USERNAME already exists.. please register again with different USERNAME..");
  97. log.info("Username "+ username+" already exists and visitor creation failed..");
  98. mv.setViewName("/index");
  99. }
  100. return mv;
  101. }
  102.  
  103. /**
  104. * <br/>
  105. * METHOD DESCRIPTION:<br/>
  106. * The method is for authenticating visitor in the index.jsp page and redirects visitor to
  107. * the homepage based on their credentials. if validation fails, redirects to index.jsp and
  108. * error message is printed on page.<br/>
  109. *
  110. * @param request (type HttpServletRequest)
  111. * @param response (type HttpServletResponse)
  112. *
  113. * @return ModelAndView
  114. *
  115. * @throws FERSGenericException
  116. *
  117. *
  118. */
  119.  
  120. @RequestMapping("/searchVisitor")
  121. public ModelAndView searchVisitor(HttpServletRequest request,
  122. HttpServletResponse response,HttpSession hs) throws Exception {
  123. if(request==null || response==null)
  124. {
  125. System.out.println("request not found");
  126. log.info("Request or Response failed for SEARCHVISITOR METHOD..");
  127. throw new FERSGenericException("Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder", new NullPointerException());
  128. }
  129. System.out.println("get the parameters");
  130. String username=request.getParameter("USERNAME");
  131. String password=request.getParameter("PASSWORD");
  132. System.out.println("got username parameter successfully");
  133. hs=request.getSession();
  134. System.out.println("got session successfulyy");
  135. if(hs.isNew())
  136. {
  137. hs.setAttribute("USERNAME", username);
  138. hs.setAttribute("PASSWORD", password);
  139. }
  140. /* else
  141. { username=(String) hs.getAttribute("USERNAME");
  142. password=(String) hs.getAttribute("PASSWORD");
  143. }*/
  144.  
  145. log.info("Logging into FERS using username :"+username+" and password :"+password);
  146.  
  147. Visitor visitor=new Visitor();
  148. VisitorFacade vServiceImpl=new VisitorServiceImpl();
  149. visitor=vServiceImpl.searchVisitor(username, password);
  150. System.out.println("got username and password successfully");
  151. ModelAndView mv=new ModelAndView();
  152.  
  153. if(visitor.getVisitorId() == 0)
  154. {
  155. mv.addObject("ERROR","Invalid Username / Password.");
  156. System.out.println("invalid username and password");
  157. mv.setViewName("/index");
  158. return mv;
  159. }
  160. else
  161. {
  162. System.out.println("visitor details retrieved successfully");
  163. log.info("Visitor details available for the username :"+username);
  164.  
  165. List<Event> eventList=new ArrayList<Event>();
  166. EventFacade serviceImpl=new EventServiceImpl();
  167. eventList=serviceImpl.getAllEvents();
  168. System.out.println("got events successfully");
  169. log.info("All events listed for th visitor :"+eventList);
  170.  
  171. List<Event> regList=new ArrayList<Event>();
  172. regList=vServiceImpl.showRegisteredEvents(visitor);
  173.  
  174. log.info("All Registered events listed for the visitor :"+regList);
  175.  
  176. HttpSession session=request.getSession();
  177. session.setAttribute("VISITOR", visitor);
  178.  
  179. mv.addObject("visitor",visitor);
  180. mv.addObject("allEvents",eventList);
  181. mv.addObject("regEvents",regList);
  182. mv.setViewName("/visitormain");
  183. return mv;
  184. }
  185. }
  186.  
  187. /**
  188. * <br/>
  189. * METHOD DESCRIPTION:<br/>
  190. * The method is used to register a visitor for an event from visitormain.jsp and maintains the list
  191. * of all the events visitor registered. if user status is already registered for an event, then displays
  192. * error message in visitormain.jsp page.<br/>
  193.  
  194. *
  195. * @param request (type HttpServletRequest)
  196. * @param response (type HttpServletResponse)
  197. *
  198. * @return ModelAndView
  199. *
  200. * @throws FERSGenericException
  201. *
  202. */
  203.  
  204.  
  205. @RequestMapping("/eventreg.htm")
  206. public ModelAndView registerVisitor(HttpServletRequest request,
  207. HttpServletResponse response) throws Exception {
  208. System.out.println("registrion method entered");
  209. if(request==null || response==null)
  210. {
  211. System.out.println("request is null");
  212. log.info("Request or Response failed for REGISTERVISITOR METHOD..");
  213. throw new FERSGenericException("Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder", new NullPointerException());
  214.  
  215. }
  216.  
  217. HttpSession session=request.getSession();
  218. Visitor visitor=(Visitor)session.getAttribute("VISITOR");
  219. int eventid=Integer.parseInt(request.getParameter("eventId"));
  220.  
  221. log.info("Visitor registered for the event :"+eventid);
  222.  
  223. ModelAndView mv=new ModelAndView();
  224.  
  225. VisitorFacade vServiceImpl=new VisitorServiceImpl();
  226. EventFacade serviceImpl=new EventServiceImpl();
  227. System.out.println("go to check events of visitor");
  228. boolean regStatus=serviceImpl.checkEventsofVisitor(visitor, eventid);
  229. System.out.println("returned from checkEvents of visitor");
  230.  
  231. log.info("Status of the visitor for the event :"+regStatus);
  232.  
  233. if(regStatus==false)
  234. {
  235. System.out.println("user is not registerd!! new event for a visitor");
  236. vServiceImpl.RegisterVisitor(visitor, eventid);
  237. vServiceImpl.UpdateEvent(eventid);
  238. System.out.println("user registered for the event successfully");
  239. log.info("Visitor succesfully registed for event :"+eventid);
  240. }
  241. else
  242. {
  243. System.out.println("user is already registered!!");
  244. mv.addObject("RegError", "User already Registered for the EVENT !!");
  245. }
  246.  
  247. List<Event> regList=new ArrayList<Event>();
  248. regList=vServiceImpl.showRegisteredEvents(visitor);
  249.  
  250. List<Event> eventList=new ArrayList<Event>();
  251.  
  252. eventList=serviceImpl.getAllEvents();
  253.  
  254.  
  255. mv.addObject("visitor",visitor);
  256. mv.addObject("allEvents",eventList);
  257. mv.addObject("regEvents",regList);
  258. mv.setViewName("/visitormain");
  259. return mv;
  260.  
  261. }
  262.  
  263. /**
  264. * <br/>
  265. * METHOD DESCRIPTION:<br/>
  266. * The method will update account details of the visitor and logout the visitor
  267. * and to force the visitor to re-login and confirm the updated account details
  268. * and new password.<br/>
  269. *
  270. * @param request (type HttpServletRequest)
  271. * @param response (type HttpServletResponse)
  272. *
  273. * @return ModelAndView
  274. *
  275. * @throws FERSGenericException
  276. *
  277. */
  278.  
  279. @RequestMapping("/updatevisitor")
  280. public ModelAndView updateVisitor(HttpServletRequest request,
  281. HttpServletResponse response) throws Exception {
  282.  
  283. if(request==null || response==null)
  284. {
  285. log.info("Request or Response failed for UPDATEVISITOR METHOD..");
  286. throw new FERSGenericException("Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder", new NullPointerException());
  287. }
  288.  
  289. HttpSession session=request.getSession();
  290. Visitor visitor=(Visitor)session.getAttribute("VISITOR");
  291.  
  292. log.info("Updating visitor details with VisitorID :"+visitor.getVisitorId());
  293.  
  294. String username=request.getParameter("username");
  295. String password=request.getParameter("password");
  296. String firstname=request.getParameter("firstname");
  297. String lastname=request.getParameter("lastname");
  298. String email=request.getParameter("email");
  299. String phoneno=request.getParameter("phoneno");
  300. String place=request.getParameter("address");
  301.  
  302. visitor.setFirstName(firstname);
  303. visitor.setLastName(lastname);
  304. visitor.setUserName(username);
  305. visitor.setPassword(password);
  306. visitor.setEmail(email);
  307. visitor.setPhoneNumber(phoneno);
  308. visitor.setAddress(place);
  309.  
  310. VisitorFacade vServiceImpl=new VisitorServiceImpl();
  311. int status=vServiceImpl.updateVisitorDetails(visitor);
  312.  
  313. log.info("Number of Visitor records updated is :"+status);
  314.  
  315. ModelAndView mv=new ModelAndView();
  316.  
  317. if(status>0)
  318. {
  319. mv.addObject("status","success");
  320. mv.setViewName("/updatevisitor");
  321. }
  322. else
  323. {
  324. mv.addObject("updatestatus", "Error in updation.. Please Check fields and retry");
  325. mv.setViewName("/updatevisitor");
  326. }
  327. return mv;
  328. }
  329.  
  330. /**
  331. * <br/>
  332. * METHOD DESCRIPTION: <br/>
  333. * The method is to unregisters a visitor from an event within the visitormain.jsp
  334. * page and the seats will be released. The visitormain.jsp page is then refreshed
  335. * to confirm the updates. <br/>
  336. *
  337. * @param request (type HttpServletRequest)
  338. * @param response (type HttpServletResponse)
  339. *
  340. * @return ModelAndView
  341. *
  342. * @throws FERSGenericException
  343. *
  344. */
  345.  
  346. @RequestMapping("/eventunreg.htm")
  347. public ModelAndView unregisterEvent(HttpServletRequest request,
  348. HttpServletResponse response) throws Exception {
  349.  
  350. if(request==null || response==null)
  351. {
  352. log.info("Request or Response failed for UNREGISTEREVENT METHOD..");
  353. throw new FERSGenericException("Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder", new NullPointerException());
  354. }
  355.  
  356. HttpSession session=request.getSession();
  357. Visitor visitor=(Visitor)session.getAttribute("VISITOR");
  358. int eventid=Integer.parseInt(request.getParameter("eventId"));
  359.  
  360. log.info("Unregistering for the event :"+eventid);
  361.  
  362. VisitorFacade vServiceImpl=new VisitorServiceImpl();
  363. vServiceImpl.unregisterEvent(visitor, eventid);
  364.  
  365.  
  366.  
  367. List<Event> regList=new ArrayList<Event>();
  368. regList=vServiceImpl.showRegisteredEvents(visitor);
  369.  
  370. List<Event> eventList=new ArrayList<Event>();
  371. EventFacade serviceImpl=new EventServiceImpl();
  372.  
  373. serviceImpl.updateEventDeletions(eventid);
  374.  
  375. log.info("Seats allocated for the event are released :"+eventid);
  376.  
  377. eventList=serviceImpl.getAllEvents();
  378.  
  379.  
  380.  
  381. ModelAndView mv=new ModelAndView();
  382. mv.addObject("visitor",visitor);
  383. mv.addObject("allEvents",eventList);
  384. mv.addObject("regEvents",regList);
  385. mv.setViewName("/visitormain");
  386. return mv;
  387. }
  388.  
  389.  
  390. }
Add Comment
Please, Sign In to add comment