|
- #include "project_model.h"
-
- #include <algorithm>
-
- namespace integrated_platform::domain {
-
- namespace {
-
- void setError(std::string *error, const std::string &message)
- {
- if (error != nullptr)
- {
- *error = message;
- }
- }
-
- template <typename TItem>
- bool containsDuplicateId(const std::vector<TItem> &items)
- {
- for (auto current = items.cbegin(); current != items.cend(); ++current)
- {
- const auto duplicate = std::find_if(
- current + 1,
- items.cend(),
- [¤t](const TItem &item) { return item.id == current->id; });
- if (duplicate != items.cend())
- {
- return true;
- }
- }
- return false;
- }
-
- } // namespace
-
- bool Project::validate(std::string *error) const
- {
- if (metadata.id.empty() || metadata.name.empty() || metadata.formatVersion.empty())
- {
- setError(error, "project id, name and format version must not be empty");
- return false;
- }
- if (containsDuplicateId(hmiPages))
- {
- setError(error, "HMI page ids must be unique within a project");
- return false;
- }
- if (containsDuplicateId(controlLogics))
- {
- setError(error, "control logic ids must be unique within a project");
- return false;
- }
- for (const HmiPage &page : hmiPages)
- {
- if (!page.validate(error))
- {
- return false;
- }
- }
- for (const ControlLogic &logic : controlLogics)
- {
- if (!logic.validate(error))
- {
- return false;
- }
- }
- return true;
- }
-
- } // namespace integrated_platform::domain
|