package act.impl;
import dao.DAOFactory;
import dao.tro.Flight;
import frwa.ActionResult;
import frwa.IAction;
import org.apache.log4j.Logger;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
public class ShowFlightsFrom implements IAction{
final static Logger log = Logger.getLogger(ShowFlightInformation.class);
public String getName() {
return "ShowFlightsFrom";
}
public ActionResult perform(HttpServletRequest request) {
DAOFactory factory = DAOFactory.getDAOFactory(1);
String FlightsFrom = null;
FlightsFrom = request.getParameter("flightFromTo");
List<Flight> flights = factory.getFlightDAO().searchForFlightsFromAirport(FlightsFrom);
for (Flight flight: flights) {
flight.setDepartureAirport(factory.getAirportDAO().loadCountryName(flight.getDepartureAirport()));
flight.setDestinationAirport(factory.getAirportDAO().loadCountryName(flight.getDestinationAirport()));
}
ActionResult actionResult = new ActionResult();
actionResult.setUrlAddress("flt/ShowFlightsInformation.jsp");
if (flights!=null) {
actionResult.setUrlAddress("/flt/ShowFlightsInformation.jsp");
} else {
actionResult.setUrlAddress("flt/FlightNotFound.jsp");
}
FlightsFormObject flightsFormObject = new FlightsFormObject();
flightsFormObject.setFlights(flights);
actionResult.setFormObject(flightsFormObject);
return actionResult;
}
}