aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-05-15 06:41:15 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-05-15 06:41:15 +0200
commite70ec39488c0688d8144fa529d58d60ae9564fbd (patch)
tree07ef8e905d56b5ab2142f7a787d98317debcb38d /src/main/java/at/gv
parent1c252d7fc336831188c628ecdd39cd1b84b0cada (diff)
downloadmoa-zs-e70ec39488c0688d8144fa529d58d60ae9564fbd.tar.gz
moa-zs-e70ec39488c0688d8144fa529d58d60ae9564fbd.tar.bz2
moa-zs-e70ec39488c0688d8144fa529d58d60ae9564fbd.zip
WIP: Generate Map of Config Profiles from Spring Environment
Augmenter - Replace default Config Profile with map of Config Profiles. Now, Augmenter can choose a config profile at runtime and augment it. - Move Augmenter to sub package. WIP - Implement ConfigProfileGenerator, which retrieves Config profiles from Spring Environment and returns an easy-to-use map with profiles that is keyed with profile id's. - Replace application.properties with application.yaml. - Remove Augmenter test cases: They need to be adapted.
Diffstat (limited to 'src/main/java/at/gv')
-rw-r--r--src/main/java/at/gv/egiz/moazs/App2MzsService.java1
-rw-r--r--src/main/java/at/gv/egiz/moazs/config/DeliveryRequestAugmenterConfig.java25
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java87
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java (renamed from src/main/java/at/gv/egiz/moazs/DeliveryRequestAugmenter.java)11
4 files changed, 101 insertions, 23 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/App2MzsService.java b/src/main/java/at/gv/egiz/moazs/App2MzsService.java
index 622f1dc..19eb856 100644
--- a/src/main/java/at/gv/egiz/moazs/App2MzsService.java
+++ b/src/main/java/at/gv/egiz/moazs/App2MzsService.java
@@ -1,6 +1,7 @@
package at.gv.egiz.moazs;
import at.gv.egiz.moazs.pipeline.DeliveryPipeline;
+import at.gv.egiz.moazs.preprocess.DeliveryRequestAugmenter;
import at.gv.egiz.moazs.repository.DeliveryRepository;
import at.gv.zustellung.app2mzs.xsd.App2MzsPortType;
import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
diff --git a/src/main/java/at/gv/egiz/moazs/config/DeliveryRequestAugmenterConfig.java b/src/main/java/at/gv/egiz/moazs/config/DeliveryRequestAugmenterConfig.java
index 93615c4..d5b52c5 100644
--- a/src/main/java/at/gv/egiz/moazs/config/DeliveryRequestAugmenterConfig.java
+++ b/src/main/java/at/gv/egiz/moazs/config/DeliveryRequestAugmenterConfig.java
@@ -1,31 +1,20 @@
package at.gv.egiz.moazs.config;
+import at.gv.egiz.moazs.preprocess.ConfigProfileGenerator;
import at.gv.zustellung.app2mzs.xsd.ConfigType;
-import org.springframework.beans.factory.annotation.Value;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder;
-import static at.gv.zustellung.app2mzs.xsd.ServerType.serverTypeBuilder;
+import java.util.Map;
@Configuration
public class DeliveryRequestAugmenterConfig {
-
- @Value("${msg.default.url}")
- private String zuseUrlID;
-
@Bean
- public ConfigType defaultMzsConfig() {
-
- var server = serverTypeBuilder()
- .withZUSEUrlID(zuseUrlID)
- .withX509(null) //todo load cert!
- .build();
-
- return configTypeBuilder()
- .withPerformQueryPersonRequest(false)
- .withServer(server)
- .build();
+ @Autowired
+ Map<String, ConfigType> deliveryRequestConfigs(ConfigProfileGenerator generator) {
+ return generator.generate();
}
+
}
diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java
new file mode 100644
index 0000000..cba776d
--- /dev/null
+++ b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java
@@ -0,0 +1,87 @@
+package at.gv.egiz.moazs.preprocess;
+
+import at.gv.zustellung.app2mzs.xsd.ConfigType;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.AbstractEnvironment;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.core.env.MutablePropertySources;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+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.toMap;
+
+@Component
+public class ConfigProfileGenerator {
+
+ @Autowired
+ private Environment env;
+
+ private final String profilePrefix = "delivery-request-configuration-profiles.";
+ private final String tnvzRequestKey = "perform-query-person-request";
+ private final String msgUrlKey = "msg.url";
+
+ public Map<String, ConfigType> generate() {
+ MutablePropertySources propSrcs = ((AbstractEnvironment) env).getPropertySources();
+
+ Map<String, Set<String>> groupedKeys = StreamSupport.stream(propSrcs.spliterator(), false)
+ .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()
+ .collect(toMap(Entry::getKey, this::createConfig));
+ }
+
+ private String keepPrefix(String name) {
+ return name.substring(0, name.indexOf("."));
+ }
+
+ private String removePrefix(String name) {
+ return name.substring(name.indexOf(".") + 1);
+ }
+
+ private ConfigType createConfig(Entry<String, Set<String>> entry) {
+
+ var profile = entry.getKey();
+
+ var values = new HashMap<String,String>();
+
+ entry.getValue().stream()
+ .forEach(key -> {
+ var assembledKey = profilePrefix + "." + profile + "." + key;
+ var value = env.getProperty(assembledKey);
+ values.put(key, value);
+ });
+
+ var server = serverTypeBuilder()
+ .withZUSEUrlID(values.get(msgUrlKey))
+ .build();
+
+ Boolean performQueryPersonRequest = values.get(tnvzRequestKey) == null
+ ? null : Boolean.getBoolean(values.get(tnvzRequestKey));
+
+ return configTypeBuilder()
+ .withPerformQueryPersonRequest(performQueryPersonRequest)
+ .withServer(server)
+ .build();
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/moazs/DeliveryRequestAugmenter.java b/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java
index 96197d0..623af38 100644
--- a/src/main/java/at/gv/egiz/moazs/DeliveryRequestAugmenter.java
+++ b/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java
@@ -1,4 +1,4 @@
-package at.gv.egiz.moazs;
+package at.gv.egiz.moazs.preprocess;
import at.gv.zustellung.app2mzs.xsd.ConfigType;
import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
@@ -7,9 +7,10 @@ import at.gv.zustellung.app2mzs.xsd.ServerType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import static at.gv.egiz.moazs.util.NullCoalesce.coalesce;
+import java.util.Map;
+
import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder;
-import static at.gv.zustellung.app2mzs.xsd.ServerType.*;
+import static at.gv.zustellung.app2mzs.xsd.ServerType.serverTypeBuilder;
@Component
public class DeliveryRequestAugmenter {
@@ -17,8 +18,8 @@ public class DeliveryRequestAugmenter {
private final ConfigType defaultMzsConfig;
@Autowired
- public DeliveryRequestAugmenter(ConfigType defaultMzsConfig) {
- this.defaultMzsConfig = defaultMzsConfig;
+ public DeliveryRequestAugmenter(Map<String, ConfigType> deliveryRequestConfigs) {
+ this.defaultMzsConfig = deliveryRequestConfigs.get("default");
}
/**