use of com.adja.evchargerappserver.api.person.Person in project iet-hf-2022-k-k-k-k-k-k by BME-MIT-IET.
the class ElectricCarController method hasRightForUpdate.
@Override
public boolean hasRightForUpdate(Long id, ElectricCar car, HttpHeaders headers) {
String username = JwtUtil.getUsernameFromJwt(headers.getFirst(HttpHeaders.AUTHORIZATION));
Person personByName = this.personService.getByUsername(username);
return Objects.equals(car.getId(), personByName.getCar().getId());
}
use of com.adja.evchargerappserver.api.person.Person 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.person.Person 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;
}
}
use of com.adja.evchargerappserver.api.person.Person in project iet-hf-2022-k-k-k-k-k-k by BME-MIT-IET.
the class TokenController method refreshToken.
@PostMapping("/token/refresh")
public void refreshToken(HttpServletRequest request, HttpServletResponse response) throws IOException {
String authorizationHeader = request.getHeader(HttpHeaders.AUTHORIZATION);
if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ")) {
try {
Person person = this.personService.getByUsername(JwtUtil.getUsernameFromJwt(authorizationHeader));
String accessToken = JwtUtil.createAccessToken(request.getRequestURL().toString(), person.getRoles().stream().map(Role::getName).collect(Collectors.toList()), request.getRequestURL().toString());
String refreshToken = authorizationHeader.substring("Bearer ".length());
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
Map<String, String> tokens = new HashMap<>();
tokens.put("accessToken", accessToken);
tokens.put("refreshToken", refreshToken);
new ObjectMapper().writeValue(response.getOutputStream(), tokens);
} catch (Exception e) {
response.setHeader("error", e.getMessage());
response.setStatus(HttpStatus.FORBIDDEN.value());
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
Map<String, String> error = new HashMap<>();
error.put("error_message", e.getMessage());
new ObjectMapper().writeValue(response.getOutputStream(), error);
}
} else {
throw new RuntimeException("Refresh token is missing");
}
}
Aggregations