private void moveCurrentCarToCarHistory(Employee employee) { Car currentCar = carRepository.findOne(employee.getCurrentCar().getId()); Set<Car> carHistory = employee.getCarHistory(); carHistory.add(employee.getCurrentCar()); if (currentCar.getEndLeasing().isAfter(LocalDate.now()) && !(currentCar.getEndLeasing().isEqual(LocalDate.now()))) { currentCar.setInThePool(true); } carRepository.save(currentCar); }
@Override public CarDTO assignPoolCarToEmployee(EmployeeDTO employeeDTO, CarDTO carDTO) { Employee employee = employeeRepository.findOneByEmail(employeeDTO.getEmail()).get(); updatePoolCar(carRepository.findOne(carDTO.getId())); Car currentCar = employee.getCurrentCar(); if (currentCar != null) { Set<Car> carHistory = employee.getCarHistory(); currentCar.setEndLeasing(LocalDate.now()); carHistory.add(currentCar); } employee.setCurrentCar(carRepository.findOne(carDTO.getId())); employee.setReceivedMailForNewCar(false); employeeRepository.save(employee); return carDTO; }
public Car createNewCarFromOrder( Order order, int leasingDurationInYears, String numberPlate, String vinNumber) { Car car = new Car(); car.setCarType(order.getCarType()); if (order.getOptions().size() > 1) { List<CarOption> optionList = order.getOptions(); car.setCarOptions(optionList); } car.setLeasingDurationYears(leasingDurationInYears); car.setNumberPlate(numberPlate); car.setStartLeasing(LocalDate.now()); car.setVinNumber(vinNumber); orderRepository.delete(order); carRepository.save(car); return car; }
public void updatePoolCar(Car car) { car.setInThePool(false); car.setStartLeasing(LocalDate.now()); carRepository.save(car); }