From 0a291f215de762a208508edcdf2c8e319129f112 Mon Sep 17 00:00:00 2001
From: Krzysztof <krzysztof.witukiewicz@mgm-tp.com>
Date: Fri, 4 Apr 2025 14:14:15 +0200
Subject: [PATCH 1/2] OZG-7773 OZG-8001 Link to set mails as unread

---
 .../ClientAttributeService.java               |  3 +++
 .../postfach/PostfachMailModelAssembler.java  |  6 ++---
 ....java => SetNewPostfachNachrichtBody.java} |  2 +-
 .../alfa/vorgang/VorgangController.java       | 12 ++++------
 .../ClientAttributeServiceTest.java           | 14 +++++++++--
 .../PostfachMailModelAssemblerTest.java       | 24 +++++++++++++++++++
 .../alfa/vorgang/VorgangControllerTest.java   | 11 ++++-----
 7 files changed, 53 insertions(+), 19 deletions(-)
 rename alfa-service/src/main/java/de/ozgcloud/alfa/vorgang/{ResetNewPostfachNachrichtBody.java => SetNewPostfachNachrichtBody.java} (96%)

diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/common/clientattribute/ClientAttributeService.java b/alfa-service/src/main/java/de/ozgcloud/alfa/common/clientattribute/ClientAttributeService.java
index 3920a077b0..109c3cc16f 100644
--- a/alfa-service/src/main/java/de/ozgcloud/alfa/common/clientattribute/ClientAttributeService.java
+++ b/alfa-service/src/main/java/de/ozgcloud/alfa/common/clientattribute/ClientAttributeService.java
@@ -37,4 +37,7 @@ public class ClientAttributeService {
 		remoteService.setBooleanReadOnlyClientAttribute(vorgangId, ClientAttribute.HAS_NEW_POSTFACH_NACHRICHT, false);
 	}
 
+	public void setHasNewPostfachNachricht(String vorgangId) {
+		remoteService.setBooleanReadOnlyClientAttribute(vorgangId, ClientAttribute.HAS_NEW_POSTFACH_NACHRICHT, true);
+	}
 }
diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssembler.java b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssembler.java
index d1f3b17742..792d90d96a 100644
--- a/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssembler.java
+++ b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssembler.java
@@ -58,6 +58,7 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac
 	public static final String REL_SEND = "send";
 	public static final String REL_RESEND_POSTFACH_MAIL = "resendPostfachMail";
 	public static final String REL_RESET_NEW_POSTFACH_MAIL = "resetHasNewPostfachNachricht";
+	public static final String REL_SET_HAS_NEW_POSTFACH_MAIL = "setHasNewPostfachNachricht";
 	public static final String REL_ATTACHMENTS = "attachments";
 	public static final String REL_EDIT = "edit";
 	static final String REL_UPLOAD_ATTACHMENT = "uploadAttachment";
@@ -116,9 +117,8 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac
 		model.add(linkTo(BinaryFileController.class).slash(vorgangId).slash(POSTFACH_NACHRICHT_ATTACHMENT_FIELD).slash(FILE_PATH)
 				.withRel(REL_UPLOAD_ATTACHMENT));
 
-		if (vorgang.isHasNewPostfachNachricht()) {
-			model.add(linkTo(VorgangController.class).slash(vorgangId).slash(HAS_NEW_POSTFACH_NACHRICHT_FIELD).withRel(REL_RESET_NEW_POSTFACH_MAIL));
-		}
+		model.add(linkTo(VorgangController.class).slash(vorgangId).slash(HAS_NEW_POSTFACH_NACHRICHT_FIELD)
+				.withRel(vorgang.isHasNewPostfachNachricht() ? REL_RESET_NEW_POSTFACH_MAIL : REL_SET_HAS_NEW_POSTFACH_MAIL));
 	}
 
 	@Override
diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/vorgang/ResetNewPostfachNachrichtBody.java b/alfa-service/src/main/java/de/ozgcloud/alfa/vorgang/SetNewPostfachNachrichtBody.java
similarity index 96%
rename from alfa-service/src/main/java/de/ozgcloud/alfa/vorgang/ResetNewPostfachNachrichtBody.java
rename to alfa-service/src/main/java/de/ozgcloud/alfa/vorgang/SetNewPostfachNachrichtBody.java
index 70ec293220..15f2a5c2a1 100644
--- a/alfa-service/src/main/java/de/ozgcloud/alfa/vorgang/ResetNewPostfachNachrichtBody.java
+++ b/alfa-service/src/main/java/de/ozgcloud/alfa/vorgang/SetNewPostfachNachrichtBody.java
@@ -28,7 +28,7 @@ import lombok.Setter;
 
 @Getter
 @Setter
-class ResetNewPostfachNachrichtBody {
+public class SetNewPostfachNachrichtBody {
 
 	private boolean hasNewPostfachNachricht;
 }
diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/vorgang/VorgangController.java b/alfa-service/src/main/java/de/ozgcloud/alfa/vorgang/VorgangController.java
index 865d83fb59..997800dcf6 100644
--- a/alfa-service/src/main/java/de/ozgcloud/alfa/vorgang/VorgangController.java
+++ b/alfa-service/src/main/java/de/ozgcloud/alfa/vorgang/VorgangController.java
@@ -25,8 +25,6 @@ package de.ozgcloud.alfa.vorgang;
 
 import java.util.Optional;
 
-import jakarta.servlet.http.HttpServletResponse;
-
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.hateoas.EntityModel;
 import org.springframework.hateoas.RepresentationModel;
@@ -45,6 +43,7 @@ import de.ozgcloud.alfa.common.clientattribute.ClientAttributeService;
 import de.ozgcloud.alfa.common.user.UserId;
 import de.ozgcloud.alfa.statistic.StatisticController;
 import de.ozgcloud.alfa.vorgang.Vorgang.VorgangStatus;
+import jakarta.servlet.http.HttpServletResponse;
 import lombok.RequiredArgsConstructor;
 
 @RestController
@@ -178,14 +177,13 @@ public class VorgangController {
 	}
 
 	@PutMapping(path = "/{vorgangId}/hasNewPostfachNachricht", consumes = MediaType.APPLICATION_JSON_VALUE)
-	public void resetNewPostfachNachricht(@PathVariable String vorgangId, @RequestBody ResetNewPostfachNachrichtBody body,
+	public void setNewPostfachNachricht(@PathVariable String vorgangId, @RequestBody SetNewPostfachNachrichtBody body,
 			HttpServletResponse response) {
 		if (body.isHasNewPostfachNachricht()) {
-			response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
-			return;
+			clientAttributeService.setHasNewPostfachNachricht(vorgangId);
+		} else {
+			clientAttributeService.resetPostfachNachricht(vorgangId);
 		}
-
-		clientAttributeService.resetPostfachNachricht(vorgangId);
 		response.setStatus(HttpStatus.NO_CONTENT.value());
 	}
 
diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/common/clientattribute/ClientAttributeServiceTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/common/clientattribute/ClientAttributeServiceTest.java
index 59bd03ddbb..25866dae17 100644
--- a/alfa-service/src/test/java/de/ozgcloud/alfa/common/clientattribute/ClientAttributeServiceTest.java
+++ b/alfa-service/src/test/java/de/ozgcloud/alfa/common/clientattribute/ClientAttributeServiceTest.java
@@ -42,13 +42,23 @@ class ClientAttributeServiceTest {
 
 	@Nested
 	class TestResetNewPostfachNachricht {
-		private final ClientAttribute clientAttribute = ClientAttribute.HAS_NEW_POSTFACH_NACHRICHT;
 
 		@Test
 		void shouldCallRemoteService() {
 			service.resetPostfachNachricht(VorgangHeaderTestFactory.ID);
 
-			verify(remoteService).setBooleanReadOnlyClientAttribute(VorgangHeaderTestFactory.ID, clientAttribute, false);
+			verify(remoteService).setBooleanReadOnlyClientAttribute(VorgangHeaderTestFactory.ID, ClientAttribute.HAS_NEW_POSTFACH_NACHRICHT, false);
+		}
+	}
+
+	@Nested
+	class TestSetHasNewPostfachNachricht {
+
+		@Test
+		void shouldCallRemoteService() {
+			service.setHasNewPostfachNachricht(VorgangHeaderTestFactory.ID);
+
+			verify(remoteService).setBooleanReadOnlyClientAttribute(VorgangHeaderTestFactory.ID, ClientAttribute.HAS_NEW_POSTFACH_NACHRICHT, true);
 		}
 	}
 }
diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssemblerTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssemblerTest.java
index 091797403a..01b02c1d5f 100644
--- a/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssemblerTest.java
+++ b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssemblerTest.java
@@ -449,6 +449,7 @@ class PostfachMailModelAssemblerTest {
 
 		@Nested
 		class ResetNewPostfachNachrichtLink {
+
 			@Test
 			void shouldBePresent() {
 				callModelAssembler(VorgangWithEingangTestFactory.create());
@@ -469,6 +470,29 @@ class PostfachMailModelAssemblerTest {
 			}
 		}
 
+		@Nested
+		class SetHasNewPostfachNachrichtLink {
+
+			@Test
+			void shouldBePresent() {
+				callModelAssembler(VorgangWithEingangTestFactory.createBuilder().hasNewPostfachNachricht(false).build());
+
+				var link = model.getLink(PostfachMailModelAssembler.REL_SET_HAS_NEW_POSTFACH_MAIL);
+				assertThat(link).isPresent().get().extracting(Link::getHref)
+						.isEqualTo(UriComponentsBuilder.fromUriString("/api/vorgangs")
+								.pathSegment(VorgangHeaderTestFactory.ID, "hasNewPostfachNachricht")
+								.build().toString());
+			}
+
+			@Test
+			void shouldNotBePresent() {
+				callModelAssembler(VorgangWithEingangTestFactory.create());
+
+				var link = model.getLink(PostfachMailModelAssembler.REL_SET_HAS_NEW_POSTFACH_MAIL);
+				assertThat(link).isNotPresent();
+			}
+		}
+
 		@DisplayName("send postfach mail")
 		@Nested
 		class SendPostfachMailLink {
diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/vorgang/VorgangControllerTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/vorgang/VorgangControllerTest.java
index 609ea5ccf1..5f641cbf43 100644
--- a/alfa-service/src/test/java/de/ozgcloud/alfa/vorgang/VorgangControllerTest.java
+++ b/alfa-service/src/test/java/de/ozgcloud/alfa/vorgang/VorgangControllerTest.java
@@ -869,22 +869,21 @@ class VorgangControllerTest {
 		}
 	}
 
-	@DisplayName("Reset new postfachNachricht")
 	@Nested
-	class TestResetNewPostfachNachricht {
+	class TestSetNewPostfachNachricht {
 
 		@Test
-		void resetNewPostfachNachricht() {
+		void shouldResetNewPostfachNachricht() {
 			performRequest("{\"hasNewPostfachNachricht\":false}").assertThat().hasStatus(HttpStatus.NO_CONTENT);
 
 			verify(clientAttributeService).resetPostfachNachricht(VorgangHeaderTestFactory.ID);
 		}
 
 		@Test
-		void shouldReturnUnprocessableEntity() {
-			performRequest("{\"hasNewPostfachNachricht\":true}").assertThat().hasStatus(HttpStatus.UNPROCESSABLE_ENTITY);
+		void shouldSetHasNewPostfachNachricht() {
+			performRequest("{\"hasNewPostfachNachricht\":true}").assertThat().hasStatus(HttpStatus.NO_CONTENT);
 
-			verify(clientAttributeService, never()).resetPostfachNachricht(VorgangHeaderTestFactory.ID);
+			verify(clientAttributeService).setHasNewPostfachNachricht(VorgangHeaderTestFactory.ID);
 		}
 
 		private MockMvcRequestBuilder performRequest(String body) {
-- 
GitLab


From 1b09d06ddb5900ba729966152ba6b4819d8df0ac Mon Sep 17 00:00:00 2001
From: Krzysztof <krzysztof.witukiewicz@mgm-tp.com>
Date: Fri, 4 Apr 2025 14:23:55 +0200
Subject: [PATCH 2/2] OZG-7773 OZG-8001 Fix test

---
 .../alfa/vorgang/VorgangControllerITCase.java  | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/vorgang/VorgangControllerITCase.java b/alfa-service/src/test/java/de/ozgcloud/alfa/vorgang/VorgangControllerITCase.java
index 257f019b7f..36d0bc99fb 100644
--- a/alfa-service/src/test/java/de/ozgcloud/alfa/vorgang/VorgangControllerITCase.java
+++ b/alfa-service/src/test/java/de/ozgcloud/alfa/vorgang/VorgangControllerITCase.java
@@ -39,6 +39,8 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -281,24 +283,16 @@ class VorgangControllerITCase {
 	@Nested
 	class TestClientAttribute {
 
-		@Test
-		void shouldReturnNoContent() throws Exception {
-			var content = VorgangHeaderTestFactory.createHasNewPostfachNachrichtContent(false);
+		@ParameterizedTest
+		@ValueSource(booleans = {true, false})
+		void shouldReturnNoContent(boolean hasNewPostfachNachricht) throws Exception {
+			var content = VorgangHeaderTestFactory.createHasNewPostfachNachrichtContent(hasNewPostfachNachricht);
 
 			var response = doRequest(content);
 
 			response.andExpect(status().isNoContent());
 		}
 
-		@Test
-		void shouldReturnUnprocessableEntity() throws Exception {
-			var content = VorgangHeaderTestFactory.createHasNewPostfachNachrichtContent(true);
-
-			var response = doRequest(content);
-
-			response.andExpect(status().isUnprocessableEntity());
-		}
-
 		private ResultActions doRequest(String content) throws Exception {
 			return mockMvc.perform(put("/api/vorgangs/{0}/hasNewPostfachNachricht", VorgangHeaderTestFactory.ID).with(csrf())
 					.contentType(MediaType.APPLICATION_JSON)
-- 
GitLab