-
Notifications
You must be signed in to change notification settings - Fork 27
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
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…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.
…et_id` type hints
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactor NamespaceSet
NamespaceSet.add()
as it was too big- Extracted some methods, in particular
_execute_item_del_hook
. I used the method also in other places