From 870439300e7596d6833644ec9e6d1f38a1e0b6b5 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Tue, 14 May 2019 13:18:55 +0200 Subject: Implement Per-Field-Overriding of Configuration in Augmenter - Rewrite DeliveryRequestAugmenter to allow per-field-overriding of configuration parameters and add test suite. - Mzs schema change: Move DeliveryRequest/Server into DeliveryRequest/Config; Reason: DeliveryRequest/Config contains all parameters exclusively needed by moazs to execute the delivery request. The msg's server url belongs to this set of parameters. - WIP: Add prototype implementation of MsgClient and move MsgClient to dedicated package. - Refactor: move TnvzClient to dedicated package. --- .../at/gv/egiz/moazs/DeliveryRequestAugmenter.java | 46 +++++++++++-- src/main/java/at/gv/egiz/moazs/MsgClient.java | 26 ------- src/main/java/at/gv/egiz/moazs/TnvzClient.java | 18 ----- .../config/DeliveryRequestAugmenterConfig.java | 31 +++++++++ src/main/java/at/gv/egiz/moazs/msg/MsgClient.java | 28 ++++++++ .../moazs/pipeline/SameThreadDeliveryPipeline.java | 4 +- .../java/at/gv/egiz/moazs/tnvz/TnvzClient.java | 18 +++++ src/main/resources/mzs/app2mzs.xsd | 19 ++--- .../egiz/moazs/DeliveryRequestAugmenterTest.java | 80 ++++++++++++++++++++++ .../egiz/moazs/SameThreadDeliveryPipelineTest.java | 3 +- 10 files changed, 212 insertions(+), 61 deletions(-) delete mode 100644 src/main/java/at/gv/egiz/moazs/MsgClient.java delete mode 100644 src/main/java/at/gv/egiz/moazs/TnvzClient.java create mode 100644 src/main/java/at/gv/egiz/moazs/config/DeliveryRequestAugmenterConfig.java create mode 100644 src/main/java/at/gv/egiz/moazs/msg/MsgClient.java create mode 100644 src/main/java/at/gv/egiz/moazs/tnvz/TnvzClient.java create mode 100644 src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java (limited to 'src') diff --git a/src/main/java/at/gv/egiz/moazs/DeliveryRequestAugmenter.java b/src/main/java/at/gv/egiz/moazs/DeliveryRequestAugmenter.java index 35c1e77..96197d0 100644 --- a/src/main/java/at/gv/egiz/moazs/DeliveryRequestAugmenter.java +++ b/src/main/java/at/gv/egiz/moazs/DeliveryRequestAugmenter.java @@ -3,14 +3,24 @@ package at.gv.egiz.moazs; import at.gv.zustellung.app2mzs.xsd.ConfigType; import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.DeliveryRequestTypeBuilder; +import at.gv.zustellung.app2mzs.xsd.ServerType; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import static at.gv.egiz.moazs.util.NullCoalesce.coalesce; import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder; +import static at.gv.zustellung.app2mzs.xsd.ServerType.*; @Component public class DeliveryRequestAugmenter { + private final ConfigType defaultMzsConfig; + + @Autowired + public DeliveryRequestAugmenter(ConfigType defaultMzsConfig) { + this.defaultMzsConfig = defaultMzsConfig; + } + /** * Augments an incoming {@code request} by filling gaps with config- or default parameters. * @@ -18,15 +28,41 @@ public class DeliveryRequestAugmenter { * @return augmented request */ public DeliveryRequestType augment(DeliveryRequestType request) { + + var config = merge(request.getConfig(), defaultMzsConfig); + return new DeliveryRequestTypeBuilder(request) - .withConfig(coalesce(request.getConfig(), initDefaultConfig()).get()) + .withConfig(config) .build(); } - private ConfigType initDefaultConfig() { - return configTypeBuilder() - .withPerformQueryPersonRequest(false) - .build(); + private ConfigType merge(ConfigType primary, ConfigType fallback) { + + var builder = configTypeBuilder(fallback); + + if(primary != null) { + + if(primary.getServer() != null) { + builder.withServer(merge(primary.getServer(), fallback.getServer())); + } + + if(primary.isPerformQueryPersonRequest() != null) { + builder.withPerformQueryPersonRequest(primary.isPerformQueryPersonRequest()); + } + + } + + return builder.build(); + } + private ServerType merge(ServerType primary, ServerType fallback) { + + var builder = serverTypeBuilder(fallback); + + if (primary.getX509() != null) builder.withX509 (primary.getX509() ); + if (primary.getZUSEUrlID() != null) builder.withZUSEUrlID(primary.getZUSEUrlID()); + + return builder.build(); + } } diff --git a/src/main/java/at/gv/egiz/moazs/MsgClient.java b/src/main/java/at/gv/egiz/moazs/MsgClient.java deleted file mode 100644 index 3a6b5ce..0000000 --- a/src/main/java/at/gv/egiz/moazs/MsgClient.java +++ /dev/null @@ -1,26 +0,0 @@ -package at.gv.egiz.moazs; - -import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; -import at.gv.zustellung.msg.xsd.DeliveryRequestType; -import org.springframework.stereotype.Component; - -import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.Success.successBuilder; -import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder; - -@Component -public class MsgClient { - - public DeliveryRequestStatusType send(DeliveryRequestType msgRequest) { - - //stub implementation - var success = successBuilder() - .withAppDeliveryID(msgRequest.getMetaData().getAppDeliveryID()) - .build(); - - return deliveryRequestStatusTypeBuilder() - .withSuccess(success) - .build(); - - } - -} diff --git a/src/main/java/at/gv/egiz/moazs/TnvzClient.java b/src/main/java/at/gv/egiz/moazs/TnvzClient.java deleted file mode 100644 index 4a69aea..0000000 --- a/src/main/java/at/gv/egiz/moazs/TnvzClient.java +++ /dev/null @@ -1,18 +0,0 @@ -package at.gv.egiz.moazs.tnvz; - -import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.Sender; -import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.Receiver; -import at.gv.zustellung.tnvz.xsd.PersonResultSuccessType; -import at.gv.zustellung.tnvz.xsd.PersonResultType; -import at.gv.zustellung.tnvz.xsd.PersonResultType.PersonResultTypeBuilder; -import org.springframework.stereotype.Component; - -@Component -public class TnvzClient { - - public PersonResultType queryPerson(Sender sender, Receiver receiver) { - PersonResultSuccessType success = new PersonResultSuccessType.PersonResultSuccessTypeBuilder().build(); - return new PersonResultTypeBuilder().withSuccess(success).build(); - } - -} diff --git a/src/main/java/at/gv/egiz/moazs/config/DeliveryRequestAugmenterConfig.java b/src/main/java/at/gv/egiz/moazs/config/DeliveryRequestAugmenterConfig.java new file mode 100644 index 0000000..93615c4 --- /dev/null +++ b/src/main/java/at/gv/egiz/moazs/config/DeliveryRequestAugmenterConfig.java @@ -0,0 +1,31 @@ +package at.gv.egiz.moazs.config; + +import at.gv.zustellung.app2mzs.xsd.ConfigType; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder; +import static at.gv.zustellung.app2mzs.xsd.ServerType.serverTypeBuilder; + +@Configuration +public class DeliveryRequestAugmenterConfig { + + + @Value("${msg.default.url}") + private String zuseUrlID; + + @Bean + public ConfigType defaultMzsConfig() { + + var server = serverTypeBuilder() + .withZUSEUrlID(zuseUrlID) + .withX509(null) //todo load cert! + .build(); + + return configTypeBuilder() + .withPerformQueryPersonRequest(false) + .withServer(server) + .build(); + } +} diff --git a/src/main/java/at/gv/egiz/moazs/msg/MsgClient.java b/src/main/java/at/gv/egiz/moazs/msg/MsgClient.java new file mode 100644 index 0000000..5742c83 --- /dev/null +++ b/src/main/java/at/gv/egiz/moazs/msg/MsgClient.java @@ -0,0 +1,28 @@ +package at.gv.egiz.moazs.msg; + +import at.gv.zustellung.app2mzs.xsd.ConfigType; +import at.gv.zustellung.msg.xsd.App2ZusePort; +import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; +import at.gv.zustellung.msg.xsd.DeliveryRequestType; +import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; +import org.springframework.stereotype.Component; + +@Component +public class MsgClient { + + public DeliveryRequestStatusType send(DeliveryRequestType msgRequest, ConfigType config) { + + var address = config.getServer().getZUSEUrlID(); + var proxy = connect(address); + return proxy.delivery(msgRequest); + + } + + private App2ZusePort connect(String address) { + var factory = new JaxWsProxyFactoryBean(); + factory.setServiceClass(App2ZusePort.class); + factory.setAddress(address); + return (App2ZusePort) factory.create(); + } + +} diff --git a/src/main/java/at/gv/egiz/moazs/pipeline/SameThreadDeliveryPipeline.java b/src/main/java/at/gv/egiz/moazs/pipeline/SameThreadDeliveryPipeline.java index bc80188..3d7f8e9 100644 --- a/src/main/java/at/gv/egiz/moazs/pipeline/SameThreadDeliveryPipeline.java +++ b/src/main/java/at/gv/egiz/moazs/pipeline/SameThreadDeliveryPipeline.java @@ -1,7 +1,7 @@ package at.gv.egiz.moazs.pipeline; -import at.gv.egiz.moazs.MsgClient; +import at.gv.egiz.moazs.msg.MsgClient; import at.gv.egiz.moazs.tnvz.TnvzClient; import at.gv.egiz.moazs.repository.DeliveryRepository; import at.gv.egiz.moazs.scheme.Mzs2MsgConverter; @@ -48,7 +48,7 @@ public class SameThreadDeliveryPipeline implements DeliveryPipeline { ? converter.convert(mzsRequest, queryPerson(mzsRequest)) : converter.convert(mzsRequest); - var status = msgClient.send(msgRequest); + var status = msgClient.send(msgRequest, mzsRequest.getConfig()); repository.add(status); } diff --git a/src/main/java/at/gv/egiz/moazs/tnvz/TnvzClient.java b/src/main/java/at/gv/egiz/moazs/tnvz/TnvzClient.java new file mode 100644 index 0000000..4a69aea --- /dev/null +++ b/src/main/java/at/gv/egiz/moazs/tnvz/TnvzClient.java @@ -0,0 +1,18 @@ +package at.gv.egiz.moazs.tnvz; + +import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.Sender; +import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.Receiver; +import at.gv.zustellung.tnvz.xsd.PersonResultSuccessType; +import at.gv.zustellung.tnvz.xsd.PersonResultType; +import at.gv.zustellung.tnvz.xsd.PersonResultType.PersonResultTypeBuilder; +import org.springframework.stereotype.Component; + +@Component +public class TnvzClient { + + public PersonResultType queryPerson(Sender sender, Receiver receiver) { + PersonResultSuccessType success = new PersonResultSuccessType.PersonResultSuccessTypeBuilder().build(); + return new PersonResultTypeBuilder().withSuccess(success).build(); + } + +} diff --git a/src/main/resources/mzs/app2mzs.xsd b/src/main/resources/mzs/app2mzs.xsd index 9818d5a..e97e9b6 100644 --- a/src/main/resources/mzs/app2mzs.xsd +++ b/src/main/resources/mzs/app2mzs.xsd @@ -5,14 +5,6 @@ - - - - - - - - @@ -88,7 +80,15 @@ - + + + + + + + + + @@ -190,4 +190,5 @@ + diff --git a/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java b/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java new file mode 100644 index 0000000..a98da74 --- /dev/null +++ b/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java @@ -0,0 +1,80 @@ +package at.gv.egiz.moazs; + +import at.gv.zustellung.app2mzs.xsd.ConfigType; +import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; +import org.junit.Test; + +import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder; +import static at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.deliveryRequestTypeBuilder; +import static at.gv.zustellung.app2mzs.xsd.ServerType.serverTypeBuilder; +import static org.assertj.core.api.Assertions.assertThat; + +public class DeliveryRequestAugmenterTest { + + private final String msgUrl = "http://mzs"; + + @Test + public void augmentPrimaryWithoutConfig() { + var fallback = createConfig(msgUrl, false); + var augmenter = new DeliveryRequestAugmenter(fallback); + + var actual = augmenter.augment(createRequest(null)).getConfig(); + + assertThat(actual).isEqualToComparingFieldByFieldRecursively(fallback); + } + + @Test + public void augmentPrimaryWithEmptyConfig() { + var fallback = createConfig(msgUrl, false); + var augmenter = new DeliveryRequestAugmenter(fallback); + var primary = createConfig(null, null); + + var actual = augmenter.augment(createRequest(primary)).getConfig(); + + assertThat(actual).isEqualToComparingFieldByFieldRecursively(fallback); + } + + @Test + public void overrideFallbacksUrlWithPrimary() { + var fallback = createConfig("http://fallback.url", false); + var primary = createConfig("http://primary.url", null); + var augmenter = new DeliveryRequestAugmenter(fallback); + + var actual = augmenter.augment(createRequest(primary)).getConfig(); + + var expected = createConfig("http://primary.url", false); + assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); + } + + @Test + public void overrideFallbacksTvnzQueryWithPrimary() { + var fallback = createConfig(msgUrl, false); + var primary = createConfig(null, true); + var augmenter = new DeliveryRequestAugmenter(fallback); + + var actual = augmenter.augment(createRequest(primary)).getConfig(); + + var expected = createConfig(msgUrl, true); + assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); + } + + private ConfigType createConfig(String url, Boolean performTnvz) { + + var server = serverTypeBuilder() + .withZUSEUrlID(url) + .build(); + + return configTypeBuilder() + .withServer(server) + .withPerformQueryPersonRequest(performTnvz) + .build(); + } + + private DeliveryRequestType createRequest(ConfigType config) { + + return deliveryRequestTypeBuilder() + .withConfig(config) + .build(); + } + +} diff --git a/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java b/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java index f394a63..9ee3ceb 100644 --- a/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java +++ b/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java @@ -1,5 +1,6 @@ package at.gv.egiz.moazs; +import at.gv.egiz.moazs.msg.MsgClient; import at.gv.egiz.moazs.pipeline.DeliveryPipeline; import at.gv.egiz.moazs.pipeline.SameThreadDeliveryPipeline; import at.gv.egiz.moazs.repository.DeliveryRepository; @@ -128,7 +129,7 @@ public class SameThreadDeliveryPipelineTest { when(tnvzClient.queryPerson(any(), any())).thenReturn(setupTnvzSuccess(acceptedTypes)); when(converter.convert(eq(mzsRequest) )).thenReturn(msgRequest); when(converter.convert(eq(mzsRequest), any())).thenReturn(msgRequest); - when(msgClient.send(msgRequest)).thenReturn(status); + when(msgClient.send(msgRequest, mzsRequest.getConfig())).thenReturn(status); return status; -- cgit v1.2.3