130 {
132
133 StoragePlan plan;
134
135 const nlohmann::json& projectionsJson =
json.contains(
"projections") ?
json.at(
"projections") :
json;
136 if (!projectionsJson.is_array()) {
137 throw std::runtime_error("mqttstore projection configuration must be an array or contain a projections array");
138 }
139
140 for (const nlohmann::json& projectionJson : projectionsJson) {
142 projection.
name = projectionJson.value(
"name",
"");
143 projection.topic = projectionJson.at("topic").get<std::string>();
144 projection.table = projectionJson.at("table").get<std::string>();
145
146 const nlohmann::json& columnsJson = projectionJson.at("columns");
147 if (!columnsJson.is_object()) {
148 throw std::runtime_error("mqttstore projection columns must be an object");
149 }
150
151 for (auto columnIterator = columnsJson.begin(); columnIterator != columnsJson.end(); ++columnIterator) {
153 mapping.
column = columnIterator.key();
154
155 if (columnIterator.value().is_string()) {
156 mapping.jsonPointer = columnIterator.value().get<std::string>();
157 } else {
158 const nlohmann::json& mappingJson = columnIterator.value();
159 mapping.jsonPointer = mappingJson.value("json_pointer", "");
160 mapping.required = mappingJson.value("required", false);
161
162 if (mappingJson.contains("topic_level")) {
163 mapping.topicLevel = mappingJson.at("topic_level").get<std::size_t>();
164 }
165 if (mappingJson.contains("literal")) {
166 mapping.literal = mappingJson.at("literal").get<std::string>();
167 }
168 }
169
170 projection.columns.push_back(mapping);
171 }
172
173 plan.projections.push_back(projection);
174 }
175
176 return plan;
177 }
void validateProjectionConfiguration(const nlohmann::json &json)