Skip to content

Commit

Permalink
Change construct_asset_information() in files `xml_deserialization.…
Browse files Browse the repository at this point in the history
…py` and `json_deserialization.py` to adapt to Constraint AASd-131

Both methods create the `asset_information` object with the `globalAssetId` and `specificAssetId` instead of adding both afterward. This is important, because else AASd-131 is raised.
  • Loading branch information
David Niebert committed Jun 27, 2023
1 parent 1b94d0e commit da5bb81
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
15 changes: 10 additions & 5 deletions basyx/aas/adapter/json/json_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,19 @@ def _construct_value_reference_pair(cls, dct: Dict[str, object], value_format: m
@classmethod
def _construct_asset_information(cls, dct: Dict[str, object], object_class=model.AssetInformation)\
-> model.AssetInformation:
ret = object_class(asset_kind=ASSET_KIND_INVERSE[_get_ts(dct, 'assetKind', str)])
cls._amend_abstract_attributes(ret, dct)
global_asset_id = None
specific_asset_id = None
if 'globalAssetId' in dct:
ret.global_asset_id = cls._construct_reference(_get_ts(dct, 'globalAssetId', dict))
global_asset_id = cls._construct_reference(_get_ts(dct, 'globalAssetId', dict))
if 'specificAssetIds' in dct:
specific_asset_id = []
for desc_data in _get_ts(dct, "specificAssetIds", list):
ret.specific_asset_id.add(cls._construct_specific_asset_id(desc_data,
model.SpecificAssetId))
specific_asset_id.add(cls._construct_specific_asset_id(desc_data, model.SpecificAssetId))
ret = object_class(asset_kind=ASSET_KIND_INVERSE[_get_ts(dct, 'assetKind', str)],
global_asset_id=global_asset_id,
specific_asset_id=specific_asset_id)
cls._amend_abstract_attributes(ret, dct)

if 'defaultThumbnail' in dct:
ret.default_thumbnail = cls._construct_resource(_get_ts(dct, 'defaultThumbnail', dict))
return ret
Expand Down
13 changes: 4 additions & 9 deletions basyx/aas/adapter/xml/xml_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,18 +985,13 @@ def construct_specific_asset_id(cls, element: etree.Element, object_class=model.
@classmethod
def construct_asset_information(cls, element: etree.Element, object_class=model.AssetInformation, **_kwargs: Any) \
-> model.AssetInformation:
asset_information = object_class(
_child_text_mandatory_mapped(element, NS_AAS + "assetKind", ASSET_KIND_INVERSE),
)
global_asset_id = _failsafe_construct(element.find(NS_AAS + "globalAssetId"),
cls.construct_reference, cls.failsafe)
if global_asset_id is not None:
asset_information.global_asset_id = global_asset_id
specific_assset_ids = element.find(NS_AAS + "specificAssetIds")
if specific_assset_ids is not None:
for id in _child_construct_multiple(specific_assset_ids, NS_AAS + "specificAssetId",
cls.construct_specific_asset_id, cls.failsafe):
asset_information.specific_asset_id.add(id)
asset_information = object_class(asset_kind=_child_text_mandatory_mapped(element, NS_AAS + "assetKind",
ASSET_KIND_INVERSE),
global_asset_id=global_asset_id,
specific_asset_id=specific_assset_ids)
thumbnail = _failsafe_construct(element.find(NS_AAS + "defaultThumbnail"),
cls.construct_resource, cls.failsafe)
if thumbnail is not None:
Expand Down

0 comments on commit da5bb81

Please sign in to comment.