Skip to content
Snippets Groups Projects
Commit 7b26bc2a authored by Lukasz Lopatowski's avatar Lukasz Lopatowski
Browse files

Merge branch 'update-webhooks-update' into 'develop'

Update webhooks update

See merge request !211
parents 9a21e743 6bff48cf
No related branches found
No related tags found
1 merge request!211Update webhooks update
Pipeline #94400 passed
...@@ -151,11 +151,7 @@ public class RemoteClusterManager implements ClusterMonitoringService { ...@@ -151,11 +151,7 @@ public class RemoteClusterManager implements ClusterMonitoringService {
.state(KClusterState.UNKNOWN) .state(KClusterState.UNKNOWN)
.contactEmail(view.getContactEmail()) .contactEmail(view.getContactEmail())
.currentStateSince(OffsetDateTime.now()) .currentStateSince(OffsetDateTime.now())
.domains(!view.getDomainNames().isEmpty() ? view.getDomainNames().stream().map(d -> { .domains(prepareList(view))
Optional<Domain> dom = domainService.findDomain(d);
return dom.orElse(null);
}
).toList() : Collections.emptyList())
.build(), .build(),
file); file);
...@@ -170,6 +166,17 @@ public class RemoteClusterManager implements ClusterMonitoringService { ...@@ -170,6 +166,17 @@ public class RemoteClusterManager implements ClusterMonitoringService {
return null; return null;
} }
private List<Domain> prepareList(RemoteClusterView view) {
if (view == null || view.getDomainNames() == null) {
return Collections.emptyList();
}
return view.getDomainNames().stream().map(d -> {
Optional<Domain> dom = domainService.findDomain(d);
return dom.orElse(null);
}
).toList();
}
public RemoteClusterView updateCluster(RemoteClusterView cluster, Long id) { public RemoteClusterView updateCluster(RemoteClusterView cluster, Long id) {
Optional<KCluster> entity = clusterRepository.findById(id); Optional<KCluster> entity = clusterRepository.findById(id);
...@@ -332,7 +339,7 @@ public class RemoteClusterManager implements ClusterMonitoringService { ...@@ -332,7 +339,7 @@ public class RemoteClusterManager implements ClusterMonitoringService {
public void removeCluster(Long id) { public void removeCluster(Long id) {
try { try {
if(clusterRepository.existsById(id)) { if (clusterRepository.existsById(id)) {
this.clusterRepository.deleteById(id); this.clusterRepository.deleteById(id);
} }
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
......
...@@ -49,13 +49,13 @@ public class WebhookEventController { ...@@ -49,13 +49,13 @@ public class WebhookEventController {
@PutMapping("/{id}") @PutMapping("/{id}")
@Transactional @Transactional
@PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN')") @PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN')")
public void updateWebhook(@PathVariable Long id, @RequestBody @Valid WebhookEventDto webhook) { public ResponseEntity<WebhookEventDto> updateWebhook(@PathVariable Long id, @RequestBody @Valid WebhookEventDto webhook) {
if (!id.equals(webhook.getId())) { if (!id.equals(webhook.getId())) {
throw new ProcessingException(UNABLE_TO_CHANGE_WEBHOOK_EVENT); throw new ProcessingException(UNABLE_TO_CHANGE_WEBHOOK_EVENT);
} }
try { try {
webhookEventService.update(webhook); return ResponseEntity.ok(webhookEventService.update(webhook));
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
...@@ -35,10 +35,11 @@ public class WebhookEventService { ...@@ -35,10 +35,11 @@ public class WebhookEventService {
return webhookRepository.save(webhookEvent); return webhookRepository.save(webhookEvent);
} }
public void update(WebhookEventDto webhookEventDto) throws GeneralSecurityException { public WebhookEventDto update(WebhookEventDto webhookEventDto) throws GeneralSecurityException {
WebhookEvent webhookEvent = webhookRepository.findById(webhookEventDto.getId()).orElseThrow(() -> new MissingElementException(WEBHOOK_EVENT_NOT_FOUND)); WebhookEvent webhookEvent = webhookRepository.findById(webhookEventDto.getId()).orElseThrow(() -> new MissingElementException(WEBHOOK_EVENT_NOT_FOUND));
setWebhookEvent(webhookEvent, webhookEventDto); setWebhookEvent(webhookEvent, webhookEventDto);
webhookRepository.save(webhookEvent); webhookEvent = webhookRepository.save(webhookEvent);
return modelMapper.map(webhookEvent, WebhookEventDto.class);
} }
private void setWebhookEvent(WebhookEvent webhookEvent, WebhookEventDto webhookEventDto) throws GeneralSecurityException { private void setWebhookEvent(WebhookEvent webhookEvent, WebhookEventDto webhookEventDto) throws GeneralSecurityException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment