Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model.base: improve NamespaceSet #154

Closed
wants to merge 28 commits into from

Conversation

zrgt
Copy link
Contributor

@zrgt zrgt commented Nov 8, 2023

Refactor NamespaceSet

  • Refactored NamespaceSet.add() as it was too big
      - Extracted some methods, in particular _execute_item_del_hook. I used the method also in other places
  • As we check different constraints for uniqueness in the namespace, I defined ATTRIBUTES_CONSTRAINT_IDS. The dict will be used when throwing exception. The solution with the dict is temporary, we need other solution here.
  • Use correct constraint ids for each NamespaceSet in tests, use "0" if not constraint id is suitable

zrgt and others added 28 commits October 27, 2023 21:19
…use the spec has changed

- Add check of constraint AASd-014 for Entity, see https://rwth-iat.github.io/aas-specs/AASiD/AASiD_1_Metamodel/index.html#Entity
- Add check of constraint AASd-131 for AssetInformation, see https://rwth-iat.github.io/aas-specs/AASiD/AASiD_1_Metamodel/index.html#AssetInformation
- Refactor de-/serialization of Entity
- Refactor deserialization of AssetInformation because of check of constraint AASd-131
Add function for checking `Iterable[SpecificAssetId]`
- Add globalAssetId for all `ÀssetInformation`
- Fix Entity.specificAssetIds in test files
- Use getter/setter decorators for global_asset_id
- Refactor `Entity.__init__`: use setter for `entity_type` and remove `_validate_asset_ids_for_entity_type()` from init because it will be called in `entity_type` setter
- Add return type to some init funcs of abstract classes to calm down MyPy
The default inherited `clear()` implementation repeatedly deletes the
last item of the list until the list is empty. If the last item can be
deleted successfully, but an item in front of it that will be deleted
later cannot, this makes `clear()` non-atomic.

Thus, the `clear()` method is now overriden in an atomic way.
Furthermore, the ConstrainedList atomicity test is fixed to correctly
test for this as well.
This decorator silently overrides the `global_asset_id` property,
resulting in the constraints not being checked properly.
… to setter

This only needs to be checked if the `global_asset_id` changes.
`_validate_asset_ids_for_entity_type()` only needs to know whether there
are `specific_asset_ids` or not. This can be represented by a boolean,
allowing the delete hook of the `ConstrainedList` to make use of this
function as well.
Similar to `submodel.Entity`, this is done to reduce duplicate code.
…ecific_asset_id`

Since `__setitem__` can be used to clear the list as well (e.g.
`list[:] = ()`), the constraints need to be verified in this case as
well.
The attributes need to be assigned bypassing the setters because the
setters try to access attributes that haven't been set yet for
constraint validation. Only `global_asset_id` is set via the setter
as a final constraint validation, and because `global_asset_id` is
also constrained via a string constraint.
…ty}.specific_asset_id`

This prevents setting the attributes without verification of the constraints.
…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.
improve `AssetInformation` and `Entity` constraint validation + add tests
- Refactor hook funcs param names
- Set all private attributes, bypassing setters.
- Place setting of `Entity._global_asset_id` ahead of `Entity._specific_asset_id` to set item_add_hook directly in the ConstrainedList initialization
- Rename `Entity._validate_asset_ids_for_entity_type` to `Entity._validate_asset_ids`
- Place check of `global_asset_id` value into `_validate_asset_ids`
- Run `_validate_asset_ids` at the end of init
- Bundle check methods together at the end of classes
- Extract validation of `global_asset_id` to `_validate_asset_ids()`
- Rename `Entity._validate_asset_ids()` to `_validate_aasd_014` and `AssetInformation._validate_asset_ids()` to `_validate_aasd_131`, as the methods only validate these constraints and not all asset ids
- Refactored `NamespaceSet.add()` as too big
  - Extracted some methods, in particular `_execute_item_del_hook`. I used the method also in other places
- As we check different constraints for uniqueness in the namespace, I defined ATTRIBUTES_CONSTRAINT_IDS. The dict will be used when throwing exception. The solution with the dict is temporary, we need other solution here.
- Use correct constraint ids for each NamespaceSet in tests, use 000 if not constraint id is suitable
@zrgt zrgt closed this Nov 8, 2023
@zrgt zrgt deleted the improve/namespaceset branch November 8, 2023 18:23
@s-heppner s-heppner added the v3.0 label Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants