From cd466480a88dfd487296d6d0dc7377dd1c2f92a1 Mon Sep 17 00:00:00 2001 From: sgallou Date: Thu, 5 Sep 2024 18:40:13 +0200 Subject: [PATCH] Refactor plugin config/schema merge --- .../service/PluginConfigurationMerger.cpp | 60 ++++++++----------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/sources/server/web/rest/service/PluginConfigurationMerger.cpp b/sources/server/web/rest/service/PluginConfigurationMerger.cpp index 60cdb1901..89bbe32e4 100644 --- a/sources/server/web/rest/service/PluginConfigurationMerger.cpp +++ b/sources/server/web/rest/service/PluginConfigurationMerger.cpp @@ -1,4 +1,4 @@ -#include "stdafx.h" +#include "stdafx.h" #include "PluginConfigurationMerger.h" @@ -39,9 +39,7 @@ namespace web || parameterType == "comboSection") { out->set(item.first + ".activeSection", - instanceConfiguration.exists(item.first + ".activeSection") - ? instanceConfiguration.get(item.first + ".activeSection") - : ""); + instanceConfiguration.getWithDefault(item.first + ".activeSection", "")); } } else if (parameterType == "checkboxSection") @@ -53,11 +51,9 @@ namespace web item.first + ".content", {}))); out->set(item.first + ".checkbox", - instanceConfiguration.exists(item.first + ".checkbox") - ? instanceConfiguration.get(item.first + ".checkbox") - : out->exists(item.first + ".defaultValue") - ? out->get(item.first + ".defaultValue") - : false); + instanceConfiguration.getWithDefault( + item.first + ".checkbox", + out->getWithDefault(item.first + ".defaultValue", false))); } else { @@ -65,49 +61,41 @@ namespace web || parameterType == "time") { out->set(item.first + ".value", - instanceConfiguration.exists(item.first) - ? instanceConfiguration.get(item.first) - : out->exists(item.first + ".defaultValue") - ? out->get(item.first + ".defaultValue") - : ""); + instanceConfiguration.getWithDefault( + item.first, + out->getWithDefault(item.first + ".defaultValue", ""))); } else if (parameterType == "enum") { out->set(item.first + ".value", - instanceConfiguration.exists(item.first) - ? instanceConfiguration.get(item.first) - : out->exists(item.first + ".defaultValue") - ? out->get(item.first + ".defaultValue") - : out->exists(item.first + ".values") && !out->getKeys(item.first + ".values").empty() - ? out->getKeys(item.first + ".values").at(0) - : ""); + instanceConfiguration.getWithDefault( + item.first, + out->getWithDefault( + item.first + ".defaultValue", + out->exists(item.first + ".values") && !out->getKeys(item.first + ".values").empty() + ? out->getKeys(item.first + ".values").at(0) + : ""))); } else if (parameterType == "bool") { out->set(item.first + ".value", - instanceConfiguration.exists(item.first) - ? instanceConfiguration.get(item.first) - : out->exists(item.first + ".defaultValue") - ? out->get(item.first + ".defaultValue") - : false); + instanceConfiguration.getWithDefault( + item.first, + out->getWithDefault(item.first + ".defaultValue", false))); } else if (parameterType == "int") { out->set(item.first + ".value", - instanceConfiguration.exists(item.first) - ? instanceConfiguration.get(item.first) - : out->exists(item.first + ".defaultValue") - ? out->get(item.first + ".defaultValue") - : 0); + instanceConfiguration.getWithDefault( + item.first, + out->getWithDefault(item.first + ".defaultValue", 0))); } else if (parameterType == "decimal") { out->set(item.first + ".value", - instanceConfiguration.exists(item.first) - ? instanceConfiguration.get(item.first) - : out->exists(item.first + ".defaultValue") - ? out->get(item.first + ".defaultValue") - : 0.0); + instanceConfiguration.getWithDefault( + item.first, + out->getWithDefault(item.first + ".defaultValue", 0.0))); } else {