use of com.adja.evchargerappserver.api.electriccar.ElectricCar in project iet-hf-2022-k-k-k-k-k-k by BME-MIT-IET.
the class ChargerService method carAttemptsCharging.
@Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = NotValidUpdateException.class)
public boolean carAttemptsCharging(Long chargerId, Long carId) throws NotValidUpdateException {
Optional<Charger> chargerById = this.repository.findById(chargerId);
if (chargerById.isEmpty()) {
throw new NotValidUpdateException("");
} else {
Charger charger = chargerById.get();
if (charger.getCurrentlyChargingCar() != null) {
return false;
} else {
Optional<ElectricCar> carOptional = this.electricCarRepository.findById(carId);
if (carOptional.isEmpty())
throw new NotValidUpdateException("");
ElectricCar car = carOptional.get();
if (!car.getCarType().getCompatibleChargerTypes().contains(charger.getChargerType())) {
return false;
}
car.setCharger(charger);
this.electricCarRepository.save(car);
charger.setCurrentlyChargingCar(car);
this.repository.save(charger);
return true;
}
}
}
use of com.adja.evchargerappserver.api.electriccar.ElectricCar in project iet-hf-2022-k-k-k-k-k-k by BME-MIT-IET.
the class MockElectricCarHandler method onBatteryPercentageChanged.
private void onBatteryPercentageChanged(ElectricCarRepresentation car) {
this.electricCarService.persistBatteryPercentageChanges(car.getID(), car.getBatteryPercentage());
ElectricCar persistedCar = this.electricCarService.getById(car.getID());
if (persistedCar.getCharger() != null) {
this.websocket.sendChargingStationUpdateFromJava(new ChargingStationStateChange(persistedCar.getCharger().getChargingStation().getId()));
if (persistedCar.getBatteryPercentage() == 80) {
this.notificationService.carReached80PercentBattery(persistedCar);
}
}
this.websocket.sendCarBatteryPercentageUpdateFromJava(new CarBatteryStateChange(persistedCar.getId(), (long) persistedCar.getBatteryPercentage()));
}
use of com.adja.evchargerappserver.api.electriccar.ElectricCar in project iet-hf-2022-k-k-k-k-k-k by BME-MIT-IET.
the class PersonService method setCarToPerson.
@Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = NotValidUpdateException.class)
public void setCarToPerson(Long id, Long carId) throws NotValidUpdateException {
try {
Person person = this.getById(id);
ElectricCar car = this.electricCarService.getById(carId);
if (car.getDriver() != null)
throw new NotValidUpdateException("");
if (person.getCar() != null) {
person.getCar().setDriver(null);
}
car.setDriver(person);
person.setCar(car);
this.put(id, person);
} catch (EntityNotFoundException e) {
throw new NotValidUpdateException("");
}
}
Aggregations