Package classes

Examples of classes.DAO


        /* create new user */
        User user = new User(username, password, userType);

        /* instance of database */
        DAO dao = DAO.getInstance();

        /* all fields must be filled && pass must match */
        if (username.isEmpty() || password.isEmpty() || userType == null
                || !dao.exists(user.id, username)
                /*extract the pass from the DB and compare with the one that
                 the user enters now*/
                || !password.equals(((User) dao.get(user.id, username)).password)) {
           
            HttpSession session = request.getSession(false);
            session.removeAttribute("username");
            session.removeAttribute("userType");
           
View Full Code Here


        String cardNo = request.getParameter("cardNo");
        String CardExpiresMonth = request.getParameter("cardExpiresMonth");
        String CardExpiresYear = request.getParameter("cardExpiresYear");

        /* instance of database */
        DAO dao = DAO.getInstance();


        /* create new users - There are different types of users: Normal
         * Users and Company Users
         * Note! At this DB model the unique ID si the username
         */

        //Normal Users
        User user = new User("ion.morozan", "test", "User");
        dao.put(user);

        user = new User("milan", "test", "User");
        dao.put(user);

        user = new User("andreea.sandu", "test", "User");
        dao.put(user);

        //Company Users
        User companyUser = new User("KLM", "test", "Company");
        dao.put(companyUser);

        companyUser = new User("Luthansa", "test", "Company");
        dao.put(companyUser);

        companyUser = new User("AirFrance", "test", "Company");
        dao.put(companyUser);


        //Admin User
        User admin = new User("admin", "admin", "Admin");
        dao.put(admin);


        //User Profile
        Profile profile = new Profile("ion.morozan", "test", "ion", "morozan",
                "ion.morozan@gmail.com", "0745342231", "Kolej Strahov", "Prague", "6");
        dao.put(profile);
        profile = new Profile("andreea.sandu", "test", "andreea", "sandu",
                "andreea.sandu@cti.cz", "0745343453", "Kolej Strahov", "Prague", "6");
        dao.put(profile);
        profile = new Profile("milan", "test", "milan", "milan",
                "milan@milan.com", "0745111111", "Devijka", "Prague", "6");
        dao.put(profile);

         //Company Profile
        CompanyProfile companyProfile = new CompanyProfile("KLM", "test", "KLM",
                "123456789", "No12403", "klm@klm.com", "0765342167", "Vanickova", "Prague", "6");
        dao.put(companyProfile);
        companyProfile = new CompanyProfile("Luthansa", "test", "Luthansa",
                "234232423", "No23403", "lht@lht.com", "0765342167", "Mustek", "Prague", "1");
        dao.put(companyProfile);
        companyProfile = new CompanyProfile("AirFrance", "test", "AirFrance",
                "23545645322", "No1223443", "afr@kafr.com", "072756443", "Center", "Prague", "1");
        dao.put(companyProfile);


        /*
         * Add new Flight - this feature can be use only by the
         * airline companies
         * Note! The unique identifier is the flight number
         */

        // Flight from Barcelona - Prais
        Flight flight = new Flight("KLM1200", "Barcelona", "Paris", "25-NOV-2012",
                "12:54", "3:15", "30-NOV-2012", "13:45", "4:25", "A7", "250");
        dao.put(flight);
        flight = new Flight("LHT213", "Barcelona", "Paris", "25-NOV-2012",
                "18:00", "21:20", "30-NOV-2012", "1400", "18:00", "C34", "280");
        dao.put(flight);
        flight = new Flight("AFR4502", "Barcelona", "Paris", "25-NOV-2012",
                "21:25", "23:45", "30-NOV-2012", "8:45", "12:05", "B9", "300");
        dao.put(flight);


        //Flight from Liverpool to Madrid
        flight = new Flight("KLM1400", "Liverpool", "Madrid", "25-NOV-2012",
                "18:20", "21:20", "30-NOV-2012", "14:45", "18:05", "B5", "320");
        dao.put(flight);
        flight = new Flight("LHT21211", "Liverpool", "Madrid", "25-NOV-2012",
                "18:00", "21:20", "30-NOV-2012", "1400", "18:00", "C34", "280");
        dao.put(flight);
        flight = new Flight("AFR045", "Liverpool", "Madrid", "25-NOV-2012",
                "21:25", "23:45", "30-NOV-2012", "8:45", "12:05", "B9", "300");
        dao.put(flight);

        //Flight from Vienna to Rome
        dao.put(flight);
        flight = new Flight("KLM140", "Vienna", "Rome", "25-NOV-2012",
                "18:20", "21:20", "30-NOV-2012", "14:45", "18:05", "B5", "320");
        dao.put(flight);
        flight = new Flight("LHT2311", "Vienna", "Rome", "25-NOV-2012",
                "18:20", "21:20", "30-NOV-2012", "14:45", "18:05", "B5", "320");
        dao.put(flight);
        flight = new Flight("AFR5630", "Vienna", "Rome", "25-NOV-2012",
                "18:20", "21:20", "30-NOV-2012", "14:45", "18:05", "B5", "320");
        dao.put(flight);

        //Flight from Antalya to Zagreb
        flight = new Flight("KLM560", "Antalya", "Zagreb", "25-NOV-2012",
                "18:20", "21:20", "30-NOV-2012", "14:45", "18:05", "B5", "320");
        dao.put(flight);
        flight = new Flight("LHT12030", "Antalya", "Zagreb", "25-NOV-2012",
                "18:00", "21:20", "30-NOV-2012", "14:00", "18:00", "C34", "280");
        dao.put(flight);
        flight = new Flight("AFR2100", "Antalya", "Zagreb", "25-NOV-2012",
                "21:25", "23:45", "30-NOV-2012", "8:45", "12:05", "B9", "300");
        dao.put(flight);


        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
View Full Code Here

        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String userType = "User";

        /* instance of database */
        DAO dao = DAO.getInstance();

        /* get the confirmation number */
        int confirmNumber = 0;
        if (!confNumber.isEmpty()) confirmNumber = Integer.valueOf(confNumber);

        /* create new user */
        User user = new User(username, password, userType);


        /* all fields must be filled && pass must match */
        if (username.isEmpty() || password.isEmpty() || !dao.exists(user.id, username)
                /*extract the pass from the DB and compare with the one that
                 the user enters now*/
                || !password.equals(((User) dao.get(user.id, username)).password)) {
            request.setAttribute("errorMessage", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "Invalid username or password. Please try again! <br/>"
                    + "</font>");
            RequestDispatcher rd = request.getRequestDispatcher("checkInOnline.jsp");
            rd.forward(request, response);
        } else if (!confNumber.matches("[0-9]*") ||
                (dao.getConfirmationNumber(username) != confirmNumber) ||
                (confirmNumber == 0)) {
           
            /* the confirmation number must contain only digits and it must match*/
            request.setAttribute("errorMessage", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
View Full Code Here

        /* create new user */
        Profile profile = new Profile(username, password, firstName, lastName,
                email, phone, street, city, department);
        /* instance of database */
        DAO dao = DAO.getInstance();

        /* all fields must be filled */
        if (username.isEmpty() || password.isEmpty() || firstName.isEmpty()
                || lastName.isEmpty() || email.isEmpty() || phone.isEmpty()) {
            request.setAttribute("fillAllFields", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "You must fill all the fields! </font>");
            RequestDispatcher rd = request.getRequestDispatcher("register.jsp");
            rd.forward(request, response);
            /* wrong phone format*/
        } else if (!phone.matches("[0-9]+")) {
            request.setAttribute("wrongPhoneFormat", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "Wrong Phone Format! Must contains only numbers </font>");
            RequestDispatcher rd = request.getRequestDispatcher("register.jsp");
            rd.forward(request, response);
            /* username already exists */
        } else if (dao.exists(profile.getId(), username)) {
            request.setAttribute("userAlreadyExists", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "Username already exists! Choose another one!</font>");
            RequestDispatcher rd = request.getRequestDispatcher("register.jsp");
            rd.forward(request, response);
            /*check if password matches */
        } else if (!passwordAgain.equals(password)) {
            request.setAttribute("passDontMatch", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "Password dosen't match!</font>");
            RequestDispatcher rd = request.getRequestDispatcher("register.jsp");
            rd.forward(request, response);
            /* add the user to the database*/
        } else {
            /*create an user for the login database */
            User user = new User(username, password, "User");

            /*create admin*/
            //User user = new User(username, password, "Admin");

            dao.put(user);

            dao.put(profile);
            request.setAttribute("username", "<font size=\"3\" "
                    + "face=\"arial\"> You are logged as " + username + "</font>");
            RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
            rd.forward(request, response);
            response.sendRedirect("login.jsp");
View Full Code Here

       
        /* create new user */
        CompanyProfile profile = new CompanyProfile(username, password, firstName,
                regNumber, regAuth, email, phone, street, city, department);
        /* instance of database */
        DAO dao = DAO.getInstance();

        /* all fields must be filled */
        if (username.isEmpty() || password.isEmpty() || firstName.isEmpty()
                || regAuth.isEmpty() || regNumber.isEmpty() || email.isEmpty()
                || phone.isEmpty()) {
            request.setAttribute("fillAllFields", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "You must fill all the fields! </font>");
            RequestDispatcher rd = request.getRequestDispatcher("register.jsp");
            rd.forward(request, response);
            /* wrong phone format*/
        } else if (!phone.matches("[0-9]+")) {
            request.setAttribute("wrongPhoneFormat", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "Wrong Phone Format! Must contains only numbers </font>");
            RequestDispatcher rd = request.getRequestDispatcher("register.jsp");
            rd.forward(request, response);
            /*wrong registration number format*/
        } else if (!regNumber.matches("[0-9]+")){
            request.setAttribute("wrongRegNumberFormat", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "Wrong Registration Number Format! Must contains only numbers </font>");
            RequestDispatcher rd = request.getRequestDispatcher("register.jsp");
            rd.forward(request, response);
            /* username already exists */
        } else if (dao.exists(profile.id, username)) {
            request.setAttribute("userAlreadyExists", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "Username already exists! Choose another one!</font>");
            RequestDispatcher rd = request.getRequestDispatcher("register.jsp");
            rd.forward(request, response);
            /*check if password matches */
        } else if (!passwordAgain.equals(password)) {
            request.setAttribute("passDontMatch", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "Password dosen't match!</font>");
            RequestDispatcher rd = request.getRequestDispatcher("register.jsp");
            rd.forward(request, response);
            /* add the user to the database*/
        } else {
            /*create an user for the login database */
            User user = new User(username, password, "Company");
            dao.put(user);

            dao.put(profile);
            request.setAttribute("username", "<font size=\"3\" "
                    + "face=\"arial\"> You are logged as " + username + "</font>");
            RequestDispatcher rd = request.getRequestDispatcher("company.jsp");
            rd.forward(request, response);
            response.sendRedirect("company.jsp");
View Full Code Here

        String email = request.getParameter("email");
        String room_id = request.getParameter("rooms_id");


        /* instance of database */
        DAO dao = DAO.getInstance();


        /* test if the req fields are filled */
        if (name.isEmpty() || email.isEmpty()) {
            /* sent error  message if not */
            request.setAttribute("errorMessage", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "You must fill all fields!");
            RequestDispatcher rd = request.getRequestDispatcher("bookHotel.jsp");
            rd.forward(request, response);
            /* verify if the email address is in a correct format*/
        } else if (!rfc2822.matcher(email).matches()) {
            request.setAttribute("errorMessage", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "Invalid email address!");
            RequestDispatcher rd = request.getRequestDispatcher("bookHotel.jsp");
            rd.forward(request, response);
        } else {
            /* POST method */

            /*erase all the whiteSpaces*/
            String auxName = name;
            /* create the query link */
            String link = "http://mdwhotel.appspot.com/api/v1/reservation?start=";
            link += checkin + "&end=" + checkout + "&room_id=" + room_id
                    + "&username=" + auxName.replaceAll(" ", "") + "&email=" + email;

            Client client = Client.create();
            WebResource webResource = client.resource(link);
            webResource.accept("application/xml");
            String resp = webResource.post(String.class);

            /*parsing the String to XML format and extract important fields*/
            StringToXML(resp);

            /* getting the session information to find out the current user*/
            HttpSession session = request.getSession(false);
            String username = (String) session.getAttribute("username");
            String cityTo = (String) session.getAttribute("cityTo");

            /* if it's not the Guest user than the reservation made by an
             * autenthicate user will be saved in our local DB if there are
             * available rooms
             * !Guest customer cannot modify their reservations
             */
            if (username != null) {
                HotelReservation HR = new HotelReservation(Rid, Rstart, Rend,
                                                           RroomId, RnrOfPers, Rdesc, name, Remail, username, cityTo);
                dao.put(HR);
            }
            RequestDispatcher rd = request.getRequestDispatcher("reservationSuccessful.jsp");
            rd.forward(request, response);
            response.sendRedirect("reservationSuccessful.jsp");
        }
View Full Code Here

       
        /* create new user */
        User user = new User(username, password, userType);

        /* instance of database */
        DAO dao = DAO.getInstance();
       
        /* all fields must be filled && pass must match */
        if (username.isEmpty() || password.isEmpty() || userType == null
                || !dao.exists(user.id, username)
                /*extract the pass from the DB and compare with the one that
                the user enters now*/
                || !password.equals(((User) dao.get(user.id, username)).password)
                || !userType.equals(((User) dao.get(user.id, username)).group)) {

            HttpSession session = request.getSession(false);
            session.removeAttribute("username");
            session.removeAttribute("userType");

View Full Code Here

        /* a new ticket */
        Flight ticket = new Flight(flightNumber, flightFrom, flightTo, departureDate,
                departureHour, arrivalHour, returnDate, returnDepartureHour,
                returnArrivalHour, gate, price);

        DAO dao = DAO.getInstance();

        if (flightNumber.isEmpty() || flightFrom.isEmpty() || flightTo.isEmpty() ||
                departureDate.isEmpty() || departureHour.isEmpty() ||
                arrivalHour.isEmpty() || returnDate.isEmpty() ||
                returnDepartureHour.isEmpty() || returnArrivalHour.isEmpty() ||
                price.isEmpty() || gate.isEmpty()) {
            /* all required fields must be filled in */
            request.setAttribute("fillAllFields", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "You must fill all the fields! </font>");
            RequestDispatcher rd = request.getRequestDispatcher("company.jsp");
            rd.forward(request, response);
        }
        else if (!price.matches("[0-9]+")) {
            /* the price must contain only digits */
            request.setAttribute("wrongPriceFormat", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "Wrong Price Format! Must contains only numbers </font>");
            RequestDispatcher rd = request.getRequestDispatcher("company.jsp");
            rd.forward(request, response);
        }
        else if (!departureHour.matches("[0-9]+:[0-9]+") ||
                !arrivalHour.matches("[0-9]+:[0-9]+") ||
                !returnDepartureHour.matches("[0-9]+:[0-9]+") ||
                !returnArrivalHour.matches("[0-9]+:[0-9]+")) {
            /* the arrival and departure hours must follow the format HH:MM */
            request.setAttribute("wrongHourFormat", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "Wrong Hour Format! The right format is HH:MM </font>");
            RequestDispatcher rd = request.getRequestDispatcher("company.jsp");
            rd.forward(request, response);
        }
        else {
            dao.put(ticket);

            request.setAttribute("flightAdded", "<font size=\"3\" "
                    + "face=\"arial\" color=\"green\">"
                    + "Your flight was added! </font>");
            RequestDispatcher rd = request.getRequestDispatcher("company.jsp");
View Full Code Here

TOP

Related Classes of classes.DAO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.