aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-02 16:42:43 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-02 16:42:43 +0200
commit4b6ce58f339d69c70ef746ceecae78bf7ed0f0ba (patch)
tree7708c40ffdc7e29aa784ee5d26308f18aa1f460b /src/main/java/at/gv/egiz/moazs
parent030488bb7ff9572f35032d80d4101c06cfc98bf5 (diff)
downloadmoa-zs-4b6ce58f339d69c70ef746ceecae78bf7ed0f0ba.tar.gz
moa-zs-4b6ce58f339d69c70ef746ceecae78bf7ed0f0ba.tar.bz2
moa-zs-4b6ce58f339d69c70ef746ceecae78bf7ed0f0ba.zip
Handle tnvz Query Edge Cases by Improving Validation
TnvzHelper Fixes - Handle additional edge cases. - Mzs:Schema Change: Eliminate PreAdviceNote redundancy by removing it from mzs:DeliveryRequest/TnvzMetaData; PreadviceNote is already in the Receiver element. Update TnvzHelper accordingly. - Implement and integrate tnvz completeness check into DeliveryRequestAugmenter to ensure that, after augmentation, tnvz can be performed. Refactor mzs:DeliveryRequest Validation: - Before: Validating, merging and generatig ConfigType in ConfigUtil. - Change: Need to add validation of DeliveryRequest (Reason: For performing Tnvz Requests, the DeliveryRequest needs to be in a consistent state). - Problem: DeliveryRequest validation does not fit into ConfigUtil. - Solution: Put validation of DeliveryRequest and Config into new Component "MzsValidation".
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs')
-rw-r--r--src/main/java/at/gv/egiz/moazs/config/PreprocessConfig.java3
-rw-r--r--src/main/java/at/gv/egiz/moazs/mzs/MzsValidator.java70
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java17
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java51
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java35
-rw-r--r--src/main/java/at/gv/egiz/moazs/tnvz/TnvzHelper.java46
6 files changed, 137 insertions, 85 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/config/PreprocessConfig.java b/src/main/java/at/gv/egiz/moazs/config/PreprocessConfig.java
index d1295b1..b90b6a3 100644
--- a/src/main/java/at/gv/egiz/moazs/config/PreprocessConfig.java
+++ b/src/main/java/at/gv/egiz/moazs/config/PreprocessConfig.java
@@ -1,5 +1,6 @@
package at.gv.egiz.moazs.config;
+import at.gv.egiz.moazs.mzs.MzsValidator;
import at.gv.egiz.moazs.preprocess.*;
import at.gv.zustellung.app2mzs.xsd.ConfigType;
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,12 +28,14 @@ public class PreprocessConfig {
@Autowired
public ConfigProfileGenerator configProfileGenerator(
SpringPropertiesFacade properties,
+ MzsValidator validator,
ConfigUtil util) {
return configProfileGeneratorBuilder()
.withProperties(properties)
.withConfigUtil(util)
.withVerifyCompletenessOfDefaultConfiguration(verifyCompletenessOfDefaultConfiguration)
+ .withValidator(validator)
.build();
}
diff --git a/src/main/java/at/gv/egiz/moazs/mzs/MzsValidator.java b/src/main/java/at/gv/egiz/moazs/mzs/MzsValidator.java
new file mode 100644
index 0000000..c5b73bb
--- /dev/null
+++ b/src/main/java/at/gv/egiz/moazs/mzs/MzsValidator.java
@@ -0,0 +1,70 @@
+package at.gv.egiz.moazs.mzs;
+
+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 org.springframework.lang.Nullable;
+import org.springframework.stereotype.Component;
+
+@Component
+public class MzsValidator {
+
+ /**
+ * Checks if the mandatory fields that are needed to send a tnvz:QueryPersonRequest are present.
+ * @param request
+ * @return true if mandatory fields are present.
+ */
+ public boolean isTnvzComplete(DeliveryRequestType request) {
+ return (!request.getConfig().isPerformQueryPersonRequest()) || request.getTnvzMetaData() != null;
+ }
+
+ /**
+ * Check if all mandatory fields of configuration are present.
+ *
+ * @param profile
+ * @return true if all mandatory fields are present.
+ */
+ public boolean isConfigProfileComplete(@Nullable ConfigType profile) {
+ return profile != null
+ && profile.isPerformQueryPersonRequest() != null
+ && isTVNZClientConfigured(profile.getTNVZClient(), profile.isPerformQueryPersonRequest())
+ && isMSGClientConfigured(profile.getMSGClient());
+ }
+
+ private boolean isTVNZClientConfigured(ClientType tnvzClient, Boolean isPerformQueryPersonRequest) {
+ return !isPerformQueryPersonRequest || (tnvzClient != null
+ && tnvzClient.getURL() != null
+ && tnvzClient.getReceiveTimeout() != null
+ && tnvzClient.getConnectionTimeout() != null
+ && isSSLConfigured(tnvzClient));
+ }
+
+ private boolean isMSGClientConfigured(ClientType msgClientParams) {
+ return msgClientParams != null
+ && msgClientParams.getURL() != null
+ && isSSLConfigured(msgClientParams)
+ && msgClientParams.getReceiveTimeout() != null
+ && msgClientParams.getConnectionTimeout() != null;
+ }
+
+ private boolean isSSLConfigured(ClientType clientParams) {
+ return !clientParams.getURL().startsWith("https") || (clientParams.getSSL() != null
+ && clientParams.getSSL().isTrustAll() != null
+ && clientParams.getSSL().isLaxHostNameVerification() != null
+ && isKeyStoreConfigured(clientParams.getSSL().getKeyStore())
+ && isTrustStoreConfigured(clientParams.getSSL().getTrustStore()));
+ }
+
+ private boolean isKeyStoreConfigured(KeyStoreType keyStore) {
+ return keyStore == null || (keyStore.getPassword() != null
+ && keyStore.getFileType() != null
+ && keyStore.getFileName() != null);
+ }
+
+ private boolean isTrustStoreConfigured(KeyStoreType trustStore) {
+ return trustStore == null || (trustStore.getPassword() != null
+ && "JKS".equals(trustStore.getFileType())
+ && trustStore.getFileName() != null);
+ }
+}
diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java
index fa1ccd6..c2f2415 100644
--- a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java
+++ b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java
@@ -1,6 +1,7 @@
package at.gv.egiz.moazs.preprocess;
import at.gv.egiz.moazs.MoaZSException;
+import at.gv.egiz.moazs.mzs.MzsValidator;
import at.gv.egiz.moazs.util.StringUtils;
import at.gv.zustellung.app2mzs.xsd.ConfigType;
import org.slf4j.Logger;
@@ -29,6 +30,7 @@ public class ConfigProfileGenerator {
private final SpringPropertiesFacade properties;
private final ConfigUtil util;
+ private final MzsValidator validator;
private final boolean verifyCompletenessOfDefaultConfiguration;
private final String profilePrefix;
private final String defaultConfigKey;
@@ -40,11 +42,12 @@ public class ConfigProfileGenerator {
private ConfigProfileGenerator(
SpringPropertiesFacade properties,
ConfigUtil util,
- boolean verifyCompletenessOfDefaultConfiguration,
+ MzsValidator validator, boolean verifyCompletenessOfDefaultConfiguration,
String profilePrefix,
String defaultConfigKey) {
this.util = util;
this.properties = properties;
+ this.validator = validator;
this.verifyCompletenessOfDefaultConfiguration = verifyCompletenessOfDefaultConfiguration;
this.profilePrefix = profilePrefix;
this.defaultConfigKey = defaultConfigKey;
@@ -68,7 +71,7 @@ public class ConfigProfileGenerator {
var defaultProfile = profiles.get(defaultConfigKey);
- if (!util.isComplete(defaultProfile)) {
+ if (!validator.isConfigProfileComplete(defaultProfile)) {
if (verifyCompletenessOfDefaultConfiguration)
throw MoaZSException.moaZSException(PROFILE_NOT_COMPLETE_ERROR_MESSAGE);
else {
@@ -110,6 +113,7 @@ public class ConfigProfileGenerator {
public static class ConfigProfileGeneratorBuilder {
private SpringPropertiesFacade properties;
private ConfigUtil util;
+ private MzsValidator validator;
private boolean verify = true;
private String profilePrefix = "delivery-request-configuration-profiles";
private String defaultConfigKey = "default";
@@ -124,6 +128,11 @@ public class ConfigProfileGenerator {
return this;
}
+ public ConfigProfileGeneratorBuilder withValidator(MzsValidator validator) {
+ this.validator = validator;
+ return this;
+ }
+
public ConfigProfileGeneratorBuilder withVerifyCompletenessOfDefaultConfiguration(
boolean verify) {
this.verify = verify;
@@ -141,10 +150,10 @@ public class ConfigProfileGenerator {
}
public ConfigProfileGenerator build() {
- if (properties == null || util == null || profilePrefix == null || defaultConfigKey == null)
+ if (properties == null || util == null || profilePrefix == null || defaultConfigKey == null || validator == null)
throw new IllegalArgumentException("Cannot build ConfigProfileGenerator: " +
"One or more arguments are null.");
- return new ConfigProfileGenerator(properties, util, verify, profilePrefix, defaultConfigKey);
+ return new ConfigProfileGenerator(properties, util, validator, verify, profilePrefix, defaultConfigKey);
}
}
}
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 6c9d264..68f833e 100644
--- a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java
+++ b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java
@@ -5,7 +5,6 @@ import at.gv.zustellung.app2mzs.xsd.ClientType;
import at.gv.zustellung.app2mzs.xsd.ConfigType;
import at.gv.zustellung.app2mzs.xsd.KeyStoreType;
import at.gv.zustellung.app2mzs.xsd.SSLType;
-import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import java.math.BigInteger;
@@ -215,54 +214,4 @@ public class ConfigUtil {
}
- /**
- * Check if all mandatory fields are set.
- *
- * @param profile
- * @return true if all mandatory fields are set
- */
- public boolean isComplete(@Nullable ConfigType profile) {
- return profile != null
- && profile.isPerformQueryPersonRequest() != null
- && isTVNZClientConfigured(profile.getTNVZClient(), profile.isPerformQueryPersonRequest())
- && isMSGClientConfigured(profile.getMSGClient());
- }
-
- private boolean isTVNZClientConfigured(ClientType tnvzClient, Boolean isPerformQueryPersonRequest) {
- return !isPerformQueryPersonRequest || (tnvzClient != null
- && tnvzClient.getURL() != null
- && tnvzClient.getReceiveTimeout() != null
- && tnvzClient.getConnectionTimeout() != null
- && isSSLConfigured(tnvzClient));
- }
-
- private boolean isMSGClientConfigured(ClientType msgClientParams) {
- return msgClientParams != null
- && msgClientParams.getURL() != null
- && isSSLConfigured(msgClientParams)
- && msgClientParams.getReceiveTimeout() != null
- && msgClientParams.getConnectionTimeout() != null;
- }
-
- private boolean isSSLConfigured(ClientType clientParams) {
- return !clientParams.getURL().startsWith("https") || (clientParams.getSSL() != null
- && clientParams.getSSL().isTrustAll() != null
- && clientParams.getSSL().isLaxHostNameVerification() != null
- && isKeyStoreConfigured(clientParams.getSSL().getKeyStore())
- && isTrustStoreConfigured(clientParams.getSSL().getTrustStore()));
- }
-
- private boolean isKeyStoreConfigured(KeyStoreType keyStore) {
- return keyStore == null || (keyStore.getPassword() != null
- && keyStore.getFileType() != null
- && keyStore.getFileName() != null);
- }
-
- private boolean isTrustStoreConfigured(KeyStoreType trustStore) {
- return trustStore == null || (trustStore.getPassword() != null
- && "JKS".equals(trustStore.getFileType())
- && trustStore.getFileName() != null);
- }
-
-
}
diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java b/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java
index aea01bb..37dbdc5 100644
--- a/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java
+++ b/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java
@@ -1,5 +1,6 @@
package at.gv.egiz.moazs.preprocess;
+import at.gv.egiz.moazs.mzs.MzsValidator;
import at.gv.zustellung.app2mzs.xsd.ConfigType;
import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
import org.springframework.beans.factory.annotation.Autowired;
@@ -15,7 +16,10 @@ public class DeliveryRequestAugmenter {
private final ConfigUtil util;
private final Map<String, ConfigType> configs;
+ private final MzsValidator validator;
+ private static final String INCOMPLETE_TNVZ_ERROR_MESSAGE = "mzs:DeliveryRequest is incomplete because mandatory " +
+ "fields for sending a tnvz:QueryPersonRequest are missing.";
private static final String INCOMPLETE_CONFIG_ERROR_MESSAGE = "Could not find a profile for " +
"the delivery request configuration, and the configuration attached to mzs:DeliveryRequest is incomplete.";
private static final String INCOMPLETE_MERGED_CONFIG_ERROR_MESSAGE = "I merged parameters from " +
@@ -23,9 +27,10 @@ public class DeliveryRequestAugmenter {
"configuration is incomplete.";
@Autowired
- public DeliveryRequestAugmenter(Map<String, ConfigType> deliveryRequestConfigs, ConfigUtil util) {
+ public DeliveryRequestAugmenter(Map<String, ConfigType> deliveryRequestConfigs, ConfigUtil util, MzsValidator validator) {
this.configs = deliveryRequestConfigs;
this.util = util;
+ this.validator = validator;
}
/**
@@ -33,7 +38,7 @@ public class DeliveryRequestAugmenter {
*
* @param request
* @throws at.gv.egiz.moazs.MoaZSException
- * @return augmented request
+ * @return augmented request and validated
*/
public DeliveryRequestType augment(DeliveryRequestType request) {
@@ -43,10 +48,13 @@ public class DeliveryRequestAugmenter {
if (fallbackConfig == null) {
- if (util.isComplete(requestConfig))
- return request;
- else
+ if (!validator.isConfigProfileComplete(request.getConfig())) {
throw moaZSException(INCOMPLETE_CONFIG_ERROR_MESSAGE);
+ } else if (!validator.isTnvzComplete(request)) {
+ throw moaZSException(INCOMPLETE_TNVZ_ERROR_MESSAGE);
+ } else {
+ return request;
+ }
} else {
@@ -54,13 +62,20 @@ public class DeliveryRequestAugmenter {
? fallbackConfig
: util.merge(requestConfig, fallbackConfig);
- if (util.isComplete(mergedConfig)) {
- return deliveryRequestTypeBuilder(request)
- .withConfig(mergedConfig)
- .build();
- } else {
+ if (!validator.isConfigProfileComplete(mergedConfig)) {
throw moaZSException(INCOMPLETE_MERGED_CONFIG_ERROR_MESSAGE, fallbackProfileId);
}
+
+ var mergedRequest = deliveryRequestTypeBuilder(request)
+ .withConfig(mergedConfig)
+ .build();
+
+ if (!validator.isTnvzComplete(mergedRequest)) {
+ throw moaZSException(INCOMPLETE_TNVZ_ERROR_MESSAGE);
+ }
+
+ return mergedRequest;
+
}
}
diff --git a/src/main/java/at/gv/egiz/moazs/tnvz/TnvzHelper.java b/src/main/java/at/gv/egiz/moazs/tnvz/TnvzHelper.java
index a14df9d..3599362 100644
--- a/src/main/java/at/gv/egiz/moazs/tnvz/TnvzHelper.java
+++ b/src/main/java/at/gv/egiz/moazs/tnvz/TnvzHelper.java
@@ -3,7 +3,6 @@ package at.gv.egiz.moazs.tnvz;
import at.gv.egiz.moazs.MoaZSException;
import at.gv.egiz.moazs.scheme.Mzs2MsgConverter;
import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
-import at.gv.zustellung.app2mzs.xsd.TnvzMetaDataType;
import at.gv.zustellung.app2mzs.xsd.persondata.AbstractAddressType;
import at.gv.zustellung.msg.xsd.persondata.IdentificationType;
import at.gv.zustellung.msg.xsd.persondata.ObjectFactory;
@@ -39,7 +38,7 @@ public class TnvzHelper {
private static final String RECEIVER_NOT_ADRESSABLE_ERROR_MSG = "Receiver is not addressable. Reason: %s";
private static final String MIMETYPE_MISSMATCH_ERROR_MSG = "Request contains attachment of type(s) %s, but " +
"receiver only accepts attachments of type(s) %s.";
- private static final String MZS_NO_TNVZ_PERSON_QUERY_RESULTS_ERROR_MSG = "tnvz:PersonQueryResult's list was empty.";
+ private static final String MZS_NO_TNVZ_PERSON_QUERY_RESULTS_ERROR_MSG = "tnvz:QueryResultList was empty.";
@Autowired
@@ -74,9 +73,9 @@ public class TnvzHelper {
private QueryPersonRequest buildQuery(DeliveryRequestType mzsRequest) {
- Sender sender = extractSender(mzsRequest.getSender().getCorporateBody());
+ Sender sender = extractSender(mzsRequest.getSender());
Receiver receiver = extractReceiver(mzsRequest.getReceiver());
- var metadata = extractMetaData(mzsRequest.getTnvzMetaData());
+ var metadata = extractMetaData(mzsRequest);
PersonQueryType personQuery = personQueryTypeBuilder()
.withEntryID(ENTRY_ID)
@@ -94,27 +93,32 @@ public class TnvzHelper {
.build();
}
- private PersonQueryType.MetaData extractMetaData(@Nullable TnvzMetaDataType meta) {
- if (meta == null) {
- return null;
- } else {
- var builder = metaDataBuilder();
+ private PersonQueryType.MetaData extractMetaData(DeliveryRequestType request) {
- if (meta.getDeliveryQuality() != null) {
- builder.withDeliveryQuality(meta.getDeliveryQuality());
- } else {
- builder.withPrivateMessageQuality(meta.getPrivateMessageQuality());
- }
+ var builder = metaDataBuilder();
- return builder
- .withOrigin(meta.getOrigin())
- .withPreAdviceNote(meta.getPreAdviceNote())
- .withIgnorePostRedirectionOrder(meta.getIgnorePostRedirectionOrder())
- .build();
+ var meta = request.getTnvzMetaData();
+
+ if (meta.getDeliveryQuality() != null) {
+ builder.withDeliveryQuality(meta.getDeliveryQuality());
+ } else {
+ builder.withPrivateMessageQuality(meta.getPrivateMessageQuality());
}
+
+ return builder
+ .withOrigin(meta.getOrigin())
+ .withPreAdviceNote(request.getReceiver().getPreAdviceNote())
+ .withIgnorePostRedirectionOrder(meta.getIgnorePostRedirectionOrder())
+ .build();
}
- private Sender extractSender(at.gv.zustellung.app2mzs.xsd.persondata.CorporateBodyType corporateBody) {
+ private Sender extractSender(DeliveryRequestType.Sender sender) {
+
+ var corporateBody = sender.getCorporateBody();
+ if (corporateBody == null) {
+ //todo! implement this case
+ throw MoaZSException.moaZSException("Not Implemented.");
+ }
var mzsIdentification = corporateBody.getIdentification().get(0);
var msgIdentification = converter.convert(mzsIdentification);
@@ -152,6 +156,8 @@ public class TnvzHelper {
private @Nullable PostalAddressType findPostalAddress(List<JAXBElement<? extends AbstractAddressType>> addresses) {
+ if (addresses == null) return null;
+
for (JAXBElement<? extends AbstractAddressType> address : addresses) {
if(address.getValue() instanceof at.gv.zustellung.app2mzs.xsd.persondata.PostalAddressType) {
var mzsPostalAddress = (at.gv.zustellung.app2mzs.xsd.persondata.PostalAddressType) address.getValue();