Skip to content

Commit

Permalink
model.submodel: verify constraints when SpecificAssetIds are added …
Browse files Browse the repository at this point in the history
…to `Entity`

This adds an `item_add_hook` to the `specific_asset_id`
`ConstrainedList`, which is called whenever a new item is added to the
list. This is necessary because a co-managed `Entity` is not allowed to
have specific asset ids, so it shouldn't be possible to add any in this
case.
  • Loading branch information
jkhsjdhjs authored and s-heppner committed Nov 14, 2023
1 parent 7a073ad commit 7fdb952
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions basyx/aas/model/submodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,12 +1111,19 @@ def __init__(self,
item_del_hook=self._check_constraint_del_spec_asset_id)
# assign private attributes, bypassing setters, as constraints will be checked below
self._entity_type: base.EntityType = entity_type
# add item_add_hook after items have been added, because checking the constraints requires the global_asset_id
# to be set
self._specific_asset_id._item_add_hook = self._check_constraint_add_spec_asset_id
# use setter for global_asset_id, as it also checks the string constraint,
# which hasn't been checked at this point
# furthermore, the setter also validates AASd-014
self._global_asset_id: Optional[base.Identifier]
self.global_asset_id = global_asset_id

def _check_constraint_add_spec_asset_id(self, _new: base.SpecificAssetId, _list: List[base.SpecificAssetId]) \
-> None:
self._validate_asset_ids_for_entity_type(self.entity_type, self.global_asset_id, True)

def _check_constraint_set_spec_asset_id(self, old: List[base.SpecificAssetId], new: List[base.SpecificAssetId],
list_: List[base.SpecificAssetId]) -> None:
self._validate_asset_ids_for_entity_type(self.entity_type, self.global_asset_id,
Expand Down

0 comments on commit 7fdb952

Please sign in to comment.