aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz')
-rw-r--r--src/main/java/at/gv/egiz/moazs/App2MzsService.java28
-rw-r--r--src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java45
-rw-r--r--src/main/java/at/gv/egiz/moazs/TnvzClient.java14
-rw-r--r--src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java6
-rw-r--r--src/main/java/at/gv/egiz/moazs/pipeline/SameThreadDeliveryPipeline.java26
5 files changed, 84 insertions, 35 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/App2MzsService.java b/src/main/java/at/gv/egiz/moazs/App2MzsService.java
index 66ab795..f84f16c 100644
--- a/src/main/java/at/gv/egiz/moazs/App2MzsService.java
+++ b/src/main/java/at/gv/egiz/moazs/App2MzsService.java
@@ -1,16 +1,12 @@
package at.gv.egiz.moazs;
-import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.DeliveryAnswerType;
import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.DeliveryAnswerType.DeliveryAnswerTypeBuilder;
import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.DeliveryRequestStatusType;
import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.DeliveryRequestStatusType.DeliveryRequestStatusTypeBuilder;
import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.DeliveryRequestStatusType.Error.ErrorBuilder;
-import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.ErrorInfoType;
import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.ErrorInfoType.ErrorInfoTypeBuilder;
-import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.ObjectFactory;
import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs.App2MzsPortType;
import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType;
-import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType.DeliveryRequestTypeBuilder;
import at.gv.egiz.moazs.pipeline.DeliveryPipeline;
import at.gv.egiz.moazs.repository.DeliveryRepository;
import org.slf4j.Logger;
@@ -37,12 +33,14 @@ public class App2MzsService implements App2MzsPortType {
private final DeliveryRepository repository;
private final DeliveryPipeline pipeline;
private final Mzs2AppClient appClient;
- private final ObjectFactory objectFactory = new ObjectFactory();
+ private final DeliveryPreprocessor preprocessor;
- public App2MzsService(@Autowired DeliveryRepository repository, @Autowired DeliveryPipeline pipeline, @Autowired Mzs2AppClient appClient) {
+ public App2MzsService(@Autowired DeliveryRepository repository, @Autowired DeliveryPipeline pipeline,
+ @Autowired Mzs2AppClient appClient, @Autowired DeliveryPreprocessor preprocessor) {
this.repository = repository;
this.pipeline = pipeline;
this.appClient = appClient;
+ this.preprocessor = preprocessor;
}
@Override
@@ -54,24 +52,25 @@ public class App2MzsService implements App2MzsPortType {
final var appDeliveryID = deliveryRequest.getMetaData().getAppDeliveryID();
- var future = supplyAsync(() -> process(deliveryRequest));
+ var future = supplyAsync(() -> preprocessor.preProcess(deliveryRequest))
+ .thenApply((request) -> process(request));
try {
return future.get(TIMEOUT_FOR_ANWSER, TimeUnit.SECONDS);
} catch (TimeoutException e) {
future.thenAccept(appClient::sendNotification);
logger.info("Answer Timed Out", e);
- return generatePartialSuccessResponse(appDeliveryID, "Your request timed out; Wait until X for receiving a notification.");
+ return generatePartialSuccessResponse(appDeliveryID);
} catch (Exception e ) {
logger.error("Could not deliver request.", e);
- final var message = format("An error occured while delivering request: {}", e.getMessage());
+ var message = format("An error occured while delivering request: {0}", e.getMessage());
return generateErrorResponse(appDeliveryID, message);
}
}
- private DeliveryRequestStatusType generatePartialSuccessResponse(String appDeliveryId, String message) {
+ private DeliveryRequestStatusType generatePartialSuccessResponse(String appDeliveryId) {
var answer = new DeliveryAnswerTypeBuilder()
.withAppDeliveryID(appDeliveryId)
@@ -107,13 +106,8 @@ public class App2MzsService implements App2MzsPortType {
repository.add(deliveryRequest);
pipeline.processRequest(appDeliveryID);
- var status = repository.getDeliveryRequestStatus(appDeliveryID);
-
- if (status.isEmpty()) {
- throw new RuntimeException(format("Could not get a response for request with appDeliveryId = {}", appDeliveryID));
- }
-
- return status.get();
+ return repository.getDeliveryRequestStatus(appDeliveryID)
+ .orElseThrow(() -> new RuntimeException("Could not get a response for appDeliveryId = " + appDeliveryID));
}
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();
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/moazs/TnvzClient.java b/src/main/java/at/gv/egiz/moazs/TnvzClient.java
new file mode 100644
index 0000000..28bcb66
--- /dev/null
+++ b/src/main/java/at/gv/egiz/moazs/TnvzClient.java
@@ -0,0 +1,14 @@
+package at.gv.egiz.moazs;
+
+import org.springframework.stereotype.Component;
+
+import static at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType.*;
+
+@Component
+public class TnvzClient {
+
+ public boolean isAddressable(Receiver receiver) {
+ return true;
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java b/src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java
index 71f5f04..c4c720d 100644
--- a/src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java
+++ b/src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java
@@ -1,6 +1,5 @@
package at.gv.egiz.moazs.config;
-import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.ObjectFactory;
import at.gv.egiz.moazs.App2MzsService;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
@@ -26,9 +25,4 @@ public class App2MzsServiceConfig {
endpoint.publish();
return endpoint;
}
-
- @Bean
- public ObjectFactory objectFactory() {
- return new ObjectFactory();
- }
}
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 20252ff..5a8e377 100644
--- a/src/main/java/at/gv/egiz/moazs/pipeline/SameThreadDeliveryPipeline.java
+++ b/src/main/java/at/gv/egiz/moazs/pipeline/SameThreadDeliveryPipeline.java
@@ -2,37 +2,39 @@ package at.gv.egiz.moazs.pipeline;
import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType;
+import at.gv.egiz.moazs.TnvzClient;
import at.gv.egiz.moazs.repository.DeliveryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
-import java.util.Optional;
-
-import static java.text.MessageFormat.format;
-
@Component
@Profile("!cluster")
public class SameThreadDeliveryPipeline implements DeliveryPipeline {
private final DeliveryRepository repository;
+ private final TnvzClient tnvzClient;
- public SameThreadDeliveryPipeline(@Autowired DeliveryRepository repository) {
+ public SameThreadDeliveryPipeline(@Autowired DeliveryRepository repository, TnvzClient tnvzClient) {
this.repository = repository;
+ this.tnvzClient = tnvzClient;
}
@Override
public void processRequest(String appDeliveryId) {
- Optional<DeliveryRequestType> request = repository.getDeliveryRequest(appDeliveryId);
- if (request.isEmpty()) {
- throw new RuntimeException(format(
- "Request with appDeliveryId = {} does not exist.", appDeliveryId));
- }
-
- //do business logic
+ var request = repository.getDeliveryRequest(appDeliveryId).orElseThrow();
+ checkAddressability(request);
//store response to repository
}
+ private void checkAddressability(DeliveryRequestType request) {
+ if (request.getConfig().isPerformQueryPersonRequest()) {
+ if (!tnvzClient.isAddressable(request.getReceiver())) {
+ throw new RuntimeException("Receiver is not addressable.");
+ }
+ }
+ }
+
}