Skip to content

Commit

Permalink
Merge pull request #106 from rwth-iat/Rename/GlobalReference
Browse files Browse the repository at this point in the history
Version 3.0 of the spec renames ReferenceTypes/GlobalReference to
ReferenceTypes/ExternalReference to avoid confusion with
KeyTypes/GlobalReference.

This merge implements these changes.
  • Loading branch information
s-heppner authored Aug 24, 2023
2 parents 3108a22 + d1dbfce commit d360723
Show file tree
Hide file tree
Showing 25 changed files with 745 additions and 737 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ submodel = model.Submodel(identifier)

Create a `Property` and add it to the `Submodel`:
```python
# create a global reference to a semantic description of the property
semantic_reference = model.GlobalReference(
# create an external reference to a semantic description of the property
semantic_reference = model.ExternalReference(
(model.Key(
type_=model.KeyTypes.GLOBAL_REFERENCE,
value='http://acplt.org/Properties/SimpleProperty'
Expand Down
2 changes: 1 addition & 1 deletion basyx/aas/adapter/_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
model.StateOfEvent.OFF: 'off'}

REFERENCE_TYPES: Dict[Type[model.Reference], str] = {
model.GlobalReference: 'GlobalReference',
model.ExternalReference: 'ExternalReference',
model.ModelReference: 'ModelReference'}

KEY_TYPES: Dict[model.KeyTypes, str] = {
Expand Down
2 changes: 1 addition & 1 deletion basyx/aas/adapter/json/aasJSONSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@
"ReferenceTypes": {
"type": "string",
"enum": [
"GlobalReference",
"ExternalReference",
"ModelReference"
]
},
Expand Down
18 changes: 9 additions & 9 deletions basyx/aas/adapter/json/json_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ def _amend_abstract_attributes(cls, obj: object, dct: Dict[str, object]) -> None
# 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_global_reference(_get_ts(dspec, 'dataSpecification',
dict)),
data_specification=cls._construct_external_reference(_get_ts(dspec, 'dataSpecification',
dict)),
data_specification_content=_get_ts(dspec, 'dataSpecificationContent',
model.DataSpecificationContent) # type: ignore
)
Expand Down Expand Up @@ -303,7 +303,7 @@ def _construct_specific_asset_id(cls, dct: Dict[str, object], object_class=model
# semantic_id can't be applied by _amend_abstract_attributes because specificAssetId is immutable
return object_class(name=_get_ts(dct, 'name', str),
value=_get_ts(dct, 'value', str),
external_subject_id=cls._construct_global_reference(
external_subject_id=cls._construct_external_reference(
_get_ts(dct, 'externalSubjectId', dict)),
semantic_id=cls._construct_reference(_get_ts(dct, 'semanticId', dict))
if 'semanticId' in dct else None,
Expand All @@ -317,16 +317,16 @@ def _construct_reference(cls, dct: Dict[str, object]) -> model.Reference:
reference_type: Type[model.Reference] = REFERENCE_TYPES_INVERSE[_get_ts(dct, 'type', str)]
if reference_type is model.ModelReference:
return cls._construct_model_reference(dct, model.Referable) # type: ignore
elif reference_type is model.GlobalReference:
return cls._construct_global_reference(dct)
elif reference_type is model.ExternalReference:
return cls._construct_external_reference(dct)
raise ValueError(f"Unsupported reference type {reference_type}!")

@classmethod
def _construct_global_reference(cls, dct: Dict[str, object], object_class=model.GlobalReference)\
-> model.GlobalReference:
def _construct_external_reference(cls, dct: Dict[str, object], object_class=model.ExternalReference)\
-> model.ExternalReference:
reference_type: Type[model.Reference] = REFERENCE_TYPES_INVERSE[_get_ts(dct, 'type', str)]
if reference_type is not model.GlobalReference:
raise ValueError(f"Expected a reference of type {model.GlobalReference}, got {reference_type}!")
if reference_type is not model.ExternalReference:
raise ValueError(f"Expected a reference of type {model.ExternalReference}, got {reference_type}!")
keys = [cls._construct_key(key_data) for key_data in _get_ts(dct, "keys", list)]
return object_class(tuple(keys), cls._construct_reference(_get_ts(dct, 'referredSemanticId', dict))
if 'referredSemanticId' in dct else None)
Expand Down
2 changes: 1 addition & 1 deletion basyx/aas/adapter/xml/AAS.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@
</xs:simpleType>
<xs:simpleType name="referenceTypes_t">
<xs:restriction base="xs:string">
<xs:enumeration value="GlobalReference"/>
<xs:enumeration value="ExternalReference"/>
<xs:enumeration value="ModelReference"/>
</xs:restriction>
</xs:simpleType>
Expand Down
16 changes: 8 additions & 8 deletions basyx/aas/adapter/xml/xml_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,18 +545,18 @@ def construct_reference(cls, element: etree.Element, namespace: str = NS_AAS, **
reference_type: Type[model.Reference] = _child_text_mandatory_mapped(element, NS_AAS + "type",
REFERENCE_TYPES_INVERSE)
references: Dict[Type[model.Reference], Callable[..., model.Reference]] = {
model.GlobalReference: cls.construct_global_reference,
model.ExternalReference: cls.construct_external_reference,
model.ModelReference: cls.construct_model_reference
}
if reference_type not in references:
raise KeyError(_element_pretty_identifier(element) + f" is of unsupported Reference type {reference_type}!")
return references[reference_type](element, namespace=namespace, **kwargs)

@classmethod
def construct_global_reference(cls, element: etree.Element, namespace: str = NS_AAS,
object_class=model.GlobalReference, **_kwargs: Any) \
-> model.GlobalReference:
_expect_reference_type(element, model.GlobalReference)
def construct_external_reference(cls, element: etree.Element, namespace: str = NS_AAS,
object_class=model.ExternalReference, **_kwargs: Any) \
-> model.ExternalReference:
_expect_reference_type(element, model.ExternalReference)
return object_class(cls._construct_key_tuple(element, namespace=namespace),
_failsafe_construct(element.find(NS_AAS + "referredSemanticId"), cls.construct_reference,
cls.failsafe, namespace=namespace))
Expand Down Expand Up @@ -967,7 +967,7 @@ def construct_specific_asset_id(cls, element: etree.Element, object_class=model.
# semantic_id can't be applied by _amend_abstract_attributes because specificAssetId is immutable
return object_class(
external_subject_id=_child_construct_mandatory(element, NS_AAS + "externalSubjectId",
cls.construct_global_reference),
cls.construct_external_reference),
name=_get_text_or_none(element.find(NS_AAS + "name")),
value=_get_text_or_none(element.find(NS_AAS + "value")),
semantic_id=_failsafe_construct(element.find(NS_AAS + "semanticId"), cls.construct_reference, cls.failsafe)
Expand Down Expand Up @@ -1059,7 +1059,7 @@ def construct_embedded_data_specification(cls, element: etree.Element, object_cl
logger.warning(f"{_element_pretty_identifier(data_specification_content)} has more than one "
"data specification, using the first one...")
embedded_data_specification = object_class(
_child_construct_mandatory(element, NS_AAS + "dataSpecification", cls.construct_global_reference),
_child_construct_mandatory(element, NS_AAS + "dataSpecification", cls.construct_external_reference),
_failsafe_construct_mandatory(data_specification_content[0], cls.construct_data_specification_content)
)
cls._amend_abstract_attributes(embedded_data_specification, element)
Expand Down Expand Up @@ -1327,7 +1327,7 @@ def read_aas_xml_element(file: IO, construct: XMLConstructables, failsafe: bool
elif construct == XMLConstructables.MODEL_REFERENCE:
constructor = decoder_.construct_model_reference
elif construct == XMLConstructables.GLOBAL_REFERENCE:
constructor = decoder_.construct_global_reference
constructor = decoder_.construct_external_reference
elif construct == XMLConstructables.ADMINISTRATIVE_INFORMATION:
constructor = decoder_.construct_administrative_information
elif construct == XMLConstructables.QUALIFIER:
Expand Down
Loading

0 comments on commit d360723

Please sign in to comment.