} 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");