aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java')
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java160
1 files changed, 119 insertions, 41 deletions
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 2c2fc36..67086a2 100644
--- a/src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java
+++ b/src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java
@@ -1,90 +1,168 @@
package at.gv.egiz.moazs.preprocess;
+import at.gv.egiz.moazs.MoaZSException;
import at.gv.zustellung.app2mzs.xsd.*;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
+import static at.gv.egiz.moazs.MoaZSException.moaZSException;
+import static at.gv.egiz.moazs.scheme.NameSpace.*;
+import static java.lang.String.format;
+
@Component
public class MzsDeliveryRequestValidator {
/**
* Checks if the mandatory fields that are needed to send a tnvz:QueryPersonRequest are present.
* @param request
- * @return true if mandatory fields are present.
+ * @throws MoaZSException if a field is missing.
*/
- public boolean isTnvzComplete(DeliveryRequestType request) {
- return !request.getConfig().isPerformQueryPersonRequest() ||
- (request.getTnvzMetaData() != null
- && request.getSender().getCorporateBody() != null);
+ public void isTnvzComplete(DeliveryRequestType request) {
+ if (request.getConfig().isPerformQueryPersonRequest()) {
+
+ if (request.getMetaData().getOrigin() == null)
+ throw mzse(MZS_DELIVERY_REQUEST, MZS_DELIVERY_REQUEST + "/MetaData/Origin is missing.");
+
+ if (request.getMetaData().getDeliveryQuality() == null)
+ throw mzse(MZS_DELIVERY_REQUEST, MZS_DELIVERY_REQUEST + "/MetaData/DeliveryQuality missing.");
+
+ if (request.getSender().getCorporateBody() == null)
+ throw mzse(MZS_DELIVERY_REQUEST, MZS_DELIVERY_REQUEST + "/Sender/CorporateBody is missing.");
+ }
}
/**
* Check if all mandatory fields of configuration are present.
*
* @param profile
- * @return true if all mandatory fields are present.
+ * @throws MoaZSException if a field is missing.
*/
- public boolean isConfigProfileComplete(@Nullable ConfigType profile) {
- return profile != null
- && profile.isPerformQueryPersonRequest() != null
- && isTVNZClientConfigured(profile.getTNVZClient(), profile.isPerformQueryPersonRequest())
- && isClientConfigured(profile.getMSGClient())
- && areSinksConfigured(profile.getMsgResponseSinks());
+ public void isConfigProfileComplete(@Nullable ConfigType profile) {
+
+ if (profile == null)
+ throw mzse(MZS_DELIVERY_REQUEST + "/Config");
+
+ if (profile.isPerformQueryPersonRequest() == null)
+ throw mzse(MZS_DELIVERY_REQUEST + "/Config", "PerformQueryPersonRequest is missing.");
+
+ isTNVZClientConfigured(profile.getTNVZClient(), profile.isPerformQueryPersonRequest());
+ areSinksConfigured(profile.getMsgResponseSinks());
+
+ try {
+ isClientConfigured(profile.getMSGClient());
+ } catch (MoaZSException ex) {
+ throw mzse(MZS_MSGCLIENT, ex.getMessage());
+ }
+
}
- private boolean isTVNZClientConfigured(ClientType tnvzClient, Boolean isPerformQueryPersonRequest) {
- return !isPerformQueryPersonRequest || (tnvzClient != null
+ private void isTNVZClientConfigured(@Nullable ClientType tnvzClient, Boolean isPerformQueryPersonRequest) {
+ if (!isPerformQueryPersonRequest) return;
+
+ var isConfigured = tnvzClient != null
&& tnvzClient.getURL() != null
&& tnvzClient.getReceiveTimeout() != null
- && tnvzClient.getConnectionTimeout() != null
- && isSSLConfigured(tnvzClient));
+ && tnvzClient.getConnectionTimeout() != null;
+
+ if (!isConfigured) {
+ if(tnvzClient == null) throw mzse(MZS_TNVZCLIENT);
+
+ var reasons = new StringBuilder("The following elements in " + MZS_TNVZCLIENT + " are missing: ");
+ if(tnvzClient.getURL() == null) reasons.append("URL;");
+ if(tnvzClient.getReceiveTimeout() == null) reasons.append("ReceiveTimeout;");
+ if(tnvzClient.getConnectionTimeout() == null) reasons.append("ConnectionTimeout;");
+ throw mzse(MZS_TNVZCLIENT, reasons.toString());
+ }
+
+ try {
+ isSSLConfigured(tnvzClient);
+ } catch (MoaZSException ex) {
+ throw mzse(MZS_TNVZCLIENT, ex.getMessage());
+ }
}
- private boolean isClientConfigured(ClientType clientParams) {
- return clientParams != null
+ private void isClientConfigured(@Nullable ClientType clientParams) {
+ var isConfigured = clientParams != null
&& clientParams.getURL() != null
- && isSSLConfigured(clientParams)
&& clientParams.getReceiveTimeout() != null
&& clientParams.getConnectionTimeout() != null;
+
+ if (!isConfigured) throw mzse("Client");
+
+ isSSLConfigured(clientParams);
+
}
- 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 void isSSLConfigured(ClientType clientParams) {
+ if (!clientParams.getURL().startsWith("https")) return;
+
+ var isConfigured = (clientParams.getSSL() != null
+ && clientParams.getSSL().isTrustAll() != null
+ && clientParams.getSSL().isLaxHostNameVerification() != null);
+ if (!isConfigured) throw mzse("SSL");
+
+ try {
+ isKeyStoreConfigured(clientParams.getSSL().getKeyStore());
+ isTrustStoreConfigured(clientParams.getSSL().getTrustStore());
+ } catch (MoaZSException ex) {
+ throw mzse("SSL", ex.getMessage());
+ }
}
- private boolean isKeyStoreConfigured(KeyStoreType keyStore) {
- return keyStore == null || (keyStore.getPassword() != null
+ private void isKeyStoreConfigured(@Nullable KeyStoreType keyStore) {
+ if (keyStore == null) return;
+
+ var isConfigured = keyStore.getPassword() != null
&& keyStore.getFileType() != null
- && keyStore.getFileName() != null);
+ && keyStore.getFileName() != null;
+ if (!isConfigured) throw mzse("KeyStore");
}
- private boolean isTrustStoreConfigured(KeyStoreType trustStore) {
- return trustStore == null || (trustStore.getPassword() != null
+ private void isTrustStoreConfigured(@Nullable KeyStoreType trustStore) {
+ if (trustStore == null) return;
+
+ var isConfigured = trustStore.getPassword() != null
&& "JKS".equals(trustStore.getFileType())
- && trustStore.getFileName() != null);
+ && trustStore.getFileName() != null;
+ if (!isConfigured) throw mzse("TrustStore");
}
- private boolean areSinksConfigured(MsgResponseSinksType sinks) {
- return sinks != null
- && sinks.isLogResponse() != null
- && isSaveResponseToFileConfigured(sinks.getSaveResponseToFile())
- && isForwardResponseToServiceConfigured(sinks.getForwardResponseToService());
+ private void areSinksConfigured(@Nullable MsgResponseSinksType sinks) {
+ var isConfigured = sinks != null && sinks.isLogResponse() != null;
+ if (!isConfigured) throw mzse("MsgResponseSinks");
+
+ isSaveResponseToFileConfigured(sinks.getSaveResponseToFile());
+ isForwardResponseToServiceConfigured(sinks.getForwardResponseToService());
}
- private boolean isSaveResponseToFileConfigured(SaveResponseToFileType fileSink) {
- return fileSink != null
+ private void isSaveResponseToFileConfigured(@Nullable SaveResponseToFileType fileSink) {
+ var isConfigured = fileSink != null
&& (!fileSink.isActive() || fileSink.getPath() != null);
+
+ if (!isConfigured) throw mzse("SaveResponseToFile");
+ }
+
+ private void isForwardResponseToServiceConfigured(@Nullable ForwardResponseToServiceType forwardSink) {
+ if (forwardSink == null) throw mzse("ForwardResponseToService");
+
+ if (forwardSink.isActive()) {
+ try {
+ isClientConfigured(forwardSink.getMzsClient());
+ } catch (MoaZSException e) {
+ throw mzse("ForwardResponseToService", e.getMessage());
+ }
+ }
}
- private boolean isForwardResponseToServiceConfigured(ForwardResponseToServiceType forwardSink) {
- return forwardSink != null
- && (!forwardSink.isActive() || isClientConfigured(forwardSink.getMzsClient()));
+ private MoaZSException mzse(String missing) {
+ return moaZSException(format("%s is not configured.", missing));
}
+ private MoaZSException mzse(String missing, String reason) {
+ return moaZSException(format("%s is not configured. Reason: %s", missing, reason));
+ }
+
+
}