From fc48262b426e10ba6eb7e05c9d87aacf6ba36713 Mon Sep 17 00:00:00 2001 From: Sebastian Heppner Date: Tue, 14 Nov 2023 15:58:49 +0100 Subject: [PATCH 01/13] adapter.xml: Update XSD Schema --- basyx/aas/adapter/xml/AAS.xsd | 120 +++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 54 deletions(-) diff --git a/basyx/aas/adapter/xml/AAS.xsd b/basyx/aas/adapter/xml/AAS.xsd index 76c1fd544..8cac50cab 100644 --- a/basyx/aas/adapter/xml/AAS.xsd +++ b/basyx/aas/adapter/xml/AAS.xsd @@ -18,20 +18,33 @@ + + + + + + + + + + + + + @@ -112,6 +125,7 @@ + @@ -119,21 +133,21 @@ - + - + - + @@ -148,6 +162,7 @@ + @@ -249,7 +264,14 @@ - + + + + + + + + @@ -338,6 +360,7 @@ + @@ -345,17 +368,11 @@ - - - - - - - - + + @@ -365,6 +382,7 @@ + @@ -382,6 +400,7 @@ + @@ -390,6 +409,7 @@ + @@ -467,21 +487,7 @@ - - - - - - - - - - - - - - @@ -526,6 +532,7 @@ + @@ -545,6 +552,7 @@ + @@ -671,6 +679,7 @@ + @@ -694,13 +703,15 @@ + - + + @@ -719,13 +730,6 @@ - - - - - - - @@ -788,6 +792,7 @@ + @@ -796,6 +801,7 @@ + @@ -808,6 +814,7 @@ + @@ -815,10 +822,11 @@ + - + @@ -905,7 +913,14 @@ - + + + + + + + + @@ -942,9 +957,9 @@ + - @@ -955,23 +970,20 @@ - - - - + - - - + + - + + + + + - - - @@ -1011,30 +1023,30 @@ - - - + + + - + - + @@ -1321,4 +1333,4 @@ - \ No newline at end of file + From d3cdbfeab84b45caa30eedb2249e529460022415 Mon Sep 17 00:00:00 2001 From: Sebastian Heppner Date: Tue, 14 Nov 2023 16:30:04 +0100 Subject: [PATCH 02/13] adapter.xml: Update XSD of `valueDataType` and `Extension` This commit remanes `valueDataType_t` from the XSD to `valueDataType`. Furthermore, it adds a missing `` tag around the `refersTo` References of `Extension`. --- basyx/aas/adapter/xml/AAS.xsd | 31 ++++++++++++------- basyx/aas/adapter/xml/xml_serialization.py | 8 +++-- .../files/test_demo_full_example.xml | 16 +++++----- .../aasx/data.xml | 16 +++++----- .../aasx/data.xml | 14 +++++---- 5 files changed, 51 insertions(+), 34 deletions(-) diff --git a/basyx/aas/adapter/xml/AAS.xsd b/basyx/aas/adapter/xml/AAS.xsd index 8cac50cab..eadb28d35 100644 --- a/basyx/aas/adapter/xml/AAS.xsd +++ b/basyx/aas/adapter/xml/AAS.xsd @@ -387,8 +387,14 @@ - - + + + + + + + + @@ -637,7 +643,7 @@ - + @@ -684,7 +690,7 @@ - + @@ -692,8 +698,8 @@ - - + + @@ -1087,11 +1093,14 @@ - - - - - + + + + + + + + diff --git a/basyx/aas/adapter/xml/xml_serialization.py b/basyx/aas/adapter/xml/xml_serialization.py index c5d454631..7751598a5 100644 --- a/basyx/aas/adapter/xml/xml_serialization.py +++ b/basyx/aas/adapter/xml/xml_serialization.py @@ -277,9 +277,11 @@ def extension_to_xml(obj: model.Extension, tag: str = NS_AAS+"extension") -> etr text=model.datatypes.XSD_TYPE_NAMES[obj.value_type])) if obj.value: et_extension.append(_value_to_xml(obj.value, obj.value_type)) # type: ignore # (value_type could be None) - for refers_to in obj.refers_to: - et_extension.append(reference_to_xml(refers_to, NS_AAS+"refersTo")) - + if obj.refers_to: + refers_to = _generate_element(NS_AAS+"refersTo") + for reference in obj.refers_to: + refers_to.append(reference_to_xml(reference, NS_AAS+"reference")) + et_extension.append(refers_to) return et_extension diff --git a/test/compliance_tool/files/test_demo_full_example.xml b/test/compliance_tool/files/test_demo_full_example.xml index 953c2bc2a..4c78a9067 100644 --- a/test/compliance_tool/files/test_demo_full_example.xml +++ b/test/compliance_tool/files/test_demo_full_example.xml @@ -347,13 +347,15 @@ xs:string ExampleExtensionValue - ModelReference - - - AssetAdministrationShell - http://acplt.org/RefersTo/ExampleRefersTo - - + + ModelReference + + + AssetAdministrationShell + http://acplt.org/RefersTo/ExampleRefersTo + + + diff --git a/test/compliance_tool/files/test_demo_full_example_xml_aasx/aasx/data.xml b/test/compliance_tool/files/test_demo_full_example_xml_aasx/aasx/data.xml index 2c864dfff..8a1d35fe8 100644 --- a/test/compliance_tool/files/test_demo_full_example_xml_aasx/aasx/data.xml +++ b/test/compliance_tool/files/test_demo_full_example_xml_aasx/aasx/data.xml @@ -355,13 +355,15 @@ xs:string ExampleExtensionValue - ModelReference - - - AssetAdministrationShell - http://acplt.org/RefersTo/ExampleRefersTo - - + + ModelReference + + + AssetAdministrationShell + http://acplt.org/RefersTo/ExampleRefersTo + + + diff --git a/test/compliance_tool/files/test_demo_full_example_xml_wrong_attribute_aasx/aasx/data.xml b/test/compliance_tool/files/test_demo_full_example_xml_wrong_attribute_aasx/aasx/data.xml index 30ebd5789..2ad0344d8 100644 --- a/test/compliance_tool/files/test_demo_full_example_xml_wrong_attribute_aasx/aasx/data.xml +++ b/test/compliance_tool/files/test_demo_full_example_xml_wrong_attribute_aasx/aasx/data.xml @@ -355,13 +355,15 @@ xs:string ExampleExtensionValue + ModelReference - - - AssetAdministrationShell - http://acplt.org/RefersTo/ExampleRefersTo - - + + + AssetAdministrationShell + http://acplt.org/RefersTo/ExampleRefersTo + + + From 0c276f756859cb9d48395e689700aec233570780 Mon Sep 17 00:00:00 2001 From: Sebastian Heppner Date: Tue, 14 Nov 2023 16:33:06 +0100 Subject: [PATCH 03/13] adapter.xml: Update `levelType` XSD --- basyx/aas/adapter/xml/AAS.xsd | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/basyx/aas/adapter/xml/AAS.xsd b/basyx/aas/adapter/xml/AAS.xsd index eadb28d35..36e48162a 100644 --- a/basyx/aas/adapter/xml/AAS.xsd +++ b/basyx/aas/adapter/xml/AAS.xsd @@ -589,6 +589,14 @@ + + + + + + + + @@ -1055,19 +1063,6 @@ - - - - - - - - - - - - - @@ -1246,6 +1241,11 @@ + + + + + From 9027a8e373ecc6c84534196cc19af7cac9f30db3 Mon Sep 17 00:00:00 2001 From: Sebastian Heppner Date: Tue, 14 Nov 2023 16:46:01 +0100 Subject: [PATCH 04/13] adapter.xml: Change order of `SubmodelElementList` objects The current order of the elements in `SubmodelElementList` was wrong. This updates the order. --- basyx/aas/adapter/xml/AAS.xsd | 6 +-- basyx/aas/adapter/xml/xml_serialization.py | 10 ++--- .../files/test_demo_full_example.xml | 44 +++++++++---------- ...test_demo_full_example_wrong_attribute.xml | 44 +++++++++---------- .../aasx/data.xml | 44 +++++++++---------- .../aasx/data.xml | 44 +++++++++---------- 6 files changed, 96 insertions(+), 96 deletions(-) diff --git a/basyx/aas/adapter/xml/AAS.xsd b/basyx/aas/adapter/xml/AAS.xsd index 36e48162a..bb31c376d 100644 --- a/basyx/aas/adapter/xml/AAS.xsd +++ b/basyx/aas/adapter/xml/AAS.xsd @@ -884,6 +884,9 @@ + + + @@ -891,9 +894,6 @@ - - - diff --git a/basyx/aas/adapter/xml/xml_serialization.py b/basyx/aas/adapter/xml/xml_serialization.py index 7751598a5..f3c93800a 100644 --- a/basyx/aas/adapter/xml/xml_serialization.py +++ b/basyx/aas/adapter/xml/xml_serialization.py @@ -679,11 +679,6 @@ def submodel_element_list_to_xml(obj: model.SubmodelElementList, tag: str = NS_AAS+"submodelElementList") -> etree.Element: et_submodel_element_list = abstract_classes_to_xml(tag, obj) et_submodel_element_list.append(_generate_element(NS_AAS + "orderRelevant", boolean_to_xml(obj.order_relevant))) - if len(obj.value) > 0: - et_value = _generate_element(NS_AAS + "value") - for se in obj.value: - et_value.append(submodel_element_to_xml(se)) - et_submodel_element_list.append(et_value) if obj.semantic_id_list_element is not None: et_submodel_element_list.append(reference_to_xml(obj.semantic_id_list_element, NS_AAS + "semanticIdListElement")) @@ -692,6 +687,11 @@ def submodel_element_list_to_xml(obj: model.SubmodelElementList, if obj.value_type_list_element is not None: et_submodel_element_list.append(_generate_element(NS_AAS + "valueTypeListElement", model.datatypes.XSD_TYPE_NAMES[obj.value_type_list_element])) + if len(obj.value) > 0: + et_value = _generate_element(NS_AAS + "value") + for se in obj.value: + et_value.append(submodel_element_to_xml(se)) + et_submodel_element_list.append(et_value) return et_submodel_element_list diff --git a/test/compliance_tool/files/test_demo_full_example.xml b/test/compliance_tool/files/test_demo_full_example.xml index 4c78a9067..584daa8f8 100644 --- a/test/compliance_tool/files/test_demo_full_example.xml +++ b/test/compliance_tool/files/test_demo_full_example.xml @@ -1180,6 +1180,17 @@ true + + ExternalReference + + + GlobalReference + http://acplt.org/Properties/ExampleProperty + + + + Property + xs:string CONSTANT @@ -1397,17 +1408,6 @@ - - ExternalReference - - - GlobalReference - http://acplt.org/Properties/ExampleProperty - - - - Property - xs:string CONSTANT @@ -1622,6 +1622,7 @@ ExampleSubmodelList + SubmodelElementCollection Instance @@ -1665,7 +1666,6 @@ Instance - SubmodelElementCollection ExampleSubmodelList2 @@ -2630,6 +2630,16 @@ true + + ExternalReference + + + GlobalReference + http://acplt.org/SubmodelElementCollections/ExampleSubmodelElementCollection + + + + SubmodelElementCollection PARAMETER @@ -2856,16 +2866,6 @@ - - ExternalReference - - - GlobalReference - http://acplt.org/SubmodelElementCollections/ExampleSubmodelElementCollection - - - - SubmodelElementCollection PARAMETER diff --git a/test/compliance_tool/files/test_demo_full_example_wrong_attribute.xml b/test/compliance_tool/files/test_demo_full_example_wrong_attribute.xml index 0f9995991..f0b2a03e1 100644 --- a/test/compliance_tool/files/test_demo_full_example_wrong_attribute.xml +++ b/test/compliance_tool/files/test_demo_full_example_wrong_attribute.xml @@ -1178,6 +1178,17 @@ true + + ExternalReference + + + GlobalReference + http://acplt.org/Properties/ExampleProperty + + + + Property + xs:string CONSTANT @@ -1395,17 +1406,6 @@ - - ExternalReference - - - GlobalReference - http://acplt.org/Properties/ExampleProperty - - - - Property - xs:string CONSTANT @@ -1620,6 +1620,7 @@ ExampleSubmodelList + SubmodelElementCollection Instance @@ -1663,7 +1664,6 @@ Instance - SubmodelElementCollection ExampleSubmodelList2 @@ -2628,6 +2628,16 @@ true + + ExternalReference + + + GlobalReference + http://acplt.org/SubmodelElementCollections/ExampleSubmodelElementCollection + + + + SubmodelElementCollection PARAMETER @@ -2854,16 +2864,6 @@ - - ExternalReference - - - GlobalReference - http://acplt.org/SubmodelElementCollections/ExampleSubmodelElementCollection - - - - SubmodelElementCollection PARAMETER diff --git a/test/compliance_tool/files/test_demo_full_example_xml_aasx/aasx/data.xml b/test/compliance_tool/files/test_demo_full_example_xml_aasx/aasx/data.xml index 8a1d35fe8..c42d76205 100644 --- a/test/compliance_tool/files/test_demo_full_example_xml_aasx/aasx/data.xml +++ b/test/compliance_tool/files/test_demo_full_example_xml_aasx/aasx/data.xml @@ -1188,6 +1188,17 @@ true + + ExternalReference + + + GlobalReference + http://acplt.org/Properties/ExampleProperty + + + + Property + xs:string CONSTANT @@ -1405,17 +1416,6 @@ - - ExternalReference - - - GlobalReference - http://acplt.org/Properties/ExampleProperty - - - - Property - xs:string CONSTANT @@ -1630,6 +1630,7 @@ ExampleSubmodelList + SubmodelElementCollection Instance @@ -1673,7 +1674,6 @@ Instance - SubmodelElementCollection ExampleSubmodelList2 @@ -2638,6 +2638,16 @@ true + + ExternalReference + + + GlobalReference + http://acplt.org/SubmodelElementCollections/ExampleSubmodelElementCollection + + + + SubmodelElementCollection PARAMETER @@ -2864,16 +2874,6 @@ - - ExternalReference - - - GlobalReference - http://acplt.org/SubmodelElementCollections/ExampleSubmodelElementCollection - - - - SubmodelElementCollection PARAMETER diff --git a/test/compliance_tool/files/test_demo_full_example_xml_wrong_attribute_aasx/aasx/data.xml b/test/compliance_tool/files/test_demo_full_example_xml_wrong_attribute_aasx/aasx/data.xml index 2ad0344d8..5a44d10cc 100644 --- a/test/compliance_tool/files/test_demo_full_example_xml_wrong_attribute_aasx/aasx/data.xml +++ b/test/compliance_tool/files/test_demo_full_example_xml_wrong_attribute_aasx/aasx/data.xml @@ -1188,6 +1188,17 @@ true + + ExternalReference + + + GlobalReference + http://acplt.org/Properties/ExampleProperty + + + + Property + xs:string CONSTANT @@ -1405,17 +1416,6 @@ - - ExternalReference - - - GlobalReference - http://acplt.org/Properties/ExampleProperty - - - - Property - xs:string CONSTANT @@ -1630,6 +1630,7 @@ ExampleSubmodelList + SubmodelElementCollection Instance @@ -1673,7 +1674,6 @@ Instance - SubmodelElementCollection ExampleSubmodelList2 @@ -2638,6 +2638,16 @@ true + + ExternalReference + + + GlobalReference + http://acplt.org/SubmodelElementCollections/ExampleSubmodelElementCollection + + + + SubmodelElementCollection PARAMETER @@ -2864,16 +2874,6 @@ - - ExternalReference - - - GlobalReference - http://acplt.org/SubmodelElementCollections/ExampleSubmodelElementCollection - - - - SubmodelElementCollection PARAMETER From 3d80e0cb12e3c5e34b5a779c9013f897504e74bf Mon Sep 17 00:00:00 2001 From: Sebastian Heppner Date: Tue, 14 Nov 2023 17:24:40 +0100 Subject: [PATCH 05/13] adapter.xml: Remove `` from `SubmodelElement`s in XSD Version 3.0 of the spec removes the attribute `kind` from `SubmodelElement`s. While we already implemented this, it was still missing in the XSD Schema, as well as the examples. This commit fixes that. --- basyx/aas/adapter/xml/AAS.xsd | 1 - .../files/test_demo_full_example.xml | 75 ------------------- ...test_demo_full_example_wrong_attribute.xml | 75 ------------------- .../aasx/data.xml | 75 ------------------- .../aasx/data.xml | 75 ------------------- 5 files changed, 301 deletions(-) diff --git a/basyx/aas/adapter/xml/AAS.xsd b/basyx/aas/adapter/xml/AAS.xsd index bb31c376d..25d7a52b9 100644 --- a/basyx/aas/adapter/xml/AAS.xsd +++ b/basyx/aas/adapter/xml/AAS.xsd @@ -862,7 +862,6 @@ - diff --git a/test/compliance_tool/files/test_demo_full_example.xml b/test/compliance_tool/files/test_demo_full_example.xml index 584daa8f8..39fae5599 100644 --- a/test/compliance_tool/files/test_demo_full_example.xml +++ b/test/compliance_tool/files/test_demo_full_example.xml @@ -371,7 +371,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -438,7 +437,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -520,7 +518,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -544,7 +541,6 @@ Beispiel Property Element - Instance ExternalReference @@ -579,7 +575,6 @@ Beispiel Property Element - Instance ExternalReference @@ -633,7 +628,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -697,7 +691,6 @@ Beispiel RelationshipElement Element - Instance ModelReference @@ -747,7 +740,6 @@ Beispiel AnnotatedRelationshipElement Element - Instance ExternalReference @@ -787,14 +779,12 @@ PARAMETER ExampleAnnotatedProperty - Instance xs:string exampleValue PARAMETER ExampleAnnotatedRange - Instance xs:integer 1 5 @@ -814,7 +804,6 @@ Beispiel Operation Element - Instance ExternalReference @@ -850,7 +839,6 @@ Beispiel Property Element - Template ExternalReference @@ -901,7 +889,6 @@ Beispiel Property Element - Template ExternalReference @@ -952,7 +939,6 @@ Beispiel Property Element - Template ExternalReference @@ -991,7 +977,6 @@ Beispiel Capability Element - Instance ExternalReference @@ -1015,7 +1000,6 @@ Beispiel BasicEventElement Element - Instance ExternalReference @@ -1067,7 +1051,6 @@ Beispiel SubmodelElementCollection Element - Instance ExternalReference @@ -1091,7 +1074,6 @@ Beispiel Blob Element - Instance ExternalReference @@ -1117,7 +1099,6 @@ Beispiel File Element - Instance ExternalReference @@ -1143,7 +1124,6 @@ Details of the Asset Administration Shell – Ein Beispiel für eine extern referenzierte Datei - Instance ExternalReference @@ -1169,7 +1149,6 @@ Beispiel SubmodelElementList Element - Instance ExternalReference @@ -1214,7 +1193,6 @@ Beispiel Property Element - Instance ExternalReference @@ -1374,7 +1352,6 @@ Beispiel Property Element - Instance ExternalReference @@ -1422,7 +1399,6 @@ Beispiel MultiLanguageProperty Element - Instance ExternalReference @@ -1474,7 +1450,6 @@ Beispiel Range Element - Instance ExternalReference @@ -1501,7 +1476,6 @@ Beispiel Reference Element Element - Instance ExternalReference @@ -1535,7 +1509,6 @@ ExampleRelationshipElement - Instance ModelReference @@ -1565,7 +1538,6 @@ ExampleAnnotatedRelationshipElement - Instance ModelReference @@ -1595,15 +1567,12 @@ ExampleOperation - Instance ExampleCapability - Instance ExampleBasicEventElement - Instance ModelReference @@ -1625,45 +1594,37 @@ SubmodelElementCollection - Instance ExampleBlob - Instance application/pdf ExampleFile - Instance application/pdf PARAMETER ExampleMultiLanguageProperty - Instance PARAMETER ExampleProperty - Instance xs:string PARAMETER ExampleRange - Instance xs:int PARAMETER ExampleReferenceElement - Instance - Instance @@ -1718,7 +1679,6 @@ Beispiel RelationshipElement Element - Instance ExternalReference @@ -1768,7 +1728,6 @@ Beispiel AnnotatedRelationshipElement Element - Instance ExternalReference @@ -1808,7 +1767,6 @@ PARAMETER ExampleAnnotatedRange - Instance xs:integer 1 5 @@ -1816,7 +1774,6 @@ PARAMETER ExampleAnnotatedProperty - Instance xs:string exampleValue @@ -1835,7 +1792,6 @@ Beispiel Operation Element - Instance ExternalReference @@ -1871,7 +1827,6 @@ Beispiel Property Element - Template ExternalReference @@ -1922,7 +1877,6 @@ Beispiel Property Element - Template ExternalReference @@ -1973,7 +1927,6 @@ Beispiel Property Element - Template ExternalReference @@ -2012,7 +1965,6 @@ Beispiel Capability Element - Instance ExternalReference @@ -2036,7 +1988,6 @@ Beispiel BasicEventElement Element - Instance ExternalReference @@ -2088,7 +2039,6 @@ Beispiel SubmodelElementCollection Element - Instance ExternalReference @@ -2112,7 +2062,6 @@ Beispiel Blob Element - Instance ExternalReference @@ -2138,7 +2087,6 @@ Beispiel File Element - Instance ExternalReference @@ -2164,7 +2112,6 @@ Beispiel MulitLanguageProperty Element - Instance ExternalReference @@ -2198,7 +2145,6 @@ Beispiel Property Element - Instance ExternalReference @@ -2230,7 +2176,6 @@ Beispiel Range Element - Instance ExternalReference @@ -2257,7 +2202,6 @@ Beispiel Reference Element Element - Instance ExternalReference @@ -2326,7 +2270,6 @@ Beispiel RelationshipElement Element - Template ExternalReference @@ -2376,7 +2319,6 @@ Beispiel AnnotatedRelationshipElement Element - Template ExternalReference @@ -2426,7 +2368,6 @@ Beispiel Operation Element - Template ExternalReference @@ -2452,7 +2393,6 @@ Beispiel Property Element - Template ExternalReference @@ -2483,7 +2423,6 @@ Beispiel Property Element - Template ExternalReference @@ -2514,7 +2453,6 @@ Beispiel Property Element - Template ExternalReference @@ -2543,7 +2481,6 @@ Beispiel Capability Element - Template ExternalReference @@ -2567,7 +2504,6 @@ Beispiel BasicEventElement Element - Template ExternalReference @@ -2619,7 +2555,6 @@ Beispiel SubmodelElementList Element - Template ExternalReference @@ -2653,7 +2588,6 @@ Beispiel SubmodelElementCollection Element - Template ExternalReference @@ -2677,7 +2611,6 @@ Beispiel Property Element - Template ExternalReference @@ -2702,7 +2635,6 @@ Beispiel MulitLanguageProperty Element - Template ExternalReference @@ -2726,7 +2658,6 @@ Beispiel Range Element - Template ExternalReference @@ -2752,7 +2683,6 @@ Beispiel Range Element - Template ExternalReference @@ -2778,7 +2708,6 @@ Beispiel Blob Element - Template ExternalReference @@ -2804,7 +2733,6 @@ Beispiel File Element - Template ExternalReference @@ -2829,7 +2757,6 @@ Beispiel Reference Element Element - Template ExternalReference @@ -2854,7 +2781,6 @@ Beispiel SubmodelElementCollection Element - Template ExternalReference @@ -2880,7 +2806,6 @@ Beispiel SubmodelElementList Element - Template ExternalReference diff --git a/test/compliance_tool/files/test_demo_full_example_wrong_attribute.xml b/test/compliance_tool/files/test_demo_full_example_wrong_attribute.xml index f0b2a03e1..ca5cd879d 100644 --- a/test/compliance_tool/files/test_demo_full_example_wrong_attribute.xml +++ b/test/compliance_tool/files/test_demo_full_example_wrong_attribute.xml @@ -369,7 +369,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -436,7 +435,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -518,7 +516,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -542,7 +539,6 @@ Beispiel Property Element - Instance ExternalReference @@ -577,7 +573,6 @@ Beispiel Property Element - Instance ExternalReference @@ -631,7 +626,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -695,7 +689,6 @@ Beispiel RelationshipElement Element - Instance ModelReference @@ -745,7 +738,6 @@ Beispiel AnnotatedRelationshipElement Element - Instance ExternalReference @@ -785,14 +777,12 @@ PARAMETER ExampleAnnotatedProperty - Instance xs:string exampleValue PARAMETER ExampleAnnotatedRange - Instance xs:integer 1 5 @@ -812,7 +802,6 @@ Beispiel Operation Element - Instance ExternalReference @@ -848,7 +837,6 @@ Beispiel Property Element - Template ExternalReference @@ -899,7 +887,6 @@ Beispiel Property Element - Template ExternalReference @@ -950,7 +937,6 @@ Beispiel Property Element - Template ExternalReference @@ -989,7 +975,6 @@ Beispiel Capability Element - Instance ExternalReference @@ -1013,7 +998,6 @@ Beispiel BasicEventElement Element - Instance ExternalReference @@ -1065,7 +1049,6 @@ Beispiel SubmodelElementCollection Element - Instance ExternalReference @@ -1089,7 +1072,6 @@ Beispiel Blob Element - Instance ExternalReference @@ -1115,7 +1097,6 @@ Beispiel File Element - Instance ExternalReference @@ -1141,7 +1122,6 @@ Details of the Asset Administration Shell – Ein Beispiel für eine extern referenzierte Datei - Instance ExternalReference @@ -1167,7 +1147,6 @@ Beispiel SubmodelElementList Element - Instance ExternalReference @@ -1212,7 +1191,6 @@ Beispiel Property Element - Instance ExternalReference @@ -1372,7 +1350,6 @@ Beispiel Property Element - Instance ExternalReference @@ -1420,7 +1397,6 @@ Beispiel MultiLanguageProperty Element - Instance ExternalReference @@ -1472,7 +1448,6 @@ Beispiel Range Element - Instance ExternalReference @@ -1499,7 +1474,6 @@ Beispiel Reference Element Element - Instance ExternalReference @@ -1533,7 +1507,6 @@ ExampleRelationshipElement - Instance ModelReference @@ -1563,7 +1536,6 @@ ExampleAnnotatedRelationshipElement - Instance ModelReference @@ -1593,15 +1565,12 @@ ExampleOperation - Instance ExampleCapability - Instance ExampleBasicEventElement - Instance ModelReference @@ -1623,45 +1592,37 @@ SubmodelElementCollection - Instance ExampleBlob - Instance application/pdf ExampleFile - Instance application/pdf PARAMETER ExampleMultiLanguageProperty - Instance PARAMETER ExampleProperty - Instance xs:string PARAMETER ExampleRange - Instance xs:int PARAMETER ExampleReferenceElement - Instance - Instance @@ -1716,7 +1677,6 @@ Beispiel RelationshipElement Element - Instance ExternalReference @@ -1766,7 +1726,6 @@ Beispiel AnnotatedRelationshipElement Element - Instance ExternalReference @@ -1806,7 +1765,6 @@ PARAMETER ExampleAnnotatedRange - Instance xs:integer 1 5 @@ -1814,7 +1772,6 @@ PARAMETER ExampleAnnotatedProperty - Instance xs:string exampleValue @@ -1833,7 +1790,6 @@ Beispiel Operation Element - Instance ExternalReference @@ -1869,7 +1825,6 @@ Beispiel Property Element - Template ExternalReference @@ -1920,7 +1875,6 @@ Beispiel Property Element - Template ExternalReference @@ -1971,7 +1925,6 @@ Beispiel Property Element - Template ExternalReference @@ -2010,7 +1963,6 @@ Beispiel Capability Element - Instance ExternalReference @@ -2034,7 +1986,6 @@ Beispiel BasicEventElement Element - Instance ExternalReference @@ -2086,7 +2037,6 @@ Beispiel SubmodelElementCollection Element - Instance ExternalReference @@ -2110,7 +2060,6 @@ Beispiel Blob Element - Instance ExternalReference @@ -2136,7 +2085,6 @@ Beispiel File Element - Instance ExternalReference @@ -2162,7 +2110,6 @@ Beispiel MulitLanguageProperty Element - Instance ExternalReference @@ -2196,7 +2143,6 @@ Beispiel Property Element - Instance ExternalReference @@ -2228,7 +2174,6 @@ Beispiel Range Element - Instance ExternalReference @@ -2255,7 +2200,6 @@ Beispiel Reference Element Element - Instance ExternalReference @@ -2324,7 +2268,6 @@ Beispiel RelationshipElement Element - Template ExternalReference @@ -2374,7 +2317,6 @@ Beispiel AnnotatedRelationshipElement Element - Template ExternalReference @@ -2424,7 +2366,6 @@ Beispiel Operation Element - Template ExternalReference @@ -2450,7 +2391,6 @@ Beispiel Property Element - Template ExternalReference @@ -2481,7 +2421,6 @@ Beispiel Property Element - Template ExternalReference @@ -2512,7 +2451,6 @@ Beispiel Property Element - Template ExternalReference @@ -2541,7 +2479,6 @@ Beispiel Capability Element - Template ExternalReference @@ -2565,7 +2502,6 @@ Beispiel BasicEventElement Element - Template ExternalReference @@ -2617,7 +2553,6 @@ Beispiel SubmodelElementList Element - Template ExternalReference @@ -2651,7 +2586,6 @@ Beispiel SubmodelElementCollection Element - Template ExternalReference @@ -2675,7 +2609,6 @@ Beispiel Property Element - Template ExternalReference @@ -2700,7 +2633,6 @@ Beispiel MulitLanguageProperty Element - Template ExternalReference @@ -2724,7 +2656,6 @@ Beispiel Range Element - Template ExternalReference @@ -2750,7 +2681,6 @@ Beispiel Range Element - Template ExternalReference @@ -2776,7 +2706,6 @@ Beispiel Blob Element - Template ExternalReference @@ -2802,7 +2731,6 @@ Beispiel File Element - Template ExternalReference @@ -2827,7 +2755,6 @@ Beispiel Reference Element Element - Template ExternalReference @@ -2852,7 +2779,6 @@ Beispiel SubmodelElementCollection Element - Template ExternalReference @@ -2878,7 +2804,6 @@ Beispiel SubmodelElementList Element - Template ExternalReference diff --git a/test/compliance_tool/files/test_demo_full_example_xml_aasx/aasx/data.xml b/test/compliance_tool/files/test_demo_full_example_xml_aasx/aasx/data.xml index c42d76205..c0eb40769 100644 --- a/test/compliance_tool/files/test_demo_full_example_xml_aasx/aasx/data.xml +++ b/test/compliance_tool/files/test_demo_full_example_xml_aasx/aasx/data.xml @@ -379,7 +379,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -446,7 +445,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -528,7 +526,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -552,7 +549,6 @@ Beispiel Property Element - Instance ExternalReference @@ -587,7 +583,6 @@ Beispiel Property Element - Instance ExternalReference @@ -641,7 +636,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -705,7 +699,6 @@ Beispiel RelationshipElement Element - Instance ModelReference @@ -755,7 +748,6 @@ Beispiel AnnotatedRelationshipElement Element - Instance ExternalReference @@ -795,14 +787,12 @@ PARAMETER ExampleAnnotatedProperty - Instance xs:string exampleValue PARAMETER ExampleAnnotatedRange - Instance xs:integer 1 5 @@ -822,7 +812,6 @@ Beispiel Operation Element - Instance ExternalReference @@ -858,7 +847,6 @@ Beispiel Property Element - Template ExternalReference @@ -909,7 +897,6 @@ Beispiel Property Element - Template ExternalReference @@ -960,7 +947,6 @@ Beispiel Property Element - Template ExternalReference @@ -999,7 +985,6 @@ Beispiel Capability Element - Instance ExternalReference @@ -1023,7 +1008,6 @@ Beispiel BasicEventElement Element - Instance ExternalReference @@ -1075,7 +1059,6 @@ Beispiel SubmodelElementCollection Element - Instance ExternalReference @@ -1099,7 +1082,6 @@ Beispiel Blob Element - Instance ExternalReference @@ -1125,7 +1107,6 @@ Beispiel File Element - Instance ExternalReference @@ -1151,7 +1132,6 @@ Details of the Asset Administration Shell – Ein Beispiel für eine extern referenzierte Datei - Instance ExternalReference @@ -1177,7 +1157,6 @@ Beispiel SubmodelElementList Element - Instance ExternalReference @@ -1222,7 +1201,6 @@ Beispiel Property Element - Instance ExternalReference @@ -1382,7 +1360,6 @@ Beispiel Property Element - Instance ExternalReference @@ -1430,7 +1407,6 @@ Beispiel MultiLanguageProperty Element - Instance ExternalReference @@ -1482,7 +1458,6 @@ Beispiel Range Element - Instance ExternalReference @@ -1509,7 +1484,6 @@ Beispiel Reference Element Element - Instance ExternalReference @@ -1543,7 +1517,6 @@ ExampleRelationshipElement - Instance ModelReference @@ -1573,7 +1546,6 @@ ExampleAnnotatedRelationshipElement - Instance ModelReference @@ -1603,15 +1575,12 @@ ExampleOperation - Instance ExampleCapability - Instance ExampleBasicEventElement - Instance ModelReference @@ -1633,45 +1602,37 @@ SubmodelElementCollection - Instance ExampleBlob - Instance application/pdf ExampleFile - Instance application/pdf PARAMETER ExampleMultiLanguageProperty - Instance PARAMETER ExampleProperty - Instance xs:string PARAMETER ExampleRange - Instance xs:int PARAMETER ExampleReferenceElement - Instance - Instance @@ -1726,7 +1687,6 @@ Beispiel RelationshipElement Element - Instance ExternalReference @@ -1776,7 +1736,6 @@ Beispiel AnnotatedRelationshipElement Element - Instance ExternalReference @@ -1816,7 +1775,6 @@ PARAMETER ExampleAnnotatedRange - Instance xs:integer 1 5 @@ -1824,7 +1782,6 @@ PARAMETER ExampleAnnotatedProperty - Instance xs:string exampleValue @@ -1843,7 +1800,6 @@ Beispiel Operation Element - Instance ExternalReference @@ -1879,7 +1835,6 @@ Beispiel Property Element - Template ExternalReference @@ -1930,7 +1885,6 @@ Beispiel Property Element - Template ExternalReference @@ -1981,7 +1935,6 @@ Beispiel Property Element - Template ExternalReference @@ -2020,7 +1973,6 @@ Beispiel Capability Element - Instance ExternalReference @@ -2044,7 +1996,6 @@ Beispiel BasicEventElement Element - Instance ExternalReference @@ -2096,7 +2047,6 @@ Beispiel SubmodelElementCollection Element - Instance ExternalReference @@ -2120,7 +2070,6 @@ Beispiel Blob Element - Instance ExternalReference @@ -2146,7 +2095,6 @@ Beispiel File Element - Instance ExternalReference @@ -2172,7 +2120,6 @@ Beispiel MulitLanguageProperty Element - Instance ExternalReference @@ -2206,7 +2153,6 @@ Beispiel Property Element - Instance ExternalReference @@ -2238,7 +2184,6 @@ Beispiel Range Element - Instance ExternalReference @@ -2265,7 +2210,6 @@ Beispiel Reference Element Element - Instance ExternalReference @@ -2334,7 +2278,6 @@ Beispiel RelationshipElement Element - Template ExternalReference @@ -2384,7 +2327,6 @@ Beispiel AnnotatedRelationshipElement Element - Template ExternalReference @@ -2434,7 +2376,6 @@ Beispiel Operation Element - Template ExternalReference @@ -2460,7 +2401,6 @@ Beispiel Property Element - Template ExternalReference @@ -2491,7 +2431,6 @@ Beispiel Property Element - Template ExternalReference @@ -2522,7 +2461,6 @@ Beispiel Property Element - Template ExternalReference @@ -2551,7 +2489,6 @@ Beispiel Capability Element - Template ExternalReference @@ -2575,7 +2512,6 @@ Beispiel BasicEventElement Element - Template ExternalReference @@ -2627,7 +2563,6 @@ Beispiel SubmodelElementList Element - Template ExternalReference @@ -2661,7 +2596,6 @@ Beispiel SubmodelElementCollection Element - Template ExternalReference @@ -2685,7 +2619,6 @@ Beispiel Property Element - Template ExternalReference @@ -2710,7 +2643,6 @@ Beispiel MulitLanguageProperty Element - Template ExternalReference @@ -2734,7 +2666,6 @@ Beispiel Range Element - Template ExternalReference @@ -2760,7 +2691,6 @@ Beispiel Range Element - Template ExternalReference @@ -2786,7 +2716,6 @@ Beispiel Blob Element - Template ExternalReference @@ -2812,7 +2741,6 @@ Beispiel File Element - Template ExternalReference @@ -2837,7 +2765,6 @@ Beispiel Reference Element Element - Template ExternalReference @@ -2862,7 +2789,6 @@ Beispiel SubmodelElementCollection Element - Template ExternalReference @@ -2888,7 +2814,6 @@ Beispiel SubmodelElementList Element - Template ExternalReference diff --git a/test/compliance_tool/files/test_demo_full_example_xml_wrong_attribute_aasx/aasx/data.xml b/test/compliance_tool/files/test_demo_full_example_xml_wrong_attribute_aasx/aasx/data.xml index 5a44d10cc..5e952db2f 100644 --- a/test/compliance_tool/files/test_demo_full_example_xml_wrong_attribute_aasx/aasx/data.xml +++ b/test/compliance_tool/files/test_demo_full_example_xml_wrong_attribute_aasx/aasx/data.xml @@ -379,7 +379,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -446,7 +445,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -528,7 +526,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -552,7 +549,6 @@ Beispiel Property Element - Instance ExternalReference @@ -587,7 +583,6 @@ Beispiel Property Element - Instance ExternalReference @@ -641,7 +636,6 @@ Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist - Instance ExternalReference @@ -705,7 +699,6 @@ Beispiel RelationshipElement Element - Instance ModelReference @@ -755,7 +748,6 @@ Beispiel AnnotatedRelationshipElement Element - Instance ExternalReference @@ -795,14 +787,12 @@ PARAMETER ExampleAnnotatedProperty - Instance xs:string exampleValue PARAMETER ExampleAnnotatedRange - Instance xs:integer 1 5 @@ -822,7 +812,6 @@ Beispiel Operation Element - Instance ExternalReference @@ -858,7 +847,6 @@ Beispiel Property Element - Template ExternalReference @@ -909,7 +897,6 @@ Beispiel Property Element - Template ExternalReference @@ -960,7 +947,6 @@ Beispiel Property Element - Template ExternalReference @@ -999,7 +985,6 @@ Beispiel Capability Element - Instance ExternalReference @@ -1023,7 +1008,6 @@ Beispiel BasicEventElement Element - Instance ExternalReference @@ -1075,7 +1059,6 @@ Beispiel SubmodelElementCollection Element - Instance ExternalReference @@ -1099,7 +1082,6 @@ Beispiel Blob Element - Instance ExternalReference @@ -1125,7 +1107,6 @@ Beispiel File Element - Instance ExternalReference @@ -1151,7 +1132,6 @@ Details of the Asset Administration Shell – Ein Beispiel für eine extern referenzierte Datei - Instance ExternalReference @@ -1177,7 +1157,6 @@ Beispiel SubmodelElementList Element - Instance ExternalReference @@ -1222,7 +1201,6 @@ Beispiel Property Element - Instance ExternalReference @@ -1382,7 +1360,6 @@ Beispiel Property Element - Instance ExternalReference @@ -1430,7 +1407,6 @@ Beispiel MultiLanguageProperty Element - Instance ExternalReference @@ -1482,7 +1458,6 @@ Beispiel Range Element - Instance ExternalReference @@ -1509,7 +1484,6 @@ Beispiel Reference Element Element - Instance ExternalReference @@ -1543,7 +1517,6 @@ ExampleRelationshipElement - Instance ModelReference @@ -1573,7 +1546,6 @@ ExampleAnnotatedRelationshipElement - Instance ModelReference @@ -1603,15 +1575,12 @@ ExampleOperation - Instance ExampleCapability - Instance ExampleBasicEventElement - Instance ModelReference @@ -1633,45 +1602,37 @@ SubmodelElementCollection - Instance ExampleBlob - Instance application/pdf ExampleFile - Instance application/pdf PARAMETER ExampleMultiLanguageProperty - Instance PARAMETER ExampleProperty - Instance xs:string PARAMETER ExampleRange - Instance xs:int PARAMETER ExampleReferenceElement - Instance - Instance @@ -1726,7 +1687,6 @@ Beispiel RelationshipElement Element - Instance ExternalReference @@ -1776,7 +1736,6 @@ Beispiel AnnotatedRelationshipElement Element - Instance ExternalReference @@ -1816,7 +1775,6 @@ PARAMETER ExampleAnnotatedRange - Instance xs:integer 1 5 @@ -1824,7 +1782,6 @@ PARAMETER ExampleAnnotatedProperty - Instance xs:string exampleValue @@ -1843,7 +1800,6 @@ Beispiel Operation Element - Instance ExternalReference @@ -1879,7 +1835,6 @@ Beispiel Property Element - Template ExternalReference @@ -1930,7 +1885,6 @@ Beispiel Property Element - Template ExternalReference @@ -1981,7 +1935,6 @@ Beispiel Property Element - Template ExternalReference @@ -2020,7 +1973,6 @@ Beispiel Capability Element - Instance ExternalReference @@ -2044,7 +1996,6 @@ Beispiel BasicEventElement Element - Instance ExternalReference @@ -2096,7 +2047,6 @@ Beispiel SubmodelElementCollection Element - Instance ExternalReference @@ -2120,7 +2070,6 @@ Beispiel Blob Element - Instance ExternalReference @@ -2146,7 +2095,6 @@ Beispiel File Element - Instance ExternalReference @@ -2172,7 +2120,6 @@ Beispiel MulitLanguageProperty Element - Instance ExternalReference @@ -2206,7 +2153,6 @@ Beispiel Property Element - Instance ExternalReference @@ -2238,7 +2184,6 @@ Beispiel Range Element - Instance ExternalReference @@ -2265,7 +2210,6 @@ Beispiel Reference Element Element - Instance ExternalReference @@ -2334,7 +2278,6 @@ Beispiel RelationshipElement Element - Template ExternalReference @@ -2384,7 +2327,6 @@ Beispiel AnnotatedRelationshipElement Element - Template ExternalReference @@ -2434,7 +2376,6 @@ Beispiel Operation Element - Template ExternalReference @@ -2460,7 +2401,6 @@ Beispiel Property Element - Template ExternalReference @@ -2491,7 +2431,6 @@ Beispiel Property Element - Template ExternalReference @@ -2522,7 +2461,6 @@ Beispiel Property Element - Template ExternalReference @@ -2551,7 +2489,6 @@ Beispiel Capability Element - Template ExternalReference @@ -2575,7 +2512,6 @@ Beispiel BasicEventElement Element - Template ExternalReference @@ -2627,7 +2563,6 @@ Beispiel SubmodelElementList Element - Template ExternalReference @@ -2661,7 +2596,6 @@ Beispiel SubmodelElementCollection Element - Template ExternalReference @@ -2685,7 +2619,6 @@ Beispiel Property Element - Template ExternalReference @@ -2710,7 +2643,6 @@ Beispiel MulitLanguageProperty Element - Template ExternalReference @@ -2734,7 +2666,6 @@ Beispiel Range Element - Template ExternalReference @@ -2760,7 +2691,6 @@ Beispiel Range Element - Template ExternalReference @@ -2786,7 +2716,6 @@ Beispiel Blob Element - Template ExternalReference @@ -2812,7 +2741,6 @@ Beispiel File Element - Template ExternalReference @@ -2837,7 +2765,6 @@ Beispiel Reference Element Element - Template ExternalReference @@ -2862,7 +2789,6 @@ Beispiel SubmodelElementCollection Element - Template ExternalReference @@ -2888,7 +2814,6 @@ Beispiel SubmodelElementList Element - Template ExternalReference From 60719344aafe19e9b0cd02f61d4e9e7308687545 Mon Sep 17 00:00:00 2001 From: Sebastian Heppner Date: Wed, 15 Nov 2023 09:46:42 +0100 Subject: [PATCH 06/13] adapter.xml: Fix deserialization for `Extension` Currently, the XML deserialization missed the `` wrapper around the single references inside `Extension.refers_to`. This commit fixes that. --- basyx/aas/adapter/xml/xml_deserialization.py | 6 ++++-- .../test_demo_full_example_wrong_attribute.xml | 14 ++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/basyx/aas/adapter/xml/xml_deserialization.py b/basyx/aas/adapter/xml/xml_deserialization.py index a2acc55a2..abc737b2f 100644 --- a/basyx/aas/adapter/xml/xml_deserialization.py +++ b/basyx/aas/adapter/xml/xml_deserialization.py @@ -692,8 +692,10 @@ def construct_extension(cls, element: etree.Element, object_class=model.Extensio value = _get_text_or_none(element.find(NS_AAS + "value")) if value is not None: extension.value = model.datatypes.from_xsd(value, extension.value_type) - extension.refers_to = _failsafe_construct_multiple(element.findall(NS_AAS + "refersTo"), - cls._construct_referable_reference, cls.failsafe) + extension.refers_to = _failsafe_construct_multiple( + element.find(NS_AAS + "refersTo").findall(NS_AAS + "reference"), + cls._construct_referable_reference, cls.failsafe + ) cls._amend_abstract_attributes(extension, element) return extension diff --git a/test/compliance_tool/files/test_demo_full_example_wrong_attribute.xml b/test/compliance_tool/files/test_demo_full_example_wrong_attribute.xml index ca5cd879d..061ee58b6 100644 --- a/test/compliance_tool/files/test_demo_full_example_wrong_attribute.xml +++ b/test/compliance_tool/files/test_demo_full_example_wrong_attribute.xml @@ -347,13 +347,15 @@ xs:string ExampleExtensionValue + ModelReference - - - AssetAdministrationShell - http://acplt.org/RefersTo/ExampleRefersTo - - + + + AssetAdministrationShell + http://acplt.org/RefersTo/ExampleRefersTo + + + From 58f4597cdf8e34c600761fb070ff81eeb68b0b25 Mon Sep 17 00:00:00 2001 From: Sebastian Heppner Date: Wed, 15 Nov 2023 10:10:18 +0100 Subject: [PATCH 07/13] model.Extension: Change refers_to to be of type `List[Reference]` Currently, `Extension.refers_to` is declared as a `Iterable[Reference]`. This implies, that we can not necessarily check, whether or not the attribute is empty or not. This creates a problem with the XML serialization, since the `` element should only appear if there is at least one `Reference` inside. This commit changes the `Extension.refers_to` to be a list of `Reference`s, as well as adapting a more clear check whether or not the attribute is empty in `adapter.xml.xml_serialization`. --- basyx/aas/adapter/xml/xml_serialization.py | 2 +- basyx/aas/examples/data/example_aas.py | 4 ++-- basyx/aas/model/base.py | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/basyx/aas/adapter/xml/xml_serialization.py b/basyx/aas/adapter/xml/xml_serialization.py index f3c93800a..106535ae1 100644 --- a/basyx/aas/adapter/xml/xml_serialization.py +++ b/basyx/aas/adapter/xml/xml_serialization.py @@ -277,7 +277,7 @@ def extension_to_xml(obj: model.Extension, tag: str = NS_AAS+"extension") -> etr text=model.datatypes.XSD_TYPE_NAMES[obj.value_type])) if obj.value: et_extension.append(_value_to_xml(obj.value, obj.value_type)) # type: ignore # (value_type could be None) - if obj.refers_to: + if len(obj.refers_to) > 0: refers_to = _generate_element(NS_AAS+"refersTo") for reference in obj.refers_to: refers_to.append(reference_to_xml(reference, NS_AAS+"reference")) diff --git a/basyx/aas/examples/data/example_aas.py b/basyx/aas/examples/data/example_aas.py index 49d3847c4..925b4508f 100644 --- a/basyx/aas/examples/data/example_aas.py +++ b/basyx/aas/examples/data/example_aas.py @@ -101,9 +101,9 @@ def create_example_asset_identification_submodel() -> model.Submodel: name='ExampleExtension', value_type=model.datatypes.String, value="ExampleExtensionValue", - refers_to=(model.ModelReference((model.Key(type_=model.KeyTypes.ASSET_ADMINISTRATION_SHELL, + refers_to=[model.ModelReference((model.Key(type_=model.KeyTypes.ASSET_ADMINISTRATION_SHELL, value='http://acplt.org/RefersTo/ExampleRefersTo'),), - model.AssetAdministrationShell),)) + model.AssetAdministrationShell)],) # Property-Element conform to 'Verwaltungssschale in der Praxis' page 41 ManufacturerName: # https://www.plattform-i40.de/PI40/Redaktion/DE/Downloads/Publikation/2019-verwaltungsschale-in-der-praxis.html diff --git a/basyx/aas/model/base.py b/basyx/aas/model/base.py index 439f45427..951adaafc 100644 --- a/basyx/aas/model/base.py +++ b/basyx/aas/model/base.py @@ -1458,7 +1458,7 @@ def __init__(self, name: NameType, value_type: Optional[DataTypeDefXsd] = None, value: Optional[ValueDataType] = None, - refers_to: Iterable[ModelReference] = (), + refers_to: Optional[List[ModelReference]] = None, semantic_id: Optional[Reference] = None, supplemental_semantic_id: Iterable[Reference] = ()): super().__init__() @@ -1468,7 +1468,10 @@ def __init__(self, self.value_type: Optional[DataTypeDefXsd] = value_type self._value: Optional[ValueDataType] self.value = value - self.refers_to: Iterable[ModelReference] = refers_to + if refers_to is None: + self.refers_to: List[ModelReference] = [] + else: + self.refers_to = refers_to self.semantic_id: Optional[Reference] = semantic_id self.supplemental_semantic_id: ConstrainedList[Reference] = ConstrainedList(supplemental_semantic_id) From a14eed996e1626f7b8c1e7b6a0a7606a1b0fcb0c Mon Sep 17 00:00:00 2001 From: zrgt Date: Wed, 15 Nov 2023 18:16:10 +0100 Subject: [PATCH 08/13] Refactor _abstract_classes_to_json extract methods --- basyx/aas/adapter/json/json_serialization.py | 103 ++++++++++++------- 1 file changed, 65 insertions(+), 38 deletions(-) diff --git a/basyx/aas/adapter/json/json_serialization.py b/basyx/aas/adapter/json/json_serialization.py index 17fff2680..705682415 100644 --- a/basyx/aas/adapter/json/json_serialization.py +++ b/basyx/aas/adapter/json/json_serialization.py @@ -62,7 +62,7 @@ def default(self, obj: object) -> object: :param obj: The object to serialize to json :return: The serialized object """ - mapping: Dict[Type, Callable] = { + serialization_methods: Dict[Type, Callable] = { model.AdministrativeInformation: self._administrative_information_to_json, model.AnnotatedRelationshipElement: self._annotated_relationship_element_to_json, model.AssetAdministrationShell: self._asset_administration_shell_to_json, @@ -92,10 +92,10 @@ def default(self, obj: object) -> object: model.SubmodelElementList: self._submodel_element_list_to_json, model.ValueReferencePair: self._value_reference_pair_to_json, } - for typ in mapping: + for typ in serialization_methods: if isinstance(obj, typ): - mapping_method = mapping[typ] - return mapping_method(obj) + serialization_method = serialization_methods[typ] + return serialization_method(obj) return super().default(obj) @classmethod @@ -108,48 +108,75 @@ def _abstract_classes_to_json(cls, obj: object) -> Dict[str, object]: """ data: Dict[str, object] = {} if isinstance(obj, model.HasExtension) and not cls.stripped: - if obj.extension: - data['extensions'] = list(obj.extension) + cls._extend_with_has_extension_attrs(data, obj) if isinstance(obj, model.HasDataSpecification) and not cls.stripped: - if obj.embedded_data_specifications: - data['embeddedDataSpecifications'] = [ - {'dataSpecification': spec.data_specification, - 'dataSpecificationContent': spec.data_specification_content} - for spec in obj.embedded_data_specifications - ] - + cls._extend_with_has_data_specification_specific_attrs(data, obj) if isinstance(obj, model.Referable): - if obj.id_short and not isinstance(obj.parent, model.SubmodelElementList): - data['idShort'] = obj.id_short - if obj.display_name: - data['displayName'] = obj.display_name - if obj.category: - data['category'] = obj.category - if obj.description: - data['description'] = obj.description - try: - ref_type = next(iter(t for t in inspect.getmro(type(obj)) if t in model.KEY_TYPES_CLASSES)) - except StopIteration as e: - raise TypeError("Object of type {} is Referable but does not inherit from a known AAS type" - .format(obj.__class__.__name__)) from e - data['modelType'] = ref_type.__name__ + cls._extend_with_referable_attrs(data, obj) if isinstance(obj, model.Identifiable): - data['id'] = obj.id - if obj.administration: - data['administration'] = obj.administration + cls._extend_with_identifiable_attrs(data, obj) if isinstance(obj, model.HasSemantics): - if obj.semantic_id: - data['semanticId'] = obj.semantic_id - if obj.supplemental_semantic_id: - data['supplementalSemanticIds'] = list(obj.supplemental_semantic_id) + cls._extend_with_has_semantics_attrs(data, obj) if isinstance(obj, model.HasKind): - if obj.kind is model.ModellingKind.TEMPLATE: - data['kind'] = _generic.MODELLING_KIND[obj.kind] + cls._extend_with_has_kind_attrs(data, obj) if isinstance(obj, model.Qualifiable) and not cls.stripped: - if obj.qualifier: - data['qualifiers'] = list(obj.qualifier) + cls._extend_with_qualifiable_attrs(data, obj) return data + @classmethod + def _extend_with_has_extension_attrs(cls, data: Dict[str, object], obj: model.HasExtension): + if obj.extension: + data['extensions'] = list(obj.extension) + + @classmethod + def _extend_with_has_data_specification_specific_attrs(cls, data: Dict[str, object], obj: model.HasDataSpecification): + if obj.embedded_data_specifications: + data['embeddedDataSpecifications'] = [ + {'dataSpecification': spec.data_specification, + 'dataSpecificationContent': spec.data_specification_content} + for spec in obj.embedded_data_specifications + ] + + @classmethod + def _extend_with_referable_attrs(cls, data: Dict[str, object], obj: model.Referable): + if obj.id_short and not isinstance(obj.parent, model.SubmodelElementList): + data['idShort'] = obj.id_short + if obj.display_name: + data['displayName'] = obj.display_name + if obj.category: + data['category'] = obj.category + if obj.description: + data['description'] = obj.description + try: + ref_type = next(iter(t for t in inspect.getmro(type(obj)) if t in model.KEY_TYPES_CLASSES)) + except StopIteration as e: + raise TypeError("Object of type {} is Referable but does not inherit from a known AAS type" + .format(obj.__class__.__name__)) from e + data['modelType'] = ref_type.__name__ + + @classmethod + def _extend_with_identifiable_attrs(cls, data: Dict[str, object], obj: model.Identifiable): + data['id'] = obj.id + if obj.administration: + data['administration'] = obj.administration + + @classmethod + def _extend_with_has_semantics_attrs(cls, data: Dict[str, object], obj: model.HasSemantics): + if obj.semantic_id: + data['semanticId'] = obj.semantic_id + if obj.supplemental_semantic_id: + data['supplementalSemanticIds'] = list(obj.supplemental_semantic_id) + + @classmethod + def _extend_with_has_kind_attrs(cls, data: Dict[str, object], obj: model.HasKind): + if obj.kind is model.ModellingKind.TEMPLATE: + data['kind'] = _generic.MODELLING_KIND[obj.kind] + + @classmethod + def _extend_with_qualifiable_attrs(cls, data: Dict[str, object], obj: model.Qualifiable): + if obj.qualifier: + data['qualifiers'] = list(obj.qualifier) + # ############################################################# # transformation functions to serialize classes from model.base # ############################################################# From c66a4bd9b3b5d5b9d89cc62c014eebde7175a7c3 Mon Sep 17 00:00:00 2001 From: zrgt Date: Wed, 15 Nov 2023 18:35:53 +0100 Subject: [PATCH 09/13] Refactor _amend_abstract_attributes extract methods --- .../aas/adapter/json/json_deserialization.py | 106 +++++++++++------- 1 file changed, 65 insertions(+), 41 deletions(-) diff --git a/basyx/aas/adapter/json/json_deserialization.py b/basyx/aas/adapter/json/json_deserialization.py index 262aebea4..ee46b8c0f 100644 --- a/basyx/aas/adapter/json/json_deserialization.py +++ b/basyx/aas/adapter/json/json_deserialization.py @@ -70,7 +70,7 @@ def _get_ts(dct: Dict[str, object], key: str, type_: Type[T]) -> T: return val -def _expect_type(object_: object, type_: Type, context: str, failsafe: bool) -> bool: +def _is_of_type(object_: object, type_: Type, context: str, failsafe: bool) -> bool: """ Helper function to check type of an embedded object. @@ -232,48 +232,72 @@ def _amend_abstract_attributes(cls, obj: object, dct: Dict[str, object]) -> None :param dct: The object's dict representation from JSON """ if isinstance(obj, model.Referable): - if 'idShort' in dct: - obj.id_short = _get_ts(dct, 'idShort', str) - if 'category' in dct: - obj.category = _get_ts(dct, 'category', str) - if 'displayName' in dct: - obj.display_name = cls._construct_lang_string_set(_get_ts(dct, 'displayName', list), - model.MultiLanguageNameType) - if 'description' in dct: - obj.description = cls._construct_lang_string_set(_get_ts(dct, 'description', list), - model.MultiLanguageTextType) + cls._amend_referable_attrs(obj, dct) if isinstance(obj, model.Identifiable): - if 'administration' in dct: - obj.administration = cls._construct_administrative_information(_get_ts(dct, 'administration', dict)) + cls._amend_identifiable_attrs(obj, dct) if isinstance(obj, model.HasSemantics): - if 'semanticId' in dct: - obj.semantic_id = cls._construct_reference(_get_ts(dct, 'semanticId', dict)) - if 'supplementalSemanticIds' in dct: - for ref in _get_ts(dct, 'supplementalSemanticIds', list): - obj.supplemental_semantic_id.append(cls._construct_reference(ref)) + cls._amend_has_semantics_attrs(obj, dct) # `HasKind` provides only mandatory, immutable attributes; so we cannot do anything here, after object creation. # However, the `cls._get_kind()` function may assist by retrieving them from the JSON object if isinstance(obj, model.Qualifiable) and not cls.stripped: - if 'qualifiers' in dct: - for constraint_dct in _get_ts(dct, 'qualifiers', list): - constraint = cls._construct_qualifier(constraint_dct) - obj.qualifier.add(constraint) + cls._amend_qualifiable_attrs(obj, dct) if isinstance(obj, model.HasDataSpecification) and not cls.stripped: - if 'embeddedDataSpecifications' in dct: - for dspec in _get_ts(dct, 'embeddedDataSpecifications', list): - obj.embedded_data_specifications.append( - # TODO: remove the following type: ignore comment when mypy supports abstract types for Type[T] - # see https://github.com/python/mypy/issues/5374 - model.EmbeddedDataSpecification( - data_specification=cls._construct_reference(_get_ts(dspec, 'dataSpecification', dict)), - data_specification_content=_get_ts(dspec, 'dataSpecificationContent', - model.DataSpecificationContent) # type: ignore - ) - ) + cls._amend_has_data_specification_attrs(obj, dct) if isinstance(obj, model.HasExtension) and not cls.stripped: - if 'extensions' in dct: - for extension in _get_ts(dct, 'extensions', list): - obj.extension.add(cls._construct_extension(extension)) + cls._amend_has_extension_attrs(obj, dct) + + @classmethod + def _amend_referable_attrs(cls, obj: model.Referable, dct: Dict[str, object]): + if 'idShort' in dct: + obj.id_short = _get_ts(dct, 'idShort', str) + if 'category' in dct: + obj.category = _get_ts(dct, 'category', str) + if 'displayName' in dct: + obj.display_name = cls._construct_lang_string_set(_get_ts(dct, 'displayName', list), + model.MultiLanguageNameType) + if 'description' in dct: + obj.description = cls._construct_lang_string_set(_get_ts(dct, 'description', list), + model.MultiLanguageTextType) + + @classmethod + def _amend_identifiable_attrs(cls, obj: model.Identifiable, dct: Dict[str, object]): + if 'administration' in dct: + obj.administration = cls._construct_administrative_information(_get_ts(dct, 'administration', dict)) + + @classmethod + def _amend_has_semantics_attrs(cls, obj: model.HasSemantics, dct: Dict[str, object]): + if 'semanticId' in dct: + obj.semantic_id = cls._construct_reference(_get_ts(dct, 'semanticId', dict)) + if 'supplementalSemanticIds' in dct: + for ref in _get_ts(dct, 'supplementalSemanticIds', list): + obj.supplemental_semantic_id.append(cls._construct_reference(ref)) + + @classmethod + def _amend_qualifiable_attrs(cls, obj: model.Qualifiable, dct: Dict[str, object]): + if 'qualifiers' in dct: + for constraint_dct in _get_ts(dct, 'qualifiers', list): + constraint = cls._construct_qualifier(constraint_dct) + obj.qualifier.add(constraint) + + @classmethod + def _amend_has_data_specification_attrs(cls, obj: model.HasDataSpecification, dct: Dict[str, object]): + if 'embeddedDataSpecifications' in dct: + for dspec in _get_ts(dct, 'embeddedDataSpecifications', list): + obj.embedded_data_specifications.append( + # TODO: remove the following type: ignore comment when mypy supports abstract types for Type[T] + # see https://github.com/python/mypy/issues/5374 + model.EmbeddedDataSpecification( + data_specification=cls._construct_reference(_get_ts(dspec, 'dataSpecification', dict)), + data_specification_content=_get_ts(dspec, 'dataSpecificationContent', + model.DataSpecificationContent) # type: ignore + ) + ) + + @classmethod + def _amend_has_extension_attrs(cls, obj: model.HasExtension, dct: Dict[str, object]): + if 'extensions' in dct: + for extension in _get_ts(dct, 'extensions', list): + obj.extension.add(cls._construct_extension(extension)) @classmethod def _get_kind(cls, dct: Dict[str, object]) -> model.ModellingKind: @@ -517,7 +541,7 @@ def _construct_entity(cls, dct: Dict[str, object], object_class=model.Entity) -> cls._amend_abstract_attributes(ret, dct) if not cls.stripped and 'statements' in dct: for element in _get_ts(dct, "statements", list): - if _expect_type(element, model.SubmodelElement, str(ret), cls.failsafe): + if _is_of_type(element, model.SubmodelElement, str(ret), cls.failsafe): ret.statement.add(element) return ret @@ -554,7 +578,7 @@ def _construct_submodel(cls, dct: Dict[str, object], object_class=model.Submodel cls._amend_abstract_attributes(ret, dct) if not cls.stripped and 'submodelElements' in dct: for element in _get_ts(dct, "submodelElements", list): - if _expect_type(element, model.SubmodelElement, str(ret), cls.failsafe): + if _is_of_type(element, model.SubmodelElement, str(ret), cls.failsafe): ret.submodel_element.add(element) return ret @@ -633,7 +657,7 @@ def _construct_annotated_relationship_element( cls._amend_abstract_attributes(ret, dct) if not cls.stripped and 'annotations' in dct: for element in _get_ts(dct, 'annotations', list): - if _expect_type(element, model.DataElement, str(ret), cls.failsafe): + if _is_of_type(element, model.DataElement, str(ret), cls.failsafe): ret.annotation.add(element) return ret @@ -645,7 +669,7 @@ def _construct_submodel_element_collection(cls, dct: Dict[str, object], cls._amend_abstract_attributes(ret, dct) if not cls.stripped and 'value' in dct: for element in _get_ts(dct, "value", list): - if _expect_type(element, model.SubmodelElement, str(ret), cls.failsafe): + if _is_of_type(element, model.SubmodelElement, str(ret), cls.failsafe): ret.value.add(element) return ret @@ -670,7 +694,7 @@ def _construct_submodel_element_list(cls, dct: Dict[str, object], object_class=m cls._amend_abstract_attributes(ret, dct) if not cls.stripped and 'value' in dct: for element in _get_ts(dct, 'value', list): - if _expect_type(element, type_value_list_element, str(ret), cls.failsafe): + if _is_of_type(element, type_value_list_element, str(ret), cls.failsafe): ret.value.add(element) return ret From 2a49abdeef829be97dc88759d7133c7e56077152 Mon Sep 17 00:00:00 2001 From: zrgt Date: Wed, 15 Nov 2023 18:43:49 +0100 Subject: [PATCH 10/13] Refactor _amend_abstract_attributes extract methods --- basyx/aas/adapter/xml/xml_deserialization.py | 106 ++++++++++++------- 1 file changed, 65 insertions(+), 41 deletions(-) diff --git a/basyx/aas/adapter/xml/xml_deserialization.py b/basyx/aas/adapter/xml/xml_deserialization.py index abc737b2f..87a3ff80b 100644 --- a/basyx/aas/adapter/xml/xml_deserialization.py +++ b/basyx/aas/adapter/xml/xml_deserialization.py @@ -436,52 +436,76 @@ def _amend_abstract_attributes(cls, obj: object, element: etree.Element) -> None :return: None """ if isinstance(obj, model.Referable): - id_short = _get_text_or_none(element.find(NS_AAS + "idShort")) - if id_short is not None: - obj.id_short = id_short - category = _get_text_or_none(element.find(NS_AAS + "category")) - display_name = _failsafe_construct(element.find(NS_AAS + "displayName"), - cls.construct_multi_language_name_type, cls.failsafe) - if display_name is not None: - obj.display_name = display_name - if category is not None: - obj.category = category - description = _failsafe_construct(element.find(NS_AAS + "description"), - cls.construct_multi_language_text_type, cls.failsafe) - if description is not None: - obj.description = description + cls._amend_referable_attrs(element, obj) if isinstance(obj, model.Identifiable): - administration = _failsafe_construct(element.find(NS_AAS + "administration"), - cls.construct_administrative_information, cls.failsafe) - if administration: - obj.administration = administration + cls._amend_identifiable_attrs(element, obj) if isinstance(obj, model.HasSemantics): - semantic_id = _failsafe_construct(element.find(NS_AAS + "semanticId"), cls.construct_reference, - cls.failsafe) - if semantic_id is not None: - obj.semantic_id = semantic_id - supplemental_semantic_ids = element.find(NS_AAS + "supplementalSemanticIds") - if supplemental_semantic_ids is not None: - for supplemental_semantic_id in _child_construct_multiple(supplemental_semantic_ids, - NS_AAS + "reference", cls.construct_reference, - cls.failsafe): - obj.supplemental_semantic_id.append(supplemental_semantic_id) + cls._amend_has_semantics_attrs(element, obj) if isinstance(obj, model.Qualifiable) and not cls.stripped: - qualifiers_elem = element.find(NS_AAS + "qualifiers") - if qualifiers_elem is not None and len(qualifiers_elem) > 0: - for qualifier in _failsafe_construct_multiple(qualifiers_elem, cls.construct_qualifier, cls.failsafe): - obj.qualifier.add(qualifier) + cls._amend_qualifiable_attrs(element, obj) if isinstance(obj, model.HasDataSpecification) and not cls.stripped: - embedded_data_specifications_elem = element.find(NS_AAS + "embeddedDataSpecifications") - if embedded_data_specifications_elem is not None: - for eds in _failsafe_construct_multiple(embedded_data_specifications_elem, - cls.construct_embedded_data_specification, cls.failsafe): - obj.embedded_data_specifications.append(eds) + cls.amend_has_data_specification_attrs(element, obj) if isinstance(obj, model.HasExtension) and not cls.stripped: - extension_elem = element.find(NS_AAS + "extension") - if extension_elem is not None: - for extension in _failsafe_construct_multiple(extension_elem, cls.construct_extension, cls.failsafe): - obj.extension.add(extension) + cls._amend_extension_attrs(element, obj) + + @classmethod + def _amend_referable_attrs(cls, element: etree.Element, obj: model.Referable): + id_short = _get_text_or_none(element.find(NS_AAS + "idShort")) + if id_short is not None: + obj.id_short = id_short + display_name = _failsafe_construct(element.find(NS_AAS + "displayName"), + cls.construct_multi_language_name_type, cls.failsafe) + if display_name is not None: + obj.display_name = display_name + category = _get_text_or_none(element.find(NS_AAS + "category")) + if category is not None: + obj.category = category + description = _failsafe_construct(element.find(NS_AAS + "description"), + cls.construct_multi_language_text_type, cls.failsafe) + if description is not None: + obj.description = description + + @classmethod + def _amend_identifiable_attrs(cls, element: etree.Element, obj: model.Identifiable): + administration = _failsafe_construct(element.find(NS_AAS + "administration"), + cls.construct_administrative_information, cls.failsafe) + if administration: + obj.administration = administration + + @classmethod + def _amend_has_semantics_attrs(cls, element: etree.Element, obj: model.HasSemantics): + semantic_id = _failsafe_construct(element.find(NS_AAS + "semanticId"), cls.construct_reference, + cls.failsafe) + if semantic_id is not None: + obj.semantic_id = semantic_id + supplemental_semantic_ids = element.find(NS_AAS + "supplementalSemanticIds") + if supplemental_semantic_ids is not None: + for supplemental_semantic_id in _child_construct_multiple(supplemental_semantic_ids, + NS_AAS + "reference", cls.construct_reference, + cls.failsafe): + obj.supplemental_semantic_id.append(supplemental_semantic_id) + + @classmethod + def _amend_qualifiable_attrs(cls, element: etree.Element, obj: model.Qualifiable): + qualifiers_elem = element.find(NS_AAS + "qualifiers") + if qualifiers_elem is not None and len(qualifiers_elem) > 0: + for qualifier in _failsafe_construct_multiple(qualifiers_elem, cls.construct_qualifier, cls.failsafe): + obj.qualifier.add(qualifier) + + @classmethod + def amend_has_data_specification_attrs(cls, element: etree.Element, obj: model.HasDataSpecification): + embedded_data_specifications_elem = element.find(NS_AAS + "embeddedDataSpecifications") + if embedded_data_specifications_elem is not None: + for eds in _failsafe_construct_multiple(embedded_data_specifications_elem, + cls.construct_embedded_data_specification, cls.failsafe): + obj.embedded_data_specifications.append(eds) + + @classmethod + def _amend_extension_attrs(cls, element: etree.Element, obj: model.HasExtension): + extension_elem = element.find(NS_AAS + "extension") + if extension_elem is not None: + for extension in _failsafe_construct_multiple(extension_elem, cls.construct_extension, cls.failsafe): + obj.extension.add(extension) @classmethod def _construct_relationship_element_internal(cls, element: etree.Element, object_class: Type[RE], **_kwargs: Any) \ From 05e423d16704437b1e2293ece1f1889dbd3b87ed Mon Sep 17 00:00:00 2001 From: zrgt Date: Wed, 15 Nov 2023 18:50:51 +0100 Subject: [PATCH 11/13] Refactor dicts with NS_AAS tags --- basyx/aas/adapter/xml/xml_deserialization.py | 50 ++++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/basyx/aas/adapter/xml/xml_deserialization.py b/basyx/aas/adapter/xml/xml_deserialization.py index 87a3ff80b..e2350eb8b 100644 --- a/basyx/aas/adapter/xml/xml_deserialization.py +++ b/basyx/aas/adapter/xml/xml_deserialization.py @@ -729,16 +729,16 @@ def construct_submodel_element(cls, element: etree.Element, **kwargs: Any) -> mo This function doesn't support the object_class parameter. Overwrite each individual SubmodelElement/DataElement constructor function instead. """ - submodel_elements: Dict[str, Callable[..., model.SubmodelElement]] = {NS_AAS + k: v for k, v in { - "annotatedRelationshipElement": cls.construct_annotated_relationship_element, - "basicEventElement": cls.construct_basic_event_element, - "capability": cls.construct_capability, - "entity": cls.construct_entity, - "operation": cls.construct_operation, - "relationshipElement": cls.construct_relationship_element, - "submodelElementCollection": cls.construct_submodel_element_collection, - "submodelElementList": cls.construct_submodel_element_list - }.items()} + submodel_elements: Dict[str, Callable[..., model.SubmodelElement]] = { + f"{NS_AAS}annotatedRelationshipElement": cls.construct_annotated_relationship_element, + f"{NS_AAS}basicEventElement": cls.construct_basic_event_element, + f"{NS_AAS}capability": cls.construct_capability, + f"{NS_AAS}entity": cls.construct_entity, + f"{NS_AAS}operation": cls.construct_operation, + f"{NS_AAS}relationshipElement": cls.construct_relationship_element, + f"{NS_AAS}submodelElementCollection": cls.construct_submodel_element_collection, + f"{NS_AAS}submodelElementList": cls.construct_submodel_element_list + } if element.tag not in submodel_elements: return cls.construct_data_element(element, abstract_class_name="SubmodelElement", **kwargs) return submodel_elements[element.tag](element, **kwargs) @@ -750,14 +750,14 @@ def construct_data_element(cls, element: etree.Element, abstract_class_name: str This function does not support the object_class parameter. Overwrite each individual DataElement constructor function instead. """ - data_elements: Dict[str, Callable[..., model.DataElement]] = {NS_AAS + k: v for k, v in { - "blob": cls.construct_blob, - "file": cls.construct_file, - "multiLanguageProperty": cls.construct_multi_language_property, - "property": cls.construct_property, - "range": cls.construct_range, - "referenceElement": cls.construct_reference_element, - }.items()} + data_elements: Dict[str, Callable[..., model.DataElement]] = { + f"{NS_AAS}blob": cls.construct_blob, + f"{NS_AAS}file": cls.construct_file, + f"{NS_AAS}multiLanguageProperty": cls.construct_multi_language_property, + f"{NS_AAS}property": cls.construct_property, + f"{NS_AAS}range": cls.construct_range, + f"{NS_AAS}referenceElement": cls.construct_reference_element, + } if element.tag not in data_elements: raise KeyError(_element_pretty_identifier(element) + f" is not a valid {abstract_class_name}!") return data_elements[element.tag](element, **kwargs) @@ -1112,9 +1112,9 @@ def construct_data_specification_content(cls, element: etree.Element, **kwargs: Overwrite each individual DataSpecificationContent constructor function instead. """ data_specification_contents: Dict[str, Callable[..., model.DataSpecificationContent]] = \ - {NS_AAS + k: v for k, v in { - "dataSpecificationIec61360": cls.construct_data_specification_iec61360, - }.items()} + { + f"{NS_AAS}dataSpecificationIec61360": cls.construct_data_specification_iec61360, + } if element.tag not in data_specification_contents: raise KeyError(f"{_element_pretty_identifier(element)} is not a valid DataSpecificationContent!") return data_specification_contents[element.tag](element, **kwargs) @@ -1435,13 +1435,11 @@ def read_aas_xml_file_into(object_store: model.AbstractObjectStore[model.Identif decoder_ = _select_decoder(failsafe, stripped, decoder) element_constructors: Dict[str, Callable[..., model.Identifiable]] = { - "assetAdministrationShell": decoder_.construct_asset_administration_shell, - "conceptDescription": decoder_.construct_concept_description, - "submodel": decoder_.construct_submodel + f"{NS_AAS}assetAdministrationShell": decoder_.construct_asset_administration_shell, + f"{NS_AAS}conceptDescription": decoder_.construct_concept_description, + f"{NS_AAS}submodel": decoder_.construct_submodel } - element_constructors = {NS_AAS + k: v for k, v in element_constructors.items()} - root = _parse_xml_document(file, failsafe=decoder_.failsafe, **parser_kwargs) if root is None: From 3e21ec3ceb76318cb73c8bd867f9749ab7d8622d Mon Sep 17 00:00:00 2001 From: zrgt Date: Wed, 15 Nov 2023 18:57:39 +0100 Subject: [PATCH 12/13] Refactor read_aas_xml_element --- basyx/aas/adapter/xml/xml_deserialization.py | 126 +++++++------------ 1 file changed, 46 insertions(+), 80 deletions(-) diff --git a/basyx/aas/adapter/xml/xml_deserialization.py b/basyx/aas/adapter/xml/xml_deserialization.py index e2350eb8b..952046d8d 100644 --- a/basyx/aas/adapter/xml/xml_deserialization.py +++ b/basyx/aas/adapter/xml/xml_deserialization.py @@ -1319,86 +1319,52 @@ def read_aas_xml_element(file: IO, construct: XMLConstructables, failsafe: bool decoder_ = _select_decoder(failsafe, stripped, decoder) constructor: Callable[..., object] - if construct == XMLConstructables.KEY: - constructor = decoder_.construct_key - elif construct == XMLConstructables.REFERENCE: - constructor = decoder_.construct_reference - elif construct == XMLConstructables.MODEL_REFERENCE: - constructor = decoder_.construct_model_reference - elif construct == XMLConstructables.GLOBAL_REFERENCE: - constructor = decoder_.construct_external_reference - elif construct == XMLConstructables.ADMINISTRATIVE_INFORMATION: - constructor = decoder_.construct_administrative_information - elif construct == XMLConstructables.QUALIFIER: - constructor = decoder_.construct_qualifier - elif construct == XMLConstructables.ANNOTATED_RELATIONSHIP_ELEMENT: - constructor = decoder_.construct_annotated_relationship_element - elif construct == XMLConstructables.BASIC_EVENT_ELEMENT: - constructor = decoder_.construct_basic_event_element - elif construct == XMLConstructables.BLOB: - constructor = decoder_.construct_blob - elif construct == XMLConstructables.CAPABILITY: - constructor = decoder_.construct_capability - elif construct == XMLConstructables.ENTITY: - constructor = decoder_.construct_entity - elif construct == XMLConstructables.EXTENSION: - constructor = decoder_.construct_extension - elif construct == XMLConstructables.FILE: - constructor = decoder_.construct_file - elif construct == XMLConstructables.RESOURCE: - constructor = decoder_.construct_resource - elif construct == XMLConstructables.MULTI_LANGUAGE_PROPERTY: - constructor = decoder_.construct_multi_language_property - elif construct == XMLConstructables.OPERATION: - constructor = decoder_.construct_operation - elif construct == XMLConstructables.PROPERTY: - constructor = decoder_.construct_property - elif construct == XMLConstructables.RANGE: - constructor = decoder_.construct_range - elif construct == XMLConstructables.REFERENCE_ELEMENT: - constructor = decoder_.construct_reference_element - elif construct == XMLConstructables.RELATIONSHIP_ELEMENT: - constructor = decoder_.construct_relationship_element - elif construct == XMLConstructables.SUBMODEL_ELEMENT_COLLECTION: - constructor = decoder_.construct_submodel_element_collection - elif construct == XMLConstructables.SUBMODEL_ELEMENT_LIST: - constructor = decoder_.construct_submodel_element_list - elif construct == XMLConstructables.ASSET_ADMINISTRATION_SHELL: - constructor = decoder_.construct_asset_administration_shell - elif construct == XMLConstructables.ASSET_INFORMATION: - constructor = decoder_.construct_asset_information - elif construct == XMLConstructables.SPECIFIC_ASSET_ID: - constructor = decoder_.construct_specific_asset_id - elif construct == XMLConstructables.SUBMODEL: - constructor = decoder_.construct_submodel - elif construct == XMLConstructables.VALUE_REFERENCE_PAIR: - constructor = decoder_.construct_value_reference_pair - elif construct == XMLConstructables.CONCEPT_DESCRIPTION: - constructor = decoder_.construct_concept_description - elif construct == XMLConstructables.MULTI_LANGUAGE_NAME_TYPE: - constructor = decoder_.construct_multi_language_name_type - elif construct == XMLConstructables.MULTI_LANGUAGE_TEXT_TYPE: - constructor = decoder_.construct_multi_language_text_type - elif construct == XMLConstructables.DEFINITION_TYPE_IEC61360: - constructor = decoder_.construct_definition_type_iec61360 - elif construct == XMLConstructables.PREFERRED_NAME_TYPE_IEC61360: - constructor = decoder_.construct_preferred_name_type_iec61360 - elif construct == XMLConstructables.SHORT_NAME_TYPE_IEC61360: - constructor = decoder_.construct_short_name_type_iec61360 - elif construct == XMLConstructables.EMBEDDED_DATA_SPECIFICATION: - constructor = decoder_.construct_embedded_data_specification - elif construct == XMLConstructables.DATA_SPECIFICATION_IEC61360: - constructor = decoder_.construct_data_specification_iec61360 - # the following constructors decide which constructor to call based on the elements tag - elif construct == XMLConstructables.DATA_ELEMENT: - constructor = decoder_.construct_data_element - elif construct == XMLConstructables.SUBMODEL_ELEMENT: - constructor = decoder_.construct_submodel_element - elif construct == XMLConstructables.DATA_SPECIFICATION_CONTENT: - constructor = decoder_.construct_data_specification_content - # type aliases - elif construct == XMLConstructables.VALUE_LIST: - constructor = decoder_.construct_value_list + type_constructors = { + XMLConstructables.KEY: decoder_.construct_key, + XMLConstructables.REFERENCE: decoder_.construct_reference, + XMLConstructables.MODEL_REFERENCE: decoder_.construct_model_reference, + XMLConstructables.GLOBAL_REFERENCE: decoder_.construct_external_reference, + XMLConstructables.ADMINISTRATIVE_INFORMATION: decoder_.construct_administrative_information, + XMLConstructables.QUALIFIER: decoder_.construct_qualifier, + XMLConstructables.ANNOTATED_RELATIONSHIP_ELEMENT: decoder_.construct_annotated_relationship_element, + XMLConstructables.BASIC_EVENT_ELEMENT: decoder_.construct_basic_event_element, + XMLConstructables.BLOB: decoder_.construct_blob, + XMLConstructables.CAPABILITY: decoder_.construct_capability, + XMLConstructables.ENTITY: decoder_.construct_entity, + XMLConstructables.EXTENSION: decoder_.construct_extension, + XMLConstructables.FILE: decoder_.construct_file, + XMLConstructables.RESOURCE: decoder_.construct_resource, + XMLConstructables.MULTI_LANGUAGE_PROPERTY: decoder_.construct_multi_language_property, + XMLConstructables.OPERATION: decoder_.construct_operation, + XMLConstructables.PROPERTY: decoder_.construct_property, + XMLConstructables.RANGE: decoder_.construct_range, + XMLConstructables.REFERENCE_ELEMENT: decoder_.construct_reference_element, + XMLConstructables.RELATIONSHIP_ELEMENT: decoder_.construct_relationship_element, + XMLConstructables.SUBMODEL_ELEMENT_COLLECTION: decoder_.construct_submodel_element_collection, + XMLConstructables.SUBMODEL_ELEMENT_LIST: decoder_.construct_submodel_element_list, + XMLConstructables.ASSET_ADMINISTRATION_SHELL: decoder_.construct_asset_administration_shell, + XMLConstructables.ASSET_INFORMATION: decoder_.construct_asset_information, + XMLConstructables.SPECIFIC_ASSET_ID: decoder_.construct_specific_asset_id, + XMLConstructables.SUBMODEL: decoder_.construct_submodel, + XMLConstructables.VALUE_REFERENCE_PAIR: decoder_.construct_value_reference_pair, + XMLConstructables.CONCEPT_DESCRIPTION: decoder_.construct_concept_description, + XMLConstructables.MULTI_LANGUAGE_NAME_TYPE: decoder_.construct_multi_language_name_type, + XMLConstructables.MULTI_LANGUAGE_TEXT_TYPE: decoder_.construct_multi_language_text_type, + XMLConstructables.DEFINITION_TYPE_IEC61360: decoder_.construct_definition_type_iec61360, + XMLConstructables.PREFERRED_NAME_TYPE_IEC61360: decoder_.construct_preferred_name_type_iec61360, + XMLConstructables.SHORT_NAME_TYPE_IEC61360: decoder_.construct_short_name_type_iec61360, + XMLConstructables.EMBEDDED_DATA_SPECIFICATION: decoder_.construct_embedded_data_specification, + XMLConstructables.DATA_SPECIFICATION_IEC61360: decoder_.construct_data_specification_iec61360, + # the following constructors decide which constructor to call based on the elements tag + XMLConstructables.DATA_ELEMENT: decoder_.construct_data_element, + XMLConstructables.SUBMODEL_ELEMENT: decoder_.construct_submodel_element, + XMLConstructables.DATA_SPECIFICATION_CONTENT: decoder_.construct_data_specification_content, + # type aliases + XMLConstructables.VALUE_LIST: decoder_.construct_value_list, + } + + if construct in type_constructors: + constructor = type_constructors[construct] else: raise ValueError(f"{construct.name} cannot be constructed!") From 34a6c517d7ccd38c09c01d7269df90ce448cc6e6 Mon Sep 17 00:00:00 2001 From: zrgt Date: Wed, 15 Nov 2023 19:03:37 +0100 Subject: [PATCH 13/13] Refactor abstract_classes_to_xml extract methods --- basyx/aas/adapter/xml/xml_serialization.py | 106 +++++++++++++-------- 1 file changed, 67 insertions(+), 39 deletions(-) diff --git a/basyx/aas/adapter/xml/xml_serialization.py b/basyx/aas/adapter/xml/xml_serialization.py index 106535ae1..a621d1d06 100644 --- a/basyx/aas/adapter/xml/xml_serialization.py +++ b/basyx/aas/adapter/xml/xml_serialization.py @@ -83,54 +83,82 @@ def abstract_classes_to_xml(tag: str, obj: object) -> etree.Element: """ elm = _generate_element(tag) if isinstance(obj, model.HasExtension): - if obj.extension: - et_extension = _generate_element(NS_AAS + "extensions") - for extension in obj.extension: - if isinstance(extension, model.Extension): - et_extension.append(extension_to_xml(extension, tag=NS_AAS + "extension")) - elm.append(et_extension) + _extend_with_has_extension_attrs(elm, obj) if isinstance(obj, model.Referable): - if obj.category: - elm.append(_generate_element(name=NS_AAS + "category", text=obj.category)) - if obj.id_short and not isinstance(obj.parent, model.SubmodelElementList): - elm.append(_generate_element(name=NS_AAS + "idShort", text=obj.id_short)) - if obj.display_name: - elm.append(lang_string_set_to_xml(obj.display_name, tag=NS_AAS + "displayName")) - if obj.description: - elm.append(lang_string_set_to_xml(obj.description, tag=NS_AAS + "description")) + _extend_with_referable_attrs(elm, obj) if isinstance(obj, model.Identifiable): - if obj.administration: - elm.append(administrative_information_to_xml(obj.administration)) - elm.append(_generate_element(name=NS_AAS + "id", text=obj.id)) + _extend_with_identifiable_attrs(elm, obj) if isinstance(obj, model.HasKind): - if obj.kind is model.ModellingKind.TEMPLATE: - elm.append(_generate_element(name=NS_AAS + "kind", text="Template")) - else: - # then modelling-kind is Instance - elm.append(_generate_element(name=NS_AAS + "kind", text="Instance")) + _extend_with_has_kind_attrs(elm, obj) if isinstance(obj, model.HasSemantics): - if obj.semantic_id: - elm.append(reference_to_xml(obj.semantic_id, tag=NS_AAS+"semanticId")) - if obj.supplemental_semantic_id: - et_supplemental_semantic_ids = _generate_element(NS_AAS + "supplementalSemanticIds") - for supplemental_semantic_id in obj.supplemental_semantic_id: - et_supplemental_semantic_ids.append(reference_to_xml(supplemental_semantic_id, NS_AAS+"reference")) - elm.append(et_supplemental_semantic_ids) + _extend_with_has_semantics_attrs(elm, obj) if isinstance(obj, model.Qualifiable): - if obj.qualifier: - et_qualifier = _generate_element(NS_AAS + "qualifiers") - for qualifier in obj.qualifier: - et_qualifier.append(qualifier_to_xml(qualifier, tag=NS_AAS+"qualifier")) - elm.append(et_qualifier) + _extend_with_qualifiable_attrs(elm, obj) if isinstance(obj, model.HasDataSpecification): - if obj.embedded_data_specifications: - et_embedded_data_specifications = _generate_element(NS_AAS + "embeddedDataSpecifications") - for eds in obj.embedded_data_specifications: - et_embedded_data_specifications.append(embedded_data_specification_to_xml(eds)) - elm.append(et_embedded_data_specifications) + _extend_with_has_data_specification_attrs(elm, obj) return elm +def _extend_with_has_extension_attrs(elm: etree.Element, obj: model.HasExtension): + if obj.extension: + et_extension = _generate_element(NS_AAS + "extensions") + for extension in obj.extension: + if isinstance(extension, model.Extension): + et_extension.append(extension_to_xml(extension, tag=NS_AAS + "extension")) + elm.append(et_extension) + + +def _extend_with_referable_attrs(elm: etree.Element, obj: model.Referable): + if obj.category: + elm.append(_generate_element(name=NS_AAS + "category", text=obj.category)) + if obj.id_short and not isinstance(obj.parent, model.SubmodelElementList): + elm.append(_generate_element(name=NS_AAS + "idShort", text=obj.id_short)) + if obj.display_name: + elm.append(lang_string_set_to_xml(obj.display_name, tag=NS_AAS + "displayName")) + if obj.description: + elm.append(lang_string_set_to_xml(obj.description, tag=NS_AAS + "description")) + + +def _extend_with_identifiable_attrs(elm: etree.Element, obj: model.Identifiable): + if obj.administration: + elm.append(administrative_information_to_xml(obj.administration)) + elm.append(_generate_element(name=NS_AAS + "id", text=obj.id)) + + +def _extend_with_has_kind_attrs(elm: etree.Element, obj: model.HasKind): + if obj.kind is model.ModellingKind.TEMPLATE: + elm.append(_generate_element(name=NS_AAS + "kind", text="Template")) + else: + # then modelling-kind is Instance + elm.append(_generate_element(name=NS_AAS + "kind", text="Instance")) + + +def _extend_with_has_semantics_attrs(elm: etree.Element, obj: model.HasSemantics): + if obj.semantic_id: + elm.append(reference_to_xml(obj.semantic_id, tag=NS_AAS + "semanticId")) + if obj.supplemental_semantic_id: + et_supplemental_semantic_ids = _generate_element(NS_AAS + "supplementalSemanticIds") + for supplemental_semantic_id in obj.supplemental_semantic_id: + et_supplemental_semantic_ids.append(reference_to_xml(supplemental_semantic_id, NS_AAS + "reference")) + elm.append(et_supplemental_semantic_ids) + + +def _extend_with_qualifiable_attrs(elm: etree.Element, obj: model.Qualifiable): + if obj.qualifier: + et_qualifier = _generate_element(NS_AAS + "qualifiers") + for qualifier in obj.qualifier: + et_qualifier.append(qualifier_to_xml(qualifier, tag=NS_AAS + "qualifier")) + elm.append(et_qualifier) + + +def _extend_with_has_data_specification_attrs(elm: etree.Element, obj: model.HasDataSpecification): + if obj.embedded_data_specifications: + et_embedded_data_specifications = _generate_element(NS_AAS + "embeddedDataSpecifications") + for eds in obj.embedded_data_specifications: + et_embedded_data_specifications.append(embedded_data_specification_to_xml(eds)) + elm.append(et_embedded_data_specifications) + + # ############################################################## # transformation functions to serialize classes from model.base # ##############################################################