From b99b10e506c1ba5dbe5f2d830dc2b4027beee0f4 Mon Sep 17 00:00:00 2001 From: OZG-Cloud Team <noreply@ozg-sh.de> Date: Fri, 28 Jun 2024 11:32:39 +0200 Subject: [PATCH] OZG-6054 xta: Get messages with multiple identifiers --- .../xta/WsHeaderAddingInterceptor.java | 7 ++- .../xta/XtaCurrentIdentifierService.java | 28 +++++++++++ .../ozgcloud/eingang/xta/XtaProperties.java | 3 +- .../de/ozgcloud/eingang/xta/XtaService.java | 13 +++-- .../src/main/resources/application-local.yml | 3 +- .../helm/xta_adapter_cronjob_basic_test.yaml | 5 +- .../helm/xta_adapter_cronjob_env_test.yaml | 8 +-- .../xta_adapter_cronjob_volumes_test.yaml | 6 ++- .../xta/XtaActiveIdentifierServiceTest.java | 44 ++++++++++++++++ .../ozgcloud/eingang/xta/XtaServiceTest.java | 50 ++++++++++++++++++- .../src/test/resources/application-itcase.yml | 3 +- 11 files changed, 151 insertions(+), 19 deletions(-) create mode 100644 xta-adapter/src/main/java/de/ozgcloud/eingang/xta/XtaCurrentIdentifierService.java create mode 100644 xta-adapter/src/test/java/de/ozgcloud/eingang/xta/XtaActiveIdentifierServiceTest.java diff --git a/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/WsHeaderAddingInterceptor.java b/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/WsHeaderAddingInterceptor.java index a685b0a2..3833376f 100644 --- a/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/WsHeaderAddingInterceptor.java +++ b/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/WsHeaderAddingInterceptor.java @@ -11,7 +11,7 @@ import de.ozgcloud.eingang.common.errorhandling.TechnicalException; import eu.osci.ws._2014._10.transport.OriginatorsType; import eu.osci.ws._2014._10.transport.PartyIdentifierType; import eu.osci.ws._2014._10.transport.PartyType; -import jakarta.validation.Valid; + import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBElement; import jakarta.xml.bind.JAXBException; @@ -20,8 +20,7 @@ import jakarta.xml.bind.JAXBException; class WsHeaderAddingInterceptor implements ClientInterceptor { @Autowired - @Valid - private XtaProperties properties; + private XtaCurrentIdentifierService xtaCurrentIdentifierService; @Override public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException { @@ -44,7 +43,7 @@ class WsHeaderAddingInterceptor implements ClientInterceptor { PartyType partyType = new PartyType(); PartyIdentifierType identifier = new PartyIdentifierType(); - identifier.setValue(properties.getIdentifier()); + identifier.setValue(xtaCurrentIdentifierService.getCurrentIdentifier()); partyType.setIdentifier(identifier); var origin = new OriginatorsType(); diff --git a/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/XtaCurrentIdentifierService.java b/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/XtaCurrentIdentifierService.java new file mode 100644 index 00000000..0024ec28 --- /dev/null +++ b/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/XtaCurrentIdentifierService.java @@ -0,0 +1,28 @@ +package de.ozgcloud.eingang.xta; + +import java.util.List; + +import jakarta.validation.Valid; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import lombok.Getter; +import lombok.Setter; + +@Service +public class XtaCurrentIdentifierService { + + @Setter + @Getter + private String currentIdentifier = "*"; + + @Autowired + @Valid + private XtaProperties properties; + + public List<String> getIdentifiers() { + return properties.getIdentifiers(); + } + +} diff --git a/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/XtaProperties.java b/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/XtaProperties.java index 2f31999f..23a4e4bc 100644 --- a/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/XtaProperties.java +++ b/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/XtaProperties.java @@ -2,6 +2,7 @@ package de.ozgcloud.eingang.xta; import java.math.BigInteger; import java.net.URI; +import java.util.List; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; @@ -31,7 +32,7 @@ class XtaProperties { private KeyStore keyStore; private Actions actions; @NotEmpty - private String identifier; + private List<String> identifiers; } @Validated diff --git a/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/XtaService.java b/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/XtaService.java index 2341fbf6..ae71ea06 100644 --- a/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/XtaService.java +++ b/xta-adapter/src/main/java/de/ozgcloud/eingang/xta/XtaService.java @@ -4,14 +4,13 @@ import java.util.Spliterators; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import de.ozgcloud.eingang.common.vorgang.VorgangNummerSupplier; -import de.ozgcloud.eingang.xdomea.XdomeaMessageDataMapper; -import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import de.ozgcloud.eingang.common.formdata.FormData; +import de.ozgcloud.eingang.common.vorgang.VorgangNummerSupplier; +import de.ozgcloud.eingang.xdomea.XdomeaMessageDataMapper; import lombok.NonNull; import lombok.extern.log4j.Log4j2; @@ -31,12 +30,20 @@ class XtaService { private XdomeaMessageDataMapper xdomeaMessageDataMapper; @Autowired private XtaIncomingFilesMapper xtaIncomingFilesMapper; + @Autowired + private XtaCurrentIdentifierService service; public Stream<FormData> getMessages() { return createXtaMessageStream().filter(this::isSupportedMessageType).map(this::getFormData); } Stream<XtaMessageMetaData> createXtaMessageStream() { + return service.getIdentifiers().stream() + .flatMap(this::createXtaMessageStreamForIdentifier); + } + + private Stream<XtaMessageMetaData> createXtaMessageStreamForIdentifier(String identifier) { + service.setCurrentIdentifier(identifier); var iterator = new XtaMessageMetadataRemoteIterator(remoteService); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 0), false); } diff --git a/xta-adapter/src/main/resources/application-local.yml b/xta-adapter/src/main/resources/application-local.yml index c6202f62..592ce755 100644 --- a/xta-adapter/src/main/resources/application-local.yml +++ b/xta-adapter/src/main/resources/application-local.yml @@ -1,6 +1,7 @@ ozgcloud: xta: - identifier: gae:noreply@ozg-sh.de + identifiers: + - gae:noreply@ozg-sh.de server: address: localhost:3000 name: LI33-0005 diff --git a/xta-adapter/src/test/helm/xta_adapter_cronjob_basic_test.yaml b/xta-adapter/src/test/helm/xta_adapter_cronjob_basic_test.yaml index 3e4e37b8..7eac13e8 100644 --- a/xta-adapter/src/test/helm/xta_adapter_cronjob_basic_test.yaml +++ b/xta-adapter/src/test/helm/xta_adapter_cronjob_basic_test.yaml @@ -60,7 +60,8 @@ tests: image.name: xta-adapter xta: schedule: "1 1 * * * *" - identifier: gae:test@ozg-sh.de + identifiers: + - gae:test@ozg-sh.de server: address: 1.2.3.4 name: test @@ -144,4 +145,4 @@ tests: path: spec.jobTemplate.spec.template.spec.containers[0].securityContext.capabilities value: drop: - - ALL \ No newline at end of file + - ALL diff --git a/xta-adapter/src/test/helm/xta_adapter_cronjob_env_test.yaml b/xta-adapter/src/test/helm/xta_adapter_cronjob_env_test.yaml index 4e84137f..213a9de0 100644 --- a/xta-adapter/src/test/helm/xta_adapter_cronjob_env_test.yaml +++ b/xta-adapter/src/test/helm/xta_adapter_cronjob_env_test.yaml @@ -36,7 +36,8 @@ tests: set: image.name: xta-adapter xta: - identifier: gae:test@ozg-sh.de + identifiers: + - gae:test@ozg-sh.de server: name: test address: 1.2.3.4 @@ -116,7 +117,8 @@ tests: image.name: xta-adapter env.overrideSpringProfiles: local xta: - identifier: gae:test@ozg-sh.de + identifiers: + - gae:test@ozg-sh.de server: name: test address: 1.2.3.4 @@ -154,4 +156,4 @@ tests: path: spec.jobTemplate.spec.template.spec.containers[0].env content: name: grpc_client_vorgang-manager-vorgang-manager_negotiationType - value: "TLS" \ No newline at end of file + value: "TLS" diff --git a/xta-adapter/src/test/helm/xta_adapter_cronjob_volumes_test.yaml b/xta-adapter/src/test/helm/xta_adapter_cronjob_volumes_test.yaml index 7af81adc..352f196b 100644 --- a/xta-adapter/src/test/helm/xta_adapter_cronjob_volumes_test.yaml +++ b/xta-adapter/src/test/helm/xta_adapter_cronjob_volumes_test.yaml @@ -36,7 +36,8 @@ tests: set: image.name: xta-adapter xta: - identifier: gae:test@ozg-sh.de + identifiers: + - gae:test@ozg-sh.de server: name: test address: 1.2.3.4 @@ -66,7 +67,8 @@ tests: set: image.name: xta-adapter xta: - identifier: gae:test@ozg-sh.de + identifiers: + - gae:test@ozg-sh.de server: name: test address: 1.2.3.4 diff --git a/xta-adapter/src/test/java/de/ozgcloud/eingang/xta/XtaActiveIdentifierServiceTest.java b/xta-adapter/src/test/java/de/ozgcloud/eingang/xta/XtaActiveIdentifierServiceTest.java new file mode 100644 index 00000000..ae5b12b2 --- /dev/null +++ b/xta-adapter/src/test/java/de/ozgcloud/eingang/xta/XtaActiveIdentifierServiceTest.java @@ -0,0 +1,44 @@ +package de.ozgcloud.eingang.xta; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import java.util.List; + +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.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; + +class XtaActiveIdentifierServiceTest { + + private static final String IDENTIFIER1 = "identifier1"; + private static final String IDENTIFIER2 = "identifier2"; + private static final List<String> IDENTIFIERS = List.of(IDENTIFIER1, IDENTIFIER2); + + @Spy + @InjectMocks + private XtaCurrentIdentifierService service; + + @Mock + private XtaProperties properties; + + @DisplayName("get identifiers") + @Nested + class TestGetIdentifiers { + @BeforeEach + void mock() { + when(properties.getIdentifiers()).thenReturn(IDENTIFIERS); + } + + @DisplayName("should return") + @Test + void shouldReturn() { + assertThat(service.getIdentifiers()).isEqualTo(IDENTIFIERS); + } + } + +} diff --git a/xta-adapter/src/test/java/de/ozgcloud/eingang/xta/XtaServiceTest.java b/xta-adapter/src/test/java/de/ozgcloud/eingang/xta/XtaServiceTest.java index 75a00a66..997ce3bf 100644 --- a/xta-adapter/src/test/java/de/ozgcloud/eingang/xta/XtaServiceTest.java +++ b/xta-adapter/src/test/java/de/ozgcloud/eingang/xta/XtaServiceTest.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.stream.Stream; 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.mockito.ArgumentCaptor; @@ -19,8 +20,8 @@ import org.mockito.Spy; import de.ozgcloud.eingang.common.formdata.IncomingFileTestFactory; import de.ozgcloud.eingang.common.vorgang.VorgangNummerSupplier; import de.ozgcloud.eingang.xdomea.XdomeaMessageData; -import de.ozgcloud.eingang.xdomea.XdomeaMessageDataTestFactory; import de.ozgcloud.eingang.xdomea.XdomeaMessageDataMapper; +import de.ozgcloud.eingang.xdomea.XdomeaMessageDataTestFactory; class XtaServiceTest { @@ -43,6 +44,9 @@ class XtaServiceTest { @Mock private XdomeaMessageDataMapper xdomeaMessageDataMapper; + @Mock + private XtaCurrentIdentifierService currentIdentifierService; + @Nested class TestGetMessagesAsFormData { @@ -124,7 +128,7 @@ class XtaServiceTest { private ArgumentCaptor<XtaMessageMetaData> messageMetaDataCaptor; @Captor - private ArgumentCaptor<XdomeaMessageData> classificationCaptor; + private ArgumentCaptor<XdomeaMessageData> classificationCaptor; @BeforeEach void init() { @@ -185,4 +189,46 @@ class XtaServiceTest { } } + @DisplayName("create XTA message stream") + @Nested + class TestCreateXtaMessageStream { + private static final List<String> XTA_IDENTIFIERS = List.of("XTA_IDENTIFIER", "XTA_IDENTIFIER2"); + + @Captor + private ArgumentCaptor<String> identifierCaptor; + + @BeforeEach + void mock() { + when(remoteService.getMessagesMetadata()) + .thenReturn(XtaMessageMetaDatasAndHeaderTestFactory.create()) + .thenReturn(XtaMessageMetaDatasAndHeaderTestFactory.create()); + when(currentIdentifierService.getIdentifiers()).thenReturn(XTA_IDENTIFIERS); + } + + @DisplayName("should return") + @Test + void shouldReturn() { + var result = service.createXtaMessageStream().toList(); + + assertThat(result).isEqualTo(getExpectedMessages()); + } + + private List<XtaMessageMetaData> getExpectedMessages() { + return Stream.concat( + XtaMessageMetaDatasAndHeaderTestFactory.create().getMessages(), + XtaMessageMetaDatasAndHeaderTestFactory.create().getMessages() + ).toList(); + } + + @DisplayName("should call set current identifier") + @Test + void shouldCallSetCurrentIdentifier() { + service.createXtaMessageStream().toList(); + + verify(currentIdentifierService, times(2)) + .setCurrentIdentifier(identifierCaptor.capture()); + assertThat(identifierCaptor.getAllValues()).isEqualTo(XTA_IDENTIFIERS); + } + } + } diff --git a/xta-adapter/src/test/resources/application-itcase.yml b/xta-adapter/src/test/resources/application-itcase.yml index e2862c67..57024478 100644 --- a/xta-adapter/src/test/resources/application-itcase.yml +++ b/xta-adapter/src/test/resources/application-itcase.yml @@ -1,6 +1,7 @@ ozgcloud: xta: - identifier: afmsh:010600000000_Online-Dienste + identifiers: + - afmsh:010600000000_Online-Dienste server: address: localhost:3000 name: LI33-0005 -- GitLab