Skip to content
Snippets Groups Projects
Commit 3ff85760 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-7038 adjust handling of Abgabe

parent 836c3eb4
No related branches found
No related tags found
1 merge request!3Ozg 7038 evaluation dms quittung
...@@ -7,7 +7,7 @@ import de.ozgcloud.xta.client.model.XtaFile; ...@@ -7,7 +7,7 @@ import de.ozgcloud.xta.client.model.XtaFile;
@Component @Component
class XtaFileHelper { class XtaFileHelper {
public ImportConfirmationXtaFileHandler initImportConfirmationHandler(XtaFile file) { public XtaImportConfirmationHandler initImportConfirmationHandler(XtaFile file) {
return ImportConfirmationXtaFileHandler.initFrom(file); return XtaImportConfirmationHandler.initFrom(file);
} }
} }
\ No newline at end of file
package de.ozgcloud.archive.xta; package de.ozgcloud.archive.xta;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
import de.ozgcloud.xta.client.model.XtaFile; import de.ozgcloud.xta.client.model.XtaFile;
import de.xoev.xdomea.AbgabeImportBestaetigen0402; import de.xoev.xdomea.AbgabeImportBestaetigen0402;
import de.xoev.xdomea.ErfolgOderMisserfolgAbgabeType; import de.xoev.xdomea.ErfolgOderMisserfolgAbgabeType;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor;
class ImportConfirmationXtaFileHandler { class XtaImportConfirmationHandler {
@Getter @Getter
private final AbgabeImportBestaetigen0402 importConfirmation; private final AbgabeImportBestaetigen0402 importConfirmation;
public static ImportConfirmationXtaFileHandler initFrom(XtaFile file) { public static XtaImportConfirmationHandler initFrom(XtaFile file) {
return new ImportConfirmationXtaFileHandler(file); return new XtaImportConfirmationHandler(file);
} }
ImportConfirmationXtaFileHandler(XtaFile file) { private XtaImportConfirmationHandler(XtaFile file) {
importConfirmation = XtaFileXmlUtils.read(file, AbgabeImportBestaetigen0402.class); importConfirmation = XtaFileXmlUtils.read(file, AbgabeImportBestaetigen0402.class);
} }
public Stream<XtaAbgabeHandler> getAbgaben() {
return importConfirmation.getAbgegebenesObjekt().stream().map(XtaAbgabeHandler::new);
}
@RequiredArgsConstructor
static class XtaAbgabeHandler {
private final ErfolgOderMisserfolgAbgabeType abgabeType;
public String getVorgangId() { public String getVorgangId() {
return getFirstErfolgOderMisserfolgAbgabeType().getIDSGO(); return abgabeType.getIDSGO();
} }
public boolean isSuccessfullyDone() { public boolean isSuccessfullyDone() {
return getFirstErfolgOderMisserfolgAbgabeType().isErfolgreich(); return abgabeType.isErfolgreich();
} }
public String getFehlermeldung() { public String getFehlermeldung() {
return getFirstErfolgOderMisserfolgAbgabeType().getFehlermeldung().stream().collect(Collectors.joining(";")); return abgabeType.getFehlermeldung().stream().collect(Collectors.joining(";"));
} }
private ErfolgOderMisserfolgAbgabeType getFirstErfolgOderMisserfolgAbgabeType() {
return importConfirmation.getAbgegebenesObjekt().get(0);
} }
} }
\ No newline at end of file
...@@ -2,12 +2,13 @@ package de.ozgcloud.archive.xta; ...@@ -2,12 +2,13 @@ package de.ozgcloud.archive.xta;
import java.util.List; import java.util.List;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import de.ozgcloud.archive.common.command.CommandOrder; import de.ozgcloud.archive.common.command.CommandOrder;
import de.ozgcloud.archive.common.command.CommandService; import de.ozgcloud.archive.common.command.CommandService;
import de.ozgcloud.archive.xta.XtaImportConfirmationHandler.XtaAbgabeHandler;
import de.ozgcloud.command.Command; import de.ozgcloud.command.Command;
import de.ozgcloud.command.CommandExecutedEvent; import de.ozgcloud.command.CommandExecutedEvent;
import de.ozgcloud.command.CommandFailedEvent; import de.ozgcloud.command.CommandFailedEvent;
...@@ -41,7 +42,7 @@ class XtaService { ...@@ -41,7 +42,7 @@ class XtaService {
void consumeMessage(XtaMessage message) { void consumeMessage(XtaMessage message) {
if (isImportConfirmation(message.messageFile())) { if (isImportConfirmation(message.messageFile())) {
handleImportConfirmation(xtaFileHelper.initImportConfirmationHandler(message.messageFile())); xtaFileHelper.initImportConfirmationHandler(message.messageFile()).getAbgaben().forEach(this::handleAbgabe);
} }
} }
...@@ -49,12 +50,12 @@ class XtaService { ...@@ -49,12 +50,12 @@ class XtaService {
return XtaFileXmlUtils.isType(xtaFile, XtaFileType.IMPORT_CONFIRMATION); return XtaFileXmlUtils.isType(xtaFile, XtaFileType.IMPORT_CONFIRMATION);
} }
void handleImportConfirmation(ImportConfirmationXtaFileHandler fileHandler) { void handleAbgabe(XtaAbgabeHandler abgabeHandler) {
var vorgangId = fileHandler.getVorgangId(); var vorgangId = abgabeHandler.getVorgangId();
var pendingCommands = findPendingArchiveVorgangCommands(vorgangId); var pendingCommands = findPendingArchiveVorgangCommands(vorgangId);
if (CollectionUtils.isNotEmpty(pendingCommands)) { if (CollectionUtils.isNotEmpty(pendingCommands)) {
evaluateImportConfirmation(fileHandler, pendingCommands); evaluateAbgabe(abgabeHandler, pendingCommands);
} else { } else {
LOG.warn("No pending archive command found for vorgang: %s.", vorgangId); LOG.warn("No pending archive command found for vorgang: %s.", vorgangId);
} }
...@@ -64,14 +65,14 @@ class XtaService { ...@@ -64,14 +65,14 @@ class XtaService {
return commandService.findPending(vorgangId, CommandOrder.ARCHIVE_VORGANG).toList(); return commandService.findPending(vorgangId, CommandOrder.ARCHIVE_VORGANG).toList();
} }
void evaluateImportConfirmation(ImportConfirmationXtaFileHandler contentHandler, List<Command> pendingCommands) { void evaluateAbgabe(XtaAbgabeHandler abgabeHandler, List<Command> pendingCommands) {
if (pendingCommands.size() > 1) { if (pendingCommands.size() > 1) {
LOG.warn("Multiple pending commands found for vorgang: %s.", contentHandler.getVorgangId()); LOG.warn("Multiple pending commands found for vorgang: %s.", abgabeHandler.getVorgangId());
} }
if (contentHandler.isSuccessfullyDone()) { if (abgabeHandler.isSuccessfullyDone()) {
pendingCommands.forEach(this::publishCommandExecutedEvent); pendingCommands.forEach(this::publishCommandExecutedEvent);
} else { } else {
pendingCommands.forEach(command -> publishCommandFailedEvent(contentHandler, command)); pendingCommands.forEach(command -> publishCommandFailedEvent(abgabeHandler, command));
} }
} }
...@@ -79,7 +80,7 @@ class XtaService { ...@@ -79,7 +80,7 @@ class XtaService {
eventPublisher.publishEvent(new CommandExecutedEvent(pendingCommand)); eventPublisher.publishEvent(new CommandExecutedEvent(pendingCommand));
} }
void publishCommandFailedEvent(ImportConfirmationXtaFileHandler contentHandler, Command pendingCommand) { void publishCommandFailedEvent(XtaAbgabeHandler contentHandler, Command pendingCommand) {
eventPublisher.publishEvent(new CommandFailedEvent(pendingCommand.getId(), contentHandler.getFehlermeldung())); eventPublisher.publishEvent(new CommandFailedEvent(pendingCommand.getId(), contentHandler.getFehlermeldung()));
} }
} }
\ No newline at end of file
...@@ -20,7 +20,7 @@ class XtaFileHelperTest { ...@@ -20,7 +20,7 @@ class XtaFileHelperTest {
void shouldReturnInstanceOfHandler() { void shouldReturnInstanceOfHandler() {
var handler = service.initImportConfirmationHandler(XtaFileTestFactory.create(AbgabeImportBestaetigen0402TestFactory.FILE_PATH)); var handler = service.initImportConfirmationHandler(XtaFileTestFactory.create(AbgabeImportBestaetigen0402TestFactory.FILE_PATH));
assertThat(handler).isNotNull().isInstanceOf(ImportConfirmationXtaFileHandler.class); assertThat(handler).isNotNull().isInstanceOf(XtaImportConfirmationHandler.class);
} }
} }
} }
\ No newline at end of file
...@@ -11,14 +11,15 @@ import org.junit.jupiter.api.Test; ...@@ -11,14 +11,15 @@ import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic; import org.mockito.MockedStatic;
import org.mockito.Mockito; import org.mockito.Mockito;
import de.ozgcloud.archive.xta.XtaImportConfirmationHandler.XtaAbgabeHandler;
import de.ozgcloud.xta.client.model.XtaFile; import de.ozgcloud.xta.client.model.XtaFile;
import de.xoev.xdomea.AbgabeImportBestaetigen0402; import de.xoev.xdomea.AbgabeImportBestaetigen0402;
class ImportConfirmationXtaFileHandlerTest { class XtaImportConfirmationHandlerTest {
@DisplayName("Import confirmation Xta file handler") @DisplayName("Xta import confirmation handler")
@Nested @Nested
class TestImportConfirmationXtaFileHandler { class TestXtaImportConfirmationHandler {
private final AbgabeImportBestaetigen0402 importConfirmation = AbgabeImportBestaetigen0402TestFactory.create(); private final AbgabeImportBestaetigen0402 importConfirmation = AbgabeImportBestaetigen0402TestFactory.create();
private final XtaFile file = XtaFileTestFactory.create(AbgabeImportBestaetigen0402TestFactory.FILE_PATH); private final XtaFile file = XtaFileTestFactory.create(AbgabeImportBestaetigen0402TestFactory.FILE_PATH);
...@@ -28,41 +29,58 @@ class ImportConfirmationXtaFileHandlerTest { ...@@ -28,41 +29,58 @@ class ImportConfirmationXtaFileHandlerTest {
mockStatic(XtaFileXmlUtils.class, mock -> { mockStatic(XtaFileXmlUtils.class, mock -> {
mock.when(() -> XtaFileXmlUtils.read(any(), any())).thenReturn(importConfirmation); mock.when(() -> XtaFileXmlUtils.read(any(), any())).thenReturn(importConfirmation);
var handler = initHandler(); var handler = initImportConfirmationHandler();
assertThat(handler.getImportConfirmation()).isEqualTo(importConfirmation); assertThat(handler.getImportConfirmation()).isEqualTo(importConfirmation);
}); });
} }
@Test
void shouldReturnAbgabenAsHandler() {
var handler = initImportConfirmationHandler();
assertThat(handler.getAbgaben()).hasSize(1);
assertThat(handler.getAbgaben().findFirst()).isPresent().get().isInstanceOf(XtaAbgabeHandler.class);
}
private <T> void mockStatic(Class<T> clazz, Consumer<MockedStatic<T>> mockConfigurer) { private <T> void mockStatic(Class<T> clazz, Consumer<MockedStatic<T>> mockConfigurer) {
try (var staticMock = Mockito.mockStatic(clazz, Mockito.CALLS_REAL_METHODS)) { try (var staticMock = Mockito.mockStatic(clazz, Mockito.CALLS_REAL_METHODS)) {
mockConfigurer.accept(staticMock); mockConfigurer.accept(staticMock);
} }
} }
@DisplayName("Xta abgabe handler")
@Nested
class TestXtaAbgabeHandler {
@Test @Test
void shouldReturnVorgangId() { void shouldReturnVorgangId() {
var vorgangId = initHandler().getVorgangId(); var vorgangId = initAbgabeHandler().getVorgangId();
assertThat(vorgangId).isEqualTo(AbgabeImportBestaetigen0402TestFactory.VORGANG_ID); assertThat(vorgangId).isEqualTo(AbgabeImportBestaetigen0402TestFactory.VORGANG_ID);
} }
@Test @Test
void shouldReturnIsSucessfullyDone() { void shouldReturnIsSucessfullyDone() {
var isSuccessfullyDone = initHandler().isSuccessfullyDone(); var isSuccessfullyDone = initAbgabeHandler().isSuccessfullyDone();
assertThat(isSuccessfullyDone).isEqualTo(AbgabeImportBestaetigen0402TestFactory.ERFOLGREICH); assertThat(isSuccessfullyDone).isEqualTo(AbgabeImportBestaetigen0402TestFactory.ERFOLGREICH);
} }
@Test @Test
void shouldReturnErrorMessage() { void shouldReturnErrorMessage() {
var errorMessage = initHandler().getFehlermeldung(); var errorMessage = initAbgabeHandler().getFehlermeldung();
assertThat(errorMessage).isEqualTo(AbgabeImportBestaetigen0402TestFactory.FEHLERMELDUNG); assertThat(errorMessage).isEqualTo(AbgabeImportBestaetigen0402TestFactory.FEHLERMELDUNG);
} }
private ImportConfirmationXtaFileHandler initHandler() { private XtaAbgabeHandler initAbgabeHandler() {
return new ImportConfirmationXtaFileHandler(file); return initImportConfirmationHandler().getAbgaben().findFirst().get();
}
}
private XtaImportConfirmationHandler initImportConfirmationHandler() {
return XtaImportConfirmationHandler.initFrom(file);
} }
} }
} }
\ No newline at end of file
...@@ -23,6 +23,7 @@ import de.ozgcloud.archive.common.command.CommandOrder; ...@@ -23,6 +23,7 @@ import de.ozgcloud.archive.common.command.CommandOrder;
import de.ozgcloud.archive.common.command.CommandService; import de.ozgcloud.archive.common.command.CommandService;
import de.ozgcloud.archive.common.command.CommandTestFactory; import de.ozgcloud.archive.common.command.CommandTestFactory;
import de.ozgcloud.archive.vorgang.VorgangWithEingangTestFactory; import de.ozgcloud.archive.vorgang.VorgangWithEingangTestFactory;
import de.ozgcloud.archive.xta.XtaImportConfirmationHandler.XtaAbgabeHandler;
import de.ozgcloud.command.Command; import de.ozgcloud.command.Command;
import de.ozgcloud.command.CommandExecutedEvent; import de.ozgcloud.command.CommandExecutedEvent;
import de.ozgcloud.command.CommandFailedEvent; import de.ozgcloud.command.CommandFailedEvent;
...@@ -72,7 +73,7 @@ class XtaServiceTest { ...@@ -72,7 +73,7 @@ class XtaServiceTest {
class TestConsumeMessage { class TestConsumeMessage {
@Mock @Mock
private ImportConfirmationXtaFileHandler xtaFileContentHandler; private XtaImportConfirmationHandler xtaFileContentHandler;
private final XtaMessage xtaMessage = XtaMessageTestFactory.create(); private final XtaMessage xtaMessage = XtaMessageTestFactory.create();
...@@ -87,11 +88,15 @@ class XtaServiceTest { ...@@ -87,11 +88,15 @@ class XtaServiceTest {
@Nested @Nested
class TestOnImportConfirmation { class TestOnImportConfirmation {
@Mock
private XtaAbgabeHandler abgabeHandler;
@BeforeEach @BeforeEach
void mock() { void mock() {
doReturn(true).when(service).isImportConfirmation(any()); doReturn(true).when(service).isImportConfirmation(any());
when(xtaFileHelper.initImportConfirmationHandler(any())).thenReturn(xtaFileContentHandler); when(xtaFileHelper.initImportConfirmationHandler(any())).thenReturn(xtaFileContentHandler);
doNothing().when(service).handleImportConfirmation(any()); when(xtaFileContentHandler.getAbgaben()).thenReturn(Stream.of(abgabeHandler, abgabeHandler));
doNothing().when(service).handleAbgabe(any());
} }
@Test @Test
...@@ -103,10 +108,10 @@ class XtaServiceTest { ...@@ -103,10 +108,10 @@ class XtaServiceTest {
@DisplayName("should handle import confirmation if type from document is matching") @DisplayName("should handle import confirmation if type from document is matching")
@Test @Test
void shouldCallHandleImportConfirmation() { void shouldCallHandleAbgabe() {
service.consumeMessage(xtaMessage); service.consumeMessage(xtaMessage);
verify(service).handleImportConfirmation(xtaFileContentHandler); verify(service, times(2)).handleAbgabe(abgabeHandler);
} }
} }
...@@ -117,21 +122,21 @@ class XtaServiceTest { ...@@ -117,21 +122,21 @@ class XtaServiceTest {
service.consumeMessage(xtaMessage); service.consumeMessage(xtaMessage);
verify(service, never()).handleImportConfirmation(any()); verify(service, never()).handleAbgabe(any());
verify(xtaFileHelper, never()).initImportConfirmationHandler(any()); verify(xtaFileHelper, never()).initImportConfirmationHandler(any());
} }
} }
@DisplayName("Handle import confirmation") @DisplayName("Handle abgabe")
@Nested @Nested
class TestHandleImportConfirmation { class TestHandleAbgabe {
@Mock @Mock
private ImportConfirmationXtaFileHandler contentHandler; private XtaAbgabeHandler abgabeHandler;
@BeforeEach @BeforeEach
void mock() { void mock() {
when(contentHandler.getVorgangId()).thenReturn(VorgangWithEingangTestFactory.ID); when(abgabeHandler.getVorgangId()).thenReturn(VorgangWithEingangTestFactory.ID);
when(commandService.findPending(any(), any())).thenReturn(Stream.empty()); when(commandService.findPending(any(), any())).thenReturn(Stream.empty());
} }
...@@ -139,7 +144,7 @@ class XtaServiceTest { ...@@ -139,7 +144,7 @@ class XtaServiceTest {
void shouldGetVorgangId() { void shouldGetVorgangId() {
handleImportConfirmation(); handleImportConfirmation();
verify(contentHandler).getVorgangId(); verify(abgabeHandler).getVorgangId();
} }
@Test @Test
...@@ -159,14 +164,14 @@ class XtaServiceTest { ...@@ -159,14 +164,14 @@ class XtaServiceTest {
@BeforeEach @BeforeEach
void mock() { void mock() {
when(commandService.findPending(any(), any())).thenReturn(commands.stream()); when(commandService.findPending(any(), any())).thenReturn(commands.stream());
doNothing().when(service).evaluateImportConfirmation(any(), any()); doNothing().when(service).evaluateAbgabe(any(), any());
} }
@Test @Test
void shouldCallEvaluateConfirmation() { void shouldCallEvaluateConfirmation() {
handleImportConfirmation(); handleImportConfirmation();
verify(service).evaluateImportConfirmation(contentHandler, commands); verify(service).evaluateAbgabe(abgabeHandler, commands);
} }
} }
...@@ -174,47 +179,47 @@ class XtaServiceTest { ...@@ -174,47 +179,47 @@ class XtaServiceTest {
void shouldNotCallEvaluateImportConfirmationOnEmptyList() { void shouldNotCallEvaluateImportConfirmationOnEmptyList() {
handleImportConfirmation(); handleImportConfirmation();
verify(service, never()).evaluateImportConfirmation(any(), any()); verify(service, never()).evaluateAbgabe(any(), any());
} }
private void handleImportConfirmation() { private void handleImportConfirmation() {
service.handleImportConfirmation(contentHandler); service.handleAbgabe(abgabeHandler);
} }
} }
@DisplayName("Evaluate confirmation") @DisplayName("Evaluate abgabe")
@Nested @Nested
class TestEvaluateConfirmation { class TestEvaluateConfirmation {
@Mock @Mock
private ImportConfirmationXtaFileHandler contentHandler; private XtaAbgabeHandler abgabeHandler;
private final Command command = CommandTestFactory.create(); private final Command command = CommandTestFactory.create();
private final List<Command> commands = List.of(command, command); private final List<Command> commands = List.of(command, command);
@Test @Test
void shouldCallIsSuccessfullyDone() { void shouldCallIsSuccessfullyDone() {
service.evaluateImportConfirmation(contentHandler, commands); service.evaluateAbgabe(abgabeHandler, commands);
verify(contentHandler).isSuccessfullyDone(); verify(abgabeHandler).isSuccessfullyDone();
} }
@Test @Test
void shouldCallPublishCommendExcecutedEvent() { void shouldCallPublishCommendExcecutedEvent() {
when(contentHandler.isSuccessfullyDone()).thenReturn(true); when(abgabeHandler.isSuccessfullyDone()).thenReturn(true);
service.evaluateImportConfirmation(contentHandler, commands); service.evaluateAbgabe(abgabeHandler, commands);
verify(service, times(2)).publishCommandExecutedEvent(command); verify(service, times(2)).publishCommandExecutedEvent(command);
} }
@Test @Test
void shouldCallPublishCommandFailedEvent() { void shouldCallPublishCommandFailedEvent() {
when(contentHandler.isSuccessfullyDone()).thenReturn(false); when(abgabeHandler.isSuccessfullyDone()).thenReturn(false);
service.evaluateImportConfirmation(contentHandler, commands); service.evaluateAbgabe(abgabeHandler, commands);
verify(service, times(2)).publishCommandFailedEvent(contentHandler, command); verify(service, times(2)).publishCommandFailedEvent(abgabeHandler, command);
} }
@DisplayName("on successfully done import confirmation") @DisplayName("on successfully done import confirmation")
...@@ -246,9 +251,9 @@ class XtaServiceTest { ...@@ -246,9 +251,9 @@ class XtaServiceTest {
@DisplayName("should publish command failed event") @DisplayName("should publish command failed event")
@Test @Test
void shouldPublishCommandFailedEvent() { void shouldPublishCommandFailedEvent() {
when(contentHandler.getFehlermeldung()).thenReturn(AbgabeImportBestaetigen0402TestFactory.FEHLERMELDUNG); when(abgabeHandler.getFehlermeldung()).thenReturn(AbgabeImportBestaetigen0402TestFactory.FEHLERMELDUNG);
service.publishCommandFailedEvent(contentHandler, command); service.publishCommandFailedEvent(abgabeHandler, command);
verify(eventPublisher).publishEvent(commandFailedEventCaptor.capture()); verify(eventPublisher).publishEvent(commandFailedEventCaptor.capture());
assertThat(commandFailedEventCaptor.getValue().getSource()).isEqualTo(CommandTestFactory.ID); assertThat(commandFailedEventCaptor.getValue().getSource()).isEqualTo(CommandTestFactory.ID);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment