aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz')
-rw-r--r--src/main/java/at/gv/egiz/moazs/config/PreprocessConfig.java8
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java41
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileMerger.java46
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileValidator.java17
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java95
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java15
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/MapToConfigConverter.java29
7 files changed, 114 insertions, 137 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 ce40691..d1295b1 100644
--- a/src/main/java/at/gv/egiz/moazs/config/PreprocessConfig.java
+++ b/src/main/java/at/gv/egiz/moazs/config/PreprocessConfig.java
@@ -27,15 +27,11 @@ public class PreprocessConfig {
@Autowired
public ConfigProfileGenerator configProfileGenerator(
SpringPropertiesFacade properties,
- MapToConfigConverter converter,
- ConfigProfileValidator validator,
- ConfigProfileMerger merger) {
+ ConfigUtil util) {
return configProfileGeneratorBuilder()
.withProperties(properties)
- .withConverter(converter)
- .withValidator(validator)
- .withMerger(merger)
+ .withConfigUtil(util)
.withVerifyCompletenessOfDefaultConfiguration(verifyCompletenessOfDefaultConfiguration)
.build();
}
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 0b4bc19..6337ff2 100644
--- a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java
+++ b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java
@@ -28,9 +28,7 @@ public class ConfigProfileGenerator {
"availability.";
private final SpringPropertiesFacade properties;
- private final MapToConfigConverter converter;
- private final ConfigProfileValidator validator;
- private final ConfigProfileMerger merger;
+ private final ConfigUtil util;
private final boolean verifyCompletenessOfDefaultConfiguration;
private final String profilePrefix;
private final String defaultConfigKey;
@@ -41,16 +39,12 @@ public class ConfigProfileGenerator {
private ConfigProfileGenerator(
SpringPropertiesFacade properties,
- MapToConfigConverter converter,
- ConfigProfileValidator validator,
- ConfigProfileMerger merger,
+ ConfigUtil util,
boolean verifyCompletenessOfDefaultConfiguration,
String profilePrefix,
String defaultConfigKey) {
- this.merger = merger;
- this.validator = validator;
+ this.util = util;
this.properties = properties;
- this.converter = converter;
this.verifyCompletenessOfDefaultConfiguration = verifyCompletenessOfDefaultConfiguration;
this.profilePrefix = profilePrefix;
this.defaultConfigKey = defaultConfigKey;
@@ -70,7 +64,7 @@ public class ConfigProfileGenerator {
var defaultProfile = profiles.get(defaultConfigKey);
- if (!validator.isComplete(defaultProfile)) {
+ if (!util.isComplete(defaultProfile)) {
if (verifyCompletenessOfDefaultConfiguration)
throw MoaZSException.moaZSException(PROFILE_NOT_COMPLETE_ERROR_MESSAGE);
else {
@@ -110,7 +104,7 @@ public class ConfigProfileGenerator {
values.put(key, value);
});
- return converter.convert(values);
+ return util.convert(values);
}
@@ -118,36 +112,23 @@ public class ConfigProfileGenerator {
return profiles.entrySet().stream()
.collect(toUnmodifiableMap(
Entry::getKey,
- e -> merger.merge(e.getValue(), defaultProfile)));
+ e -> util.merge(e.getValue(), defaultProfile)));
}
public static class ConfigProfileGeneratorBuilder {
private SpringPropertiesFacade properties;
- private MapToConfigConverter converter;
- private ConfigProfileValidator validator;
- private ConfigProfileMerger merger;
+ private ConfigUtil util;
private boolean verifyCompletenessOfDefaultConfiguration = true;
private String profilePrefix = "delivery-request-configuration-profiles";
private String defaultConfigKey = "default";
-
public ConfigProfileGeneratorBuilder withProperties(SpringPropertiesFacade properties) {
this.properties = properties;
return this;
}
- public ConfigProfileGeneratorBuilder withConverter(MapToConfigConverter converter) {
- this.converter = converter;
- return this;
- }
-
- public ConfigProfileGeneratorBuilder withValidator(ConfigProfileValidator validator) {
- this.validator = validator;
- return this;
- }
-
- public ConfigProfileGeneratorBuilder withMerger(ConfigProfileMerger merger) {
- this.merger = merger;
+ public ConfigProfileGeneratorBuilder withConfigUtil(ConfigUtil util) {
+ this.util = util;
return this;
}
@@ -167,9 +148,9 @@ public class ConfigProfileGenerator {
}
public ConfigProfileGenerator build() {
- if(properties == null || converter == null || validator == null || merger == null || profilePrefix == null || defaultConfigKey == null)
+ if(properties == null || util == null || profilePrefix == null || defaultConfigKey == null)
throw new IllegalArgumentException("Cannot build ConfigProfileGenerator: One or more arguments are null.");
- return new ConfigProfileGenerator(properties, converter, validator, merger, verifyCompletenessOfDefaultConfiguration, profilePrefix, defaultConfigKey);
+ return new ConfigProfileGenerator(properties, util, verifyCompletenessOfDefaultConfiguration, profilePrefix, defaultConfigKey);
}
}
}
diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileMerger.java b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileMerger.java
deleted file mode 100644
index c94723e..0000000
--- a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileMerger.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package at.gv.egiz.moazs.preprocess;
-
-import at.gv.zustellung.app2mzs.xsd.ConfigType;
-import at.gv.zustellung.app2mzs.xsd.ServerType;
-import org.springframework.stereotype.Component;
-
-import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder;
-import static at.gv.zustellung.app2mzs.xsd.ServerType.serverTypeBuilder;
-
-@Component
-public class ConfigProfileMerger {
-
- public ConfigType merge(ConfigType primary, ConfigType fallback) {
-
- var builder = configTypeBuilder(fallback);
-
- if(primary != null) {
-
- if(primary.getServer() != null) {
- builder.withServer(merge(primary.getServer(), fallback.getServer()));
- }
-
- if(primary.isPerformQueryPersonRequest() != null) {
- builder.withPerformQueryPersonRequest(primary.isPerformQueryPersonRequest());
- }
-
- }
-
- return builder.build();
-
- }
-
- private ServerType merge(ServerType primary, ServerType fallback) {
-
- if (fallback == null) {
- return primary;
- }
-
- var builder = serverTypeBuilder(fallback);
-
- if (primary.getX509() != null) builder.withX509 (primary.getX509() );
- if (primary.getZUSEUrlID() != null) builder.withZUSEUrlID(primary.getZUSEUrlID());
-
- return builder.build();
- }
-}
diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileValidator.java b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileValidator.java
deleted file mode 100644
index 08d8aea..0000000
--- a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileValidator.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package at.gv.egiz.moazs.preprocess;
-
-import at.gv.zustellung.app2mzs.xsd.ConfigType;
-import org.springframework.stereotype.Component;
-
-@Component
-public class ConfigProfileValidator {
-
- public boolean isComplete(ConfigType profile) {
- //TODO: add check fo x509 certificate
- return profile != null
- && profile.isPerformQueryPersonRequest() != null
- && profile.getServer() != null
- && profile.getServer().getZUSEUrlID() != null;
- }
-
-}
diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java
new file mode 100644
index 0000000..736fb0a
--- /dev/null
+++ b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java
@@ -0,0 +1,95 @@
+package at.gv.egiz.moazs.preprocess;
+
+import at.gv.zustellung.app2mzs.xsd.ConfigType;
+import at.gv.zustellung.app2mzs.xsd.ServerType;
+import org.springframework.lang.Nullable;
+import org.springframework.stereotype.Component;
+
+import javax.validation.constraints.Null;
+import java.util.Map;
+
+import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder;
+import static at.gv.zustellung.app2mzs.xsd.ServerType.serverTypeBuilder;
+
+@Component
+public class ConfigUtil {
+
+ private static final String TNVZ_REQUEST_KEY = "perform-query-person-request";
+ private static final String MSG_URL_KEY = "msg.url";
+
+ /**
+ * Builds a ConvertType Object out of a Map on the Basis of it's Keys and Values.
+ *
+ * @param Map with keys and values.
+ * @return ConvertType Object
+ */
+ public ConfigType convert(Map<String, String> values) {
+ var server = serverTypeBuilder()
+ .withZUSEUrlID(values.get(MSG_URL_KEY))
+ .build();
+
+ Boolean performQueryPersonRequest = values.get(TNVZ_REQUEST_KEY) == null
+ ? null : Boolean.getBoolean(values.get(TNVZ_REQUEST_KEY));
+
+ return ConfigType.configTypeBuilder()
+ .withPerformQueryPersonRequest(performQueryPersonRequest)
+ .withServer(server)
+ .build();
+ }
+
+ /**
+ * Combines Properties of Two ConfigType Objects; {@code primary} overrides {@code fallback}.
+ *
+ * @param primary
+ * @param fallback
+ * @return Combined ConfigType
+ */
+ public ConfigType merge(@Nullable ConfigType primary, ConfigType fallback) {
+
+ var builder = configTypeBuilder(fallback);
+
+ if(primary != null) {
+
+ if(primary.getServer() != null) {
+ builder.withServer(merge(primary.getServer(), fallback.getServer()));
+ }
+
+ if(primary.isPerformQueryPersonRequest() != null) {
+ builder.withPerformQueryPersonRequest(primary.isPerformQueryPersonRequest());
+ }
+
+ }
+
+ return builder.build();
+
+ }
+
+ private ServerType merge(ServerType primary, ServerType fallback) {
+
+ if (fallback == null) {
+ return primary;
+ }
+
+ var builder = serverTypeBuilder(fallback);
+
+ if (primary.getX509() != null) builder.withX509 (primary.getX509() );
+ if (primary.getZUSEUrlID() != null) builder.withZUSEUrlID(primary.getZUSEUrlID());
+
+ return builder.build();
+ }
+
+ /**
+ *
+ *
+ * @param profile
+ * @return
+ */
+ public boolean isComplete(@Nullable ConfigType profile) {
+ //TODO: add check fo x509 certificate
+ return profile != null
+ && profile.isPerformQueryPersonRequest() != null
+ && profile.getServer() != null
+ && profile.getServer().getZUSEUrlID() != 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 0b49347..f3a05d1 100644
--- a/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java
+++ b/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java
@@ -13,9 +13,8 @@ import static at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.deliveryRequestTy
@Component
public class DeliveryRequestAugmenter {
- private final ConfigProfileMerger merger;
+ private final ConfigUtil util;
private final Map<String, ConfigType> configs;
- private final ConfigProfileValidator validator;
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.";
@@ -24,11 +23,9 @@ public class DeliveryRequestAugmenter {
"configuration is incomplete.";
@Autowired
- public DeliveryRequestAugmenter(Map<String, ConfigType> deliveryRequestConfigs, ConfigProfileMerger merger,
- ConfigProfileValidator validator) {
+ public DeliveryRequestAugmenter(Map<String, ConfigType> deliveryRequestConfigs, ConfigUtil util) {
this.configs = deliveryRequestConfigs;
- this.merger = merger;
- this.validator = validator;
+ this.util = util;
}
/**
@@ -45,16 +42,16 @@ public class DeliveryRequestAugmenter {
if (fallbackConfig == null) {
- if (validator.isComplete(requestConfig))
+ if (util.isComplete(requestConfig))
return request;
else
throw moaZSException(INCOMPLETE_CONFIG_ERROR_MESSAGE);
} else {
- var mergedConfig = merger.merge(requestConfig, fallbackConfig);
+ var mergedConfig = util.merge(requestConfig, fallbackConfig);
- if (validator.isComplete(mergedConfig)) {
+ if (util.isComplete(mergedConfig)) {
return deliveryRequestTypeBuilder(request)
.withConfig(mergedConfig)
.build();
diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/MapToConfigConverter.java b/src/main/java/at/gv/egiz/moazs/preprocess/MapToConfigConverter.java
deleted file mode 100644
index ef7cff1..0000000
--- a/src/main/java/at/gv/egiz/moazs/preprocess/MapToConfigConverter.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package at.gv.egiz.moazs.preprocess;
-
-import at.gv.zustellung.app2mzs.xsd.ConfigType;
-import org.springframework.stereotype.Component;
-
-import java.util.Map;
-
-import static at.gv.zustellung.app2mzs.xsd.ServerType.serverTypeBuilder;
-
-@Component
-public class MapToConfigConverter {
-
- private static final String TNVZ_REQUEST_KEY = "perform-query-person-request";
- private static final String MSG_URL_KEY = "msg.url";
-
- public ConfigType convert(Map<String, String> values) {
- var server = serverTypeBuilder()
- .withZUSEUrlID(values.get(MSG_URL_KEY))
- .build();
-
- Boolean performQueryPersonRequest = values.get(TNVZ_REQUEST_KEY) == null
- ? null : Boolean.getBoolean(values.get(TNVZ_REQUEST_KEY));
-
- return ConfigType.configTypeBuilder()
- .withPerformQueryPersonRequest(performQueryPersonRequest)
- .withServer(server)
- .build();
- }
-}