Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencalime committed Sep 24, 2024
1 parent f5e483c commit af7f062
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,27 +166,23 @@ public HttpResponse<Void> bulkDelete(@QueryValue(defaultValue = "*") String name
return HttpResponse.notFound();
}

Map<String, List<String>> validationErrors = new HashMap<>();

namespaces.forEach(namespace ->
validationErrors.put(
namespace.getMetadata().getName(),
namespaceService.findAllResourcesByNamespace(namespace)
.stream()
.map(FormatErrorUtils::invalidNamespaceDeleteOperation)
.toList())
);
List<String> namespaceResources = namespaces
.stream()
.flatMap(namespace -> namespaceService.findAllResourcesByNamespace(namespace)
.stream())
.toList();

if (!namespaceResources.isEmpty()) {
List<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit af7f062

Please sign in to comment.