From af7f062020b9f149e09fd30f8c22427af1ac1134 Mon Sep 17 00:00:00 2001 From: E046899 Date: Tue, 24 Sep 2024 11:00:32 +0200 Subject: [PATCH] reformat code --- .../controller/NamespaceController.java | 32 ++++++++----------- .../controller/NamespaceControllerTest.java | 1 + 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/michelin/ns4kafka/controller/NamespaceController.java b/src/main/java/com/michelin/ns4kafka/controller/NamespaceController.java index 2ed41fc1..f95c7b2a 100644 --- a/src/main/java/com/michelin/ns4kafka/controller/NamespaceController.java +++ b/src/main/java/com/michelin/ns4kafka/controller/NamespaceController.java @@ -166,27 +166,23 @@ public HttpResponse bulkDelete(@QueryValue(defaultValue = "*") String name return HttpResponse.notFound(); } - Map> validationErrors = new HashMap<>(); - - namespaces.forEach(namespace -> - validationErrors.put( - namespace.getMetadata().getName(), - namespaceService.findAllResourcesByNamespace(namespace) - .stream() - .map(FormatErrorUtils::invalidNamespaceDeleteOperation) - .toList()) - ); + List namespaceResources = namespaces + .stream() + .flatMap(namespace -> namespaceService.findAllResourcesByNamespace(namespace) + .stream()) + .toList(); + + if (!namespaceResources.isEmpty()) { + List validationErrors = namespaceResources + .stream() + .map(FormatErrorUtils::invalidNamespaceDeleteOperation) + .toList(); - if (validationErrors.values().stream() - .anyMatch(list -> !list.isEmpty())) { throw new ResourceValidationException( NAMESPACE, - validationErrors.keySet().stream() - .map(Object::toString) - .collect(Collectors.joining("/")), - validationErrors.values().stream() - .flatMap(Collection::stream) - .toList()); + String.join(",", namespaces.stream().map(namespace -> namespace.getMetadata().getName()).toList()), + validationErrors + ); } if (dryrun) { diff --git a/src/test/java/com/michelin/ns4kafka/controller/NamespaceControllerTest.java b/src/test/java/com/michelin/ns4kafka/controller/NamespaceControllerTest.java index ac505078..61685c15 100644 --- a/src/test/java/com/michelin/ns4kafka/controller/NamespaceControllerTest.java +++ b/src/test/java/com/michelin/ns4kafka/controller/NamespaceControllerTest.java @@ -481,6 +481,7 @@ void shouldNotDeleteNamespacesWhenResourcesAreStillLinkedWithIt() { @Test void shouldNotDeleteNamespacesWhenPatternMatchesNothing() { + when(namespaceService.findByWildcardName("namespace*")).thenReturn(List.of()); var result = namespaceController.bulkDelete("namespace*", false); assertEquals(HttpResponse.notFound().getStatus(), result.getStatus()); }