From c60cc3bc0390a46c772f33d18c4ae31ae4eb169d Mon Sep 17 00:00:00 2001 From: Lukasz Lopatowski <llopat@man.poznan.pl> Date: Tue, 27 May 2025 14:22:31 +0200 Subject: [PATCH] Fix in webbooks retrieval --- .../portal/service/WebhookEventService.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/geant/nmaas/portal/service/WebhookEventService.java b/src/main/java/net/geant/nmaas/portal/service/WebhookEventService.java index 7423f74cf..e13727362 100644 --- a/src/main/java/net/geant/nmaas/portal/service/WebhookEventService.java +++ b/src/main/java/net/geant/nmaas/portal/service/WebhookEventService.java @@ -23,7 +23,7 @@ public class WebhookEventService { private static final String WEBHOOK_EVENT_NOT_FOUND = "WebhookEvent not found."; @Autowired - public WebhookEventService(WebhookEventRepository webhookRepository, EncryptionService encryptionService, ModelMapper modelMapper){ + public WebhookEventService(WebhookEventRepository webhookRepository, EncryptionService encryptionService, ModelMapper modelMapper) { this.webhookRepository = webhookRepository; this.encryptionService = encryptionService; this.modelMapper = modelMapper; @@ -50,20 +50,21 @@ public class WebhookEventService { webhookEvent.setAuthorizationHeader(webhookEventDto.getAuthorizationHeader()); } - public void remove(Long id){ + public void remove(Long id) { WebhookEvent webhookEvent = webhookRepository.findById(id).orElseThrow(() -> new MissingElementException(WEBHOOK_EVENT_NOT_FOUND)); webhookRepository.delete(webhookEvent); } public List<WebhookEventDto> getAllWebhooks() { - return webhookRepository.findAll().stream().map(x -> - { + return webhookRepository.findAll().stream() + .map(x -> { try { - x.setTokenValue(x.getTokenValue() == null ? null : encryptionService.decrypt(x.getTokenValue())); + WebhookEventDto dto = modelMapper.map(x, WebhookEventDto.class); + dto.setTokenValue(x.getTokenValue() == null ? null : encryptionService.decrypt(x.getTokenValue())); + return dto; } catch (GeneralSecurityException e) { throw new RuntimeException(e); } - return modelMapper.map(x, WebhookEventDto.class); }).toList(); } @@ -74,7 +75,8 @@ public class WebhookEventService { public WebhookEventDto getById(Long id) throws GeneralSecurityException { WebhookEvent event = webhookRepository.findById(id) .orElseThrow(() -> new MissingElementException(String.format("WebhookEventType with id: %d cannot be found", id))); - event.setTokenValue(event.getTokenValue() == null ? null : encryptionService.decrypt(event.getTokenValue())); - return modelMapper.map(event, WebhookEventDto.class); + WebhookEventDto dto = modelMapper.map(event, WebhookEventDto.class); + dto.setTokenValue(event.getTokenValue() == null ? null : encryptionService.decrypt(event.getTokenValue())); + return dto; } } -- GitLab