Skip to content
Snippets Groups Projects
Commit 725af779 authored by Krzysztof Witukiewicz's avatar Krzysztof Witukiewicz
Browse files

Merge branch 'OZG-7773-nachrichten-auf-ungelesen-setzen' into 'main'

Ozg 7773 nachrichten auf ungelesen setzen

See merge request !27
parents 49ef936b 1b09d06d
Branches
Tags
1 merge request!27Ozg 7773 nachrichten auf ungelesen setzen
Showing with 59 additions and 31 deletions
...@@ -37,4 +37,7 @@ public class ClientAttributeService { ...@@ -37,4 +37,7 @@ public class ClientAttributeService {
remoteService.setBooleanReadOnlyClientAttribute(vorgangId, ClientAttribute.HAS_NEW_POSTFACH_NACHRICHT, false); remoteService.setBooleanReadOnlyClientAttribute(vorgangId, ClientAttribute.HAS_NEW_POSTFACH_NACHRICHT, false);
} }
public void setHasNewPostfachNachricht(String vorgangId) {
remoteService.setBooleanReadOnlyClientAttribute(vorgangId, ClientAttribute.HAS_NEW_POSTFACH_NACHRICHT, true);
}
} }
...@@ -58,6 +58,7 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac ...@@ -58,6 +58,7 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac
public static final String REL_SEND = "send"; public static final String REL_SEND = "send";
public static final String REL_RESEND_POSTFACH_MAIL = "resendPostfachMail"; public static final String REL_RESEND_POSTFACH_MAIL = "resendPostfachMail";
public static final String REL_RESET_NEW_POSTFACH_MAIL = "resetHasNewPostfachNachricht"; 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_ATTACHMENTS = "attachments";
public static final String REL_EDIT = "edit"; public static final String REL_EDIT = "edit";
static final String REL_UPLOAD_ATTACHMENT = "uploadAttachment"; static final String REL_UPLOAD_ATTACHMENT = "uploadAttachment";
...@@ -116,9 +117,8 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac ...@@ -116,9 +117,8 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac
model.add(linkTo(BinaryFileController.class).slash(vorgangId).slash(POSTFACH_NACHRICHT_ATTACHMENT_FIELD).slash(FILE_PATH) model.add(linkTo(BinaryFileController.class).slash(vorgangId).slash(POSTFACH_NACHRICHT_ATTACHMENT_FIELD).slash(FILE_PATH)
.withRel(REL_UPLOAD_ATTACHMENT)); .withRel(REL_UPLOAD_ATTACHMENT));
if (vorgang.isHasNewPostfachNachricht()) { model.add(linkTo(VorgangController.class).slash(vorgangId).slash(HAS_NEW_POSTFACH_NACHRICHT_FIELD)
model.add(linkTo(VorgangController.class).slash(vorgangId).slash(HAS_NEW_POSTFACH_NACHRICHT_FIELD).withRel(REL_RESET_NEW_POSTFACH_MAIL)); .withRel(vorgang.isHasNewPostfachNachricht() ? REL_RESET_NEW_POSTFACH_MAIL : REL_SET_HAS_NEW_POSTFACH_MAIL));
}
} }
@Override @Override
......
...@@ -28,7 +28,7 @@ import lombok.Setter; ...@@ -28,7 +28,7 @@ import lombok.Setter;
@Getter @Getter
@Setter @Setter
class ResetNewPostfachNachrichtBody { public class SetNewPostfachNachrichtBody {
private boolean hasNewPostfachNachricht; private boolean hasNewPostfachNachricht;
} }
...@@ -25,8 +25,6 @@ package de.ozgcloud.alfa.vorgang; ...@@ -25,8 +25,6 @@ package de.ozgcloud.alfa.vorgang;
import java.util.Optional; import java.util.Optional;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.RepresentationModel; import org.springframework.hateoas.RepresentationModel;
...@@ -45,6 +43,7 @@ import de.ozgcloud.alfa.common.clientattribute.ClientAttributeService; ...@@ -45,6 +43,7 @@ import de.ozgcloud.alfa.common.clientattribute.ClientAttributeService;
import de.ozgcloud.alfa.common.user.UserId; import de.ozgcloud.alfa.common.user.UserId;
import de.ozgcloud.alfa.statistic.StatisticController; import de.ozgcloud.alfa.statistic.StatisticController;
import de.ozgcloud.alfa.vorgang.Vorgang.VorgangStatus; import de.ozgcloud.alfa.vorgang.Vorgang.VorgangStatus;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@RestController @RestController
...@@ -178,14 +177,13 @@ public class VorgangController { ...@@ -178,14 +177,13 @@ public class VorgangController {
} }
@PutMapping(path = "/{vorgangId}/hasNewPostfachNachricht", consumes = MediaType.APPLICATION_JSON_VALUE) @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) { HttpServletResponse response) {
if (body.isHasNewPostfachNachricht()) { if (body.isHasNewPostfachNachricht()) {
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); clientAttributeService.setHasNewPostfachNachricht(vorgangId);
return; } else {
}
clientAttributeService.resetPostfachNachricht(vorgangId); clientAttributeService.resetPostfachNachricht(vorgangId);
}
response.setStatus(HttpStatus.NO_CONTENT.value()); response.setStatus(HttpStatus.NO_CONTENT.value());
} }
......
...@@ -42,13 +42,23 @@ class ClientAttributeServiceTest { ...@@ -42,13 +42,23 @@ class ClientAttributeServiceTest {
@Nested @Nested
class TestResetNewPostfachNachricht { class TestResetNewPostfachNachricht {
private final ClientAttribute clientAttribute = ClientAttribute.HAS_NEW_POSTFACH_NACHRICHT;
@Test @Test
void shouldCallRemoteService() { void shouldCallRemoteService() {
service.resetPostfachNachricht(VorgangHeaderTestFactory.ID); 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);
} }
} }
} }
...@@ -449,6 +449,7 @@ class PostfachMailModelAssemblerTest { ...@@ -449,6 +449,7 @@ class PostfachMailModelAssemblerTest {
@Nested @Nested
class ResetNewPostfachNachrichtLink { class ResetNewPostfachNachrichtLink {
@Test @Test
void shouldBePresent() { void shouldBePresent() {
callModelAssembler(VorgangWithEingangTestFactory.create()); callModelAssembler(VorgangWithEingangTestFactory.create());
...@@ -469,6 +470,29 @@ class PostfachMailModelAssemblerTest { ...@@ -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") @DisplayName("send postfach mail")
@Nested @Nested
class SendPostfachMailLink { class SendPostfachMailLink {
......
...@@ -39,6 +39,8 @@ import org.junit.jupiter.api.BeforeEach; ...@@ -39,6 +39,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; 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.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
...@@ -281,24 +283,16 @@ class VorgangControllerITCase { ...@@ -281,24 +283,16 @@ class VorgangControllerITCase {
@Nested @Nested
class TestClientAttribute { class TestClientAttribute {
@Test @ParameterizedTest
void shouldReturnNoContent() throws Exception { @ValueSource(booleans = {true, false})
var content = VorgangHeaderTestFactory.createHasNewPostfachNachrichtContent(false); void shouldReturnNoContent(boolean hasNewPostfachNachricht) throws Exception {
var content = VorgangHeaderTestFactory.createHasNewPostfachNachrichtContent(hasNewPostfachNachricht);
var response = doRequest(content); var response = doRequest(content);
response.andExpect(status().isNoContent()); 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 { private ResultActions doRequest(String content) throws Exception {
return mockMvc.perform(put("/api/vorgangs/{0}/hasNewPostfachNachricht", VorgangHeaderTestFactory.ID).with(csrf()) return mockMvc.perform(put("/api/vorgangs/{0}/hasNewPostfachNachricht", VorgangHeaderTestFactory.ID).with(csrf())
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
......
...@@ -869,22 +869,21 @@ class VorgangControllerTest { ...@@ -869,22 +869,21 @@ class VorgangControllerTest {
} }
} }
@DisplayName("Reset new postfachNachricht")
@Nested @Nested
class TestResetNewPostfachNachricht { class TestSetNewPostfachNachricht {
@Test @Test
void resetNewPostfachNachricht() { void shouldResetNewPostfachNachricht() {
performRequest("{\"hasNewPostfachNachricht\":false}").assertThat().hasStatus(HttpStatus.NO_CONTENT); performRequest("{\"hasNewPostfachNachricht\":false}").assertThat().hasStatus(HttpStatus.NO_CONTENT);
verify(clientAttributeService).resetPostfachNachricht(VorgangHeaderTestFactory.ID); verify(clientAttributeService).resetPostfachNachricht(VorgangHeaderTestFactory.ID);
} }
@Test @Test
void shouldReturnUnprocessableEntity() { void shouldSetHasNewPostfachNachricht() {
performRequest("{\"hasNewPostfachNachricht\":true}").assertThat().hasStatus(HttpStatus.UNPROCESSABLE_ENTITY); performRequest("{\"hasNewPostfachNachricht\":true}").assertThat().hasStatus(HttpStatus.NO_CONTENT);
verify(clientAttributeService, never()).resetPostfachNachricht(VorgangHeaderTestFactory.ID); verify(clientAttributeService).setHasNewPostfachNachricht(VorgangHeaderTestFactory.ID);
} }
private MockMvcRequestBuilder performRequest(String body) { private MockMvcRequestBuilder performRequest(String body) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment