diff options
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/backend')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/backend/MsgResponseBackend.java | 37 |
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(); + }; + } + } |