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

Parsing AssetAdministrationShell fails when parsing asset element #9

Closed
the-nic opened this issue Mar 21, 2022 · 2 comments
Closed

Comments

@the-nic
Copy link

the-nic commented Mar 21, 2022

When parsing an AssetAdministrationShell from json _construct_asset_administration_shell is expecting a type dict in asset element:

def _construct_asset_administration_shell(
            cls, dct: Dict[str, object], object_class=model.AssetAdministrationShell) -> model.AssetAdministrationShell:
        ret = object_class(
            asset=cls._construct_aas_reference(_get_ts(dct, 'asset', dict), model.Asset),
            identification=cls._construct_identifier(_get_ts(dct, 'identification', dict)))

However, at that point the asset element is already parsed and fails with:

TypeError: Dict entry 'asset' has unexpected type Asset

Changing the above line to

def _construct_asset_administration_shell(
            cls, dct: Dict[str, object], object_class=model.AssetAdministrationShell) -> model.AssetAdministrationShell:
        ret = object_class(
            asset=get_ts(dct, 'asset', model.Asset),
            identification=cls._construct_identifier(_get_ts(dct, 'identification', dict)))

seems to fix the problem.

Example python code:

    json_ = """
[
    {
        "conceptDictionary": [],
        "assetRef": {
            "keys": [
                {
                    "idType": "IRI",
                    "type": "Asset",
                    "value": "1030_8141_0112_5510",
                    "local": true
                }
            ]
        },
        "identification": {
            "idType": "IRI",
            "id": "1220_8141_0112_0875"
        },
        "idShort": "AAS",
        "dataSpecification": [],
        "derivedFrom": {
            "keys": [
                {
                    "idType": "IdShort",
                    "type": "AssetAdministrationShell",
                    "value": "6455_1111_0112_4769",
                    "local": true
                }
            ]
        },
        "modelType": {
            "name": "AssetAdministrationShell"
        },
        "asset": {
            "idShort": "CA",
            "modelType": {
                "name": "Asset"
            },
            "identification": {
                "id": "1030_8141_0112_5510",
                "idType": "IRI"
            },
            "kind": "Instance"
        },
        "embeddedDataSpecifications": [],
        "views": []
    }
]
    """
    shells = json.loads(json_, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
@jkhsjdhjs
Copy link
Contributor

Yes, it's retrieving the value of the asset property as a dict in order to construct a Reference object from the dict. In the DotAAS metamodel, references to other objects are described by Reference objects, which point to the actual object.
This is also the case for the asset property of an AssetAdministrationShell, you can verify it on page 234 of the spec: https://www.plattform-i40.de/IP/Redaktion/EN/Downloads/Publikation/Details_of_the_Asset_Administration_Shell_Part1_V2.pdf?__blob=publicationFile

Thus, the exemplary JSON structure you gave doesn't adhere to the DotAAS spec in version 2.0.1 and isn't compatible with this implementation.

@the-nic
Copy link
Author

the-nic commented Mar 22, 2022

Thank you very much for the explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants