aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java')
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java95
1 files changed, 95 insertions, 0 deletions
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;
+ }
+
+}