src/com/vehiclerental/logicLayer/implementations/VehicleServiceImpl.java
/**
     * Returns all the available vehicles in a specific branch for the given criteria
     * Takes in account if the branch is the booking branch or not and if it should apply an additional move time or not
     *
     * @param searchCriteriaContract the search criteria details
     * @param currentBranch the current branch
     * @param requiresMove true if it requires a vehicle move for this branch
     * @return the list of the available vehicles
     * @throws InvalidDateException if one of the dates is invalid
     */
Returns all the available vehicles in a specific branch for the given criteria
Takes in account if the branch is the booking branch or not and if it should apply an additional move time or not


Returns all the available vehicles in a specific branch for the given criteria Takes in account if the branch is the booking branch or not and if it should apply an additional move time or not
@Override
    public List<BookingSearchResultContract> searchAvailableVehicles(SearchAvailableVehiclesRequestContract searchCriteriaContract, Branch currentBranch, boolean requiresMove) throws InvalidDateException {
        Calendar startDate = DateUtils.getCalendarFromIso8601String(searchCriteriaContract.pickupDate);
        Calendar endDate = DateUtils.getCalendarFromIso8601String(searchCriteriaContract.returnDate);
        Calendar todayCalendar = DateUtils.getTodayCalendar();
        if(DateUtils.getBookingDays(startDate, endDate) > 7) {
            throw new InvalidDateException("Bookings are only available for a maximum of 7 days");
        }
        if (requiresMove) {
            startDate.add(Calendar.DAY_OF_YEAR, -1);
            endDate.add(Calendar.DAY_OF_YEAR, 1);
        }
        if (DateUtils.compareCalendar(todayCalendar, startDate) != DateUtils.DATE1_BEFORE_DATE2) {
            if (requiresMove) {
                throw new InvalidDateException("Impossible to book a vehicle on a distant branch for tomorrow or before");
            } else {
                throw new InvalidDateException("Impossible to book a vehicle for the same day or before");
            }
        }
        if (DateUtils.compareCalendar(startDate, endDate) != DateUtils.DATE1_BEFORE_DATE2) {
            throw new InvalidDateException("The return date must be after the pick up date");
        }
        List<Vehicle> vehicles = vehicleDao.getAvailableVehicles(
                currentBranch,
                searchCriteriaContract.vehicleType,
                startDate,
                endDate);
        List<BookingSearchResultContract> responseContracts = new ArrayList<BookingSearchResultContract>();
        Calendar pickupDate = DateUtils.getCalendarFromIso8601String(searchCriteriaContract.pickupDate);
        Calendar returnDate = DateUtils.getCalendarFromIso8601String(searchCriteriaContract.returnDate);
        for (Vehicle vehicle : vehicles) {
            BookingSearchResultContract result = new BookingSearchResultContract();
            result.vehicle = new VehicleContract(vehicle);
            result.daysCount = DateUtils.getBookingDays(pickupDate, returnDate);
            result.requireVehicleMove = requiresMove;
            result.pickupDate = DateUtils.getIso8601DateString(pickupDate);
            result.returnDate = DateUtils.getIso8601DateString(returnDate);
            result.price = Math.round(vehicle.getPoundsPerDay() * result.daysCount * 100.0) / 100.0;
            responseContracts.add(result);
        }
        return responseContracts;
    }
@ Override public List < BookingSearchResultContract > searchAvailableVehicles ( SearchAvailableVehiclesRequestContract searchCriteriaContract , Branch currentBranch , boolean requiresMove ) throws InvalidDateException { Calendar startDate = DateUtils . getCalendarFromIso8601String ( searchCriteriaContract . pickupDate ) ; Calendar endDate = DateUtils . getCalendarFromIso8601String ( searchCriteriaContract . returnDate ) ; Calendar todayCalendar = DateUtils . getTodayCalendar ( ) ; if ( DateUtils . getBookingDays ( startDate , endDate ) > 7 ) { throw new InvalidDateException ( "Bookings are only available for a maximum of 7 days" ) ; } if ( requiresMove ) { startDate . add ( Calendar . DAY_OF_YEAR , - 1 ) ; endDate . add ( Calendar . DAY_OF_YEAR , 1 ) ; } if ( DateUtils . compareCalendar ( todayCalendar , startDate ) != DateUtils . DATE1_BEFORE_DATE2 ) { if ( requiresMove ) { throw new InvalidDateException ( "Impossible to book a vehicle on a distant branch for tomorrow or before" ) ; } else { throw new InvalidDateException ( "Impossible to book a vehicle for the same day or before" ) ; } } if ( DateUtils . compareCalendar ( startDate , endDate ) != DateUtils . DATE1_BEFORE_DATE2 ) { throw new InvalidDateException ( "The return date must be after the pick up date" ) ; } List < Vehicle > vehicles = vehicleDao . getAvailableVehicles ( currentBranch , searchCriteriaContract . vehicleType , startDate , endDate ) ; List < BookingSearchResultContract > responseContracts = new ArrayList < BookingSearchResultContract > ( ) ; Calendar pickupDate = DateUtils . getCalendarFromIso8601String ( searchCriteriaContract . pickupDate ) ; Calendar returnDate = DateUtils . getCalendarFromIso8601String ( searchCriteriaContract . returnDate ) ; for ( Vehicle vehicle : vehicles ) { BookingSearchResultContract result = new BookingSearchResultContract ( ) ; result . vehicle = new VehicleContract ( vehicle ) ; result . daysCount = DateUtils . getBookingDays ( pickupDate , returnDate ) ; result . requireVehicleMove = requiresMove ; result . pickupDate = DateUtils . getIso8601DateString ( pickupDate ) ; result . returnDate = DateUtils . getIso8601DateString ( returnDate ) ; result . price = Math . round ( vehicle . getPoundsPerDay ( ) * result . daysCount * 100.0 ) / 100.0 ; responseContracts . add ( result ) ; } return responseContracts ; }
Returns all the available vehicles in a specific branch for the given criteria
 Takes in account if the branch is the booking branch or not and if it should apply an additional move time or not
Returns all the available vehicles in a specific branch for the given criteria Takes in account if the branch is the booking branch or not and if it should apply an additional move time or not
//Include moving time in the search //Today must be strictly before the start date //Start date must be before end date