From 1497329cd8995d0556092e57c3f0adfcac8d47a1 Mon Sep 17 00:00:00 2001 From: ChrisRousey <104754971+ChrisRousey@users.noreply.github.com> Date: Thu, 23 Mar 2023 13:29:37 +0100 Subject: [PATCH] feat(configs): add extra checks to depth config mapping refs: #181 --- .../core/utilities/JsonUtilities.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/platform-api/src/main/java/io/datacater/core/utilities/JsonUtilities.java b/platform-api/src/main/java/io/datacater/core/utilities/JsonUtilities.java index 4f151edf..4f5e5987 100644 --- a/platform-api/src/main/java/io/datacater/core/utilities/JsonUtilities.java +++ b/platform-api/src/main/java/io/datacater/core/utilities/JsonUtilities.java @@ -70,15 +70,16 @@ public static Map toObjectMap(JsonNode json) { * the `.putAll()` method would overwrite some keys. To avoid this, this method was implemented. * It takes a map, `prio2`, and overwrites the values/adds the keys from another map, `prio1` * - * @param prio2 map with the lowest priority - * @param prio1 map with the highest priority. Values from this map overwrite values from prio2 + * @param lower_priority_map map with the lowest priority + * @param higher_priority_map map with the highest priority. Values from this map overwrite values + * from prio2 * @return a combined map */ public static Map combineMaps( - Map prio2, Map prio1) { - Map result = new HashMap<>(prio2); + Map lower_priority_map, Map higher_priority_map) { + Map result = new HashMap<>(lower_priority_map); // loop over prio1 map to replace values - for (Map.Entry entry : prio1.entrySet()) { + for (Map.Entry entry : higher_priority_map.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (result.containsKey(key)) { @@ -89,12 +90,18 @@ public static Map combineMaps( result.put( key, combineMaps((Map) value, (Map) existingValue)); } else { - // if it is now a map, overwrite the value - result.put(key, value); + // do not overwrite value if it is empty + if (value != "") { + // if it is now a map, overwrite the value + result.put(key, value); + } } } else { - // add the value if it doesn't exist - result.put(key, value); + // do not add value if it is empty + if (value != "") { + // add the value if it doesn't exist + result.put(key, value); + } } } return result;