-
Notifications
You must be signed in to change notification settings - Fork 28
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
Make model.Entity.specific_asset_id a Set of model.SpecificAssetIds #149
Conversation
…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
Looks good to me. Thank you! |
@s-heppner its fine for me |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM other than the comment, also we should add a simple test case that checks whether AASd-131 is verified correctly.
@s-heppner the pull request can be merged now |
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.
…et_id` type hints
See zrgt#1 |
improve `AssetInformation` and `Entity` constraint validation + add tests
This depends on #153 and should be merged after it. |
- 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this change, as it increases the code quality by making the code less complicated and more readable.
However, as noted in a separate comment, I don't like that the global_asset_id
string constraint check is moved to _validate_asset_ids()
as well, as it only needs to be checked if the global asset id changes. It would be better if this would just be called in __init__()
and the global_asset_id
setter. The downside is of course a bit duplicate code, but since it's only 2 lines in 2 locations, I would prefer this solution over always checking it.
Another thing I thought about is introducing a new Metaclass for AssetInformation
and Entity
, since they both share 2 attributes with the same constraint. This would reduce the duplicate code a bit, as AssetInformation
and Entity
currently have 2 getters and 2 setters which basically do the same thing in both classes.
On the other hand, it would introduce a new class that is not part of the DotAAS spec and the added inheritance might make the code a bit more complicated.
Any thoughts from your side on this?
- 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice 👍
Entity.specific_asset_id
asIterable[SpecificAssetId]
, because the spec has changedcheck_entity_equal()
&`check_asset_information_equal()Fixes #144