Search in sources :

Example 1 with Charger

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;
}
Also used : NotValidUpdateException(com.adja.evchargerappserver.api.NotValidUpdateException) Charger(com.adja.evchargerappserver.api.charger.Charger) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Charger

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());
    });
}
Also used : Charger(com.adja.evchargerappserver.api.charger.Charger) Person(com.adja.evchargerappserver.api.person.Person) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Charger

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;
    }
}
Also used : Charger(com.adja.evchargerappserver.api.charger.Charger) EntityNotFoundException(javax.persistence.EntityNotFoundException) Person(com.adja.evchargerappserver.api.person.Person)

Aggregations

Charger (com.adja.evchargerappserver.api.charger.Charger)3 Person (com.adja.evchargerappserver.api.person.Person)2 Transactional (org.springframework.transaction.annotation.Transactional)2 NotValidUpdateException (com.adja.evchargerappserver.api.NotValidUpdateException)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1