diff --git a/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachService.java b/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachService.java index 2d6341f5d91d755bff17204a8cf23e7de051abc5..0a72b6c68c8c0ce9c26de78c322623683cc6e1ed 100644 --- a/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachService.java +++ b/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachService.java @@ -25,10 +25,10 @@ package de.ozgcloud.nachrichten.postfach; import java.time.ZonedDateTime; import java.util.Collection; import java.util.EnumSet; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.function.Supplier; import java.util.stream.Stream; import jakarta.annotation.PostConstruct; @@ -241,19 +241,15 @@ class PostfachService { } public Stream<Postfach> getPostfachs() { - Supplier<Stream<PostfachRemoteService>> postfachRemoteServicesStream = () -> postfachRemoteServices.stream().flatMap(Collection::stream); - var oldBayernIdPostfachStream = buildOldBayernIdPostfach(postfachRemoteServicesStream.get()); - var postfachsStream = postfachRemoteServicesStream.get().map(this::buildPostfach); - return Stream.concat(postfachsStream, oldBayernIdPostfachStream); + return postfachRemoteServices.stream().flatMap(Collection::stream).map(this::getPostfaecher).flatMap(Collection::stream); } // TODO Nach Umstellung auf BAYERN_ID entfernen - private Stream<Postfach> buildOldBayernIdPostfach(Stream<PostfachRemoteService> postfachRemoteServicesStream) { - return postfachRemoteServicesStream.filter(remotePostfach -> "BAYERN_ID".equals(remotePostfach.getPostfachType())) - .map(remotePostfach -> Postfach.builder() - .type("BayernId") - .isReplyAllowed(isReplyAllowed(remotePostfach)) - .build()); + private List<Postfach> getPostfaecher(PostfachRemoteService remoteService) { + var postfach = buildPostfach(remoteService); + return "BAYERN_ID".equals(remoteService.getPostfachType()) + ? List.of(postfach, Postfach.builder().type("BayernId").isReplyAllowed(postfach.isReplyAllowed()).build()) + : List.of(postfach); } Postfach buildPostfach(PostfachRemoteService postfachRemoteService) {