use of com.adja.evchargerappserver.api.charger.Charger 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.charger.Charger in project iet-hf-2022-k-k-k-k-k-k by BME-MIT-IET.
the class NotificationService method chargingEnded.
@Transactional(isolation = Isolation.REPEATABLE_READ)
public void chargingEnded(Long chargerId) {
NotificationFilter filter = new NotificationFilter();
filter.setChargerId(chargerId);
filter.setPersonId(null);
Collection<Notification> notificationsOfCharger = this.search(filter);
notificationsOfCharger.forEach(notification -> {
Person person = this.personService.getById(notification.getPersonToNotifyId());
Charger charger = this.chargerService.getById(notification.getObservedChargerId());
this.emailSendingService.sendChargingEndedNotificationMail(person, charger);
this.deleteById(notification.getId());
});
}
use of com.adja.evchargerappserver.api.charger.Charger in project iet-hf-2022-k-k-k-k-k-k by BME-MIT-IET.
the class NotificationService method validateEntity.
@Override
protected boolean validateEntity(Notification entity) {
if (entity.getPersonToNotifyId() == null || entity.getObservedChargerId() == null)
return false;
try {
Person person = this.personService.getById(entity.getPersonToNotifyId());
Charger charger = this.chargerService.getById(entity.getObservedChargerId());
NotificationFilter alreadyExistingNotificationFilter = new NotificationFilter(entity.getPersonToNotifyId(), entity.getObservedChargerId());
if (!this.search(alreadyExistingNotificationFilter).isEmpty())
return false;
return person.getEmail() != null && charger.getCurrentlyChargingCar() != null;
} catch (EntityNotFoundException e) {
return false;
}
}
Aggregations