From 364c37a0d2820ce9984d6944aa1d95fc5fbdce21 Mon Sep 17 00:00:00 2001 From: Hylke van der Schaaf Date: Wed, 10 Jan 2024 14:01:00 +0100 Subject: [PATCH] Fixed _. translation issue when loading settings for MQTT --- .../ilt/frostserver/settings/Settings.java | 4 ++-- .../settings/SettingsMigrator.java | 20 ++++++++++++++++++- .../mqtt/moquette/ConfigWrapper.java | 10 +++++----- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/settings/Settings.java b/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/settings/Settings.java index 21bd01132..29b91a073 100644 --- a/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/settings/Settings.java +++ b/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/settings/Settings.java @@ -44,7 +44,7 @@ private static Properties addEnvironment(Properties wrapped) { Properties wrapper = new Properties(wrapped); for (Map.Entry entry : environment.entrySet()) { - String key = entry.getKey().replace("_", "."); + String key = entry.getKey().replace('_', '.'); LOGGER.debug("Added environment variable: {}", key); wrapper.setProperty(key, entry.getValue()); } @@ -141,7 +141,7 @@ public void setLogSensitiveData(boolean logSensitiveData) { * @return prefix + propertyName */ private String getPropertyKey(String propertyName) { - return prefix + propertyName.replace("_", "."); + return prefix + propertyName.replace('_', '.'); } /** diff --git a/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/settings/SettingsMigrator.java b/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/settings/SettingsMigrator.java index 35b9de3b0..71440f3a5 100644 --- a/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/settings/SettingsMigrator.java +++ b/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/settings/SettingsMigrator.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Properties; import java.util.TreeMap; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,6 +40,7 @@ public class SettingsMigrator { private final Map> valueChanges = new HashMap<>(); private final Map keyChanges = new HashMap<>(); + private final Map valueCheckers = new HashMap<>(); private Map getReplaceValue(String key) { return valueChanges.computeIfAbsent(key, t -> new TreeMap<>()); @@ -77,6 +79,18 @@ public void migrateOldSettings(Properties properties) { for (Map.Entry> change : valueChanges.entrySet()) { migrateOldSettings(properties, change.getKey(), change.getValue()); } + for (Map.Entry checkEntry : valueCheckers.entrySet()) { + String key = checkEntry.getKey(); + ValueChecker checker = checkEntry.getValue(); + String valueOld = properties.getProperty(key); + if (valueOld != null) { + String valueNew = checker.getNewValue(valueOld); + if (!valueOld.equals(valueNew)) { + LOGGER.warn("Converting setting with key: {} from old value: {} to new value: {}", key, valueOld, valueNew); + properties.setProperty(key, valueNew); + } + } + } } private void migrateOldSettings(Properties properties, String key, Map replaces) { @@ -98,7 +112,7 @@ private void migrateOldSettings(Properties properties, String key, Map