From 672c3f365599511559a512124bbba6463e619b6d Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Mon, 7 Oct 2024 17:32:02 -0400 Subject: [PATCH] Merged changes from main-dev and added support for introduced. --- src/mtconnect/pipeline/validator.hpp | 12 ++++++++++-- src/mtconnect/validation/observations.hpp | 2 +- test_package/observation_validation_test.cpp | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/mtconnect/pipeline/validator.hpp b/src/mtconnect/pipeline/validator.hpp index 44c02bec..352cc30f 100644 --- a/src/mtconnect/pipeline/validator.hpp +++ b/src/mtconnect/pipeline/validator.hpp @@ -70,10 +70,18 @@ namespace mtconnect::pipeline { auto lit = lits.find(value); if (lit != lits.end()) { - evt->setProperty("quality", std::string("VALID")); + // Check if it has not been introduced yet + if (lit->second.first > 0 && m_contract->getSchemaVersion() < lit->second.first) + { + evt->setProperty("quality", std::string("INVALID")); + } + else + { + evt->setProperty("quality", std::string("VALID")); + } // Check if deprecated - if (lit->second > 0 && m_contract->getSchemaVersion() > lit->second) + if (lit->second.second > 0 && m_contract->getSchemaVersion() >= lit->second.second) { evt->setProperty("deprecated", true); } diff --git a/src/mtconnect/validation/observations.hpp b/src/mtconnect/validation/observations.hpp index c5a843ed..c6df2c85 100644 --- a/src/mtconnect/validation/observations.hpp +++ b/src/mtconnect/validation/observations.hpp @@ -31,7 +31,7 @@ namespace mtconnect { namespace observations { /// @brief Validation type for observations - using Validation = std::unordered_map>; + using Validation = std::unordered_map>>; /// @brief Global Validations for Event Observation's Controlled Vocabularies /// diff --git a/test_package/observation_validation_test.cpp b/test_package/observation_validation_test.cpp index 4b8da845..1fe9c7fa 100644 --- a/test_package/observation_validation_test.cpp +++ b/test_package/observation_validation_test.cpp @@ -219,3 +219,21 @@ TEST_F(ObservationValidationTest, should_not_validate_tables) auto quality = evt->get("quality"); ASSERT_EQ("VALID", quality); } + +TEST_F(ObservationValidationTest, should_be_invalid_if_entry_has_not_been_introduced_yet) +{ + ErrorList errors; + m_dataItem = + DataItem::make({{"id", "exec"s}, {"category", "EVENT"s}, {"type", "EXECUTION"s}}, errors); + + auto contract = static_cast(m_context->m_contract.get()); + contract->m_schemaVersion = SCHEMA_VERSION(1, 4); + + auto event = Observation::make(m_dataItem, {{"VALUE", "WAIT"s}}, m_time, errors); + + auto evt = (*m_validator)(std::move(event)); + auto quality = evt->get("quality"); + ASSERT_EQ("INVALID", quality); + ASSERT_FALSE(evt->hasProperty("deprecated")); +} +