Skip to content
Snippets Groups Projects
Commit 1c288700 authored by OZGCloud's avatar OZGCloud
Browse files

Merge pull request 'OZG-4381 OZG-5109 add force reply feature toggle' (#428)...

Merge pull request 'OZG-4381 OZG-5109 add force reply feature toggle' (#428) from OZG-4381-OZG-5109-add-feature-toggle into OZG-4381-versenden-von-rueckfragen

Reviewed-on: https://git.ozg-sh.de/ozgcloud-app/alfa/pulls/428
parents fd0dd3aa 99c33875
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@ server:
ozgcloud:
feature:
vorgang-export: true
reply-always-allowed: true
production: false
stage:
production: false
\ No newline at end of file
......@@ -10,6 +10,7 @@ ozgcloud:
feature:
vorgang-export: true
createBescheid: true
reply-always-allowed: true
forwarding:
lninfo:
url: classpath:files/LandesnetzInfo.html
......
......@@ -16,6 +16,7 @@ grpc:
ozgcloud:
feature:
vorgang-export: true
reply-always-allowed: true
production: false
user-assistance:
documentation:
......
......@@ -21,4 +21,9 @@ public class FeatureToggleProperties {
* Enable/Disable bescheid creation feature.
*/
private boolean createBescheid = false;
/**
* Enable mail reply option regardless of other configuration.
*/
private boolean replyAlwaysAllowed = false;
}
......@@ -55,29 +55,24 @@ import de.ozgcloud.alfa.common.file.OzgFile;
import de.ozgcloud.alfa.vorgang.VorgangController;
import de.ozgcloud.alfa.vorgang.VorgangWithEingang;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@RestController
@RequestMapping(PostfachMailController.PATH)
public class PostfachMailController {
public static final String PATH = "/api/postfachMails"; // NOSONAR
public static final String PARAM_VORGANG_ID = "vorgangId";
static final String PDF_NAME_TEMPLATE = "%s_%s_Nachrichten.pdf";
static final DateTimeFormatter PDF_NAME_DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
@Autowired
private PostfachMailService service;
@Autowired
private PostfachMailModelAssembler assembler;
private final PostfachMailService service;
@Autowired
private VorgangController vorgangController;
private final PostfachMailModelAssembler assembler;
@Autowired
private BinaryFileController binaryFileController;
private final VorgangController vorgangController;
private final BinaryFileController binaryFileController;
@GetMapping(params = PARAM_VORGANG_ID)
public RepresentationModel<EntityModel<Postfach>> getAll(@RequestParam String vorgangId) {
......@@ -86,11 +81,15 @@ public class PostfachMailController {
return assembler.toCollectionModel(sort(service.getAll(vorgangId)), buildPostfach(vorgang), vorgang);
}
private Postfach buildPostfach(VorgangWithEingang vorgang) {
return Postfach.builder().features(Features.builder().reply(service.isReplyToMessageAllowed(vorgang)).build()).build();
Postfach buildPostfach(VorgangWithEingang vorgang) {
return Postfach.builder()
.features(Features.builder()
.reply(service.isReplyToMessageAllowed(vorgang))
.build())
.build();
}
private Stream<PostfachMail> sort(Stream<PostfachMail> nachrichten) {
Stream<PostfachMail> sort(Stream<PostfachMail> nachrichten) {
return nachrichten.sorted(new PostfachNachrichtComparator().reversed());
}
......
......@@ -32,9 +32,9 @@ import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.ozgcloud.alfa.common.FeatureToggleProperties;
import de.ozgcloud.alfa.common.binaryfile.BinaryFileService;
import de.ozgcloud.alfa.common.binaryfile.FileId;
import de.ozgcloud.alfa.common.command.Command;
......@@ -47,25 +47,23 @@ import de.ozgcloud.alfa.common.user.UserProfile;
import de.ozgcloud.alfa.common.user.UserService;
import de.ozgcloud.alfa.vorgang.ServiceKonto;
import de.ozgcloud.alfa.vorgang.VorgangWithEingang;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
@RequiredArgsConstructor
@Log4j2
@Service
class PostfachMailService {
private PostfachConfigGroup postfachConfigGroup;
@Autowired
private PostfachMailRemoteService remoteService;
@Autowired
private PostfachNachrichtPdfService pdfService;
private final PostfachMailRemoteService remoteService;
private final PostfachNachrichtPdfService pdfService;
private final BinaryFileService fileService;
private final UserService userService;
private final CommandService commandService;
@Autowired
private BinaryFileService fileService;
@Autowired
private UserService userService;
@Autowired
private CommandService commandService;
private final FeatureToggleProperties featureToggleProperties;
public PostfachMail findById(PostfachNachrichtId nachrichtId) {
return remoteService.findById(nachrichtId)
......@@ -150,9 +148,14 @@ class PostfachMailService {
}
boolean isReplyAllowed(String serviceKontoType) {
if (featureToggleProperties.isReplyAlwaysAllowed()) {
return true;
}
if (!isPostfachConfigured()) {
return false;
}
return postfachConfigGroup.getPostfachConfigs().stream()
.filter(postfachConfig -> postfachConfig.getType().equals(serviceKontoType))
.map(PostfachConfig::isReplyAllowed)
......
......@@ -23,6 +23,7 @@
*/
package de.ozgcloud.alfa.postfach;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
......@@ -31,13 +32,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.io.IOException;
import java.io.OutputStream;
import java.time.LocalDate;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
......@@ -60,10 +61,13 @@ class PostfachMailControllerTest {
@Spy
@InjectMocks // NOSONAR
private PostfachMailController controller;
@Mock
private PostfachMailService service;
@Mock
private PostfachMailModelAssembler assembler;
@Mock
private VorgangController vorgangController;
@Mock
......@@ -80,9 +84,17 @@ class PostfachMailControllerTest {
@Nested
class TestGetAll {
private final VorgangWithEingang vorgang = VorgangWithEingangTestFactory.create();
private final Postfach postfach = PostfachTestFactory.create();
private final Stream<PostfachMail> postfachMails = Stream.of(PostfachMailTestFactory.create());
private final Stream<PostfachMail> sortedPostfachMails = Stream.of(PostfachMailTestFactory.create());
@BeforeEach
void mockVorgangController() {
when(vorgangController.getVorgang(anyString())).thenReturn(VorgangWithEingangTestFactory.create());
when(vorgangController.getVorgang(anyString())).thenReturn(vorgang);
when(service.getAll(VorgangHeaderTestFactory.ID)).thenReturn(postfachMails);
doReturn(postfach).when(controller).buildPostfach(vorgang);
doReturn(sortedPostfachMails).when(controller).sort(postfachMails);
}
@Test
......@@ -103,14 +115,21 @@ class PostfachMailControllerTest {
void shouldCallModelAssembler() {
doRequest();
verify(assembler).toCollectionModel(ArgumentMatchers.any(), any(Postfach.class), any());
verify(assembler).toCollectionModel(sortedPostfachMails, postfach, vorgang);
}
@Test
void shouldCheckIsReplyAllowed() {
void shouldSortPostfachMails() {
doRequest();
verify(service).isReplyToMessageAllowed(any(VorgangWithEingang.class));
verify(controller).sort(postfachMails);
}
@Test
void shouldBuildPostfach() {
doRequest();
verify(controller).buildPostfach(vorgang);
}
@SneakyThrows
......@@ -120,6 +139,32 @@ class PostfachMailControllerTest {
}
}
@Nested
class TestBuildPostfach {
private final VorgangWithEingang vorgang = VorgangWithEingangTestFactory.create();
@Test
void shouldCheckIsReplyAllowed() {
callController();
verify(service).isReplyToMessageAllowed(any(VorgangWithEingang.class));
}
@Test
void shouldSetIsReplyAllowedFeature() {
when(service.isReplyToMessageAllowed(vorgang)).thenReturn(true);
var postfach = callController();
assertThat(postfach.getFeatures().isReply()).isTrue();
}
private Postfach callController() {
return controller.buildPostfach(vorgang);
}
}
@DisplayName("Get all as pdf")
@Nested
class TestGetAllAsPdf {
......
......@@ -47,6 +47,7 @@ import org.springframework.test.util.ReflectionTestUtils;
import com.thedeanda.lorem.LoremIpsum;
import de.ozgcloud.alfa.common.FeatureToggleProperties;
import de.ozgcloud.alfa.common.binaryfile.BinaryFileService;
import de.ozgcloud.alfa.common.binaryfile.BinaryFileTestFactory;
import de.ozgcloud.alfa.common.command.CommandService;
......@@ -81,6 +82,9 @@ class PostfachMailServiceTest {
@Mock
private CommandService commandService;
@Mock
private FeatureToggleProperties featureToggleProperties;
@DisplayName("Get all")
@Nested
class TestGetAll {
......@@ -512,6 +516,11 @@ class PostfachMailServiceTest {
private static final String DUMMY_SERVICE_KONTO_TYPE = LoremIpsum.getInstance().getWords(1);
@BeforeEach
void setUp() {
when(featureToggleProperties.isReplyAlwaysAllowed()).thenReturn(false);
}
@Test
@DisplayName("reply not allowed for given ServiceKonto-type")
void shouldReturnFalseIfPostfachNotConfigured() {
......@@ -568,6 +577,15 @@ class PostfachMailServiceTest {
assertThat(replyAllowed).isTrue();
}
@Test
void shouldReturnTrueIfAlwaysAllowed() {
when(featureToggleProperties.isReplyAlwaysAllowed()).thenReturn(true);
var replyAllowed = service.isReplyAllowed(PostfachConfigTestFactory.TYPE);
assertThat(replyAllowed).isTrue();
}
}
private void setPostfachConfigGroup(PostfachConfigGroup postfachConfigGroup) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment