Skip to content

Commit

Permalink
Refactor plugin config/schema merge
Browse files Browse the repository at this point in the history
  • Loading branch information
sgallou committed Sep 5, 2024
1 parent c031b02 commit cd46648
Showing 1 changed file with 24 additions and 36 deletions.
60 changes: 24 additions & 36 deletions sources/server/web/rest/service/PluginConfigurationMerger.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "stdafx.h"
#include "stdafx.h"

#include "PluginConfigurationMerger.h"

Expand Down Expand Up @@ -39,9 +39,7 @@ namespace web
|| parameterType == "comboSection")
{
out->set(item.first + ".activeSection",
instanceConfiguration.exists(item.first + ".activeSection")
? instanceConfiguration.get<std::string>(item.first + ".activeSection")
: "");
instanceConfiguration.getWithDefault<std::string>(item.first + ".activeSection", ""));
}
}
else if (parameterType == "checkboxSection")
Expand All @@ -53,61 +51,51 @@ namespace web
item.first + ".content", {})));

out->set(item.first + ".checkbox",
instanceConfiguration.exists(item.first + ".checkbox")
? instanceConfiguration.get<bool>(item.first + ".checkbox")
: out->exists(item.first + ".defaultValue")
? out->get<bool>(item.first + ".defaultValue")
: false);
instanceConfiguration.getWithDefault<bool>(
item.first + ".checkbox",
out->getWithDefault<bool>(item.first + ".defaultValue", false)));
}
else
{
if (parameterType == "string"
|| parameterType == "time")
{
out->set(item.first + ".value",
instanceConfiguration.exists(item.first)
? instanceConfiguration.get<std::string>(item.first)
: out->exists(item.first + ".defaultValue")
? out->get<std::string>(item.first + ".defaultValue")
: "");
instanceConfiguration.getWithDefault<std::string>(
item.first,
out->getWithDefault<std::string>(item.first + ".defaultValue", "")));
}
else if (parameterType == "enum")
{
out->set(item.first + ".value",
instanceConfiguration.exists(item.first)
? instanceConfiguration.get<std::string>(item.first)
: out->exists(item.first + ".defaultValue")
? out->get<std::string>(item.first + ".defaultValue")
: out->exists(item.first + ".values") && !out->getKeys(item.first + ".values").empty()
? out->getKeys(item.first + ".values").at(0)
: "");
instanceConfiguration.getWithDefault<std::string>(
item.first,
out->getWithDefault<std::string>(
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<bool>(item.first)
: out->exists(item.first + ".defaultValue")
? out->get<bool>(item.first + ".defaultValue")
: false);
instanceConfiguration.getWithDefault<bool>(
item.first,
out->getWithDefault<bool>(item.first + ".defaultValue", false)));
}
else if (parameterType == "int")
{
out->set(item.first + ".value",
instanceConfiguration.exists(item.first)
? instanceConfiguration.get<int>(item.first)
: out->exists(item.first + ".defaultValue")
? out->get<int>(item.first + ".defaultValue")
: 0);
instanceConfiguration.getWithDefault<int>(
item.first,
out->getWithDefault<int>(item.first + ".defaultValue", 0)));
}
else if (parameterType == "decimal")
{
out->set(item.first + ".value",
instanceConfiguration.exists(item.first)
? instanceConfiguration.get<double>(item.first)
: out->exists(item.first + ".defaultValue")
? out->get<double>(item.first + ".defaultValue")
: 0.0);
instanceConfiguration.getWithDefault<double>(
item.first,
out->getWithDefault<double>(item.first + ".defaultValue", 0.0)));
}
else
{
Expand Down

0 comments on commit cd46648

Please sign in to comment.