Package classes

Examples of classes.DAO


            BigDecimal bd = new BigDecimal(targetDBL);
            bd = bd.setScale(decimalPlace,BigDecimal.ROUND_UP);

            Scalability time = new Scalability(i , bd.doubleValue());
           
            DAO dao = DAO.getInstance();
            dao.put(time);

        }else{
           long startCPU = System.currentTimeMillis();
           fc.doFilter(sr, sr1);
           long endCPU = System.currentTimeMillis();
View Full Code Here


                                  @QueryParam("depart") String departing,
                                  @QueryParam("return") String returning,
                                  @QueryParam("properties") String properties) {

        ResponseBuilder builder = Response.status(Response.Status.OK);
        DAO db = DAO.getInstance();

        GenericEntity<List<Flight>> entity = null;

        /*PROJECTION*/
        /* Projection GEThttp://localhost:8080/api/v1/flights?properties=from,to*/
        if (properties != null) {

            /* creating a list with all the disered fileds from properties */
            ArrayList<String> tags = new ArrayList<String>();

            StringTokenizer st = new StringTokenizer(properties, ",");
            while (st.hasMoreTokens()) {
                tags.add(st.nextToken());
            }
            /*get all flights from the DB*/
            List<Flight> allFlights = db.getAllFlights();
            int i;

            /* create the Xml file with the desired fields*/
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder documentBuilder = null;
            try {
                documentBuilder = documentBuilderFactory.newDocumentBuilder();
            } catch (ParserConfigurationException ex) {
                Logger.getLogger(ReservationResource.class.getName()).
                        log(Level.SEVERE, null, ex);
            }
            Document document = documentBuilder.newDocument();
            Element RootElement = document.createElement("flights");
            document.appendChild(RootElement);
            /*extract all the fields from tags and create the xml tree*/
            for (i = 0; i < allFlights.size(); i++) {

                Element Node = document.createElement("flight");
                RootElement.appendChild(Node);

                if (tags.contains("from")) {
                    Element em = document.createElement("flightFrom");
                    em.appendChild(document.createTextNode(allFlights.get(i).getFlightFrom()));
                    Node.appendChild(em);
                }
                if (tags.contains("to")) {
                    Element em = document.createElement("flightTo");
                    em.appendChild(document.createTextNode(allFlights.get(i).getFlightTo()));
                    Node.appendChild(em);
                }
                if (tags.contains("depart")) {
                    Element em = document.createElement("departureDate");
                    em.appendChild(document.createTextNode(allFlights.get(i).getDepartureDate()));
                    Node.appendChild(em);
                }
                if (tags.contains("return")) {
                    Element em = document.createElement("returnDate");
                    em.appendChild(document.createTextNode(allFlights.get(i).getReturnDate()));
                    Node.appendChild(em);
                }
            }
            builder.entity(document);
            /*SELECTION*/
            /* GEThttp://localhost:8080/api/v1/
             * flights?from=Antalya&to=Barcelona&depart=01-NOV-2012&return=07-NOV-2012
             * */
        } else if (from != null && to != null && departing != null && returning != null) {
            entity = new GenericEntity<List<Flight>>(
                    db.getFlightsFromToDepartureReturn(from,
                                                       to,
                                                       departing,
                                                       returning)) {
            };
            builder.entity(entity);

            /*SELECTION*/
            /* GET http://localhost:8080/api/v1/flights?from=Prague&to=Barcelona */
        } else if (from != null && to != null && departing == null && returning == null) {
            entity = new GenericEntity<List<Flight>>(db.getFlightsFromTo(from,
                                                                         to)) {
            };
            builder.entity(entity);
            /*SELECTION*/
            /* GET http://localhost:8080/api/v1/flights?from=Prague */
        } else if (from != null && to == null && departing == null && returning == null) {
            entity = new GenericEntity<List<Flight>>(db.getFlightsFrom(from)) {
            };
            builder.entity(entity);
            /*SELECTION*/
            /* GET http://localhost:8080/api/v1/flights */
        } else if (from == null && to == null && departing == null && returning == null) {
            entity = new GenericEntity<List<Flight>>(db.getAllFlights()) {
            };
            builder.entity(entity);
        } else {
            builder = Response.status(Response.Status.BAD_REQUEST).
                    entity(HandlingMessage("Error", "error",
View Full Code Here

    @Path("/flights/{id}")
    public Response getFlightById(
            @PathParam("id") String id) {

        ResponseBuilder builder = Response.status(Response.Status.OK);
        DAO db = DAO.getInstance();

        if (db.getFlightById(id) != null) {
            builder.entity(db.getFlightById(id));
        } else {
            builder = Response.status(Response.Status.NOT_FOUND).
                    entity(HandlingMessage("Error", "error",
                                           "Flight not found! Check the flight number again!"));
        }
View Full Code Here

    @Consumes(MediaType.APPLICATION_XML)
    @Path("/reservation/{id}")
    public Response addReservationWithId(JAXBElement<Reservation> reservation,
                                         @PathParam("id") Long id) {

        DAO db = DAO.getInstance();
        ResponseBuilder builder = null;

        Reservation newReservation = reservation.getValue();

        /* means that the ID of the reservation was included in link
         * so i will update this reservation => the xml file does not
         * need to have the resrvation id in his content otherwise it has to
         */
        if (id != null && id.equals(newReservation.getId())) {
            newReservation.setId(id);
        } else {
            builder = Response.status(Response.Status.BAD_REQUEST).
                    entity(HandlingMessage("Error", "error",
                                           "The ID of the reservation is not valid or don't exists!"
                    + "The mentioned id should be the same with the one from"
                    + "the received xml file"));
            return builder.build();
        }

        if (isReservationContentCorrect(newReservation)) {
            /* Update / Create reservation */
            db.saveReservation(newReservation);
            /* set the status that the content was added to DB */
            builder = Response.status(Response.Status.CREATED).
                    entity(HandlingMessage("Success", "success",
                                           "Your reservation was successfully updated!"));
        } else {
View Full Code Here

        /*current date*/
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();

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

        /* all fields are mandatory to search a room */
        if (checkin.isEmpty() || checkout.isEmpty() || room_size.isEmpty()) {
            /*otherwise error message is sent */
            request.setAttribute("errorMessage", "<font size=\"3\" "
                    + "face=\"arial\" color=\"red\">"
                    + "You must fill all fields!");
            RequestDispatcher rd = request.getRequestDispatcher("pay.jsp");
            rd.forward(request, response);
            /* and of course the dates must be in a logical order */
        } else if ((checkin.compareTo(checkout) > 0)
                || (checkin.compareTo(dateFormat.format(date).toString()) <= 0)) {
            request.setAttribute("errorMessage", "<font size=\"2\" "
                    + "face=\"arial\" color=\"red\">"
                    + "Wrong Date! </font> ");
            RequestDispatcher rd = request.getRequestDispatcher("pay.jsp");
            rd.forward(request, response);
        } else {
            /* GET method */

            /* create the query link*/
            String link = "http://mdwhotel.appspot.com/api/v1/reservation/?start=";
            link += checkin + "&end=" + checkout + "&nr=" + room_size;

            Client client = Client.create();
            WebResource webResource = client.resource(link);
            webResource.accept("application/xml");
            /* invoke the specific metgod(GET) for getting the avialable rooms*/
            String resp = webResource.get(String.class);


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

            /* create new availability req*/
            Availability available = new Availability(checkin, checkout, room_size, rooms_id, kind, description);
            dao.put(available);

            response.sendRedirect("bookHotel.jsp");
        }
    }
View Full Code Here

    @POST
    @Consumes(MediaType.APPLICATION_XML)
    @Path("/reservation")
    public Response addFlight(JAXBElement<Reservation> reservation) {

        DAO db = DAO.getInstance();
        ResponseBuilder builder = null;

        Reservation addNewReservation = reservation.getValue();
        Long ReservationId = addNewReservation.getId();

        /* if the Xml file contains all the req fields and it has a reservation
         * number and it's the same like the one in the link then it can be updated
         */
        if (isReservationContentCorrect(addNewReservation)
                && ReservationId != null) {
            if (!db.existReservation(ReservationId)) {
                db.addReservation(addNewReservation);

                URI reservationUri = uriInfo.getAbsolutePathBuilder().
                        path(addNewReservation.getId().toString()).
                        build();

View Full Code Here

    @Consumes(MediaType.APPLICATION_XML)
    @Path("/reservation/{id}")
    public Response removeReservationWithId(JAXBElement<Reservation> reservation,
                                            @PathParam("id") Long id) {

        DAO db = DAO.getInstance();
        Reservation deleteReservation = reservation.getValue();
        ResponseBuilder builder;
        /* if it's a good request send NO_CONTENT else BADREQ*/
        if (db.existReservation(id) && deleteReservation.getId() == id) {
            /* if I want to delete a reservation afer a given ID*/
            deleteReservation.setId(id);
            db.deleteReservation(deleteReservation);

            builder = Response.status(Response.Status.NO_CONTENT).
                    entity(HandlingMessage("Success", "success",
                                           "Your reservation was successfully deleted"));
        } else {
View Full Code Here

    @DELETE
    @Consumes(MediaType.APPLICATION_XML)
    @Path("/reservation")
    public Response removeReservation(JAXBElement<Reservation> reservation) throws ParserConfigurationException {

        DAO db = DAO.getInstance();
        Reservation deleteReservation = reservation.getValue();

        ResponseBuilder builder = null;
        /* if it's a good request send CREATE else BADREQ*/
        if (deleteReservation.getId() != null
                && db.existReservation(deleteReservation.getId())) {
            db.deleteReservation(deleteReservation);

            builder = Response.status(Response.Status.NO_CONTENT).
                    entity(HandlingMessage("Success", "success",
                                           "Your reservation was successfully deleted"));
        } else {
View Full Code Here

        String aDate = request.getParameter("adate");
        String rDate = request.getParameter("rdate");
        String updateReservation = request.getParameter("updateReservation");

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

        /*current date*/
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();

        /*useful to extract the current user*/
        HttpSession session = request.getSession(false);
        String username = (String) session.getAttribute("username");

        /* if user press the Update Reservation Button */
        if (updateReservation != null) {
            /* all fields must be filled && and reservation id must match with the one from DB*/
            if (reservationId.isEmpty() || aDate.isEmpty() || rDate.isEmpty()
                    || dao.ofy().find(HotelReservation.class, reservationId) == null) {
                request.setAttribute("errorMessage", "<font size=\"2\" "
                        + "face=\"arial\" color=\"red\">"
                        + "Invalid Reservation id! <br/>"
                        + "</font>");
                RequestDispatcher rd = request.getRequestDispatcher("reservations.jsp");
                rd.forward(request, response);
                /* The date must be in a logical order*/
            } else if ((aDate.compareTo(rDate) > 0)
                    || (aDate.compareTo(dateFormat.format(date).toString()) <= 0)) {
                request.setAttribute("errorMessage", "<font size=\"2\" "
                        + "face=\"arial\" color=\"red\">"
                        + "Wrong Date! <br/>"
                        + "</font>");
                RequestDispatcher rd = request.getRequestDispatcher("reservations.jsp");
                rd.forward(request, response);
            } else {
                /*
                 * PUT method
                 */
                /* extract from the DB the reservation that the user want to update*/
                HotelReservation HR = dao.ofy().find(HotelReservation.class, reservationId);

                /*create the query link*/
                String link = "http://mdwhotel.appspot.com/api/v1/reservation/?res_id=";
                link += reservationId + "&start=" + aDate + "&end=" + rDate + "&email=" + HR.getEmail();

                Client client = Client.create();
                WebResource webResource = client.resource(link);
                webResource.accept("application/xml");
                /*invoke the call*/
                String resp = webResource.put(String.class);

                /* if the application sends me back an XML who contains this message
                 * means that they don't have available rooms between thhose dates
                 * and I'm not deleting the reservation that he made before
                 */
                if (!resp.contains("Sorry - the room is not free in these days")) {

                    /*delete the last reservation because they will send to me anotherone*/
                    dao.ofy().delete(HR);
                    /* parse the XML file that I receive from them*/
                    StringToXML(resp);
                    /* set the new information of the reservation*/
                    HR.setStart(Rstart);
                    HR.setEnd(Rend);
                    HR.setDesc(Rdesc);
                    HR.setEmail(Remail);
                    HR.setId(Rid);
                    HR.setName(Rname);
                    HR.setRoomId(RroomId);
                    HR.setNrOfPers(RnrOfPers);
                    dao.put(HR);
                } else {
                    /* if they don't have available rooms between those date
                     * a message retrun
                     */
                    request.setAttribute("errorMessage", "<font size=\"2\" "
                            + "face=\"arial\" color=\"red\">"
                            + "No aviable rooms!<br/>"
                            + "</font>");
                }
                /* successful */
                request.setAttribute("errorMessage", "<font size=\"2\" "
                        + "face=\"arial\" color=\"green\">"
                        + "Reservation successfully updated!<br/>"
                        + "</font>");
                RequestDispatcher rd = request.getRequestDispatcher("reservations.jsp");
                rd.forward(request, response);
                response.sendRedirect("reservations.jsp");
            }
            /* if delete reservation button is pressed*/
            /* verify if the id is correct */
        } else if (reservationId.isEmpty()
                || dao.ofy().find(HotelReservation.class, reservationId) == null) {
            request.setAttribute("errorMessage", "<font size=\"2\" "
                    + "face=\"arial\" color=\"red\">"
                    + "Invalid Reservation id! <br/>"
                    + "</font>");
            RequestDispatcher rd = request.getRequestDispatcher("reservations.jsp");
            rd.forward(request, response);
        } else {
            /*
             * DELETE method
             */
            /* extract the desired reservation from DB*/
            HotelReservation HR = dao.ofy().find(HotelReservation.class, reservationId);

            /* create the query link */
            String link = "http://mdwhotel.appspot.com/api/v1/reservation/?res_id=";
            link += reservationId + "&email=" + HR.getEmail();


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

            /*delete the reservation from the DB*/
            dao.ofy().delete(HotelReservation.class, reservationId);
            /* successful */
            request.setAttribute("errorMessage", "<font size=\"2\" "
                    + "face=\"arial\" color=\"green\">"
                    + "Reservation successfully deleted!<br/>"
                    + "</font>");
View Full Code Here

                RequestDispatcher rd = request.getRequestDispatcher("profile.jsp");
                rd.forward(request, response);
            }
            else {

                DAO dao = DAO.getInstance();
                /*We find the corresponding user profile*/
                Profile profile = (Profile) dao.get(2, username);

                /*we modify the profile accordingly*/
                profile.setFirstName(firstName);
                profile.setLastName(lastName);
                profile.setEmail(email);
                profile.setPhone(phone);

                if (!street.isEmpty())
                    profile.setStreet(street);
                if (!city.isEmpty())
                    profile.setCity(city);
                if (!department.isEmpty())
                    profile.setDepartment(department);

                /*we overwrite the profile in the database*/
                dao.put(profile);

                request.setAttribute("errorMessage", "<font size=\"3\" "
                        + "face=\"arial\"color=\"green\">"
                        + "Your profile was succesfully updated!" + "</font>");
                RequestDispatcher rd = request.getRequestDispatcher("profile.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.