From dfbb2fb7e55eb99b777cc4d5f5fc5e2aca8f76c6 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Fri, 10 May 2019 11:22:46 +0200 Subject: Refactor: Rename DeliveryPreprocessor to Augmenter - Reason: Preprocessor does not perform any validation anymore! --- src/main/java/at/gv/egiz/moazs/App2MzsService.java | 10 +++--- .../at/gv/egiz/moazs/DeliveryPreprocessor.java | 42 ---------------------- .../at/gv/egiz/moazs/DeliveryRequestAugmenter.java | 37 +++++++++++++++++++ 3 files changed, 42 insertions(+), 47 deletions(-) delete mode 100644 src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java create mode 100644 src/main/java/at/gv/egiz/moazs/DeliveryRequestAugmenter.java (limited to 'src/main/java/at/gv/egiz/moazs') diff --git a/src/main/java/at/gv/egiz/moazs/App2MzsService.java b/src/main/java/at/gv/egiz/moazs/App2MzsService.java index 2fcfd15..23cc0aa 100644 --- a/src/main/java/at/gv/egiz/moazs/App2MzsService.java +++ b/src/main/java/at/gv/egiz/moazs/App2MzsService.java @@ -32,14 +32,14 @@ public class App2MzsService implements App2MzsPortType { private final DeliveryRepository repository; private final DeliveryPipeline pipeline; private final Mzs2AppClient appClient; - private final DeliveryPreprocessor preprocessor; + private final DeliveryRequestAugmenter augmenter; public App2MzsService(@Autowired DeliveryRepository repository, @Autowired DeliveryPipeline pipeline, - @Autowired Mzs2AppClient appClient, @Autowired DeliveryPreprocessor preprocessor) { + @Autowired Mzs2AppClient appClient, @Autowired DeliveryRequestAugmenter augmenter) { this.repository = repository; this.pipeline = pipeline; this.appClient = appClient; - this.preprocessor = preprocessor; + this.augmenter = augmenter; } @Override @@ -48,7 +48,7 @@ public class App2MzsService implements App2MzsPortType { name = "DeliveryRequest") DeliveryRequestType deliveryRequest) { - var future = supplyAsync(() -> preprocessor.preProcess(deliveryRequest)) + var future = supplyAsync(() -> augmenter.augment(deliveryRequest)) .thenApply(this::process); try { @@ -92,4 +92,4 @@ public class App2MzsService implements App2MzsPortType { .build(); } -} \ No newline at end of file +} diff --git a/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java b/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java deleted file mode 100644 index 5f75750..0000000 --- a/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java +++ /dev/null @@ -1,42 +0,0 @@ -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.persondata.CorporateBodyType; -import at.gv.zustellung.msg.xsd.SenderProfile; -import org.springframework.stereotype.Component; -import org.springframework.util.Assert; - -import static at.gv.egiz.moazs.util.NullCoalesce.coalesce; -import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder; -import static org.springframework.util.Assert.isTrue; -import static org.springframework.util.Assert.notNull; - -@Component -public class DeliveryPreprocessor { - - /** - * Validates and augments an incoming {@code request} - * - * Validates a {@code request} to ensure the availability of all mandatory fields. Where possible, the method - * augments the request with values taken from the app's configuration. - * @param request - * @return validated and augmented request - */ - public DeliveryRequestType preProcess(DeliveryRequestType request) { - - //validate(request); - - return new DeliveryRequestTypeBuilder(request) - .withConfig(coalesce(request.getConfig(), initDefaultConfig()).get()) - .build(); - } - - private ConfigType initDefaultConfig() { - return configTypeBuilder() - .withPerformQueryPersonRequest(false) - .build(); - } - -} diff --git a/src/main/java/at/gv/egiz/moazs/DeliveryRequestAugmenter.java b/src/main/java/at/gv/egiz/moazs/DeliveryRequestAugmenter.java new file mode 100644 index 0000000..5c11ecb --- /dev/null +++ b/src/main/java/at/gv/egiz/moazs/DeliveryRequestAugmenter.java @@ -0,0 +1,37 @@ +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.persondata.CorporateBodyType; +import at.gv.zustellung.msg.xsd.SenderProfile; +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; + +import static at.gv.egiz.moazs.util.NullCoalesce.coalesce; +import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder; +import static org.springframework.util.Assert.isTrue; +import static org.springframework.util.Assert.notNull; + +@Component +public class DeliveryRequestAugmenter { + + /** + * Augments an incoming {@code request} by filling gaps with config- or default parameters. + * + * @param request + * @return augmented request + */ + public DeliveryRequestType augment(DeliveryRequestType request) { + return new DeliveryRequestTypeBuilder(request) + .withConfig(coalesce(request.getConfig(), initDefaultConfig()).get()) + .build(); + } + + private ConfigType initDefaultConfig() { + return configTypeBuilder() + .withPerformQueryPersonRequest(false) + .build(); + } + +} -- cgit v1.2.3