diff options
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/preprocess')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java | 52 | ||||
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java | 42 |
2 files changed, 75 insertions, 19 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java index b69b828..a3329cd 100644 --- a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java +++ b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java @@ -9,6 +9,7 @@ import java.util.Map; import static at.gv.zustellung.app2mzs.xsd.ClientType.clientTypeBuilder; import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder; +import static at.gv.zustellung.app2mzs.xsd.ForwardResponseToServiceType.forwardResponseToServiceTypeBuilder; import static at.gv.zustellung.app2mzs.xsd.KeyStoreType.keyStoreTypeBuilder; import static at.gv.zustellung.app2mzs.xsd.MsgResponseSinksType.msgResponseSinksTypeBuilder; import static at.gv.zustellung.app2mzs.xsd.SSLType.SSLTypeBuilder; @@ -35,8 +36,10 @@ public class ConfigUtil { public static final String MSG_RESPONSE_SINKS_KEY = "msg-response-sinks"; public static final String LOG_RESPONSE_KEY = "log-response"; public static final String SAVE_RESPONSE_TO_FILE_KEY = "save-response-to-file"; - public static final String SAVE_RESPONSE_TO_FILE_ACTIVE_KEY = "active"; + public static final String ACTIVE_KEY = "active"; public static final String SAVE_RESPONSE_TO_FILE_PATH_KEY = "path"; + public static final String FORWARD_RESPONSE_TO_SERVICE_KEY = "forward-response-to-service"; + public static final String MZS_CLIENT_KEY = "mzs-client"; /** @@ -136,18 +139,20 @@ public class ConfigUtil { var logResponse = booleanOrNull(params.get(LOG_RESPONSE_KEY)); - var saveResponseParams = filterMapByPrefix(params, SAVE_RESPONSE_TO_FILE_KEY); - var saveResponse = buildSaveResponse(saveResponseParams); + var saveResponse = buildSaveResponse(filterMapByPrefix(params, SAVE_RESPONSE_TO_FILE_KEY)); + + var forwardResponse = buildForwardResponse(filterMapByPrefix(params, FORWARD_RESPONSE_TO_SERVICE_KEY)); return msgResponseSinksTypeBuilder() .withLogResponse(logResponse) .withSaveResponseToFile(saveResponse) + .withForwardResponseToService(forwardResponse) .build(); } private SaveResponseToFileType buildSaveResponse(Map<String, String> params) { - var isActive = booleanOrNull(params.get(SAVE_RESPONSE_TO_FILE_ACTIVE_KEY)); + var isActive = booleanOrNull(params.get(ACTIVE_KEY)); var path = params.get(SAVE_RESPONSE_TO_FILE_PATH_KEY); return saveResponseToFileTypeBuilder() @@ -156,6 +161,20 @@ public class ConfigUtil { .build(); } + private ForwardResponseToServiceType buildForwardResponse(Map<String, String> params) { + + var isActive = booleanOrNull(params.get(ACTIVE_KEY)); + var mzsClientParams = filterMapByPrefix(params, MZS_CLIENT_KEY); + ClientType mzsClient = mzsClientParams.isEmpty() + ? null : buildClient(mzsClientParams); + + return forwardResponseToServiceTypeBuilder() + .withActive(isActive) + .withMzsClient(mzsClient) + .build(); + } + + private Boolean booleanOrNull(String value) { return value == null ? null : Boolean.getBoolean(value); } @@ -261,14 +280,18 @@ public class ConfigUtil { var builder = msgResponseSinksTypeBuilder(fallback); - if (primary.isLogResponse() != null) { + if (primary.isLogResponse() != null) { builder.withLogResponse(primary.isLogResponse()); } - if (primary.getSaveResponseToFile() != null) { + if (primary.getSaveResponseToFile() != null) { builder.withSaveResponseToFile(merge(primary.getSaveResponseToFile(), fallback.getSaveResponseToFile())); } + if (primary.getForwardResponseToService() != null) { + builder.withForwardResponseToService(merge(primary.getForwardResponseToService(), fallback.getForwardResponseToService())); + } + return builder.build(); } @@ -287,6 +310,23 @@ public class ConfigUtil { } return builder.build(); + } + + private ForwardResponseToServiceType merge(ForwardResponseToServiceType primary, ForwardResponseToServiceType fallback) { + + if (fallback == null) return primary; + + var builder = forwardResponseToServiceTypeBuilder(fallback); + + if (primary.isActive() != null) { + builder.withActive(primary.isActive()); + } + + if (primary.getMzsClient() != null) { + builder.withMzsClient(merge(primary.getMzsClient(), fallback.getMzsClient())); + } + + return builder.build(); } diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java b/src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java index 8f9cd27..2c2fc36 100644 --- a/src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java +++ b/src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java @@ -1,9 +1,6 @@ package at.gv.egiz.moazs.preprocess; -import at.gv.zustellung.app2mzs.xsd.ClientType; -import at.gv.zustellung.app2mzs.xsd.ConfigType; -import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; -import at.gv.zustellung.app2mzs.xsd.KeyStoreType; +import at.gv.zustellung.app2mzs.xsd.*; import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; @@ -19,8 +16,6 @@ public class MzsDeliveryRequestValidator { return !request.getConfig().isPerformQueryPersonRequest() || (request.getTnvzMetaData() != null && request.getSender().getCorporateBody() != null); - - } /** @@ -33,7 +28,8 @@ public class MzsDeliveryRequestValidator { return profile != null && profile.isPerformQueryPersonRequest() != null && isTVNZClientConfigured(profile.getTNVZClient(), profile.isPerformQueryPersonRequest()) - && isMSGClientConfigured(profile.getMSGClient()); + && isClientConfigured(profile.getMSGClient()) + && areSinksConfigured(profile.getMsgResponseSinks()); } private boolean isTVNZClientConfigured(ClientType tnvzClient, Boolean isPerformQueryPersonRequest) { @@ -44,12 +40,12 @@ public class MzsDeliveryRequestValidator { && isSSLConfigured(tnvzClient)); } - private boolean isMSGClientConfigured(ClientType msgClientParams) { - return msgClientParams != null - && msgClientParams.getURL() != null - && isSSLConfigured(msgClientParams) - && msgClientParams.getReceiveTimeout() != null - && msgClientParams.getConnectionTimeout() != null; + private boolean isClientConfigured(ClientType clientParams) { + return clientParams != null + && clientParams.getURL() != null + && isSSLConfigured(clientParams) + && clientParams.getReceiveTimeout() != null + && clientParams.getConnectionTimeout() != null; } private boolean isSSLConfigured(ClientType clientParams) { @@ -71,4 +67,24 @@ public class MzsDeliveryRequestValidator { && "JKS".equals(trustStore.getFileType()) && trustStore.getFileName() != null); } + + private boolean areSinksConfigured(MsgResponseSinksType sinks) { + return sinks != null + && sinks.isLogResponse() != null + && isSaveResponseToFileConfigured(sinks.getSaveResponseToFile()) + && isForwardResponseToServiceConfigured(sinks.getForwardResponseToService()); + } + + private boolean isSaveResponseToFileConfigured(SaveResponseToFileType fileSink) { + return fileSink != null + && (!fileSink.isActive() || fileSink.getPath() != null); + } + + private boolean isForwardResponseToServiceConfigured(ForwardResponseToServiceType forwardSink) { + return forwardSink != null + && (!forwardSink.isActive() || isClientConfigured(forwardSink.getMzsClient())); + } + + + } |