use of com.adja.evchargerappserver.api.NotValidUpdateException in project iet-hf-2022-k-k-k-k-k-k by BME-MIT-IET.
the class AbstractService method post.
public ENTITY post(ENTITY entity) throws NotValidUpdateException {
if (this.validateEntity(entity)) {
entity.setId(null);
Long id = this.repository.save(entity).getId();
return this.getById(id);
} else
throw new NotValidUpdateException("");
}
use of com.adja.evchargerappserver.api.NotValidUpdateException 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.NotValidUpdateException in project iet-hf-2022-k-k-k-k-k-k by BME-MIT-IET.
the class ElectricCarService method endCharging.
@Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = NotValidUpdateException.class)
public boolean endCharging(Long carId) throws NotValidUpdateException {
Optional<ElectricCar> carById = this.repository.findById(carId);
if (carById.isEmpty()) {
throw new NotValidUpdateException("");
}
ElectricCar car = carById.get();
if (car.getCharger() != null) {
Charger charger = this.chargerService.getById(car.getCharger().getId());
charger.setCurrentlyChargingCar(null);
car.setCharger(null);
this.chargerService.put(charger.getId(), charger);
this.put(carId, car);
mockElectricCarHandler.endCharging(car);
this.notificationService.chargingEnded(charger.getId());
}
return true;
}
use of com.adja.evchargerappserver.api.NotValidUpdateException 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