Extracted schema and library management to Application
This commit is contained in:
1 parent
0c4afe87d9
commit
86b8861533
12 files changed
+334
-182
No files matched your search
@@ -1,3 +1,4 @@
|
||||
#include <set>
|
||||
#include "comdel_validator.h"
|
||||
#include "library.h"
|
||||
|
||||
@@ -38,11 +39,11 @@ namespace domain {
|
||||
auto message = populateMessage(
|
||||
"Not enough instances of component '{componentName}' required at least {min}, found {count}",
|
||||
context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
errors.emplace_back(Action::ERROR, message);
|
||||
} else if (count > comp.getCount().second) {
|
||||
auto message = populateMessage(
|
||||
"To many instances of component '{componentName}' allow at most {max}, found {count}", context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
errors.emplace_back(Action::ERROR, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,11 +65,11 @@ namespace domain {
|
||||
if (count < bus.getCount().first) {
|
||||
auto message = populateMessage(
|
||||
"Not enough instances of bus '{busName}' required at least {min}, found {count}", context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
errors.emplace_back(Action::ERROR, message);
|
||||
} else if (count > bus.getCount().second) {
|
||||
auto message = populateMessage(
|
||||
"To many instances of bus '{busName}' allow at most {max}, found {count}", context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
errors.emplace_back(Action::ERROR, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ namespace domain {
|
||||
context.instance = inst.get();
|
||||
context.attributes["instanceName"] = Value::fromString(inst->name);
|
||||
auto message = populateMessage(pin.getConnection().getMessage(), context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
errors.emplace_back(Action::ERROR, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,6 +153,24 @@ namespace domain {
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
std::vector<ValidationError>
|
||||
ComdelValidator::validateInstanceNames(Schema &schema, Library &library, ValidationContext context) {
|
||||
std::set<std::string> names;
|
||||
std::vector<ValidationError> errors;
|
||||
|
||||
for(auto& component: schema.componentInstances) {
|
||||
if(names.find(component->name) != names.end()) {
|
||||
context.attributes["componentName"] = Value::fromString(component->name);
|
||||
auto message = populateMessage(
|
||||
"There are multiple component instances named '{componentName}'", context);
|
||||
errors.emplace_back(Action::ERROR, message);
|
||||
}
|
||||
names.insert(component->name);
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
|
||||
std::string ComdelValidator::populateMessage(string source, ValidationContext context) {
|
||||
for (auto &[key, value]: context.attributes) {
|
||||
source = replacePlaceholder(source, key, value);
|
||||
@@ -202,5 +221,4 @@ namespace domain {
|
||||
this->validators.insert(std::make_pair(validator->getName(), validator));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,10 @@ namespace domain {
|
||||
InstanceAttribute *attribute;
|
||||
Action::ActionType type;
|
||||
std::string message;
|
||||
|
||||
ValidationError(Action::ActionType type, std::string message): instance(nullptr), attribute(nullptr), type(type), message(message) {}
|
||||
|
||||
ValidationError(ComponentInstance* instance, InstanceAttribute* attribute, Action::ActionType type, std::string message): instance(instance), attribute(attribute), type(type), message(message) {}
|
||||
};
|
||||
|
||||
struct ValidationContext {
|
||||
@@ -31,6 +35,8 @@ namespace domain {
|
||||
|
||||
std::optional<ValidationError> validateRule(Rule rule, ValidationContext context);
|
||||
|
||||
std::vector<ValidationError> validateInstanceNames(Schema &schema, Library &library, ValidationContext context);
|
||||
|
||||
std::vector<ValidationError> validateInstanceCount(Schema &schema, Library &library, ValidationContext context);
|
||||
|
||||
std::vector<ValidationError>
|
||||
|
||||
Reference in new issue
Block a user