diff options
author | Thomas <> | 2023-10-02 13:08:24 +0200 |
---|---|---|
committer | Thomas <> | 2024-02-01 07:42:44 +0100 |
commit | b6a931c21927675491af40bc32cebfa5d432124e (patch) | |
tree | 0bfe7c0599c5e7ebfe755d84b429f973eb2e3fdf /eaaf_core_utils/src | |
parent | 7bb4a6638ab04a19172dc303d1d6b387fa064aa0 (diff) | |
download | EAAF-Components-b6a931c21927675491af40bc32cebfa5d432124e.tar.gz EAAF-Components-b6a931c21927675491af40bc32cebfa5d432124e.tar.bz2 EAAF-Components-b6a931c21927675491af40bc32cebfa5d432124e.zip |
feat(core): add configuration utils to operate on specific types of configuration values
Diffstat (limited to 'eaaf_core_utils/src')
-rw-r--r-- | eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ConfigurationUtils.java | 62 | ||||
-rw-r--r-- | eaaf_core_utils/src/main/resources/messages/eaaf_utils_message.properties | 2 |
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. |