summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas <>2023-10-02 13:08:24 +0200
committerThomas <>2023-10-02 13:08:24 +0200
commit7dc56d353fcd5c76d9be3660bbdd2cb4a8b23f38 (patch)
tree64a55366956bb43f6bea22facc031e688de0ebde
parent44240b20f863fbd437e06947b539f76e73e91668 (diff)
downloadEAAF-Components-7dc56d353fcd5c76d9be3660bbdd2cb4a8b23f38.tar.gz
EAAF-Components-7dc56d353fcd5c76d9be3660bbdd2cb4a8b23f38.tar.bz2
EAAF-Components-7dc56d353fcd5c76d9be3660bbdd2cb4a8b23f38.zip
feat(core): add configuration utils to operate on specific types of configuration values
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ConfigurationUtils.java62
-rw-r--r--eaaf_core_utils/src/main/resources/messages/eaaf_utils_message.properties2
2 files changed, 64 insertions, 0 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ConfigurationUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ConfigurationUtils.java
new file mode 100644
index 00000000..2e6d53c9
--- /dev/null
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ConfigurationUtils.java
@@ -0,0 +1,62 @@
+package at.gv.egiz.eaaf.core.impl.utils;
+
+import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
+import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * Utils for configuration value mapping.
+ *
+ * @author tlenz
+ *
+ */
+@Slf4j
+public class ConfigurationUtils {
+
+
+ /**
+ * Parse Integer value from configuration.
+ *
+ * @param basicConfig Configuration object
+ * @param propertyKey Configuration key
+ * @return Configuration value
+ * @throws EaafConfigurationException If configuration value is not an Integer
+ */
+ public static int parseInteger(IConfiguration basicConfig, String propertyKey)
+ throws EaafConfigurationException {
+ try {
+ return Integer.parseInt(basicConfig.getBasicConfiguration(propertyKey));
+
+ } catch (NumberFormatException e) {
+ log.error("Can not read Integer value from configuration: {}", propertyKey, e);
+ throw new EaafConfigurationException("internal.configuration.02",
+ new Object[] { propertyKey, Integer.class.getSimpleName() }, e);
+
+ }
+ }
+
+ /**
+ * Parse Long value from configuration.
+ *
+ * @param basicConfig Configuration object
+ * @param propertyKey Configuration key
+ * @return Configuration value
+ * @throws EaafConfigurationException If configuration value is not an Long
+ */
+ public static long parseLong(IConfiguration basicConfig, String propertyKey)
+ throws EaafConfigurationException {
+ try {
+ return Long.parseLong(basicConfig.getBasicConfiguration(propertyKey));
+
+ } catch (NumberFormatException e) {
+ log.error("Can not read Long value from configuration: {}", propertyKey, e);
+ throw new EaafConfigurationException("internal.configuration.02",
+ new Object[] { propertyKey, Long.class.getSimpleName() }, e);
+
+ }
+ }
+
+ private ConfigurationUtils() {
+
+ }
+}
diff --git a/eaaf_core_utils/src/main/resources/messages/eaaf_utils_message.properties b/eaaf_core_utils/src/main/resources/messages/eaaf_utils_message.properties
index 2cc4e22e..6c29a57c 100644
--- a/eaaf_core_utils/src/main/resources/messages/eaaf_utils_message.properties
+++ b/eaaf_core_utils/src/main/resources/messages/eaaf_utils_message.properties
@@ -1,5 +1,7 @@
internal.configuration.00=Wrong configuration. Missing property: {0}
internal.configuration.01=Wrong configuration property: {0}. Reason: {1}
+internal.configuration.02=Wrong configuration property: {0}. Reason: Invalid {1} value
+
internal.keystore.00=HSM-Facade NOT INITIALIZED. KeyStore:{0} initialization failed
internal.keystore.01=KeyStore:{0} configuration has an unsupported type in configuration.