Skip to content

Commit

Permalink
Merged changes from main-dev and added support for introduced.
Browse files Browse the repository at this point in the history
  • Loading branch information
wsobel committed Oct 7, 2024
1 parent c70b920 commit 672c3f3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/mtconnect/pipeline/validator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/mtconnect/validation/observations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace mtconnect {
namespace observations {

/// @brief Validation type for observations
using Validation = std::unordered_map<std::string, std::unordered_map<std::string, int32_t>>;
using Validation = std::unordered_map<std::string, std::unordered_map<std::string, std::pair<int32_t, int32_t>>>;

/// @brief Global Validations for Event Observation's Controlled Vocabularies
///
Expand Down
18 changes: 18 additions & 0 deletions test_package/observation_validation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,21 @@ TEST_F(ObservationValidationTest, should_not_validate_tables)
auto quality = evt->get<string>("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<MockPipelineContract *>(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<string>("quality");
ASSERT_EQ("INVALID", quality);
ASSERT_FALSE(evt->hasProperty("deprecated"));
}

0 comments on commit 672c3f3

Please sign in to comment.