aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/backend
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-11-29 14:54:28 +0100
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-11-29 14:54:28 +0100
commita5b8668c0c7916a8fe2b84122d537a3e0bd67002 (patch)
treef0fd571ff0c22ff2f4567f72fc95b14c63cba7d2 /src/main/java/at/gv/egiz/moazs/backend
parent5fffae99208c7a99a5e3e8f196a6004debcc9c81 (diff)
downloadmoa-zs-a5b8668c0c7916a8fe2b84122d537a3e0bd67002.tar.gz
moa-zs-a5b8668c0c7916a8fe2b84122d537a3e0bd67002.tar.bz2
moa-zs-a5b8668c0c7916a8fe2b84122d537a3e0bd67002.zip
Alter Case Handling "Get Notification where AppDeliveryID is unknown"
- Former: Fail with Exception. - Now: Issue a warning and fall back to default configuration profile after verifying that sinks in default configuration profile are correctly configured. - Refactor: Make DEFAULT_CONFIG_KEY static.
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/backend')
-rw-r--r--src/main/java/at/gv/egiz/moazs/backend/MsgResponseBackend.java37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/backend/MsgResponseBackend.java b/src/main/java/at/gv/egiz/moazs/backend/MsgResponseBackend.java
index 276fb67..0da9c92 100644
--- a/src/main/java/at/gv/egiz/moazs/backend/MsgResponseBackend.java
+++ b/src/main/java/at/gv/egiz/moazs/backend/MsgResponseBackend.java
@@ -22,17 +22,24 @@
package at.gv.egiz.moazs.backend;
import at.gv.egiz.moazs.MoaZSException;
+import at.gv.egiz.moazs.preprocess.MzsDeliveryRequestValidator;
import at.gv.egiz.moazs.repository.DeliveryRepository;
import at.gv.egiz.moazs.scheme.MsgResponse;
import at.gv.egiz.moazs.service.MsgService;
+import at.gv.zustellung.app2mzs.xsd.ConfigType;
+import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.Map;
import java.util.function.Consumer;
+import java.util.function.Supplier;
import static at.gv.egiz.moazs.MoaZSException.*;
+import static at.gv.egiz.moazs.preprocess.ConfigProfileGenerator.DEFAULT_CONFIG_KEY;
+import static at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.deliveryRequestTypeBuilder;
import static java.lang.String.format;
import static java.util.concurrent.CompletableFuture.supplyAsync;
@@ -49,19 +56,26 @@ public class MsgResponseBackend implements Consumer<String> {
"with AppDeliveryID=%s is not valid.";
public static final String BINARY_RESPONSE_MISSING_ERROR_MSG = "Binary Response is not in repository.";
public static final String RESPONSE_MISSING_ERROR_MSG = "Response with ResponseID=%s is not in repository.";
- public static final String REQUEST_MISSING_ERROR_MSG = "Request with AppDeliveryID=%s is not in repository.";
+ public static final String REQUEST_MISSING_ERROR_MSG = "Request with AppDeliveryID=%s is not in repository. " +
+ "Falling Back to Default Configuration.";
private final DeliveryRepository repository;
private final Consumer<byte[]> signatureVerifier;
private final MsgResponseSinkHub hub;
+ private final Map<String, ConfigType> deliveryRequestConfigs;
+ private final MzsDeliveryRequestValidator validator;
@Autowired
public MsgResponseBackend(DeliveryRepository repository,
Consumer<byte[]> signatureVerifier,
- MsgResponseSinkHub hub) {
+ MsgResponseSinkHub hub,
+ Map<String, ConfigType> deliveryRequestConfigs,
+ MzsDeliveryRequestValidator validator) {
this.repository = repository;
this.signatureVerifier = signatureVerifier;
this.hub = hub;
+ this.deliveryRequestConfigs = deliveryRequestConfigs;
+ this.validator = validator;
}
/**
@@ -111,11 +125,24 @@ public class MsgResponseBackend implements Consumer<String> {
private void applySinks(MsgResponse msgResponse) {
var appDeliveryID = msgResponse.getAppDeliveryID();
- var request = repository.retrieveDeliveryRequest(appDeliveryID).orElseThrow(
- ()-> moaZSException(format(REQUEST_MISSING_ERROR_MSG, appDeliveryID)));
+ var config = repository
+ .retrieveDeliveryRequest(appDeliveryID)
+ .orElseGet(supplyRequestWithDefaultConfig(appDeliveryID))
+ .getConfig();
- var sinkParams = request.getConfig().getMsgResponseSinks();
+ var sinkParams = config.getMsgResponseSinks();
hub.applySinks(msgResponse, sinkParams);
}
+ private Supplier<DeliveryRequestType> supplyRequestWithDefaultConfig(String appDeliveryID) {
+ return () -> {
+ log.warn(format(REQUEST_MISSING_ERROR_MSG, appDeliveryID));
+ var defaultConfig = deliveryRequestConfigs.get(DEFAULT_CONFIG_KEY);
+ validator.areSinksConfigured(defaultConfig.getMsgResponseSinks());
+ return deliveryRequestTypeBuilder()
+ .withConfig(defaultConfig)
+ .build();
+ };
+ }
+
}