From aff7c021e37e64162ce4e3fe5abd419072fb464f Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Thu, 16 May 2019 14:26:03 +0200 Subject: Refactor + Document in preprocess - Refactor: Move ConfigType.merge's null check to caller. - Revise documentation of preprocess' public methods. --- .../moazs/preprocess/ConfigProfileGenerator.java | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java') 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 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); } } } -- cgit v1.2.3