Skip to content
Snippets Groups Projects
Commit 38f64d5b authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Fix for updating config properties

parent 30c0eb71
No related branches found
No related tags found
No related merge requests found
Pipeline #11180 passed
......@@ -37,7 +37,7 @@ bool update(const std::string &puri, const json_t &value);
* Resolve a JSON schema reference, but do not wait for a remote reference
* if it is not available. A null entity is returned if not resolved.
*/
json_t &resolve(const std::string &);
json_t &resolve(const std::string &, bool eager=true);
/**
* Resolve a reference object, or if not a reference object it simply returns
......@@ -85,17 +85,17 @@ using config::configure;
template <typename T, typename... ARGS>
T *ftl::config::create(json_t &link, ARGS ...args) {
auto &r = link; // = ftl::config::resolve(link);
//auto &r = link; // = ftl::config::resolve(link);
if (!r["$id"].is_string()) {
LOG(FATAL) << "Entity does not have $id or parent: " << r;
if (!link["$id"].is_string()) {
LOG(FATAL) << "Entity does not have $id or parent: " << link;
return nullptr;
}
ftl::Configurable *cfg = ftl::config::find(r["$id"].get<std::string>());
ftl::Configurable *cfg = ftl::config::find(link["$id"].get<std::string>());
if (!cfg) {
// try {
cfg = new T(r, args...);
cfg = new T(link, args...);
//} catch(...) {
// LOG(FATAL) << "Could not construct " << link;
//}
......
......@@ -218,7 +218,8 @@ bool ftl::config::update(const std::string &puri, const json_t &value) {
cfg->set<json_t>(tail, value);
} else {
DLOG(1) << "Updating: " << head << "[" << tail << "] = " << value;
auto r = resolve(head);
auto &r = resolve(head, false);
if (!r.is_structured()) {
LOG(ERROR) << "Cannot update property '" << tail << "' of '" << head << "'";
return false;
......@@ -229,7 +230,7 @@ bool ftl::config::update(const std::string &puri, const json_t &value) {
}
}
json_t &ftl::config::resolve(const std::string &puri) {
json_t &ftl::config::resolve(const std::string &puri, bool eager) {
string uri_str = puri;
// TODO(Nick) Must support alternative root (last $id)
......@@ -252,11 +253,13 @@ json_t &ftl::config::resolve(const std::string &puri) {
auto ptr = nlohmann::json::json_pointer("/"+uri.getFragment());
try {
return resolve((*ix).second->at(ptr));
return (eager) ? resolve((*ix).second->at(ptr)) : (*ix).second->at(ptr);
} catch(...) {
LOG(WARNING) << "Resolve failed for " << puri;
return null_json;
}
} else {
LOG(WARNING) << "Resolve failed for " << puri;
return null_json;
}
}
......@@ -429,6 +432,10 @@ Configurable *ftl::config::configure(int argc, char **argv, const std::string &r
rootCFG = rootcfg;
rootcfg->set("paths", paths);
process_options(rootcfg, options);
//LOG(INFO) << "CONFIG: " << config["vision_default"];
CHECK_EQ( &config, config_index["ftl://utu.fi"] );
return rootcfg;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment