diff options
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java | 54 |
1 files changed, 32 insertions, 22 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 cba776d..a0cf766 100644 --- a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java +++ b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java @@ -13,22 +13,28 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.StreamSupport; import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder; import static at.gv.zustellung.app2mzs.xsd.ServerType.serverTypeBuilder; +import static java.util.stream.Collectors.*; import static java.util.stream.Collectors.toMap; @Component public class ConfigProfileGenerator { - @Autowired - private Environment env; + private static final String PROFILE_PREFIX = "delivery-request-configuration-profiles."; + private static final String TNVZ_REQUEST_KEY = "perform-query-person-request"; + private static final String MSG_URL_KEY = "msg.url"; - private final String profilePrefix = "delivery-request-configuration-profiles."; - private final String tnvzRequestKey = "perform-query-person-request"; - private final String msgUrlKey = "msg.url"; + private final Environment env; + private final ConfigProfileMerger merger; + + @Autowired + public ConfigProfileGenerator(Environment env, ConfigProfileMerger merger) { + this.env = env; + this.merger = merger; + } public Map<String, ConfigType> generate() { MutablePropertySources propSrcs = ((AbstractEnvironment) env).getPropertySources(); @@ -37,25 +43,29 @@ public class ConfigProfileGenerator { .filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()) .flatMap(Arrays::stream) - .filter(propName -> propName.startsWith(profilePrefix)) - .map(name -> name.substring(name.indexOf(".") + 1)) - .collect( - Collectors.groupingBy( - this::keepPrefix, - Collectors.mapping( - this::removePrefix, - Collectors.toSet()))); - - return groupedKeys.entrySet().stream() + .filter(this::isConfigurationProfileProperty) + .map(this::removePrefix) + .collect(groupingBy(this::keepPrefix, mapping(this::removePrefix, toSet()))); + + Map<String, ConfigType> profiles = groupedKeys.entrySet().stream() .collect(toMap(Entry::getKey, this::createConfig)); + + var defaultProfile = profiles.get("default"); + + return profiles.entrySet().stream() + .collect(toUnmodifiableMap(Entry::getKey, e -> merger.merge(e.getValue(), defaultProfile))); + } + + private boolean isConfigurationProfileProperty(String propName) { + return propName.startsWith(PROFILE_PREFIX); } private String keepPrefix(String name) { - return name.substring(0, name.indexOf(".")); + return name.substring(0, name.indexOf('.')); } private String removePrefix(String name) { - return name.substring(name.indexOf(".") + 1); + return name.substring(name.indexOf('.') + 1); } private ConfigType createConfig(Entry<String, Set<String>> entry) { @@ -66,17 +76,17 @@ public class ConfigProfileGenerator { entry.getValue().stream() .forEach(key -> { - var assembledKey = profilePrefix + "." + profile + "." + key; + var assembledKey = PROFILE_PREFIX + '.' + profile + '.' + key; var value = env.getProperty(assembledKey); values.put(key, value); }); var server = serverTypeBuilder() - .withZUSEUrlID(values.get(msgUrlKey)) + .withZUSEUrlID(values.get(MSG_URL_KEY)) .build(); - Boolean performQueryPersonRequest = values.get(tnvzRequestKey) == null - ? null : Boolean.getBoolean(values.get(tnvzRequestKey)); + Boolean performQueryPersonRequest = values.get(TNVZ_REQUEST_KEY) == null + ? null : Boolean.getBoolean(values.get(TNVZ_REQUEST_KEY)); return configTypeBuilder() .withPerformQueryPersonRequest(performQueryPersonRequest) |