From 296d842878e530ee819fa2f58012665b76e2e670 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Tue, 30 Apr 2019 11:00:46 +0200 Subject: Add Optional mzs:DeliveryRequest/Config & Validate / Augment It Add Optional "Config" to MZS Schema: - Add mzs:DeliveryRequest/Config Element with a "PerformQueryPersonRequest" node - The config element contains parameters that are interpreted by moa-zs and not forwarded to the ZD - The boolean PerformQueryPersonRequest tells moa-zs if moa-zs should perform a QueryPersonRequest towards the TNVZ. - If config is missing, moa-zs augments the delivery request with parameters from the app's configuartion or the default configuartion Other Changes: - Validate and augment incoming requests with the DeliveryPreprocessor. - Add stub for TlnvzClient. - Remove some leftover ObjectFactory imports (because of the builder they are not needed anymore) Fixes - Fixed incorrect API usage of Messageformat.format: format string needs an index. pom.xml - Add Hamcrest Dependency (for writing more expressive tests) - Add copy constructor to JAXB Builder Testing - Test validation of incoming request - Refactor testcases to improve readability --- .../at/gv/egiz/moazs/DeliveryPreprocessor.java | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java (limited to 'src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java') diff --git a/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java b/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java new file mode 100644 index 0000000..2bb621d --- /dev/null +++ b/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java @@ -0,0 +1,45 @@ +package at.gv.egiz.moazs; + +import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.ConfigType; +import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.ConfigType.ConfigTypeBuilder; +import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType; +import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType.DeliveryRequestTypeBuilder; +import org.springframework.stereotype.Component; + +import static at.gv.egiz.moazs.util.NullCoalesce.coalesce; + +@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) { + + validateRequest(request); + + return new DeliveryRequestTypeBuilder(request) + .withConfig(coalesce(request.getConfig(), initDefaultConfig()).get()) + .build(); + } + + private void validateRequest(DeliveryRequestType request) { + if (request.getMetaData() == null) + throw new IllegalArgumentException("Metadata is missing."); + + if (request.getMetaData().getAppDeliveryID() == null) + throw new IllegalArgumentException("AppDeliveryID is missing."); + } + + private ConfigType initDefaultConfig() { + return new ConfigTypeBuilder() + .withPerformQueryPersonRequest(false) + .build(); + } + +} -- cgit v1.2.3