|
5 | 5 | from aas_test_engines.reflect import reflect, StringFormattedValue, abstract |
6 | 6 |
|
7 | 7 | from dataclasses import dataclass, field |
8 | | -from typing import List, Optional, Set, Iterator, Union |
| 8 | +from typing import List, Optional, Set, Iterator, Union, Iterable |
9 | 9 | from enum import Enum |
10 | 10 | from aas_test_engines.data_types import ( |
11 | 11 | _is_bounded_integer, |
|
20 | 20 | import re |
21 | 21 |
|
22 | 22 | # TODO: AASd-021 |
23 | | -# TODO: AASd-022 |
24 | 23 | # TODO: AASd-077 |
25 | 24 |
|
26 | 25 |
|
@@ -771,6 +770,23 @@ def check_aasd_116(self): |
771 | 770 | # 5.3.6 Submodel Element |
772 | 771 |
|
773 | 772 |
|
| 773 | +def ensure_unique_id_shorts(value: Optional[Iterable[Referable]], path: IdShortPath): |
| 774 | + """ |
| 775 | + Constraint AASd-022: idShort of non-identifiable referables within the same name space shall be unique |
| 776 | + (case-sensitive). |
| 777 | + """ |
| 778 | + if value is None: |
| 779 | + return |
| 780 | + seen: Set[str] = set() |
| 781 | + for i in value: |
| 782 | + if i.id_short is None: |
| 783 | + continue |
| 784 | + if i.id_short.raw_value in seen: |
| 785 | + raise CheckConstraintException(f"AASd-022 violated: Duplicate idShort '{i.id_short}'") |
| 786 | + else: |
| 787 | + seen.add(i.id_short.raw_value) |
| 788 | + |
| 789 | + |
774 | 790 | @dataclass |
775 | 791 | @abstract |
776 | 792 | class SubmodelElement(Referable, HasSemantics, Qualifiable, HasDataSpecification): |
@@ -1069,6 +1085,9 @@ def _set_path(self, path): |
1069 | 1085 | for el in self.value: |
1070 | 1086 | el._set_path(path + el.id_short) |
1071 | 1087 |
|
| 1088 | + def check_aasd_022(self): |
| 1089 | + ensure_unique_id_shorts(self.value, self.id_short_path) |
| 1090 | + |
1072 | 1091 | def check_aasd_117(self): |
1073 | 1092 | ensure_have_id_shorts(self.value, self.id_short_path) |
1074 | 1093 |
|
@@ -1185,8 +1204,8 @@ def check_aasd_109(self): |
1185 | 1204 |
|
1186 | 1205 | def check_aasd_120(self): |
1187 | 1206 | """ |
1188 | | - Constraint AASd-117: idShort of non-identifiable Referables not being a direct child of a |
1189 | | - SubmodelElementList shall be specified. |
| 1207 | + Constraint AASd-120: idShort of submodel elements being a direct child of a SubmodelElementList shall not |
| 1208 | + be specified. |
1190 | 1209 | """ |
1191 | 1210 | if not self.value: |
1192 | 1211 | return |
@@ -1243,10 +1262,13 @@ def elements(self) -> Iterator[SubmodelElement]: |
1243 | 1262 | for element in self.submodel_elements: |
1244 | 1263 | yield from element.elements() |
1245 | 1264 |
|
| 1265 | + def check_aasd_022(self): |
| 1266 | + ensure_unique_id_shorts(self.submodel_elements, IdShortPath(self)) |
| 1267 | + |
1246 | 1268 | def check_aasd_117(self): |
1247 | 1269 | ensure_have_id_shorts(self.submodel_elements) |
1248 | 1270 |
|
1249 | | - def check_aasd119(self): |
| 1271 | + def check_aasd_119(self): |
1250 | 1272 | """ |
1251 | 1273 | Constraint AASd-119: If any Qualifier/kind value of a Qualifiable/qualifier is equal to TemplateQualifier and |
1252 | 1274 | the qualified element inherits from "hasKind", the qualified element shall be of kind Template (HasKind/kind = |
|
0 commit comments