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 3920a077b01adce74965354f6bac185112d3fc3c..109c3cc16ff77ccd10019a80caf011c3cb1fbb7a 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 d1f3b17742b04f08c6f30d4dac6ef11159425724..792d90d96a1f927864324971cf58871a3fb3f60f 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 70ec293220e4217bec94d7da43727e48306bad85..15f2a5c2a15dd5d3ed9935a269a98e19ac4d8035 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 865d83fb59e4bad69534ca0a5ef52a2e686ef193..997800dcf6773183e235c82517eaf0b9695d9991 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 59bd03ddbb440d66be7e8fb1c262cdaa0976692d..25866dae17d71b3b5c68a9c1f71485efffe1df87 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 091797403adabd9734b63866c28185033da4e0b7..01b02c1d5fd666420cefb40d3b80a070cabe65b8 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/VorgangControllerITCase.java b/alfa-service/src/test/java/de/ozgcloud/alfa/vorgang/VorgangControllerITCase.java index 257f019b7ffc2ba3f4a0b10f74139f3ed49cc4b5..36d0bc99fb051803fe2996fed0ffab28355bf81c 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) 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 609ea5ccf1b83f33ecb2db97b2f4ff90652d2470..5f641cbf4302f0b27e863bf82f0634379a8cda6b 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) {