From 81198a24669e84abb21c79ac74e12f0a5153db82 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Thu, 31 Aug 2023 14:22:57 +0200 Subject: [PATCH 1/9] util/string_view: Add cstdint for uint8_t New compilers do not automatically include cstdint for builds, thus we need to include it ourself Signed-off-by: Tobias Klausmann --- src/util/basyx/util/string_view/string_view.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/basyx/util/string_view/string_view.hpp b/src/util/basyx/util/string_view/string_view.hpp index bc72d6d..fbde9a9 100644 --- a/src/util/basyx/util/string_view/string_view.hpp +++ b/src/util/basyx/util/string_view/string_view.hpp @@ -3,6 +3,7 @@ #include #include +#include #include @@ -12,9 +13,9 @@ namespace basyx::util { using string_view = util::basic_string_view; using wstring_view = util::basic_string_view; - using u8string_view = util::basic_string_view; + using u8string_view = util::basic_string_view; using u16string_view = util::basic_string_view; using u32string_view = util::basic_string_view; } -#endif \ No newline at end of file +#endif From 5c5f4fa56e35e9864cc48c6475eaf87eccd9d833 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Thu, 31 Aug 2023 14:43:47 +0200 Subject: [PATCH 2/9] AssetKind: Add NotApplicable enum New in metamodel V3 final Signed-off-by: Tobias Klausmann --- src/libaas/basyx/enums/AssetKind.cpp | 1 + src/libaas/basyx/enums/AssetKind.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/libaas/basyx/enums/AssetKind.cpp b/src/libaas/basyx/enums/AssetKind.cpp index e93eb29..0b4cb51 100644 --- a/src/libaas/basyx/enums/AssetKind.cpp +++ b/src/libaas/basyx/enums/AssetKind.cpp @@ -12,6 +12,7 @@ static const std::array string_to_enum = { std::make_pair("Type", AssetKind::Type), std::make_pair("Instance", AssetKind::Instance), + std::make_pair("NotApplicable", AssetKind::NotApplicable), }; AssetKind AssetKind_::from_string(util::string_view name) diff --git a/src/libaas/basyx/enums/AssetKind.h b/src/libaas/basyx/enums/AssetKind.h index 88b36e8..e3a7cf7 100644 --- a/src/libaas/basyx/enums/AssetKind.h +++ b/src/libaas/basyx/enums/AssetKind.h @@ -8,6 +8,7 @@ namespace basyx { enum class AssetKind { Type, Instance, + NotApplicable, }; class AssetKind_ From 99c113446b7676b95c9ae0f23b3133db2a23b350 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 11 Sep 2023 16:31:41 +0200 Subject: [PATCH 3/9] Identifer: Adapt to metamodel V3 As the idType is gone we can base the identifier ontop of std::string and be done with it. Signed-off-by: Tobias Klausmann --- src/libaas/basyx/identifier.cpp | 35 +++++++++++++----------- src/libaas/basyx/identifier.h | 47 ++++++++++++--------------------- 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/src/libaas/basyx/identifier.cpp b/src/libaas/basyx/identifier.cpp index 13bc98e..f53bca1 100644 --- a/src/libaas/basyx/identifier.cpp +++ b/src/libaas/basyx/identifier.cpp @@ -1,22 +1,25 @@ -#include "identifier.h" -namespace basyx -{ +#include -Identifier::Identifier(KeyType idType, util::string_view id) - : idType(idType) - , id(id.to_string()) -{}; +namespace basyx { -Identifier::Identifier(util::string_view id) - : idType(KeyType_::from_id(id)) - , id(id.to_string()) -{}; +Identifier &Identifier::operator=(const Identifier &id) noexcept { + std::string::operator=(id); + return *this; +} +Identifier &Identifier::operator=(const basyx::util::string_view& id) noexcept { + std::string::operator=(id.to_string()); + return *this; +} -bool Identifier::operator==(const Identifier & other) const -{ - return (this->getIdType() == other.getIdType()) && (this->getId() == other.getId()); -}; +Identifier &Identifier::operator=(const std::string& id) noexcept { + std::string::operator=(id); + return *this; +} + +std::string Identifier::getId() const { + return static_cast(*this); +} -}; \ No newline at end of file +}; diff --git a/src/libaas/basyx/identifier.h b/src/libaas/basyx/identifier.h index db31eae..ce6163d 100644 --- a/src/libaas/basyx/identifier.h +++ b/src/libaas/basyx/identifier.h @@ -1,42 +1,29 @@ -#pragma once - -#include - -#include - -#include +#ifndef IDENTIFIER_H +#define IDENTIFIER_H #include +#include namespace basyx { -class Identifier -{ -private: - KeyType idType; - std::string id; -private: +class Identifier: public std::string { public: - Identifier(KeyType idType, util::string_view id); - Identifier(util::string_view id); + Identifier() = default; + Identifier(const Identifier&) = default; + Identifier(const basyx::util::string_view &v) { + std::string::operator=(v.to_string()); + } + Identifier(Identifier&&) = default; - Identifier(const Identifier&) = default; - Identifier(Identifier&&) = default; + Identifier& operator=(const Identifier& id) noexcept; + Identifier& operator=(const basyx::util::string_view& id) noexcept; + Identifier& operator=(const std::string& id) noexcept; + //Identifier& operator=(Identifier &) noexcept = default; - Identifier & operator=(const Identifier&) = default; - Identifier & operator=(Identifier&&) = default; + std::string getId() const; - ~Identifier() = default; -public: - const std::string & getId() const { return id; }; - KeyType getIdType() const { return idType; }; -public: - bool operator==(const Identifier & other) const; -public: - static Identifier Custom(util::string_view id) { return Identifier(KeyType::Custom, id); } - static Identifier IRDI(util::string_view id) { return Identifier(KeyType::IRDI, id); } - static Identifier IRI(util::string_view id) { return Identifier(KeyType::IRI, id); } + ~Identifier() = default; }; - }; +#endif /* IDENTIFIER_H */ From 303476549c66da8791c7725cb53c2fae05d8c97e Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 11 Sep 2023 16:44:40 +0200 Subject: [PATCH 4/9] serialization/json: Adapt de/serialization of Identifier Signed-off-by: Tobias Klausmann --- .../basyx/serialization/json/deserializer.cpp | 14 +++----------- src/libaas/basyx/serialization/json/serializer.cpp | 8 +------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/libaas/basyx/serialization/json/deserializer.cpp b/src/libaas/basyx/serialization/json/deserializer.cpp index be1cadc..a3e2652 100644 --- a/src/libaas/basyx/serialization/json/deserializer.cpp +++ b/src/libaas/basyx/serialization/json/deserializer.cpp @@ -41,14 +41,6 @@ namespace basyx::serialization::json return langstrings; }; - Identifier deserialize_identifier(const json_t & json) - { - std::string identifier = json["id"]; - std::string idType = json["idType"]; - - return Identifier{KeyType_::from_string(idType), identifier}; - }; - template void deserialize_referable(const json_t & json, Obj & obj) { @@ -154,7 +146,7 @@ namespace basyx::serialization::json Submodel deserialize_submodel(const json_t & json) { std::string idShort = json["idShort"]; - auto identifier = deserialize_identifier(json["identification"]); + Identifier identifier = json["identification"]; Submodel submodel(std::move(idShort), std::move(identifier)); @@ -170,9 +162,9 @@ namespace basyx::serialization::json AssetAdministrationShell deserialize_aas(const json_t & json) { std::string idShort = json["idShort"]; - auto identifier = deserialize_identifier(json["identification"]); + Identifier identifier = json["identification"]; - AssetAdministrationShell aas(idShort, identifier, basyx::AssetInformation(AssetKind::Instance)); + AssetAdministrationShell aas(idShort, identifier, basyx::AssetInformation(AssetKind::Instance)); deserialize_referable(json, aas); diff --git a/src/libaas/basyx/serialization/json/serializer.cpp b/src/libaas/basyx/serialization/json/serializer.cpp index 77b3a0d..bafc459 100644 --- a/src/libaas/basyx/serialization/json/serializer.cpp +++ b/src/libaas/basyx/serialization/json/serializer.cpp @@ -234,8 +234,7 @@ void serialize_helper(json_t & json, const File & file) void serialize_helper(json_t & json, const Identifier & identifier) { - json["id"] = identifier.getId(); - json["idType"] = KeyType_::to_string( identifier.getIdType() ); + json = identifier.getId(); }; void serialize_helper(json_t & json, const Identifiable & identifiable) @@ -296,11 +295,6 @@ void serialize_helper(json_t & json, const AssetInformation & assetInf) specificAssetIds.emplace_back(serialize(assetId)); json["specificAssetIds"] = specificAssetIds; - auto billOfMaterial = json_t::array(); - for (const auto & bom : assetInf.getBillOfMaterials()) - billOfMaterial.emplace_back(serialize(bom)); - json["billOfMaterial"] = billOfMaterial; - if(assetInf.getDefaultThumbnail()) json["thumbnail"] = serialize(*assetInf.getDefaultThumbnail()); } From 3cd7ada328e1f21421f3d5580d27b6c26855754c Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 11 Sep 2023 16:46:52 +0200 Subject: [PATCH 5/9] tests: Adapt to new Identifier Add a new base test for Identifier while we are at it. Signed-off-by: Tobias Klausmann --- tests/tests_libaas/test_basyx.cpp | 34 +++++++++++++------ tests/tests_libaas/test_elementcontainer.cpp | 4 +-- tests/tests_libaas/test_json.cpp | 5 ++- tests/tests_libaas/test_json_deserializer.cpp | 16 +++------ 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/tests/tests_libaas/test_basyx.cpp b/tests/tests_libaas/test_basyx.cpp index a7dcc2b..56452f6 100644 --- a/tests/tests_libaas/test_basyx.cpp +++ b/tests/tests_libaas/test_basyx.cpp @@ -64,6 +64,22 @@ TEST_F(BaseTest, LangStringSet) ASSERT_EQ(*de, "test"); } +TEST_F(BaseTest, IdentifierTest) +{ + Identifier id("test"); + ASSERT_EQ("test", id); + + Identifier id2 = id; + ASSERT_EQ("test", id2); + + Identifier id3 { "test3" }; + ASSERT_EQ("test3", id3); + + Identifier id4("test_bad"); + id4.assign("test_good"); + ASSERT_EQ("test_good", id4); +} + TEST_F(BaseTest, AutoKeyType) { Key key_1 { "CUSTOM" }; @@ -262,12 +278,12 @@ TEST_F(BaseTest, SubmodelAddElements) { using stringProp_t = Property; - Submodel sm("sm1", Identifier::IRI("https://admin-shell.io/cpp#sm1")); + Submodel sm("sm1", Identifier("https://admin-shell.io/cpp#sm1")); sm.setCategory("test"); sm.setSemanticId("0173-1#02-AAR972#002"); sm.setAdministration({ "1.0", "v2" }); - Submodel sm2("sm2", Identifier::IRI("https://admin-shell.io/cpp#sm2")); + Submodel sm2("sm2", Identifier("https://admin-shell.io/cpp#sm2")); sm.getSubmodelElements().add(Property("testProperty1", "Yay a value!")); sm.getSubmodelElements().add(Property("testProperty2", "Values and values! :O")); @@ -298,22 +314,18 @@ TEST_F(BaseTest, QualifierTest) TEST_F(BaseTest, AutoIdentifierTest) { Asset asset{ "testAsset", "0173-1#02-AAR972#002" }; - ASSERT_EQ(asset.getIdentification().getIdType(), KeyType::IRDI); AssetAdministrationShell aas{ "aas", "https://admin-shell.io/aas", { AssetKind::Instance } }; - ASSERT_EQ(aas.getIdentification().getIdType(), KeyType::IRI); Submodel sm{ "sm", "test/sm1" }; - ASSERT_EQ(sm.getIdentification().getIdType(), KeyType::Custom); } TEST_F(BaseTest, AssetInfTest) { - Asset asset{ "testAsset", Identifier::Custom("test") }; - + Identifier id("test"); AssetInformation assetInf{ AssetKind::Instance }; - assetInf.setAsset(asset); + assetInf.setGlobalAssetId(id); }; TEST_F(BaseTest, AssetAdministrationShell) @@ -330,14 +342,14 @@ TEST_F(BaseTest, Environment) AssetAdministrationShell("aas", "https://admin-shell.io/aas", AssetInformation{ AssetKind::Instance }) ); - env.getAssets().emplace_back(Asset("cppTestAsset", basyx::Identifier::Custom("cppTestAsset"))); + env.getAssets().emplace_back(Asset("cppTestAsset", basyx::Identifier("cppTestAsset"))); } TEST_F(BaseTest, AssetInfoInAas) { - Asset asset("cppTestAsset", basyx::Identifier::Custom("cppTestAsset")); + Identifier id("cppTestAsset"); AssetInformation assetinfo(basyx::AssetKind::Instance); - assetinfo.setAsset(asset); + assetinfo.setGlobalAssetId(id); auto assetInfo2 = assetinfo; AssetAdministrationShell aas("cppAas", "cppAas", assetinfo); diff --git a/tests/tests_libaas/test_elementcontainer.cpp b/tests/tests_libaas/test_elementcontainer.cpp index 1b89dce..11969c5 100644 --- a/tests/tests_libaas/test_elementcontainer.cpp +++ b/tests/tests_libaas/test_elementcontainer.cpp @@ -216,7 +216,7 @@ TEST_F(ElementContainerTest, Submodel) ElementContainer container; ASSERT_EQ(container.size(), 0); - container.add(Submodel("sm", Identifier::Custom("test"))); + container.add(Submodel("sm", Identifier("test"))); ASSERT_EQ(container.size(), 1); } @@ -443,4 +443,4 @@ TEST_F(ElementContainerTest, Copy_Operator_3) ASSERT_NE(container.get>("intProp1"), container2.get>("intProp1")); ASSERT_NE(container.get>("intProp2"), container2.get>("intProp2")); -} \ No newline at end of file +} diff --git a/tests/tests_libaas/test_json.cpp b/tests/tests_libaas/test_json.cpp index f2b1d6d..54367db 100644 --- a/tests/tests_libaas/test_json.cpp +++ b/tests/tests_libaas/test_json.cpp @@ -199,11 +199,10 @@ TEST_F(JsonTest, Submodel) TEST_F(JsonTest, AssetInfTest) { - Asset asset{ "testAsset", Identifier::Custom("test") }; + Identifier id("test"); AssetInformation assetInf{ AssetKind::Instance }; - assetInf.setAsset(asset); + assetInf.setGlobalAssetId(id); - auto asset_j = basyx::serialization::json::serialize(asset); auto assetInf_j = basyx::serialization::json::serialize(assetInf); }; diff --git a/tests/tests_libaas/test_json_deserializer.cpp b/tests/tests_libaas/test_json_deserializer.cpp index b51cdc5..3ec72c7 100644 --- a/tests/tests_libaas/test_json_deserializer.cpp +++ b/tests/tests_libaas/test_json_deserializer.cpp @@ -102,10 +102,7 @@ class JsonDeserializerTest : public ::testing::Test // Submodel const json_t json_submodel = json_t{ { "idShort", "sm_1" }, - { "identification", { - {"id", "submodel" }, - { "idType", "Custom"} - }}, + { "identification", "submodel" }, {"kind", "Instance"}, {"modelType", { {"name" , "Submodel"} } }, { "submodelElements" , { @@ -118,10 +115,7 @@ class JsonDeserializerTest : public ::testing::Test // AAS const json_t json_aas = json_t{ { "idShort", "aas_1" }, - { "identification", { - {"id", "asset_admin_shell_1" }, - { "idType", "Custom"} - }}, + { "identification", "asset_admin_shell_1" }, {"kind", "Instance"}, {"modelType", { {"name" , "AssetAdministrationShell"} } }, { "submodels" , json_t::array({json_submodel}) } @@ -211,14 +205,13 @@ TEST_F(JsonDeserializerTest, Submodel) ASSERT_EQ(sm.getIdShort(), "sm_1"); ASSERT_EQ(sm.getIdentification().getId(), "submodel"); - ASSERT_EQ(sm.getIdentification().getIdType(), KeyType::Custom); ASSERT_EQ(sm.getSubmodelElements().size(), 2); }; TEST_F(JsonDeserializerTest, RoundTripSubmodel) { - Submodel sm_in{ "sm", Identifier::Custom("submodel")}; + Submodel sm_in{ "sm", Identifier("submodel")}; sm_in.getSubmodelElements().create>("intProp", 5000); sm_in.getSubmodelElements().create("multiLangProp", langstringset_t{ {"EN", "example"}, {"DE", "beispiel"} }); @@ -234,8 +227,7 @@ TEST_F(JsonDeserializerTest, AssetAdministrationShell) auto aas = basyx::serialization::json::deserialize_aas(json_aas); ASSERT_EQ(aas.getIdShort(), "aas_1"); - ASSERT_EQ(aas.getIdentification().getId(), "asset_admin_shell_1"); - ASSERT_EQ(aas.getIdentification().getIdType(), KeyType::Custom); + ASSERT_EQ(aas.getIdentification().getId(), "asset_admin_shell_1"); ASSERT_EQ(aas.getSubmodels().size(), 1); }; From 5352bbc5ac1ca0144ca9c6fd5f2ddd8ae4b24ff8 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 11 Sep 2023 16:55:45 +0200 Subject: [PATCH 6/9] AssetInformation: Adapt to new Identifier A cleanup of this will happen later. Signed-off-by: Tobias Klausmann --- src/libaas/basyx/asset/assetinformation.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libaas/basyx/asset/assetinformation.h b/src/libaas/basyx/asset/assetinformation.h index b2800db..780f311 100644 --- a/src/libaas/basyx/asset/assetinformation.h +++ b/src/libaas/basyx/asset/assetinformation.h @@ -18,7 +18,7 @@ class AssetInformation private: AssetKind assetKind; util::optional asset; - util::optional globalAssetIdRef; + util::optional globalAssetIdRef; std::vector specificAssetId; std::vector billOfMaterial; util::optional defaultThumbnail; @@ -40,8 +40,8 @@ class AssetInformation }; const util::optional & getAsset() const { return asset; }; - const util::optional & getGlobalAssetId() const { return this->globalAssetIdRef; }; - void setGlobalAssetId(Reference globalAssetId) { this->globalAssetIdRef.emplace(std::move(globalAssetId)); }; + const util::optional & getGlobalAssetId() const { return this->globalAssetIdRef; }; + void setGlobalAssetId(Identifier globalAssetId) { this->globalAssetIdRef.emplace(std::move(globalAssetId)); }; const util::optional & getDefaultThumbnail() const { return defaultThumbnail; }; void setDefaultThumbnail(File file) { this->defaultThumbnail.emplace(std::move(file)); }; From 5c53dffe1d258455bbf44ad8a13c9f2111a1b19d Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 11 Sep 2023 16:56:48 +0200 Subject: [PATCH 7/9] xmlDeserializer: Adapt to new Identifier --- src/libaas/basyx/serialization/xml/xmldeserializer.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libaas/basyx/serialization/xml/xmldeserializer.cpp b/src/libaas/basyx/serialization/xml/xmldeserializer.cpp index 71b8a10..1a20ad7 100644 --- a/src/libaas/basyx/serialization/xml/xmldeserializer.cpp +++ b/src/libaas/basyx/serialization/xml/xmldeserializer.cpp @@ -102,6 +102,8 @@ Environment XMLDeSerializer::deSerializeEnvNode(xml_node node) { return env; } +/* TODO: Convert legacy V2 -> V3 (asset -> assetInformation) +/* ElementVector XMLDeSerializer::convertAssetToAssetInformation( ElementVector assets) { ElementVector aiC; @@ -129,6 +131,7 @@ ElementVector XMLDeSerializer::convertAssetToAssetInformation( } return aiC; } +*/ ElementVector XMLDeSerializer::deSerializeAssets( xml_node node) { @@ -149,7 +152,7 @@ ElementVector XMLDeSerializer::deSerializeAssets( Asset XMLDeSerializer::deSerializeAssetMetamodel_V2(xml_node node) { - Asset a("", Identifier(KeyType::Custom, "")); + Asset a("", Identifier("")); deSerializeIdentifiable(node, a); deSerializeHasDataSpecification(node, a); @@ -296,8 +299,7 @@ AdministrativeInformation XMLDeSerializer::deSerializeAdministrativeInformation( Identifier XMLDeSerializer::deSerializeIdentifier(xml_node node) { xml_attribute idType_attr = findAttributeByName(node, XML_ATTR_idType); - KeyType kt = KeyType_::from_string(idType_attr.as_string()); - Identifier ident(kt, deSerializeString(node)); + Identifier ident(deSerializeString(node)); return ident; } From 9e0f5138cf27e364ba7d1a32150f8177cd409220 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Tue, 12 Sep 2023 11:09:41 +0200 Subject: [PATCH 8/9] AssetInformation: Implement V3 changes Clean up V2 element such as the asset element Signed-off-by: Tobias Klausmann --- src/libaas/basyx/asset/assetinformation.h | 29 ++++++++--------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/libaas/basyx/asset/assetinformation.h b/src/libaas/basyx/asset/assetinformation.h index 780f311..8eeb3db 100644 --- a/src/libaas/basyx/asset/assetinformation.h +++ b/src/libaas/basyx/asset/assetinformation.h @@ -4,7 +4,6 @@ #include #include #include -#include #include @@ -17,10 +16,9 @@ class AssetInformation { private: AssetKind assetKind; - util::optional asset; - util::optional globalAssetIdRef; + util::optional globalAssetId; std::vector specificAssetId; - std::vector billOfMaterial; + util::optional assetType; util::optional defaultThumbnail; public: AssetInformation(AssetKind assetkind) : assetKind(assetkind) {}; @@ -34,25 +32,18 @@ class AssetInformation AssetKind getAssetKind() const { return assetKind; }; void setAssetKind(AssetKind kind) { this->assetKind = kind; }; - void setAsset(Asset asset) { - //this->globalAssetIdRef = asset; - this->asset.emplace(std::move(asset)); - }; - const util::optional & getAsset() const { return asset; }; - - const util::optional & getGlobalAssetId() const { return this->globalAssetIdRef; }; - void setGlobalAssetId(Identifier globalAssetId) { this->globalAssetIdRef.emplace(std::move(globalAssetId)); }; - - const util::optional & getDefaultThumbnail() const { return defaultThumbnail; }; - void setDefaultThumbnail(File file) { this->defaultThumbnail.emplace(std::move(file)); }; - - void addBillOfMaterial(Reference bom) { this->billOfMaterial.emplace_back(std::move(bom)); }; - const std::vector & getBillOfMaterials() const { return this->billOfMaterial; }; - std::vector & getBillOfMaterials() { return this->billOfMaterial; }; + const util::optional & getGlobalAssetId() const { return this->globalAssetId; }; + void setGlobalAssetId(Identifier globalAssetId) { this->globalAssetId.emplace(std::move(globalAssetId)); }; void addSpecificAssetId(IdentifierKeyValuePair specificAssetId) { this->specificAssetId.emplace_back(std::move(specificAssetId)); }; const std::vector & getSpecificAssetIds() const { return this->specificAssetId; }; std::vector & getSpecificAssetIds() { return this->specificAssetId; }; + + const util::optional & getAssetType() const { return this->assetType; }; + void setAssetType(Identifier assetType) { this->assetType.emplace(std::move(assetType)); }; + + const util::optional & getDefaultThumbnail() const { return defaultThumbnail; }; + void setDefaultThumbnail(File file) { this->defaultThumbnail.emplace(std::move(file)); }; }; From c0bf5a0ca97499ffde9be50865ddde828f8668cb Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Tue, 12 Sep 2023 11:12:19 +0200 Subject: [PATCH 9/9] Remove Asset class Remove it from the Environment and the tests Signed-off-by: Tobias Klausmann --- src/libaas/basyx/asset/asset.cpp | 0 src/libaas/basyx/asset/asset.h | 66 ------------------- src/libaas/basyx/environment.h | 6 -- .../basyx/serialization/json/serializer.cpp | 5 -- .../basyx/serialization/json/serializer_fwd.h | 2 - .../serialization/xml/xmldeserializer.cpp | 15 +++-- .../basyx/serialization/xml/xmldeserializer.h | 5 ++ src/libaas/sources.cmake | 2 - tests/tests_libaas/test_basyx.cpp | 5 -- tests/tests_libaas/test_copyable.cpp | 1 - tests/tests_libaas/test_property.cpp | 1 - tests/tests_libaas/test_qualifier.cpp | 1 - 12 files changed, 16 insertions(+), 93 deletions(-) delete mode 100644 src/libaas/basyx/asset/asset.cpp delete mode 100644 src/libaas/basyx/asset/asset.h diff --git a/src/libaas/basyx/asset/asset.cpp b/src/libaas/basyx/asset/asset.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/libaas/basyx/asset/asset.h b/src/libaas/basyx/asset/asset.h deleted file mode 100644 index e5e2004..0000000 --- a/src/libaas/basyx/asset/asset.h +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include - -#include - -#include -#include -#include -#include -#include - -#include - -namespace basyx -{ - -using namespace basyx::base; -using namespace basyx::serialization::priv; - -class Asset : - public Identifiable, - public ModelType -{ -private: - // Legacy AAS Part 1 - V2 - util::optional assetKind; - util::optional billOfMaterialModelRef; - util::optional assetIdentificationModelRef; -public: - Asset(util::string_view idShort, Identifier identifier) : Identifiable(idShort, std::move(identifier)) {}; - Asset(util::string_view idShort, util::string_view id) : Identifiable(idShort, id) {}; -public: - Asset(const Asset &) = default; - Asset& operator=(const Asset &) = default; - - Asset(Asset &&) = default; - Asset& operator=(Asset &&) = default; - - // Legacy AAS Part 1 - V2 - const util::optional & getAssetKind() { - return assetKind; - }; - void setAssetKind(AssetKind kind) { this->assetKind = kind; }; - - util::optional & getBillOfMaterialModelRef() { - return billOfMaterialModelRef; - } - void setBillOfMaterialModelRef(Reference bomModelRef) { - billOfMaterialModelRef = bomModelRef; - } - - const util::optional & getAssetIDentificationModelRef() { - return assetIdentificationModelRef; - } - const void setAssetIdentificationModelRef(Reference assetIdentModelRef) { - assetIdentificationModelRef = assetIdentModelRef; - } - - // Identifiable - special purpose - void setIdentification(Token t, Identifier identifier) { - this->Identifiable::setIdentification(identifier); - } -}; - -}; diff --git a/src/libaas/basyx/environment.h b/src/libaas/basyx/environment.h index 323f21b..812cf00 100644 --- a/src/libaas/basyx/environment.h +++ b/src/libaas/basyx/environment.h @@ -4,7 +4,6 @@ #include #include #include -#include namespace basyx { @@ -17,7 +16,6 @@ class Environment { private: ElementContainer aass; - ElementVector assets; public: Environment() = default; public: @@ -30,10 +28,6 @@ class Environment const ElementContainer & getAssetAdministrationShells() const { return this->aass; }; ElementContainer & getAssetAdministrationShells() { return this->aass; }; void setAssetAdministrationShells(ElementContainer aass) { this->aass = aass; }; - - const ElementVector & getAssets() const { return this->assets; }; - ElementVector & getAssets() { return this->assets; }; - void setAssets(ElementVector assets) { this->assets = std::move(assets); }; }; }; diff --git a/src/libaas/basyx/serialization/json/serializer.cpp b/src/libaas/basyx/serialization/json/serializer.cpp index bafc459..e45c9c3 100644 --- a/src/libaas/basyx/serialization/json/serializer.cpp +++ b/src/libaas/basyx/serialization/json/serializer.cpp @@ -278,11 +278,6 @@ void serialize_helper(json_t & json, const Submodel & submodel) }; -void serialize_helper(json_t & json, const Asset & asset) -{ - serialize_helper_h(json, asset); -} - void serialize_helper(json_t & json, const AssetInformation & assetInf) { json["assetKind"] = AssetKind_::to_string(assetInf.getAssetKind()); diff --git a/src/libaas/basyx/serialization/json/serializer_fwd.h b/src/libaas/basyx/serialization/json/serializer_fwd.h index 2588f01..f0e1b42 100644 --- a/src/libaas/basyx/serialization/json/serializer_fwd.h +++ b/src/libaas/basyx/serialization/json/serializer_fwd.h @@ -28,7 +28,6 @@ namespace basyx class Submodel; class File; class Blob; - class Asset; class AssetInformation; template @@ -49,7 +48,6 @@ namespace basyx::serialization::json void serialize_helper(json_t & json, const HasSemantics &); void serialize_helper(json_t & json, const HasKind &); void serialize_helper(json_t & json, const modeltype_base &); - void serialize_helper(json_t & json, const Asset &); void serialize_helper(json_t & json, const AssetInformation &); void serialize_helper(json_t & json, const Identifier &); void serialize_helper(json_t & json, const IdentifierKeyValuePair &); diff --git a/src/libaas/basyx/serialization/xml/xmldeserializer.cpp b/src/libaas/basyx/serialization/xml/xmldeserializer.cpp index 1a20ad7..bf21f6b 100644 --- a/src/libaas/basyx/serialization/xml/xmldeserializer.cpp +++ b/src/libaas/basyx/serialization/xml/xmldeserializer.cpp @@ -12,9 +12,7 @@ using namespace pugi; // Environment #define XML_ENV "aas:aasenv" -// Asset -#define XML_assets "aas:assets" -#define XML_asset "aas:asset" + #define XML_assetKind "aas:kind" #define XML_billOfMaterialRef "aas:billOfMaterialRef" #define XML_assetIdentificationModelRef "aas:assetIdentificationModelRef" @@ -58,6 +56,11 @@ using namespace pugi; #define XML_ATTR_idType "idType" #define XML_ATTR_type "type" +// Legacy V2 +// Asset +#define XML_assets "aas:assets" +#define XML_asset "aas:asset" + XMLDeSerializer::XMLDeSerializer() { ds = new Deserializer(); } @@ -78,12 +81,14 @@ Environment XMLDeSerializer::deSerializeEnvNode(xml_node node) { Environment env; // Legacy AAS Part 1 - V2 + /* xml_node asset_container_node = findChildByName(node, XML_assets); ElementVector assets; if (asset_container_node.root()) { assets = deSerializeAssets(asset_container_node); env.setAssets(assets); } + */ xml_node submodel_container_node = findChildByName(node, XML_submodels); ElementVector submodels; @@ -102,7 +107,7 @@ Environment XMLDeSerializer::deSerializeEnvNode(xml_node node) { return env; } -/* TODO: Convert legacy V2 -> V3 (asset -> assetInformation) +/* TODO: Convert legacy V2 -> V3 (asset -> assetInformation) */ /* ElementVector XMLDeSerializer::convertAssetToAssetInformation( ElementVector assets) { @@ -133,6 +138,7 @@ ElementVector XMLDeSerializer::convertAssetToAssetInformation( } */ +/* ElementVector XMLDeSerializer::deSerializeAssets( xml_node node) { @@ -181,6 +187,7 @@ Asset XMLDeSerializer::deSerializeAssetMetamodel_V2(xml_node node) { } return a; } +*/ AssetKind XMLDeSerializer::deSerializeAssetKind(xml_node node) { std::string kind = deSerializeString(node); diff --git a/src/libaas/basyx/serialization/xml/xmldeserializer.h b/src/libaas/basyx/serialization/xml/xmldeserializer.h index 7c14138..036200a 100644 --- a/src/libaas/basyx/serialization/xml/xmldeserializer.h +++ b/src/libaas/basyx/serialization/xml/xmldeserializer.h @@ -30,12 +30,17 @@ class XMLDeSerializer { Environment deSerializeEnv(util::string_view node); Environment deSerializeEnvNode(pugi::xml_node node); + /* V2 Legacy */ + /* ElementVector deSerializeAssets( pugi::xml_node node); + ElementVector convertAssetToAssetInformation( ElementVector assets); Asset deSerializeAssetMetamodel_V2(pugi::xml_node node); + */ + AssetKind deSerializeAssetKind(pugi::xml_node node); ElementContainer deSerializeAASs( diff --git a/src/libaas/sources.cmake b/src/libaas/sources.cmake index b239e3c..65e3093 100644 --- a/src/libaas/sources.cmake +++ b/src/libaas/sources.cmake @@ -1,6 +1,5 @@ SET(SOURCE_FILES_BASYX_AAS ${CMAKE_CURRENT_SOURCE_DIR}/basyx/administrative_information.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/basyx/asset/asset.cpp ${CMAKE_CURRENT_SOURCE_DIR}/basyx/asset/assetinformation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/basyx/assetadministrationshell.cpp ${CMAKE_CURRENT_SOURCE_DIR}/basyx/base/basyx_enums.cpp @@ -64,7 +63,6 @@ SET(SOURCE_FILES_BASYX_AAS SET(HEADER_FILES_BASYX_AAS ${CMAKE_CURRENT_SOURCE_DIR}/basyx/administrative_information.h - ${CMAKE_CURRENT_SOURCE_DIR}/basyx/asset/asset.h ${CMAKE_CURRENT_SOURCE_DIR}/basyx/asset/assetinformation.h ${CMAKE_CURRENT_SOURCE_DIR}/basyx/assetadministrationshell.h ${CMAKE_CURRENT_SOURCE_DIR}/basyx/base/basyx_enum_base.h diff --git a/tests/tests_libaas/test_basyx.cpp b/tests/tests_libaas/test_basyx.cpp index 56452f6..96abc4d 100644 --- a/tests/tests_libaas/test_basyx.cpp +++ b/tests/tests_libaas/test_basyx.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -313,8 +312,6 @@ TEST_F(BaseTest, QualifierTest) TEST_F(BaseTest, AutoIdentifierTest) { - Asset asset{ "testAsset", "0173-1#02-AAR972#002" }; - AssetAdministrationShell aas{ "aas", "https://admin-shell.io/aas", { AssetKind::Instance } }; Submodel sm{ "sm", "test/sm1" }; @@ -341,8 +338,6 @@ TEST_F(BaseTest, Environment) env.getAssetAdministrationShells().add( AssetAdministrationShell("aas", "https://admin-shell.io/aas", AssetInformation{ AssetKind::Instance }) ); - - env.getAssets().emplace_back(Asset("cppTestAsset", basyx::Identifier("cppTestAsset"))); } TEST_F(BaseTest, AssetInfoInAas) diff --git a/tests/tests_libaas/test_copyable.cpp b/tests/tests_libaas/test_copyable.cpp index 03dde68..b717bd3 100644 --- a/tests/tests_libaas/test_copyable.cpp +++ b/tests/tests_libaas/test_copyable.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include diff --git a/tests/tests_libaas/test_property.cpp b/tests/tests_libaas/test_property.cpp index 5ab5244..5a444a1 100644 --- a/tests/tests_libaas/test_property.cpp +++ b/tests/tests_libaas/test_property.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include diff --git a/tests/tests_libaas/test_qualifier.cpp b/tests/tests_libaas/test_qualifier.cpp index 88d2d94..2326771 100644 --- a/tests/tests_libaas/test_qualifier.cpp +++ b/tests/tests_libaas/test_qualifier.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include