package it.hotel.controller.sms;
import it.hotel.model.booking.Booking;
import it.hotel.model.booking.manager.IBookingManager;
import it.hotel.model.sms.manager.ISmsManager;
import java.io.IOException;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.client.ClientProtocolException;
import org.springframework.web.servlet.ModelAndView;
public class SmsController implements ISmsController {
private IBookingManager bookingManager = null;
private ISmsManager smsManager = null;
/**
*
*
* @param x description
* @return x description.
* @throws exception description
*/
// public ModelAndView create(HttpServletRequest req, HttpServletResponse resp){
// String incoming = req.getParameter("TextMessage");
// if (incoming == null)
// {
// resp.setStatus(400);
// return new ModelAndView("404");
// }
//
// String message = incoming.substring(11);
//
// List<Booking> bookings = smsManager.parse(message);
// for (Booking booking : bookings){
// bookingManager.add(booking);
// }
//
// return new ModelAndView("sms.ok");
//
// }
public ModelAndView create(HttpServletRequest req, HttpServletResponse resp) throws ClientProtocolException, IOException{
String incoming = req.getParameter("TextMessage");
String customerPhoneNumber = req.getParameter("Sender");
String hotelName = null;
if (incoming == null)
{
resp.setStatus(400);
return new ModelAndView("404");
}
String message = incoming.substring(11);
List<Booking> bookings = smsManager.parse(message);
for (Booking booking : bookings){
bookingManager.add(booking);
}
Booking booking = bookings.get(0);
hotelName = booking.getHotel().getName();
if(customerPhoneNumber != null)
{
boolean answer = smsManager.smsResponse(customerPhoneNumber);
}
return new ModelAndView("sms.ok");
}
@Resource(name = "bookingRawManager")
public void setBookingManager(IBookingManager bookingManager) {
this.bookingManager = bookingManager;
}
@Resource(name = "smsManager")
public void setSmsManager(ISmsManager smsManager) {
this.smsManager = smsManager;
}
}