From baee1727cc0cf795e0ba3387fb874d1fc5ab662f Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Mon, 14 Oct 2024 12:28:24 +0200
Subject: [PATCH] OZG-6522 fix deprecated old bayernid type

---
 .../nachrichten/postfach/PostfachService.java | 29 +++++++++----------
 .../postfach/PostfachServiceTest.java         |  6 ----
 2 files changed, 14 insertions(+), 21 deletions(-)

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 650a7a0..2d6341f 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
@@ -28,6 +28,7 @@ import java.util.EnumSet;
 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;
@@ -240,21 +241,19 @@ class PostfachService {
 	}
 
 	public Stream<Postfach> getPostfachs() {
-		return postfachRemoteServices.stream().flatMap(Collection::stream).map(this::buildPostfach);
-	}
-
-	// TODO wieder einbauen
-	private Stream<Postfach> getPostfaecher() {
-		var postfach = buildPostfach(postfachRemoteService);
-		// TODO Nach Umstellung auf BAYERN_ID entfernen
-		if (postfachRemoteService.getPostfachType().equals("BAYERN_ID")) {
-			return Stream.of(postfach, Postfach.builder()
-					.type("BayernId")
-					.isReplyAllowed(postfach.isReplyAllowed())
-					.build());
-		}
-		//
-		return Stream.of(postfach);
+		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);
+	}
+
+	// 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());
 	}
 
 	Postfach buildPostfach(PostfachRemoteService postfachRemoteService) {
diff --git a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachServiceTest.java b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachServiceTest.java
index 2271307..ca8bde6 100644
--- a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachServiceTest.java
+++ b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachServiceTest.java
@@ -860,11 +860,6 @@ class PostfachServiceTest {
 
 		private final Postfach postfach = PostfachTestFactory.create();
 
-		@BeforeEach
-		void init() {
-			doReturn(postfach).when(service).buildPostfach(any());
-		}
-
 		@Test
 		void shouldCallBuildPostfach() {
 			when(postfachRemoteService.getPostfachType()).thenReturn(PostfachTestFactory.POSTFACH_TYPE);
@@ -898,7 +893,6 @@ class PostfachServiceTest {
 
 			@BeforeEach
 			void mock() {
-				doReturn(true).when(service).isPostfachConfigured();
 				when(postfachRemoteService.getPostfachType()).thenReturn(BAYERN_ID_POSTFACH);
 			}
 
-- 
GitLab