Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package lapr.project.controller;
- import java.sql.Timestamp;
- import lapr.project.model.Bicycle;
- import lapr.project.model.Journey;
- import lapr.project.model.Park;
- import lapr.project.model.ParkingSlot;
- /**
- *
- * @author morei
- */
- public class ReturnRentedBicycleController {
- private ReturnRentedBicycleController() {
- }
- public static boolean returnRentendBicycle(String email, Timestamp inicialDate, Timestamp finalDate, Park destinationPark) {
- Journey journey = getJorney(email, inicialDate);
- Bicycle bicycle = getBicycleById(journey);
- ParkingSlot parkingSlot = getParkingSlot(destinationPark, bicycle);
- if (parkingSlot != null) {
- updateParkingSlot(parkingSlot, bicycle.getId_bicycle());
- parkingSlot.saveParkingSlot();
- }
- updateJourney(journey, finalDate, destinationPark);
- Journey.updateJourney(journey);
- Park originPark = journey.getOriginPark();
- updatePark(destinationPark, originPark, bicycle);
- originPark.save();
- destinationPark.save();
- return true;
- }
- public static boolean updateParkingSlot(ParkingSlot parkingSlot, int idBicycle) {
- parkingSlot.setIdBicycle(idBicycle);
- return true;
- }
- public static boolean updateJourney(Journey journey, Timestamp finalDate, Park destinationPark) {
- journey.setFinalDate(finalDate);
- journey.setDestinationPark(destinationPark);
- return true;
- }
- public static boolean updatePark(Park destinationPark, Park originPark, Bicycle bicycle) {
- if (bicycle.getType() == 0) {
- destinationPark.setElectricOccupation(destinationPark.getElectricOccupation() + 1);
- originPark.setElectricOccupation(originPark.getElectricOccupation() - 1);
- } else {
- destinationPark.setNonElectricOccupation(destinationPark.getNonElectricOccupation() + 1);
- originPark.setNonElectricOccupation(originPark.getNonElectricOccupation() - 1);
- }
- return true;
- }
- public static Bicycle getBicycleById(Journey journey) {
- return Bicycle.getBicycle(journey.getIdBicycle());
- }
- public static Journey getJorney(String email, Timestamp inicialDate) {
- return Journey.getJourney(email, inicialDate);
- }
- public static ParkingSlot getParkingSlot(Park p, Bicycle b) {
- ParkingSlot pa = null;
- for (ParkingSlot ps : p.getSlots()) {
- if (ps.getIdType() == b.getType() && ps.getIdBicycle() == 0) {
- pa = ps;
- }
- }
- return pa;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement