diff --git a/src/main/java/controllers/ReservationController.java b/src/main/java/controllers/ReservationController.java index 2292634..1fdb01c 100644 --- a/src/main/java/controllers/ReservationController.java +++ b/src/main/java/controllers/ReservationController.java @@ -10,37 +10,71 @@ package controllers; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.util.Assert; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; +import security.UserAccount; +import services.ActorService; +import services.ReservationService; +import domain.Actor; +import domain.Driver; +import domain.Passenger; +import domain.Reservation; + @Controller @RequestMapping("/reservation") public class ReservationController extends AbstractController { + @Autowired + private ReservationService reservationService; + + @Autowired + private ActorService actorService; + + // Display --------------------------------------------------------------- - @RequestMapping("/display") - public ModelAndView action1() { - ModelAndView result; + @RequestMapping(value = "/display", method = RequestMethod.GET) + public ModelAndView display(@RequestParam final int reservationId) { + Assert.notNull(reservationId); + ModelAndView res; + Reservation reservation; + UserAccount ua; + Actor actor = this.actorService.findByPrincipal(); + Driver driver = null; + Passenger passenger = null; - result = new ModelAndView("reservation/action-1"); + if (actor instanceof Passenger) { - return result; - } + passenger = (Passenger) actor; + + } else if (actor instanceof Driver) { + + driver = (Driver) actor; + + } else { + + Assert.isTrue(1 == 0, "El usuario no es ni Drive ni Passenger"); + + } + + reservation = this.reservationService.findOne(reservationId); + Assert.isTrue((reservation.getPassenger().getId() == passenger.getId()) || reservation.getRoute().getDriver().getId() == driver.getId()); - // Action-2 --------------------------------------------------------------- + res = new ModelAndView("reservation/display"); - @RequestMapping("/action-2") - public ModelAndView action2() { - ModelAndView result; + res.addObject("reservation", reservation); - result = new ModelAndView("reservation/action-2"); + return res; - return result; } - // Action-2 --------------------------------------------------------------- + // Listing --------------------------------------------------------------- @RequestMapping("/action-3") public ModelAndView action3() { diff --git a/src/main/java/controllers/RouteController.java b/src/main/java/controllers/RouteController.java index e5970f8..9be5dfe 100644 --- a/src/main/java/controllers/RouteController.java +++ b/src/main/java/controllers/RouteController.java @@ -1,7 +1,11 @@ package controllers; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; import java.util.Collection; +import java.util.Date; import javax.validation.Valid; @@ -14,10 +18,18 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; +import security.LoginService; +import security.UserAccount; import services.ActorService; +import services.ReservationService; import services.RouteService; +import domain.Actor; +import domain.Administrator; import domain.Driver; import domain.Finder; +import domain.Passenger; +import domain.Reservation; +import domain.ReservationStatus; import domain.Route; @Controller @@ -25,12 +37,13 @@ public class RouteController extends AbstractController { // Services --------------------------------------------------------------- - @Autowired - private RouteService routeService; + private RouteService routeService; + @Autowired + private ReservationService reservationService; @Autowired - private ActorService actorService; + private ActorService actorService; // Constructors ----------------------------------------------------------- @@ -54,23 +67,111 @@ public ModelAndView list() { } - // Creation --------------------------------------------------------------- + // Display --------------------------------------------------------------- @RequestMapping(value = "/display", method = RequestMethod.GET) - public ModelAndView display(@RequestParam final int routeID) { - + public ModelAndView display(@RequestParam final int routeId) { ModelAndView result; Route route; - - route = this.routeService.findOne(routeID); + Collection reservations, displayableReservations; + Integer occupiedSeats; + UserAccount ua; + Actor actor; + Integer rol = 0; //1->conductor de la ruta | 2->pasajero con reserva | 3-> pasajero sin reserva | 4->admin + // Reservation reservation; + boolean startedRoute = false; + boolean hasPassed10Minutes = false; + boolean arrivalPlus10Min = false; + + route = this.routeService.findOne(routeId); Assert.notNull(route); result = new ModelAndView("route/display"); - + // reservation = this.reservationService.create(); + // reservation.setRoute(route); + // reservation.setPrice(route.getPricePerPassenger()); + // reservation.setLuggageSize(LuggageSize.NOTHING); + // reservation.setStatus(ReservationStatus.PENDING); + + reservations = route.getReservations(); + displayableReservations = new ArrayList(); + occupiedSeats = 0; + ua = LoginService.getPrincipal(); + actor = this.actorService.findByUserAccount(ua); + Assert.notNull(actor); + + if (actor instanceof Driver) { + final Driver driver = (Driver) actor; + if (route.getDriver().equals(driver)) + rol = 1; + } + if (reservations != null && reservations.size() > 0) + for (final Reservation res : reservations) { + if (res.getStatus().equals(ReservationStatus.ACCEPTED)) { + occupiedSeats++; //Contamos asientos ocupados + displayableReservations.add(res); //añadimos las reservas aceptadas + } + if (actor instanceof Driver) { + final Driver driver = (Driver) actor; + if (route.getDriver().equals(driver)) { //Si el conductor logeado es el de la ruta... + rol = 1; //...se considerará como "conductor de la ruta"... + if (route.getDepartureDate().after(new Date())) // ...y además si la ruta no ha empezado... + if (res.getStatus().equals(ReservationStatus.PENDING)) + displayableReservations.add(res); //...añadimos tambien reservas pendientes + } + } + + if (actor instanceof Passenger) { //Si el actor logueado es pasajero... + final Passenger passenger = (Passenger) actor; + for (final Reservation r : reservations) + //...y ha hecho alguna reserva en la ruta + if (r.getPassenger().equals(passenger)) { + rol = 2; //...se considerara como "pasajero con reserva" + result.addObject("reservation", r); + if (route.getDepartureDate().before(new Date())) + startedRoute = true; + break; + } else + rol = 3; + //reservation.setPassenger(passenger); + } + + if (actor instanceof Administrator) + rol = 4; + } + else if (actor instanceof Passenger) + //final Passenger passenger = (Passenger) actor; + rol = 3; + + //----proceso para conseguir la fecha de llegada--- + final Calendar date = Calendar.getInstance(); + date.setTime(route.getDepartureDate()); + final long departureDateMilis = date.getTimeInMillis(); + final Date arrivalDate = new Date(departureDateMilis + route.getEstimatedDuration() * 60000); + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); + sdf.format(arrivalDate); + //------------------------------------------------ + + //----proceso para conseguir la fecha de salida + 10 minutos--- + final Date tenMinutesAfterDeparture = new Date(departureDateMilis + 600000); + if (new Date().after(tenMinutesAfterDeparture)) + hasPassed10Minutes = true; + //----proceso para conseguir la fecha de llegada + 10 minutos--- + final Date tenMinutesAfterArrival = new Date(departureDateMilis + (route.getEstimatedDuration() * 60000) + 600000); + if (new Date().after(tenMinutesAfterArrival)) + arrivalPlus10Min = true; + //------------------------------------------------ result.addObject("route", route); + result.addObject("remainingSeats", route.getAvailableSeats() - occupiedSeats); + result.addObject("arrivalDate", sdf.format(arrivalDate)); + result.addObject("reservations", displayableReservations); + result.addObject("rol", rol); + // result.addObject("newReservation", reservation); + result.addObject("startedRoute", startedRoute); + result.addObject("hasPassed10Minutes", hasPassed10Minutes); + result.addObject("hasPassed20Minutes", arrivalPlus10Min); return result; } - @RequestMapping(value = "/search", method = RequestMethod.GET) public ModelAndView searchView() { final ModelAndView result; diff --git a/src/main/java/controllers/driver/ReservationDriverController.java b/src/main/java/controllers/driver/ReservationDriverController.java index f8756a8..7fb0ea0 100644 --- a/src/main/java/controllers/driver/ReservationDriverController.java +++ b/src/main/java/controllers/driver/ReservationDriverController.java @@ -37,62 +37,43 @@ public class ReservationDriverController extends AbstractController { public ReservationDriverController() { super(); } - - + // Accept Reservation --------------------------------------------------------------- - @RequestMapping(value="/acceptReservation", method=RequestMethod.POST, params = "acceptReservation") - public ModelAndView acceptReservation(@RequestParam(defaultValue = "0") int reservationId){ + @RequestMapping(value = "/acceptReservation", method = RequestMethod.POST, params = "acceptReservation") + //, params = "acceptReservation") + public ModelAndView acceptReservation(@RequestParam(defaultValue = "0") final int reservationId) { ModelAndView res; - Reservation reservation = reservationService.findOne(reservationId); - Route route = reservation.getRoute(); + final Reservation reservation = this.reservationService.findOne(reservationId); + final Route route = reservation.getRoute(); - try{ + try { this.reservationService.acceptReservation(reservationId); res = new ModelAndView("redirect:/route/display.do?routeId=" + route.getId()); - }catch (Exception e) { + } catch (final Exception e) { res = new ModelAndView("redirect:/route/display.do?routeId=" + route.getId()); } - + return res; } - + // Reject Reservation --------------------------------------------------------------- - - @RequestMapping(value="/rejectReservation", method=RequestMethod.POST, params = "rejectReservation") - public ModelAndView rejectReservation(@RequestParam(defaultValue = "0") int reservationId){ + + @RequestMapping(value = "/rejectReservation", method = RequestMethod.POST, params = "rejectReservation") + public ModelAndView rejectReservation(@RequestParam(defaultValue = "0") final int reservationId) { ModelAndView res; - Reservation reservation = reservationService.findOne(reservationId); - Route route = routeService.findOne(reservation.getRoute().getId()); + final Reservation reservation = this.reservationService.findOne(reservationId); + final Route route = this.routeService.findOne(reservation.getRoute().getId()); - try{ + try { this.reservationService.rejectReservation(reservationId); - res = new ModelAndView("redirect:/route/display.do" + route.getId()); + res = new ModelAndView("redirect:/route/display.do?routeId=" + route.getId()); - }catch (Exception e) { - res = new ModelAndView("redirect:/route/display.do" + route.getId()); + } catch (final Exception e) { + res = new ModelAndView("redirect:/route/display.do?routeId=" + route.getId()); } - - return res; - } - - // Cancel Reservation --------------------------------------------------------------- - - @RequestMapping(value="/cancelReservation", method=RequestMethod.POST, params = "cancelReservation") - public ModelAndView cancelReservation(@RequestParam(defaultValue = "0") int reservationId){ - ModelAndView res; - Reservation reservation = reservationService.findOne(reservationId); - Route route = routeService.findOne(reservation.getRoute().getId()); - try{ - this.reservationService.cancelReservation(reservationId); - res = new ModelAndView("redirect:/route/display.do" + route.getId()); - - }catch (Exception e) { - res = new ModelAndView("redirect:/route/display.do" + route.getId()); - } - return res; } diff --git a/src/main/java/controllers/driver/RouteDriverController.java b/src/main/java/controllers/driver/RouteDriverController.java index b9afc6d..4692154 100644 --- a/src/main/java/controllers/driver/RouteDriverController.java +++ b/src/main/java/controllers/driver/RouteDriverController.java @@ -90,7 +90,7 @@ public ModelAndView edit(@RequestParam final int routeId) { return result; } - @RequestMapping(value = "/edit", method = RequestMethod.POST, params = "save") + @RequestMapping(value = "/create", method = RequestMethod.POST, params = "save") public ModelAndView save(@Valid final Route route, final BindingResult binding) { Route saved; @@ -115,14 +115,14 @@ public ModelAndView save(@Valid final Route route, final BindingResult binding) } @RequestMapping(value = "/cancel", method = RequestMethod.GET) - public ModelAndView cancel(@RequestParam final int routeID) { + public ModelAndView cancel(@RequestParam final int routeId) { ModelAndView result; Route route; - route = this.routeService.findOne(routeID); + route = this.routeService.findOne(routeId); try { this.routeService.cancel(route); - result = this.routeDisplayModelAndView(route, null); + result = new ModelAndView("redirect:/route/driver/listActive.do"); } catch (final Throwable oops) { oops.printStackTrace(); result = this.routeDisplayModelAndView(route, "driver.cancel.error"); @@ -134,7 +134,7 @@ public ModelAndView cancel(@RequestParam final int routeID) { // Delete/Confirm route --------------------------------------------------------------- @RequestMapping(value = "/delete", method = RequestMethod.GET) - public ModelAndView delete(final Route route, final BindingResult binding) { + public ModelAndView delete(final Route route) { ModelAndView result; try { @@ -146,6 +146,20 @@ public ModelAndView delete(final Route route, final BindingResult binding) { return result; } + @RequestMapping(value = "/edit", method = RequestMethod.POST, params = "delete") + public ModelAndView delete(final Route route, final BindingResult binding) { + ModelAndView result; + for (final ObjectError oe : binding.getAllErrors()) + System.out.println(oe); + try { + this.routeService.delete(route); + result = new ModelAndView("redirect:list.do"); + } catch (final Throwable oops) { + result = this.createEditModelAndView(route, "route.commit.error"); + } + return result; + } + @RequestMapping(value = "/confirmRoute", method = RequestMethod.GET) public ModelAndView confirmRoute(@RequestParam final int routeId) { ModelAndView result; @@ -181,7 +195,7 @@ private ModelAndView createEditModelAndView(final Route route, final String mess final Driver driver = (Driver) this.actorService.findByPrincipal(); - requestURI = "route/driver/edit.do"; + requestURI = "route/driver/create.do"; result = new ModelAndView("route/driver/create"); result.addObject("route", route); result.addObject("vehicles", driver.getVehicles()); diff --git a/src/main/java/controllers/passenger/ReservationPassengerController.java b/src/main/java/controllers/passenger/ReservationPassengerController.java index c8a3769..d3df7bb 100644 --- a/src/main/java/controllers/passenger/ReservationPassengerController.java +++ b/src/main/java/controllers/passenger/ReservationPassengerController.java @@ -10,8 +10,11 @@ package controllers.passenger; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collection; +import java.util.Date; import javax.validation.Valid; @@ -19,17 +22,23 @@ import org.springframework.stereotype.Controller; import org.springframework.util.Assert; import org.springframework.validation.BindingResult; -import org.springframework.validation.ObjectError; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; +import security.LoginService; +import security.UserAccount; +import services.ActorService; import services.ReservationService; import services.RouteService; import controllers.AbstractController; -import domain.ControlPoint; +import domain.Actor; +import domain.Administrator; +import domain.Driver; +import domain.Passenger; import domain.Reservation; +import domain.ReservationStatus; import domain.Route; @Controller @@ -40,6 +49,8 @@ public class ReservationPassengerController extends AbstractController { private ReservationService reservationService; @Autowired private RouteService routeService; + @Autowired + private ActorService actorService; // Constructor -------------------------------------------------------- @@ -53,30 +64,37 @@ public ModelAndView create(@RequestParam final int routeId) { ModelAndView result; Route route; Reservation reservation; + UserAccount ua; + Passenger passenger; + + ua = LoginService.getPrincipal(); + passenger = (Passenger) this.actorService.findByUserAccount(ua); + Assert.notNull(passenger); route = this.routeService.findOne(routeId); + reservation = this.reservationService.create(); reservation.setRoute(route); + reservation.setPrice(route.getPricePerPassenger()); + reservation.setPassenger(passenger); result = this.createEditModelAndView(reservation); return result; } - + @RequestMapping(value = "/create", method = RequestMethod.POST, params = "save") public ModelAndView save(@Valid final Reservation reservation, final BindingResult binding) { ModelAndView result; Route route; - for (final ObjectError oe : binding.getAllErrors()) - System.out.println(oe); - - if (binding.hasErrors()) + if (binding.hasErrors()) { result = this.createEditModelAndView(reservation); - else + System.out.println(binding.getAllErrors()); + } else try { - this.reservationService.save(reservation); route = reservation.getRoute(); - result = new ModelAndView("route/passenger/display.do?routeId=" + route.getId()); //TODO: aun por ver adonde redirigira + this.reservationService.save(reservation); + result = new ModelAndView("redirect:/route/display.do?routeId=" + route.getId()); } catch (final Throwable oops) { oops.printStackTrace(); result = this.createEditModelAndView(reservation, "reservation.commit.error"); @@ -84,16 +102,226 @@ public ModelAndView save(@Valid final Reservation reservation, final BindingResu return result; } - // Action-2 --------------------------------------------------------------- + // Confirmacion de que conductor me ha recogido --------------------------------------------------------------- - @RequestMapping("/action-2") - public ModelAndView action2() { + @RequestMapping(value = "/driverPickUp", method = RequestMethod.GET) + public ModelAndView driverPickUp(final int reservationId) { ModelAndView result; - result = new ModelAndView("reservation/action-2"); + this.reservationService.driverPickedMe(reservationId); + result = new ModelAndView("reservation/passenger/driverPickUp"); + + //TENGO QUE PASARLE OTRA VEZ TODA LA INFO QUE HAY EN EL DISPLAY DE ROUTE + + Route route; + Collection reservations, displayableReservations; + Integer occupiedSeats; + UserAccount ua; + Actor actor; + Integer rol = 0; //1->conductor de la ruta | 2->pasajero con reserva | 3-> pasajero sin reserva | 4->admin + Reservation reservation; + final Reservation currentReservation; + boolean startedRoute = false; + boolean hasPassed10Minutes = false; + boolean hasPassed20Minutes = false; + + currentReservation = this.reservationService.findOne(reservationId); + route = currentReservation.getRoute(); + Assert.notNull(route); + reservation = this.reservationService.create(); + reservation.setRoute(route); + + reservations = route.getReservations(); + System.out.println(reservations); + displayableReservations = new ArrayList(); + occupiedSeats = 0; + ua = LoginService.getPrincipal(); + actor = this.actorService.findByUserAccount(ua); + Assert.notNull(actor); + + if (reservations != null && reservations.size() > 0) + for (final Reservation res : reservations) { + if (res.getStatus().equals(ReservationStatus.ACCEPTED)) { + occupiedSeats++; //Contamos asientos ocupados + displayableReservations.add(res); //añadimos las reservas aceptadas + } + if (actor instanceof Driver) { + final Driver driver = (Driver) actor; + if (route.getDriver().equals(driver)) { //Si el conductor logeado es el de la ruta... + rol = 1; //...se considerará como "conductor de la ruta"... + if (route.getDepartureDate().after(new Date())) // ...y además si la ruta no ha empezado... + if (res.getStatus().equals(ReservationStatus.PENDING)) + displayableReservations.add(res); //...añadimos tambien reservas pendientes + } + } + + if (actor instanceof Passenger) { //Si el actor logueado es pasajero... + final Passenger passenger = (Passenger) actor; + for (final Reservation r : reservations) + //...y ha hecho alguna reserva en la ruta + if (r.getPassenger().equals(passenger)) { + rol = 2; //...se considerara como "pasajero con reserva" + result.addObject("reservation", r); + if (route.getDepartureDate().before(new Date())) + startedRoute = true; + break; + } else + rol = 3; //si no, se considera "pasajero sin reserva" + } + + if (actor instanceof Administrator) + rol = 4; + } + + //----proceso para conseguir la fecha de llegada--- + final Calendar date = Calendar.getInstance(); + date.setTime(route.getDepartureDate()); + final long departureDateMilis = date.getTimeInMillis(); + final Date arrivalDate = new Date(departureDateMilis + route.getEstimatedDuration() * 60000); + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); + sdf.format(arrivalDate); + //------------------------------------------------ + + //----proceso para conseguir la fecha de salida + 10 minutos--- + final Date tenMinutesAfterDeparture = new Date(departureDateMilis + 600000); + if (new Date().after(tenMinutesAfterDeparture)) + hasPassed10Minutes = true; + //----proceso para conseguir la fecha de salida + 10 minutos--- + final Date twentyMinutesAfterDeparture = new Date(departureDateMilis + (600000 * 2)); + if (new Date().after(twentyMinutesAfterDeparture)) + hasPassed20Minutes = true; + //------------------------------------------------ + result.addObject("route", route); + result.addObject("remainingSeats", route.getAvailableSeats() - occupiedSeats); + result.addObject("arrivalDate", sdf.format(arrivalDate)); + result.addObject("reservations", displayableReservations); + result.addObject("rol", rol); + result.addObject("newReservation", reservation); + result.addObject("startedRoute", startedRoute); + result.addObject("hasPassed10Minutes", hasPassed10Minutes); + result.addObject("hasPassed20Minutes", hasPassed20Minutes); return result; } + // Confirmacion de que conductor NO me ha recogido --------------------------------------------------------------- + + @RequestMapping(value = "/driverNoPickUp", method = RequestMethod.GET) + public ModelAndView driverNoPickUp(final int reservationId) { + ModelAndView result; + + this.reservationService.driverNoPickedMe(reservationId); + result = new ModelAndView("reservation/passenger/driverNoPickUp"); + + //TENGO QUE PASARLE OTRA VEZ TODA LA INFO QUE HAY EN EL DISPLAY DE ROUTE + + Route route; + Collection reservations, displayableReservations; + Integer occupiedSeats; + UserAccount ua; + Actor actor; + Integer rol = 0; //1->conductor de la ruta | 2->pasajero con reserva | 3-> pasajero sin reserva | 4->admin + Reservation reservation; + final Reservation currentReservation; + boolean startedRoute = false; + boolean hasPassed10Minutes = false; + boolean hasPassed20Minutes = false; + + currentReservation = this.reservationService.findOne(reservationId); + route = currentReservation.getRoute(); + Assert.notNull(route); + reservation = this.reservationService.create(); + reservation.setRoute(route); + + reservations = route.getReservations(); + displayableReservations = new ArrayList(); + occupiedSeats = 0; + ua = LoginService.getPrincipal(); + actor = this.actorService.findByUserAccount(ua); + Assert.notNull(actor); + + if (reservations != null && reservations.size() > 0) + for (final Reservation res : reservations) { + if (res.getStatus().equals(ReservationStatus.ACCEPTED)) { + occupiedSeats++; //Contamos asientos ocupados + displayableReservations.add(res); //añadimos las reservas aceptadas + } + if (actor instanceof Driver) { + final Driver driver = (Driver) actor; + if (route.getDriver().equals(driver)) { //Si el conductor logeado es el de la ruta... + rol = 1; //...se considerará como "conductor de la ruta"... + if (route.getDepartureDate().after(new Date())) // ...y además si la ruta no ha empezado... + if (res.getStatus().equals(ReservationStatus.PENDING)) + displayableReservations.add(res); //...añadimos tambien reservas pendientes + } + } + + if (actor instanceof Passenger) { //Si el actor logueado es pasajero... + final Passenger passenger = (Passenger) actor; + for (final Reservation r : reservations) + //...y ha hecho alguna reserva en la ruta + if (r.getPassenger().equals(passenger)) { + rol = 2; //...se considerara como "pasajero con reserva" + result.addObject("reservation", r); + if (route.getDepartureDate().before(new Date())) + startedRoute = true; + break; + } else + rol = 3; //si no, se considera "pasajero sin reserva" + } + + if (actor instanceof Administrator) + rol = 4; + } + + //----proceso para conseguir la fecha de llegada--- + final Calendar date = Calendar.getInstance(); + date.setTime(route.getDepartureDate()); + final long departureDateMilis = date.getTimeInMillis(); + final Date arrivalDate = new Date(departureDateMilis + route.getEstimatedDuration() * 60000); + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); + sdf.format(arrivalDate); + //------------------------------------------------ + + //----proceso para conseguir la fecha de salida + 10 minutos--- + final Date tenMinutesAfterDeparture = new Date(departureDateMilis + 600000); + if (new Date().after(tenMinutesAfterDeparture)) + hasPassed10Minutes = true; + //----proceso para conseguir la fecha de salida + 20 minutos--- + final Date twentyMinutesAfterDeparture = new Date(departureDateMilis + (600000 * 2)); + if (new Date().after(twentyMinutesAfterDeparture)) + hasPassed20Minutes = true; + //------------------------------------------------ + result.addObject("route", route); + result.addObject("remainingSeats", route.getAvailableSeats() - occupiedSeats); + result.addObject("arrivalDate", sdf.format(arrivalDate)); + result.addObject("reservations", displayableReservations); + result.addObject("rol", rol); + result.addObject("newReservation", reservation); + result.addObject("startedRoute", startedRoute); + result.addObject("hasPassed10Minutes", hasPassed10Minutes); + result.addObject("hasPassed20Minutes", hasPassed20Minutes); + + return result; + } + + // Cancel Reservation --------------------------------------------------------------- + + @RequestMapping(value = "/cancelReservation", method = RequestMethod.POST, params = "cancelReservation") + public ModelAndView cancelReservation(@RequestParam(defaultValue = "0") final int reservationId) { + ModelAndView res; + final Reservation reservation = this.reservationService.findOne(reservationId); + final Route route = this.routeService.findOne(reservation.getRoute().getId()); + + try { + this.reservationService.cancelReservation(reservationId); + res = new ModelAndView("redirect:/route/display.do?routeId=" + route.getId()); + + } catch (final Exception e) { + res = new ModelAndView("redirect:/route/display.do?routeId=" + route.getId()); + } + + return res; + } //Ancilliary methods @@ -108,33 +336,34 @@ private ModelAndView createEditModelAndView(final Reservation reservation) { private ModelAndView createEditModelAndView(final Reservation reservation, final String message) { ModelAndView result; Route route; - Collection places; + // Collection places; Collection routeAcceptedReservations; Integer remainingSeats; route = reservation.getRoute(); //---Lista de strings de lugares por donde pasa la ruta--- - places = new ArrayList(); - places.add(route.getOrigin()); + // places = new ArrayList(); + // places.add(route.getOrigin()); - if (route.getControlPoints() != null && !route.getControlPoints().isEmpty()) - for (final ControlPoint c : route.getControlPoints()) - places.add(c.getLocation()); - places.add(route.getDestination()); + // if (route.getControlPoints() != null && !route.getControlPoints().isEmpty()) + // for (final ControlPoint c : route.getControlPoints()) + // places.add(c.getLocation()); + // places.add(route.getDestination()); //----------------------------------------------------- //------------Asientos restantes-------------------- routeAcceptedReservations = this.reservationService.findAcceptedReservationsByRoute(route.getId()); remainingSeats = route.getAvailableSeats() - routeAcceptedReservations.size(); + //Comprobamos que haya asientos disponibles Assert.isTrue(remainingSeats > 0); //------------------------------------------------------ - result = new ModelAndView("reservation/create"); + result = new ModelAndView("reservation/passenger/create"); result.addObject("reservation", reservation); result.addObject("route", route); - result.addObject("places", places); + // result.addObject("places", places); result.addObject("remainingSeats", remainingSeats); result.addObject("message", message); @@ -143,7 +372,7 @@ private ModelAndView createEditModelAndView(final Reservation reservation, final // Action-2 --------------------------------------------------------------- - @RequestMapping("/action-3") + @RequestMapping("/driverPickMe") public ModelAndView action3() { throw new RuntimeException("Oops! An *expected* exception was thrown. This is normal behaviour."); } diff --git a/src/main/java/converters/PassengerToStringConverter.java b/src/main/java/converters/PassengerToStringConverter.java new file mode 100644 index 0000000..9569f6c --- /dev/null +++ b/src/main/java/converters/PassengerToStringConverter.java @@ -0,0 +1,25 @@ + +package converters; + +import javax.transaction.Transactional; + +import org.springframework.core.convert.converter.Converter; +import org.springframework.stereotype.Component; + +import domain.Passenger; + +@Component +@Transactional +public class PassengerToStringConverter implements Converter { + + @Override + public String convert(final Passenger passenger) { + String result; + + if (passenger == null) + result = null; + else + result = String.valueOf(passenger.getId()); + return result; + } +} diff --git a/src/main/java/converters/StringToPassengerConverter.java b/src/main/java/converters/StringToPassengerConverter.java new file mode 100644 index 0000000..01f2887 --- /dev/null +++ b/src/main/java/converters/StringToPassengerConverter.java @@ -0,0 +1,40 @@ + +package converters; + +import javax.transaction.Transactional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.convert.converter.Converter; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +import repositories.PassengerRepository; +import domain.Passenger; + +@Component +@Transactional +public class StringToPassengerConverter implements Converter { + + @Autowired + private PassengerRepository passengerRepository; + + + @Override + public Passenger convert(final String text) { + Passenger result; + int id; + + try { + if (StringUtils.isEmpty(text)) + result = null; + else { + id = Integer.valueOf(text); + result = this.passengerRepository.findOne(id); + } + } catch (final Throwable oops) { + throw new IllegalArgumentException(oops); + } + return result; + } + +} diff --git a/src/main/java/domain/Actor.java b/src/main/java/domain/Actor.java index 52887cf..92b7f14 100644 --- a/src/main/java/domain/Actor.java +++ b/src/main/java/domain/Actor.java @@ -69,6 +69,8 @@ public String getPhone() { @Range(min = (long) 0.0, max = (long) 5.0) public Double getMediumStars() { + if (this.mediumStars == null) + this.mediumStars = 0.0; return this.mediumStars; } diff --git a/src/main/java/domain/Reservation.java b/src/main/java/domain/Reservation.java index 25f9bcc..4a59c65 100644 --- a/src/main/java/domain/Reservation.java +++ b/src/main/java/domain/Reservation.java @@ -23,6 +23,8 @@ public class Reservation extends DomainEntity { private String destination; private Integer seat; private ReservationStatus status; + private boolean driverPickedMe; + private boolean driverNoPickedMe; //Relationships @@ -79,6 +81,15 @@ public ReservationStatus getStatus() { return this.status; } + @NotNull + public boolean isDriverPickedMe() { + return this.driverPickedMe; + } + @NotNull + public boolean isDriverNoPickedMe() { + return this.driverNoPickedMe; + } + //Setters public void setLuggageSize(final LuggageSize luggageSize) { @@ -113,4 +124,12 @@ public void setStatus(final ReservationStatus status) { this.status = status; } + public void setDriverPickedMe(final boolean driverPickedMe) { + this.driverPickedMe = driverPickedMe; + } + + public void setDriverNoPickedMe(final boolean driverNoPickedMe) { + this.driverNoPickedMe = driverNoPickedMe; + } + } diff --git a/src/main/java/services/PassengerService.java b/src/main/java/services/PassengerService.java new file mode 100644 index 0000000..ed582e6 --- /dev/null +++ b/src/main/java/services/PassengerService.java @@ -0,0 +1,84 @@ + +package services; + +import java.util.ArrayList; +import java.util.Collection; + +import javax.transaction.Transactional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import repositories.PassengerRepository; +import security.Authority; +import security.UserAccount; +import security.UserAccountService; +import domain.Passenger; + +@Service +@Transactional +public class PassengerService { + + //managed repository + @Autowired + private PassengerRepository passengerRepository; + + //Supporting Services + @Autowired + private ActorService actorService; + @Autowired + private UserAccountService userAccountService; + + + //CRUD + + public Passenger create() { + final Passenger result; + UserAccount ua; + Authority authority; + Collection authorities; + + ua = this.userAccountService.create(); + ua.setUsername(""); + ua.setPassword(""); + ua.setEnabled(true); + authority = new Authority(); + authority.setAuthority(Authority.ADMIN); + authorities = new ArrayList(); + authorities.add(authority); + ua.setAuthorities(authorities); + + result = new Passenger(); + result.setUserAccount(ua); + + return result; + } + + public Passenger findOne(final int adminId) { + Passenger result; + + result = this.passengerRepository.findOne(adminId); + + return result; + } + + public Collection findAll() { + Collection result; + + result = this.passengerRepository.findAll(); + + return result; + } + + public Passenger save(final Passenger passenger) { + Assert.notNull(passenger); + + Passenger result; + + result = (Passenger) this.actorService.save(passenger); + + return result; + } + +} diff --git a/src/main/java/services/ReservationService.java b/src/main/java/services/ReservationService.java index 05505c9..7998c55 100644 --- a/src/main/java/services/ReservationService.java +++ b/src/main/java/services/ReservationService.java @@ -17,6 +17,7 @@ import security.UserAccount; import domain.Actor; import domain.Driver; +import domain.LuggageSize; import domain.Passenger; import domain.Reservation; import domain.ReservationStatus; @@ -38,9 +39,10 @@ public class ReservationService { @Autowired private RouteService routeService; + @Autowired + private PassengerService passengerService; + - // @Autowired - // private PassengerService passengerService; //TODO: a espera de que se cree //Constructor public ReservationService() { super(); @@ -49,17 +51,18 @@ public ReservationService() { //CRUD public Reservation create() { - UserAccount ua; - Passenger passenger; + // final UserAccount ua; + // Passenger passenger; Reservation result; - ua = LoginService.getPrincipal(); - passenger = (Passenger) this.actorService.findByUserAccount(ua); - Assert.notNull(ua); + // ua = LoginService.getPrincipal(); + // passenger = (Passenger) this.actorService.findByUserAccount(ua); + // Assert.notNull(ua); result = new Reservation(); - result.setPassenger(passenger); + // result.setPassenger(passenger); result.setStatus(ReservationStatus.PENDING); + result.setLuggageSize(LuggageSize.NOTHING); return result; } @@ -104,7 +107,7 @@ public Reservation save(final Reservation reservation) { passenger = (Passenger) this.actorService.findByUserAccount(ua); Assert.notNull(passenger); Assert.isTrue(passenger.equals(reservation.getPassenger())); - + reservation.setPassenger(passenger); //Comprobamos que la solicitud no se manda 5 minutos antes de la hora de salida route = reservation.getRoute(); @@ -116,6 +119,9 @@ public Reservation save(final Reservation reservation) { //--------------------------------------------------------------------------------- Assert.isTrue(lastFiveMinutes.after(new Date())); + if (reservation.getStatus() == ReservationStatus.ACCEPTED) + route.setAvailableSeats(route.getAvailableSeats() - reservation.getSeat()); + //Al guardarse la reserva se añade a la lista de reservas de la ruta reservationsRoute = route.getReservations(); reservationsRoute.add(reservation); @@ -126,28 +132,27 @@ public Reservation save(final Reservation reservation) { reservationsPassenger = passenger.getReservations(); reservationsPassenger.add(reservation); passenger.setReservations(reservationsPassenger); - // this.passengerService.save(passenger); + this.passengerService.save(passenger); result = this.reservationRepository.save(reservation); return result; } - + // Esta función solo se debe llamar desde RouteService.cancel(route), ya que las // comprobaciones se hacen en el cancel y las condiciones del autoReject no son // exactamente las mismas que cuando un driver rechaza una solicitud manualmente - public void autoReject(Route route) { + public void autoReject(final Route route) { Assert.notNull(route); - - Collection reservations = findReservationsByRouteAndStatusPendingOrAccepted(route.getId()); - + + final Collection reservations = this.findReservationsByRouteAndStatusPendingOrAccepted(route.getId()); + if (!reservations.isEmpty()) { - for (Reservation r : reservations) { + for (final Reservation r : reservations) r.setStatus(ReservationStatus.REJECTED); - } - - reservationRepository.save(reservations); - reservationRepository.flush(); + + this.reservationRepository.save(reservations); + this.reservationRepository.flush(); } } @@ -174,9 +179,11 @@ public void delete(final Reservation reservation) { //Si se borra la reserva, se elimina de la lista de reservas del pasajero reservationsPassenger = passenger.getReservations(); reservationsPassenger.remove(reservation); - // this.passengerService.save(passenger); + this.passengerService.save(passenger); //Si se borra la reserva, se elimina de la lista de reservas de la ruta + if (reservation.getStatus() == ReservationStatus.CANCELLED || reservation.getStatus() == ReservationStatus.REJECTED) + route.setAvailableSeats(route.getAvailableSeats() + reservation.getSeat()); reservationsRoute = route.getReservations(); reservationsRoute.remove(reservation); this.routeService.save(route); @@ -205,14 +212,14 @@ public Collection findReservationsByRoute(final int routeId) { return result; } - - public Collection findReservationsByRouteAndStatusPendingOrAccepted(int routeId) { + + public Collection findReservationsByRouteAndStatusPendingOrAccepted(final int routeId) { Assert.isTrue(routeId != 0); - + Collection result; - - result = reservationRepository.findReservationsByRouteAndStatusPendingOrAccepted(routeId, ReservationStatus.PENDING, ReservationStatus.ACCEPTED); - + + result = this.reservationRepository.findReservationsByRouteAndStatusPendingOrAccepted(routeId, ReservationStatus.PENDING, ReservationStatus.ACCEPTED); + return result; } @@ -264,57 +271,68 @@ public Collection findCancelledReservationsByRoute(final int routeI return result; } + public void driverPickedMe(final int reservationId) { + final Reservation reservation = this.reservationRepository.findOne(reservationId); + + reservation.setDriverPickedMe(true); + reservation.setDriverNoPickedMe(false); + } + + public void driverNoPickedMe(final int reservationId) { + final Reservation reservation = this.reservationRepository.findOne(reservationId); + + reservation.setDriverPickedMe(false); + reservation.setDriverNoPickedMe(true); + } + public void acceptReservation(final int reservationId) { Assert.isTrue(reservationId > 0); - Reservation reservation = this.findOne(reservationId); - Route route = reservation.getRoute(); - + final Reservation reservation = this.findOne(reservationId); + final Route route = reservation.getRoute(); + //Comprobamos que la ruta está en pendiente Assert.isTrue(reservation.getStatus().equals(ReservationStatus.PENDING)); - + //Comprobamos que la ruta no ha empezado todavía Assert.isTrue(route.getDepartureDate().after(new Date())); - + //Comprobamos que quedan plazas disponibles - Integer availableSeats = route.getAvailableSeats(); + final Integer availableSeats = route.getAvailableSeats(); Integer countSeats = 0; Integer totalSeats = 0; - - Collection reservations = new ArrayList(); + + final Collection reservations = new ArrayList(); reservations.addAll(this.findAcceptedReservationsByRoute(route.getId())); - - for(Reservation r: reservations){ + + for (final Reservation r : reservations) countSeats = countSeats + r.getSeat(); - } totalSeats = availableSeats - countSeats; Assert.isTrue(totalSeats >= 0); - + reservation.setStatus(ReservationStatus.ACCEPTED); this.reservationRepository.save(reservation); } - + public void rejectReservation(final int reservationId) { Assert.isTrue(reservationId > 0); - Reservation reservation = this.findOne(reservationId); - Route route = reservation.getRoute(); - Assert.isTrue(reservation.getStatus().equals(ReservationStatus.PENDING) || - reservation.getStatus().equals(ReservationStatus.ACCEPTED)); + final Reservation reservation = this.findOne(reservationId); + final Route route = reservation.getRoute(); + Assert.isTrue(reservation.getStatus().equals(ReservationStatus.PENDING) || reservation.getStatus().equals(ReservationStatus.ACCEPTED)); Assert.isTrue(route.getDepartureDate().after(new Date())); - + reservation.setStatus(ReservationStatus.REJECTED); this.reservationRepository.save(reservation); } - + public void cancelReservation(final int reservationId) { Assert.isTrue(reservationId > 0); - Reservation reservation = this.findOne(reservationId); - Route route = reservation.getRoute(); - Assert.isTrue(reservation.getStatus().equals(ReservationStatus.ACCEPTED) || - reservation.getStatus().equals(ReservationStatus.REJECTED)); + final Reservation reservation = this.findOne(reservationId); + final Route route = reservation.getRoute(); + Assert.isTrue(reservation.getStatus().equals(ReservationStatus.ACCEPTED) || reservation.getStatus().equals(ReservationStatus.REJECTED)); Assert.isTrue(route.getDepartureDate().after(new Date())); - + reservation.setStatus(ReservationStatus.CANCELLED); this.reservationRepository.save(reservation); } - + } diff --git a/src/main/java/services/RouteService.java b/src/main/java/services/RouteService.java index 65245b2..63594e1 100644 --- a/src/main/java/services/RouteService.java +++ b/src/main/java/services/RouteService.java @@ -5,6 +5,7 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -49,9 +50,9 @@ public class RouteService { //Simple CRUD methods public Route create() { - Route r = new Route(); + final Route r = new Route(); - Driver d = (Driver) this.actorService.findByPrincipal(); + final Driver d = (Driver) this.actorService.findByPrincipal(); r.setDriver(d); r.setIsCancelled(false); r.setReservations(new ArrayList()); @@ -62,7 +63,7 @@ public Route create() { return r; } - public Route findOne(int id) { + public Route findOne(final int id) { Assert.notNull(id); return this.routeRepository.findOne(id); @@ -72,17 +73,17 @@ public Collection findAll() { return this.routeRepository.findAll(); } - public Route save(Route r) { + public Route save(final Route r) { Assert.notNull(r); Double distance = 0.0; Double price = 0.0; - Date date = new Date(); + final Date date = new Date(); Assert.isTrue(r.getDepartureDate().after(date)); //Assertion that the user modifying this task has the correct privilege. - Assert.isTrue(this.actorService.findByPrincipal().getId() == r.getDriver().getId()); - + if (this.actorService.findByPrincipal() instanceof Driver) + Assert.isTrue(this.actorService.findByPrincipal().getId() == r.getDriver().getId()); //Assertion that the avaliable seats isn't a bigger value than the vehicle capacity Assert.isTrue(r.getAvailableSeats() < r.getVehicle().getSeatsCapacity()); // @@ -103,13 +104,13 @@ public Route save(Route r) { // r.setOrigin(cps.get(0).getLocation()); // r.setDestination(cps.get(cps.size() - 1).getLocation()); // } - String origin = r.getOrigin(); - String destination = r.getDestination(); + final String origin = r.getOrigin(); + final String destination = r.getDestination(); distance = this.getDistance(origin, destination); price = this.getPrice(distance); r.setPricePerPassenger(price); r.setDistance(distance); - Route saved = this.routeRepository.save(r); + final Route saved = this.routeRepository.save(r); return saved; } @@ -157,46 +158,47 @@ public void delete(final Route r) { // this.routeRepository.delete(route); // } - public Double getDistance(String origin, String destination) { + public Double getDistance(final String origin, final String destination) { Double value = 0.0; try { - String url = "https://maps.googleapis.com/maps/api/directions/json?origin=" + origin.replaceAll(" ", "+") + "&destination=" + destination.replaceAll(" ", "+") + "&key=AIzaSyAKoI-jZJQyPjIp1XGUSsbWh47JBix7qws"; - URL obj = new URL(url); - HttpURLConnection con = (HttpURLConnection) obj.openConnection(); + final String url = "https://maps.googleapis.com/maps/api/directions/json?origin=" + origin.replaceAll(" ", "+") + "&destination=" + destination.replaceAll(" ", "+") + "&key=AIzaSyAKoI-jZJQyPjIp1XGUSsbWh47JBix7qws"; + final URL obj = new URL(url); + final HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("User-Agent", "Mozilla/5.0"); - BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + // final BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + final BufferedReader in = new BufferedReader(new InputStreamReader(((HttpURLConnection) (new URL(url)).openConnection()).getInputStream(), Charset.forName("UTF-8"))); String inputLine; - StringBuffer response = new StringBuffer(); + final StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) response.append(inputLine); in.close(); - JSONObject myResponse = new JSONObject(response.toString()); + final JSONObject myResponse = new JSONObject(response.toString()); - JSONArray routes = myResponse.getJSONArray("routes"); - JSONObject obj1 = routes.getJSONObject(0); - JSONArray dst = obj1.getJSONArray("legs"); - JSONObject obj2 = dst.getJSONObject(0); - JSONObject obj3 = obj2.getJSONObject("distance"); + final JSONArray routes = myResponse.getJSONArray("routes"); + final JSONObject obj1 = routes.getJSONObject(0); + final JSONArray dst = obj1.getJSONArray("legs"); + final JSONObject obj2 = dst.getJSONObject(0); + final JSONObject obj3 = obj2.getJSONObject("distance"); value = obj3.getDouble("value"); value = value / 1000; - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } return DoubleRounder.round(value, 2); } - public Double getPrice(Double distance) { + public Double getPrice(final Double distance) { Double price = 0.0; - Double price3km = 0.33; - Double profit = 0.10; + final Double price3km = 0.33; + final Double profit = 0.10; if (distance < 9.0) price = 1 + profit; else { - String str = String.valueOf(distance / 3); - Integer intNumber = Integer.parseInt(str.substring(0, str.indexOf('.'))); + final String str = String.valueOf(distance / 3); + final Integer intNumber = Integer.parseInt(str.substring(0, str.indexOf('.'))); price = intNumber * price3km + profit; } @@ -205,34 +207,33 @@ public Double getPrice(Double distance) { //Finder - public Collection searchRoutes(Finder finder) { + public Collection searchRoutes(final Finder finder) { this.validateFinder(finder); Collection queryResult, finalResult; - Date departureDate = finder.getDepartureDate(); - LocalTime timeStart = finder.getOriginTime(); - LocalTime timeEnds = finder.getDestinationTime(); - Integer availableSeats = finder.getAvailableSeats(); - Boolean pets = finder.getPets(); - Boolean childs = finder.getChilds(); - Boolean smoke = finder.getSmoke(); - Boolean music = finder.getMusic(); - LuggageSize luggageSize = finder.getLuggageSize(); + final Date departureDate = finder.getDepartureDate(); + final LocalTime timeStart = finder.getOriginTime(); + final LocalTime timeEnds = finder.getDestinationTime(); + final Integer availableSeats = finder.getAvailableSeats(); + final Boolean pets = finder.getPets(); + final Boolean childs = finder.getChilds(); + final Boolean smoke = finder.getSmoke(); + final Boolean music = finder.getMusic(); + final LuggageSize luggageSize = finder.getLuggageSize(); VehicleType vehicleType = null; - Integer vehicleTypeInteger = finder.getVehicleType(); + final Integer vehicleTypeInteger = finder.getVehicleType(); - if (vehicleTypeInteger != 0) { + if (vehicleTypeInteger != 0) vehicleType = finder.getVehicleTypeById(vehicleTypeInteger); - } // En los set de origin y destination, se ponen como "" o lo que sea en minusculas - String origin = finder.getOrigin(); - String destination = finder.getDestination(); + final String origin = finder.getOrigin(); + final String destination = finder.getDestination(); - Calendar departureDateFinder = Calendar.getInstance(); + final Calendar departureDateFinder = Calendar.getInstance(); if (departureDate != null) departureDateFinder.setTime(departureDate); @@ -241,67 +242,56 @@ public Collection searchRoutes(Finder finder) { queryResult = this.routeRepository.searchRoutes(availableSeats); finalResult = new ArrayList(); - Calendar rutaActual = Calendar.getInstance(); + final Calendar rutaActual = Calendar.getInstance(); - for (Route r : queryResult) { + for (final Route r : queryResult) { rutaActual.setTime(r.getDepartureDate()); // Primero filtramos por FECHA Y HORA: - if (departureDate != null && rutaActual.get(Calendar.DAY_OF_YEAR) != departureDateFinder.get(Calendar.DAY_OF_YEAR)) { + if (departureDate != null && rutaActual.get(Calendar.DAY_OF_YEAR) != departureDateFinder.get(Calendar.DAY_OF_YEAR)) continue; - } - LocalTime departureTime = LocalTime.fromDateFields(r.getDepartureDate()); + final LocalTime departureTime = LocalTime.fromDateFields(r.getDepartureDate()); - if (timeStart != null && departureTime.isBefore(timeStart)) { + if (timeStart != null && departureTime.isBefore(timeStart)) // Si la hora de inicio de la ruta es anterior a la del finder, ignorar esta ruta continue; - } - if (timeEnds != null && departureTime.isAfter(timeEnds)) { + if (timeEnds != null && departureTime.isAfter(timeEnds)) //Si la hora de fin de la ruta es posterior a la del finder, ignorar esta ruta continue; - } // Luego por origen y destino: - if (origin != "" && !r.getOrigin().toLowerCase().contains(origin)) { + if (origin != "" && !r.getOrigin().toLowerCase().contains(origin)) continue; - } - if (destination != "" && !r.getDestination().toLowerCase().contains(destination)) { + if (destination != "" && !r.getDestination().toLowerCase().contains(destination)) continue; - } // Después smoke, pets, childs, music - Driver driver = r.getDriver(); + final Driver driver = r.getDriver(); - if (smoke && !driver.getSmoke()) { + if (smoke && !driver.getSmoke()) continue; - } - if (pets && !driver.getPets()) { + if (pets && !driver.getPets()) continue; - } - if (childs && !driver.getChilds()) { + if (childs && !driver.getChilds()) continue; - } - if (music && !driver.getMusic()) { + if (music && !driver.getMusic()) continue; - } // Y por ultimo LuggageSize y VehicleType - if (vehicleType != null && r.getVehicle().getType() != vehicleType) { + if (vehicleType != null && r.getVehicle().getType() != vehicleType) continue; - } - if (luggageSize != null && r.getMaxLuggage().getId() < luggageSize.getId()) { + if (luggageSize != null && r.getMaxLuggage().getId() < luggageSize.getId()) continue; - } finalResult.add(r); @@ -309,7 +299,7 @@ public Collection searchRoutes(Finder finder) { return finalResult; } - private void validateFinder(Finder finder) { + private void validateFinder(final Finder finder) { Assert.notNull(finder); @@ -317,36 +307,32 @@ private void validateFinder(Finder finder) { Assert.isTrue(!finder.getDestination().isEmpty()); // La hora minima de salida debe ser inferior a la hora máxima de salida - if (finder.getOriginTime() != null && finder.getDestinationTime() != null) { + if (finder.getOriginTime() != null && finder.getDestinationTime() != null) Assert.isTrue((finder.getOriginTime().isBefore(finder.getDestinationTime()))); - } //Solamente podemos buscar rutas que sean del día actual hasta el futuro if (finder.getDepartureDate() != null) { - Calendar de = Calendar.getInstance(); - Calendar now = Calendar.getInstance(); + final Calendar de = Calendar.getInstance(); + final Calendar now = Calendar.getInstance(); de.setTime(finder.getDepartureDate()); now.setTime(new Date()); Assert.isTrue(de.get(Calendar.DAY_OF_YEAR) >= now.get(Calendar.DAY_OF_YEAR)); } } - public Collection findActiveRoutesByPassenger(int passengerId) { + public Collection findActiveRoutesByPassenger(final int passengerId) { Assert.isTrue(passengerId != 0); Collection routes, result; - Date now = new Date(); + final Date now = new Date(); routes = this.routeRepository.findActiveRoutesByPassenger(passengerId, ReservationStatus.CANCELLED, ReservationStatus.REJECTED); result = new ArrayList(); - for (Route r : routes) { - Calendar date = Calendar.getInstance(); + for (final Route r : routes) { + final Calendar date = Calendar.getInstance(); date.setTime(r.getDepartureDate()); - long departureDateMilis = date.getTimeInMillis(); - Date arrivalDate = new Date(departureDateMilis + (r.getEstimatedDuration() * 60000)); - System.out.println("--------------"); - System.out.println(r.getDepartureDate() + "->" + arrivalDate); - + final long departureDateMilis = date.getTimeInMillis(); + final Date arrivalDate = new Date(departureDateMilis + (r.getEstimatedDuration() * 60000)); if (arrivalDate.after(now)) result.add(r); } @@ -354,7 +340,7 @@ public Collection findActiveRoutesByPassenger(int passengerId) { return result; } - public Collection findActiveRoutesByDriver(int driverId, Date now) { + public Collection findActiveRoutesByDriver(final int driverId, final Date now) { Assert.isTrue(driverId != 0); Assert.notNull(now); diff --git a/src/main/resources/PopulateDatabase.xml b/src/main/resources/PopulateDatabase.xml index 58f5f52..a7414f7 100644 --- a/src/main/resources/PopulateDatabase.xml +++ b/src/main/resources/PopulateDatabase.xml @@ -6245,7 +6245,6 @@ - @@ -6321,7 +6320,6 @@ - diff --git a/src/main/resources/spring/config/converters.xml b/src/main/resources/spring/config/converters.xml index eb40596..4f6968a 100644 --- a/src/main/resources/spring/config/converters.xml +++ b/src/main/resources/spring/config/converters.xml @@ -28,7 +28,8 @@ - + + diff --git a/src/main/resources/spring/config/security.xml b/src/main/resources/spring/config/security.xml index a264f77..a3dde37 100644 --- a/src/main/resources/spring/config/security.xml +++ b/src/main/resources/spring/config/security.xml @@ -59,10 +59,12 @@ + + - + diff --git a/src/main/webapp/favicon.ico b/src/main/webapp/favicon.ico index 8ed7992..6a17b81 100644 Binary files a/src/main/webapp/favicon.ico and b/src/main/webapp/favicon.ico differ diff --git a/src/main/webapp/images/Thumbs.db b/src/main/webapp/images/Thumbs.db index a97e7a8..3171de7 100644 Binary files a/src/main/webapp/images/Thumbs.db and b/src/main/webapp/images/Thumbs.db differ diff --git a/src/main/webapp/views/master-page/footer.jsp b/src/main/webapp/views/master-page/footer.jsp index a0dfac0..728e791 100644 --- a/src/main/webapp/views/master-page/footer.jsp +++ b/src/main/webapp/views/master-page/footer.jsp @@ -16,4 +16,4 @@
-Copyright © Trond \ No newline at end of file +
Copyright © Trond
\ No newline at end of file diff --git a/src/main/webapp/views/master-page/header.jsp b/src/main/webapp/views/master-page/header.jsp index 7e0acff..a78affa 100644 --- a/src/main/webapp/views/master-page/header.jsp +++ b/src/main/webapp/views/master-page/header.jsp @@ -52,7 +52,16 @@ window.cookieconsent.initialise({
@@ -79,64 +88,73 @@ window.cookieconsent.initialise({
- - - + + + + +
+ \ No newline at end of file diff --git a/src/main/webapp/views/reservation/display.jsp b/src/main/webapp/views/reservation/display.jsp deleted file mode 100644 index 6eca9cd..0000000 --- a/src/main/webapp/views/reservation/display.jsp +++ /dev/null @@ -1,42 +0,0 @@ -<%-- - * action-2.jsp - * - * Copyright (C) 2019 Universidad de Sevilla - * - * The use of this project is hereby constrained to the conditions of the - * TDG Licence, a copy of which you may download from - * http://www.tdg-seville.info/License.html - --%> - -<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> - -<%@taglib prefix="jstl" uri="http://java.sun.com/jsp/jstl/core"%> -<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%> -<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%> -<%@taglib prefix="security" uri="http://www.springframework.org/security/tags"%> -<%@taglib prefix="display" uri="http://displaytag.sf.net"%> - -
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
\ No newline at end of file diff --git a/src/main/webapp/views/reservation/tiles.xml b/src/main/webapp/views/reservation/tiles.xml index 36ebe93..1047a0c 100644 --- a/src/main/webapp/views/reservation/tiles.xml +++ b/src/main/webapp/views/reservation/tiles.xml @@ -16,7 +16,7 @@ - + diff --git a/src/main/webapp/views/reservation/tiles_es.xml b/src/main/webapp/views/reservation/tiles_es.xml index b0887dc..3dfb8cb 100644 --- a/src/main/webapp/views/reservation/tiles_es.xml +++ b/src/main/webapp/views/reservation/tiles_es.xml @@ -16,7 +16,7 @@ - + diff --git a/src/main/webapp/views/route/confirmRoute.jsp b/src/main/webapp/views/route/confirmRoute.jsp index dd4c6bf..9cefca2 100644 --- a/src/main/webapp/views/route/confirmRoute.jsp +++ b/src/main/webapp/views/route/confirmRoute.jsp @@ -50,12 +50,12 @@
- + -
diff --git a/src/main/webapp/views/route/display.jsp b/src/main/webapp/views/route/display.jsp index 677842f..edfb9d6 100644 --- a/src/main/webapp/views/route/display.jsp +++ b/src/main/webapp/views/route/display.jsp @@ -9,6 +9,9 @@ <%@taglib prefix="security" uri="http://www.springframework.org/security/tags"%> <%@taglib prefix="display" uri="http://displaytag.sf.net"%> + +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> + @@ -60,35 +63,55 @@
Preferences: - -

Pets

-
- - <%-- -

Pets

-
--%> - - -

Music

-
- - <%-- -

Music

-
--%> - - -

Smoke

-
- - <%-- -

Smoke

-
--%> - -

Children

-
- <%-- -

Children

-
--%> + + + + + + + + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + + +
+ + + + +
+ + + + +
+ + + + +
+ +
Luggage size: @@ -169,4 +192,177 @@ - \ No newline at end of file + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + + + + + +
+ +
+
+ + +
+ +
+
+
+
+ +
+
+ +
+
+ + + + +
+
+ +
+ + + + + + + + + +
+ +
+
+ +
+ +
+ +
+ +
+ + + + +
+ +
+ + + + + + + + +
+ +
+
+ + +
+ +
+
+ + + + + +
+ +
+
+ + +
+ +
+
+ +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+ +
+
+ + + +
+ +
+ +
+ +
+
+ + + + + + + + + + + + + diff --git a/src/main/webapp/views/route/edit.jsp b/src/main/webapp/views/route/edit.jsp index a704716..b07c8f6 100644 --- a/src/main/webapp/views/route/edit.jsp +++ b/src/main/webapp/views/route/edit.jsp @@ -23,6 +23,9 @@

Create route

+ + +
@@ -149,14 +152,28 @@ value="" onclick="javascript: relativeRedir('route/driver/confirmRoute.do');" /> - + <%-- " /> - - - --%> + + + + + + + + + + + + + + " - onclick="javascript: relativeRedir('route/list.do');" />
+ onclick="javascript: relativeRedir('route/driver/listActive.do');" /> +

diff --git a/src/main/webapp/views/route/list.jsp b/src/main/webapp/views/route/list.jsp index 5a9c055..56c9869 100644 --- a/src/main/webapp/views/route/list.jsp +++ b/src/main/webapp/views/route/list.jsp @@ -20,6 +20,7 @@ uri="http://www.springframework.org/security/tags"%> <%@taglib prefix="display" uri="http://displaytag.sf.net"%> + <%-- @@ -41,7 +42,10 @@
- + <%-- --%> +
-

Available seats:

+

Available seats :

-

seats

+
diff --git a/src/main/webapp/views/route/messages.properties b/src/main/webapp/views/route/messages.properties index aade1de..f4a40db 100644 --- a/src/main/webapp/views/route/messages.properties +++ b/src/main/webapp/views/route/messages.properties @@ -6,29 +6,64 @@ # TDG Licence, a copy of which you may download from # http://www.tdg-seville.info/License.html -route.create = Create route +route.route = Route +route.create = New Route route.distance = Distance route.price = Price -route.departureDate = Departure date -route.origin = Origin +route.departureDate = Departure Date +route.origin = Origin route.destination = Destination -route.stimatedDuration = Stimated duration -route.daysRepeat = Repeated days -route.availableSeats = Available seats +route.stimatedDuration = Estimated Duration +route.daysRepeat = Days to Repeat +route.availableSeats = Available Seats route.details = Details -route.isCancelled = Abort Route -route.maxLuggage = Allowed luggage size +route.isCancelled = Aborted Route +route.maxLuggage = Allowed Luggage Size route.save = Save -route.abort = Abort trip -route.cancel = Cancel route.confirm = Confirm -route.commit.error = Cannot commit operation -driver.commit.error = Error while saving the transaction +route.abort = Abort Route +route.cancel = Cancel +driver.commit.error = Error while saving during transaction route.vehicle = Vehicles -origin.time = Minimum Hour -destination.time = Maximum Hour -route.vehicleType=VehicleType -route.pets=Pets -route.music=Music -route.childs=Children -route.smoke=Smoke \ No newline at end of file +route.vehicleType = Vehicle type + +origin.time = Departure Time +destination.time = Arrival Time +route.formatDate = dd/MM/yyyy HH:mm + +route.driver = Driver +route.passengers = Passengers +route.preferences = Preferences +route.pets = Pets +route.smoke = Smoke +route.music = Music +route.children = Children +route.seats = Seats +route.price.per.passenger = Price per Passenger +route.luggage = Luggage +route.commit.error = Cannot commit operation + +route.request.seats = Request Seats +route.total = Total +route.request = Request + +route.reservation.accept = Accept Request +route.reservation.reject = Reject Request + +route.cancel.route = Cancel Route + +route.vehicle.type = Type +route.vehicle.brand = Brand +route.vehicle.model = Model +route.vehicle.description = Description + +route.reserv.pending = Your reservation is pending of approval +route.reserv.rejected = Your reservation has been rejected by the driver +route.reserv.accepted = Your reservation has been accepted by the driver +route.reserv.cancelled = You have cancelled your reservation + +route.reserv.cancel = Cancel Reservation +route.driver.pick.up = The driver picked me up +route.driver.no.pick.up = The driver didn't pick me up + +route.date.format = {0,date,yyyy/MM/dd HH:mm} diff --git a/src/main/webapp/views/route/messages_es.properties b/src/main/webapp/views/route/messages_es.properties index f3e4bff..2223c4a 100644 --- a/src/main/webapp/views/route/messages_es.properties +++ b/src/main/webapp/views/route/messages_es.properties @@ -6,6 +6,7 @@ # TDG Licence, a copy of which you may download from # http://www.tdg-seville.info/License.html +route.route = Ruta route.create = Crear Ruta route.distance = Distancia route.price = Precio @@ -19,15 +20,50 @@ route.details = Detalles route.isCancelled = Abortar Ruta route.maxLuggage = Tamaño Equipage Permitido route.save = Guardar +route.confirm = Confirmar route.abort = Abortar Viaje route.cancel = Cancelar -route.confirm = Confirmar route.commit.error = Error al guardar en la transaccion route.vehicle = Vehiculos -origin.time =Hora mínima de espera -destination.time =Hora máxima de espera -route.vehicleType=Tipo de vehículo -route.pets=Mascotas -route.music=Música -route.childs=Niños -route.smoke=Tabaco \ No newline at end of file +route.vehicleType = Tipo de vehículo + +origin.time = Hora de salida +destination.time = Hora de llegada +route.formatDate = dd/MM/yyyy HH:mm + +route.driver = Conductor +route.passengers = Pasajeros +route.preferences = Preferencias +route.pets = Mascotas +route.smoke = Fumar +route.music = Musica +route.children = Niños +route.seats = Asientos +route.price.per.passenger = Precio por Pasajero +route.luggage = Equipaje + +route.request.seats = Solicitar Asientos +route.total = Total +route.request = Solicitar + +route.reservation.accept = Aceptar Solicitud +route.reservation.reject = Rechazar Solicitud + +route.cancel.route = Cancelar Ruta + +route.vehicle.type = Tipo +route.vehicle.brand = Marca +route.vehicle.model = Modelo +route.vehicle.description = Descripcion + +route.reserv.pending = Tu reserva está pendiente de aprobación +route.reserv.rejected = Tu reserva ha sido denegada por el conductor +route.reserv.accepted = Tu reserva ha sido aceptada por el conductor +route.reserv.cancelled = Has cancelado tu reserva + +route.reserv.cancel = Cancelar Reserva +route.driver.pick.up = El conductor me ha recogido +route.driver.no.pick.up = El conductor no me ha recogido + +route.date.format = {0,date,dd/MM/yyyy HH:mm} + diff --git a/src/main/webapp/views/route/search.jsp b/src/main/webapp/views/route/search.jsp index bbed453..be7e129 100644 --- a/src/main/webapp/views/route/search.jsp +++ b/src/main/webapp/views/route/search.jsp @@ -83,7 +83,7 @@ id="inputPassword4" required="true"/>
- + @@ -123,7 +123,7 @@
- +
diff --git a/src/main/webapp/views/security/tiles.xml b/src/main/webapp/views/security/tiles.xml index 8654a80..29031f4 100644 --- a/src/main/webapp/views/security/tiles.xml +++ b/src/main/webapp/views/security/tiles.xml @@ -17,7 +17,7 @@ - + diff --git a/src/main/webapp/views/security/tiles_es.xml b/src/main/webapp/views/security/tiles_es.xml index b53c54d..ad2fbfe 100644 --- a/src/main/webapp/views/security/tiles_es.xml +++ b/src/main/webapp/views/security/tiles_es.xml @@ -17,7 +17,7 @@ - +