aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-05-16 14:26:03 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-05-16 14:26:03 +0200
commitaff7c021e37e64162ce4e3fe5abd419072fb464f (patch)
treefdf3b0b7f609e6c9c42f436dda298095c7d2a5cb /src/main/java/at/gv
parentf18a151a98482093118f3b728c514b918afda8c5 (diff)
downloadmoa-zs-aff7c021e37e64162ce4e3fe5abd419072fb464f.tar.gz
moa-zs-aff7c021e37e64162ce4e3fe5abd419072fb464f.tar.bz2
moa-zs-aff7c021e37e64162ce4e3fe5abd419072fb464f.zip
Refactor + Document in preprocess
- Refactor: Move ConfigType.merge's null check to caller. - Revise documentation of preprocess' public methods.
Diffstat (limited to 'src/main/java/at/gv')
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java23
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java31
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java4
3 files changed, 30 insertions, 28 deletions
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 6337ff2..be14852 100644
--- a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java
+++ b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java
@@ -16,7 +16,6 @@ public class ConfigProfileGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigProfileGenerator.class);
-
private static final String PROFILE_NOT_COMPLETE_WARNING_MESSAGE = "The default values for a incoming " +
"mzs:DeliveryRequest/Config element could not be extracted from configuration because some values were " +
"missing.";
@@ -50,7 +49,11 @@ public class ConfigProfileGenerator {
this.defaultConfigKey = defaultConfigKey;
}
-
+ /**
+ * Generate a map of Config profiles on the basis of supplied properties.
+ *
+ * @return map with profiles, indexed by ProfileId
+ */
public Map<String, ConfigType> generate() {
var groupedKeys = properties.getPropertyNames()
@@ -60,7 +63,7 @@ public class ConfigProfileGenerator {
.collect(groupingBy(this::keepPrefix, mapping(this::removePrefix, toSet())));
var profiles = groupedKeys.entrySet().stream()
- .collect(toMap(Entry::getKey, this::createConfigFromEnv));
+ .collect(toUnmodifiableMap(Entry::getKey, this::createConfigFromEnv));
var defaultProfile = profiles.get(defaultConfigKey);
@@ -118,7 +121,7 @@ public class ConfigProfileGenerator {
public static class ConfigProfileGeneratorBuilder {
private SpringPropertiesFacade properties;
private ConfigUtil util;
- private boolean verifyCompletenessOfDefaultConfiguration = true;
+ private boolean verify = true;
private String profilePrefix = "delivery-request-configuration-profiles";
private String defaultConfigKey = "default";
@@ -132,8 +135,9 @@ public class ConfigProfileGenerator {
return this;
}
- public ConfigProfileGeneratorBuilder withVerifyCompletenessOfDefaultConfiguration(boolean verifyCompletenessOfDefaultConfiguration) {
- this.verifyCompletenessOfDefaultConfiguration = verifyCompletenessOfDefaultConfiguration;
+ public ConfigProfileGeneratorBuilder withVerifyCompletenessOfDefaultConfiguration(
+ boolean verify) {
+ this.verify = verify;
return this;
}
@@ -148,9 +152,10 @@ public class ConfigProfileGenerator {
}
public ConfigProfileGenerator build() {
- 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, util, verifyCompletenessOfDefaultConfiguration, profilePrefix, defaultConfigKey);
+ 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, util, 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 79666a4..3fef4bd 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.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;
@@ -18,10 +17,10 @@ public class ConfigUtil {
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.
+ * Convert a map into a Config object.
*
- * @param Map with keys and values.
- * @return ConvertType Object
+ * @param map with well-defined indexes and values
+ * @return Config
*/
public ConfigType convert(Map<String, String> values) {
var server = serverTypeBuilder()
@@ -38,26 +37,22 @@ public class ConfigUtil {
}
/**
- * Combines Properties of Two ConfigType Objects; {@code primary} overrides {@code fallback}.
+ * Combine properties of two Configs; {@code primary} overrides {@code fallback}.
*
* @param primary
* @param fallback
- * @return Combined ConfigType
+ * @return Merged Config
*/
- public ConfigType merge(@Nullable ConfigType primary, ConfigType fallback) {
+ 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());
- }
+ if(primary.getServer() != null) {
+ builder.withServer(merge(primary.getServer(), fallback.getServer()));
+ }
+ if(primary.isPerformQueryPersonRequest() != null) {
+ builder.withPerformQueryPersonRequest(primary.isPerformQueryPersonRequest());
}
return builder.build();
@@ -79,10 +74,10 @@ public class ConfigUtil {
}
/**
- * Checks if all mandatory fields are set.
+ * Check if all mandatory fields are set.
*
* @param profile
- * @return
+ * @return true if all mandatory fields are set
*/
public boolean isComplete(@Nullable ConfigType profile) {
//TODO: add check fo x509 certificate
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 f3a05d1..057c3d4 100644
--- a/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java
+++ b/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java
@@ -49,7 +49,9 @@ public class DeliveryRequestAugmenter {
} else {
- var mergedConfig = util.merge(requestConfig, fallbackConfig);
+ var mergedConfig = (requestConfig == null)
+ ? fallbackConfig
+ : util.merge(requestConfig, fallbackConfig);
if (util.isComplete(mergedConfig)) {
return deliveryRequestTypeBuilder(request)