Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //visitor controller
- package com.accenture.adf.businesstier.controller;
- import java.util.ArrayList;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import javax.swing.JOptionPane;
- import org.apache.log4j.Logger;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.servlet.ModelAndView;
- import com.accenture.adf.businesstier.entity.Event;
- import com.accenture.adf.businesstier.entity.Visitor;
- import com.accenture.adf.businesstier.service.EventFacade;
- import com.accenture.adf.businesstier.service.EventServiceImpl;
- import com.accenture.adf.businesstier.service.VisitorFacade;
- import com.accenture.adf.businesstier.service.VisitorServiceImpl;
- import com.accenture.adf.exceptions.FERSGenericException;
- /**
- * <br/>
- * CLASS DESCRIPTION: <br/>
- * A controller class for receiving and handling all visitor related transactions from the
- * User Interface including visitor account access, visitor account maintenance,
- * and visitor event registration requests. <br/>
- *
- */
- @Controller
- public class VisitorController {
- private static Logger log = Logger.getLogger(VisitorController.class);
- /**
- * <br/>
- * METHOD DESCRIPTION: <br/>
- * This method will receive request from Registration.jsp and directs to
- * service class to register new Visitor into system
- * by accepting details and persist into database <br/>
- *
- * @param request (type HttpServletRequest)
- * @param response (type HttpServletResponse)
- *
- * @return ModelAndView
- *
- * @throws FERSGenericException
- *
- *
- */
- @RequestMapping("/newVistor.htm")
- public ModelAndView newVisitor(HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- if(request==null || response==null)
- {
- log.info("Request or Response failed for NEWVISITOR METHOD..");
- throw new FERSGenericException("Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder", new NullPointerException());
- }
- String username=request.getParameter("USERNAME");
- String password=request.getParameter("PASSWORD");
- String firstname=request.getParameter("FIRSTNAME");
- String lastname=request.getParameter("LASTNAME");
- String email=request.getParameter("EMAIL");
- String phoneno=request.getParameter("PHONENO");
- String address=request.getParameter("ADDRESS");
- log.info("creating new visitor with UserName :"+username);
- Visitor visitor=new Visitor();
- visitor.setUserName(username);
- visitor.setPassword(password);
- visitor.setFirstName(firstname);
- visitor.setLastName(lastname);
- visitor.setEmail(email);
- visitor.setPhoneNumber(phoneno);
- visitor.setAddress(address);
- VisitorFacade vServiceImpl=new VisitorServiceImpl();
- boolean insertStatus=vServiceImpl.createVisitor(visitor);
- System.out.println("insert status"+insertStatus);
- ModelAndView mv=new ModelAndView();
- if(insertStatus==true)
- {
- mv.addObject("REGISTRATIONSTATUSMESSAGE", "User Registered Succesfully !!!");
- log.info("Succesfully created visitor "+ username);
- mv.setViewName("/registration.jsp");
- }
- else
- {
- mv.addObject("REGISTRATIONSTATUSMESSAGE", "USERNAME already exists.. please register again with different USERNAME..");
- log.info("Username "+ username+" already exists and visitor creation failed..");
- mv.setViewName("/registration.jsp");
- }
- return mv;
- }
- /**
- * <br/>
- * METHOD DESCRIPTION:<br/>
- * The method is for authenticating visitor in the index.jsp page and redirects visitor to
- * the homepage based on their credentials. if validation fails, redirects to index.jsp and
- * error message is printed on page.<br/>
- *
- * @param request (type HttpServletRequest)
- * @param response (type HttpServletResponse)
- *
- * @return ModelAndView
- *
- * @throws FERSGenericException
- *
- *
- */
- @RequestMapping("/searchVisitor.htm")
- public ModelAndView searchVisitor(HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- if(request==null || response==null)
- {
- log.info("Request or Response failed for SEARCHVISITOR METHOD..");
- throw new FERSGenericException("Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder", new NullPointerException());
- }
- String username=request.getParameter("USERNAME");
- String password=request.getParameter("PASSWORD");
- HttpSession hs=request.getSession();
- if(hs.isNew())
- {
- hs.setAttribute("USERNAME", username);
- hs.setAttribute("PASSWORD", password);
- }
- else
- {
- username=hs.getAttribute("USERNAME").toString();
- password=hs.getAttribute("PASSWORD").toString();
- }
- log.info("Logging into FERS using username :"+username+" and password :"+password);
- Visitor visitor=new Visitor();
- VisitorFacade vServiceImpl=new VisitorServiceImpl();
- visitor=vServiceImpl.searchVisitor(username, password);
- ModelAndView mv=new ModelAndView();
- if(visitor==null)
- {
- mv.addObject("ERROR","Invalid Username / Password.");
- mv.setViewName("/index.jsp");
- return mv;
- }
- else
- {
- log.info("Visitor details available for the username :"+username);
- List<Event> eventList=new ArrayList<Event>();
- EventFacade serviceImpl=new EventServiceImpl();
- eventList=serviceImpl.getAllEvents();
- log.info("All events listed for th visitor :"+eventList);
- List<Event> regList=new ArrayList<Event>();
- regList=vServiceImpl.showRegisteredEvents(visitor);
- log.info("All Registered events listed for the visitor :"+regList);
- HttpSession session=request.getSession();
- session.setAttribute("VISITOR", visitor);
- mv.addObject("visitor",visitor);
- mv.addObject("allEvents",eventList);
- mv.addObject("regEvents",regList);
- mv.setViewName("/visitormain.jsp");
- return mv;
- }
- }
- /**
- * <br/>
- * METHOD DESCRIPTION:<br/>
- * The method is used to register a visitor for an event from visitormain.jsp and maintains the list
- * of all the events visitor registered. if user status is already registered for an event, then displays
- * error message in visitormain.jsp page.<br/>
- *
- * @param request (type HttpServletRequest)
- * @param response (type HttpServletResponse)
- *
- * @return ModelAndView
- *
- * @throws FERSGenericException
- *
- */
- /* @RequestMapping("/eventreg.htm")
- public ModelAndView registerVisitor(HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- if(request==null || response==null)
- {
- log.info("Request or Response failed for REGISTERVISITOR METHOD..");
- throw new FERSGenericException("Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder", new NullPointerException());
- }
- HttpSession session=request.getSession();
- Visitor visitor=(Visitor)session.getAttribute("VISITOR");
- int eventid=Integer.parseInt(request.getParameter("eventId"));
- log.info("Visitor registered for the event :"+eventid);
- ModelAndView mv=new ModelAndView();
- VisitorFacade vServiceImpl=new VisitorServiceImpl();
- EventFacade serviceImpl=new EventServiceImpl();
- boolean regStatus=serviceImpl.checkEventsofVisitor(visitor, eventid);
- log.info("Status of the visitor for the event :"+regStatus);
- if(regStatus==false)
- {
- vServiceImpl.RegisterVisitor(visitor, eventid);
- log.info("Visitor succesfully registed for event :"+eventid);
- }
- else
- {
- mv.addObject("RegError", "User already Registered for the EVENT !!");
- }
- List<Event> regList=new ArrayList<Event>();
- regList=vServiceImpl.showRegisteredEvents(visitor);
- List<Event> eventList=new ArrayList<Event>();
- eventList=serviceImpl.getAllEvents();
- mv.addObject("visitor",visitor);
- mv.addObject("allEvents",eventList);
- mv.addObject("regEvents",regList);
- mv.setViewName("/visitormain.jsp");
- return mv;
- }
- /**
- * <br/>
- * METHOD DESCRIPTION:<br/>
- * The method will update account details of the visitor and logout the visitor
- * and to force the visitor to re-login and confirm the updated account details
- * and new password.<br/>
- *
- * @param request (type HttpServletRequest)
- * @param response (type HttpServletResponse)
- *
- * @return ModelAndView
- *
- * @throws FERSGenericException
- *
- */
- @RequestMapping("/updatevisitor.htm")
- public ModelAndView updateVisitor(HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- if(request==null || response==null)
- {
- log.info("Request or Response failed for UPDATEVISITOR METHOD..");
- throw new FERSGenericException("Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder", new NullPointerException());
- }
- HttpSession session=request.getSession();
- Visitor visitor=(Visitor)session.getAttribute("VISITOR");
- log.info("Updating visitor details with VisitorID :"+visitor.getVisitorId());
- String username=request.getParameter("username");
- //String password=request.getParameter("password");
- String firstname=request.getParameter("firstname");
- String lastname=request.getParameter("lastname");
- String email=request.getParameter("email");
- String phoneno=request.getParameter("phoneno");
- String address=request.getParameter("address");
- visitor.setFirstName(firstname);
- visitor.setLastName(lastname);
- visitor.setUserName(username);
- //visitor.setPassword(password);
- visitor.setEmail(email);
- visitor.setPhoneNumber(phoneno);
- visitor.setAddress(address);
- VisitorFacade vServiceImpl=new VisitorServiceImpl();
- int status=vServiceImpl.updateVisitorDetails(visitor);
- log.info("Number of Visitor records updated is :"+status);
- ModelAndView mv=new ModelAndView();
- if(status>0)
- {
- mv.addObject("status","success");
- mv.setViewName("/updatevisitor.jsp");
- }
- else
- {
- mv.addObject("updatestatus", "Error in updation.. Please Check fields and retry");
- mv.setViewName("/updatevisitor.jsp");
- }
- return mv;
- }
- }
- /**
- * <br/>
- * METHOD DESCRIPTION: <br/>
- * The method is to unregisters a visitor from an event within the visitormain.jsp
- * page and the seats will be released. The visitormain.jsp page is then refreshed
- * to confirm the updates. <br/>
- *
- * @param request (type HttpServletRequest)
- * @param response (type HttpServletResponse)
- *
- * @return ModelAndView
- *
- * @throws FERSGenericException
- *
- */
- /* @RequestMapping("/eventunreg.htm")
- public ModelAndView unregisterEvent(HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- if(request==null || response==null)
- {
- log.info("Request or Response failed for UNREGISTEREVENT METHOD..");
- throw new FERSGenericException("Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder", new NullPointerException());
- }
- HttpSession session=request.getSession();
- Visitor visitor=(Visitor)session.getAttribute("VISITOR");
- int eventid=Integer.parseInt(request.getParameter("eventId"));
- log.info("Unregistering for the event :"+eventid);
- VisitorFacade vServiceImpl=new VisitorServiceImpl();
- vServiceImpl.unregisterEvent(visitor, eventid);
- List<Event> regList=new ArrayList<Event>();
- regList=vServiceImpl.showRegisteredEvents(visitor);
- List<Event> eventList=new ArrayList<Event>();
- EventFacade serviceImpl=new EventServiceImpl();
- serviceImpl.updateEventDeletions(eventid);
- log.info("Seats allocated for the event are released :"+eventid);
- eventList=serviceImpl.getAllEvents();
- ModelAndView mv=new ModelAndView();
- mv.addObject("visitor",visitor);
- mv.addObject("allEvents",eventList);
- mv.addObject("regEvents",regList);
- mv.setViewName("/visitormain.jsp");
- return mv;
- }
- /*
- @RequestMapping("/changePWD.htm")
- public ModelAndView changePassword(HttpServletRequest request, HttpServletResponse response) throws FERSGenericException {
- int status = -1;
- HttpSession session=request.getSession();
- Visitor visitor=(Visitor)session.getAttribute("VISITOR");
- if(visitor != null){
- log.info("Changing visitor password with VisitorID :"+visitor.getVisitorId());
- String password=request.getParameter("password");
- if(password != null)
- {
- visitor.setPassword(password);
- VisitorFacade vServiceImpl=new VisitorServiceImpl();
- status=vServiceImpl.changePassword(visitor);
- }
- else{
- log.error("Password cannot be blank");
- }
- log.info("Visitor password changed :"+status);
- }
- else
- {
- log.error("Visitor details are invalid");
- }
- ModelAndView mv=new ModelAndView();
- if(status > 0){
- mv.addObject("status","success");
- mv.setViewName("/changePWD.jsp");
- }else if(status == -5){
- mv.addObject("status", "error");
- mv.addObject("errorMsg", "System error occurred, Please verify log file for more details");
- mv.setViewName("/changePWD.jsp");
- }else if(status == -10){
- mv.addObject("status", "error");
- mv.addObject("errorMsg", "New password must be different from current password, please choose a different password and retry");
- mv.setViewName("/changePWD.jsp");
- }else{
- mv.addObject("status", "error");
- mv.addObject("errorMsg", "Error while changing password.. Please verify visitor and password details and retry again");
- mv.setViewName("/changePWD.jsp");
- }
- return mv;
- }
- }*/
- //visitorDEO
- package com.accenture.adf.businesstier.dao;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import org.apache.log4j.Logger;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import com.accenture.adf.businesstier.entity.Event;
- import com.accenture.adf.businesstier.entity.Visitor;
- import com.accenture.adf.exceptions.FERSGenericException;
- import com.accenture.adf.helper.FERSDataConnection;
- import com.accenture.adf.helper.FERSDbQuery;
- /**
- *
- * <br/>
- * CLASS DESCRIPTION:<br/>
- * A Data Access Object (DAO) class for handling and managing visitor related data requested,
- * used, and processed in the application and maintained in the database.
- * The interface between the application and visitor data persisting in the database.
- *
- */
- public class VisitorDAO {
- // LOGGER for handling all transaction messages in VISITORDAO
- private static Logger log = Logger.getLogger(VisitorDAO.class);
- //JDBC API classes for data persistence
- private Connection connection = null;
- private PreparedStatement statement = null;
- private ResultSet resultSet = null;
- private FERSDbQuery query;
- //Default constructor for injecting Spring dependencies for SQL queries
- public VisitorDAO() {
- ApplicationContext context = new ClassPathXmlApplicationContext(
- "applicationContext.xml");
- query = (FERSDbQuery) context.getBean("SqlBean");
- }
- /**
- * <br/>
- * METHOD DESCRIPTION:<br/>
- * DAO method to loading visitor details into VISITOR table in database<br/>
- * and validating about existing visitor details before inserting a visitor <br/>
- *
- * <br/>
- * PSEUDOCODE: <br/>
- * Create a connection to database<br/>
- * Prepare a statement object using the connection that uses a query that inserts visitor information <br/>
- * into the visitor table <br/>
- * Execute a statement object selects all the usernames from the visitor table<br/>
- * if the username is not in the visitor table <br/>
- *
- * @param visitor (type Visitor)
- *
- * @return boolean
- *
- * @throws ClassNotFoundException
- * @throws SQLException
- * @throws Exception
- *
- */
- public boolean insertData(Visitor visitor) throws ClassNotFoundException,
- SQLException, Exception {
- // TODO: Add code here.....
- // TODO: Pseudo-code are in the block comments above this method
- // TODO: For more comprehensive pseudo-code with details, refer to the Component/Class Detailed Design Document
- int row=0;
- connection = FERSDataConnection.createConnection();
- boolean userFound = false;
- userFound = validateUserName(visitor);
- if (userFound == false) {
- PreparedStatement ps = connection.prepareStatement(query.getInsertQuery());
- ps.setString(1, visitor.getUserName());
- ps.setString(2, visitor.getPassword());
- ps.setString(3, visitor.getFirstName());
- ps.setString(4, visitor.getLastName());
- ps.setString(5, visitor.getEmail());
- ps.setString(6, visitor.getPhoneNumber());
- ps.setString(7, visitor.getAddress());
- int insertRows = ps.executeUpdate();
- if (insertRows != 0) {
- System.out.println("Data inserted successfully!");
- }
- connection.close();
- return true;
- }else{
- connection.close();
- return false;
- }
- }
- private boolean validateUserName(Visitor visitor) throws ClassNotFoundException, SQLException {
- Connection connection =FERSDataConnection.createConnection();
- Statement statement=connection.createStatement();
- ResultSet resultSet=statement.executeQuery(query.getValidateVisitor());
- boolean userFound=false;
- while(resultSet.next()){
- if(resultSet.getString("USERNAME").equals(visitor.getUserName()))
- {
- userFound= true;
- break;
- }
- }
- connection.close();
- return userFound;
- }
- /**
- * <br/>
- * METHOD DESCRIPTION:<br/>
- * DAO method for searching for visitor details using USERNAME and PASSWORD<br/>
- *
- * <br/>
- * PSEUDOCODE: <br/>
- * Create a connection to database<br/>
- * Prepare a statement object using the connection<br/>
- * that uses a query that retrieves all the data from the visitor
- * table based on the username and password provided. Execute the query and <br/>
- * Using a WHILE LOOP, store the results in the result set record in the visitor object.<br/>
- *
- * @param username (type String)
- * @param password (type String)
- *
- * @return Visitor
- *
- * @throws ClassNotFoundException
- * @throws SQLException
- *
- *
- */
- public Visitor searchUser(String username, String password)
- throws ClassNotFoundException, SQLException {
- Connection connection= FERSDataConnection.createConnection();
- PreparedStatement ps = connection.prepareStatement(query.getSearchQuery());
- ps.setString(1, username);
- ps.setString(2, password);
- ResultSet rs = ps.executeQuery();
- Visitor visitor = null;
- while(rs.next()){
- visitor = new Visitor();
- visitor.setVisitorId(rs.getInt("visitorId"));
- visitor.setUserName(rs.getString("username"));
- visitor.setFirstName(rs.getString("firstname"));
- visitor.setLastName(rs.getString("lastname"));
- visitor.setEmail(rs.getString("email"));
- visitor.setPhoneNumber(rs.getString("phonenumber"));
- visitor.setAddress(rs.getString("address"));
- }
- connection.close();
- return visitor;
- }
- /**
- * <br/>
- * METHOD DESCRIPTION: <br/>
- * DAO method to register visitor to specific event and checking about status
- * of visitor to particular event. <br/>
- *
- * PSEUDO-CODE: <br/>
- * Create a connection to the database <br/>
- * Prepare a statement object using the connection: that inserts the
- * visitor and event IDs into the EVENTSESSIONSIGNUP table <br/>
- * Execute the query to perform the update <br/>
- *
- *
- * @param visitor
- * @param eventid
- *
- * @throws ClassNotFoundException
- * @throws SQLException
- * @throws Exception
- *
- */
- public void registerVisitorToEvent(Visitor visitor, int eventid)
- throws ClassNotFoundException, SQLException, Exception {
- // TODO: Add code here.....
- // TODO: Pseudo-code are in the block comments above this method
- // TODO: For more comprehensive pseudo-code with details, refer to the Component/Class Detailed Design Document
- }
- /**
- * <br/>
- * METHOD DESCRIPTION:<br/>
- * DAO method to display all the events registered by particular visitor<br/>
- *
- * PSEUDO-CODE: <br/>
- * Create a connection to the database <br/>
- * Prepare a statement object using the connection: that returns the event
- * information for all the events that are registered to a visitor<br/>
- * Execute the query to retrieve the results into a result set<br/>
- * Place each event record‘s information in an event list. <br/>
- *
- * @param visitor (type Visitor)
- *
- * @return Collection of Event Arrays (type Event)
- *
- * @throws ClassNotFoundException
- * @throws SQLException
- *
- */
- public ArrayList<Event> registeredEvents(Visitor visitor)
- throws ClassNotFoundException, SQLException {
- // TODO: Add code here.....
- // TODO: Pseudo-code are in the block comments above this method
- // TODO: For more comprehensive pseudo-code with details, refer to the Component/Class Detailed Design Document
- return null;
- }
- /**
- * <br/>
- * METHOD DESCRIPTION:<br/>
- * DAO method to update visitor with additional information <br/>
- * <br/>
- *
- * @param visitor (type Visitor)
- *
- * @return int
- *
- * @throws ClassNotFoundException
- * @throws SQLException
- *
- *
- */
- public int updateVisitor(Visitor visitor) throws ClassNotFoundException,
- SQLException {
- connection = FERSDataConnection.createConnection();
- statement = connection.prepareStatement(query.getUpdateQuery());
- statement.setString(1, visitor.getFirstName());
- statement.setString(2, visitor.getLastName());
- statement.setString(3, visitor.getUserName());
- //statement.setString(4, visitor.getPassword());
- statement.setString(4, visitor.getEmail());
- statement.setString(5, visitor.getPhoneNumber());
- statement.setString(6, visitor.getAddress());
- statement.setInt(7, visitor.getVisitorId());
- int status = statement.executeUpdate();
- log.info("Updating visitor details in Database for Visitor ID :"
- + visitor.getVisitorId());
- FERSDataConnection.closeConnection();
- return status;
- }
- /**
- * <br/>
- * METHOD DESCRIPTION: <br/>
- * DAO method to unregister from events <br/>
- *
- *
- * @param visitor (type Visitor)
- * @param eventid (type int)
- *
- * @throws ClassNotFoundException
- * @throws SQLException
- * @throws Exception
- *
- */
- public void unregisterEvent(Visitor visitor, int eventid)
- throws ClassNotFoundException, SQLException, Exception {
- connection = FERSDataConnection.createConnection();
- statement = connection.prepareStatement(query.getDeleteEventQuery());
- statement.setInt(1, eventid);
- statement.setInt(2, visitor.getVisitorId());
- int status = statement.executeUpdate();
- if (status <= 0)
- throw new FERSGenericException("Records not updated properly",
- new Exception());
- log.info("unregistering event in Database for the visitor :"
- + visitor.getFirstName());
- FERSDataConnection.closeConnection();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement