eclipse-basyx / basyx-java-sdk

java-sdk
MIT License
26 stars 33 forks source link

SubmodelElements incorrectly returned via json #63

Closed the-nic closed 2 years ago

the-nic commented 2 years ago

I've set up a AAS server and request all submodels. I generate it like this using https://github.com/eclipse-basyx/basyx-python-sdk

submodel = model.Submodel(
    identification=model.Identifier(
        "https://acplt.org/Simple_Submodel", model.IdentifierType.IRI
    ),
    submodel_element={
        model.Property(
            id_short="ExampleProperty",
            value_type=basyx.aas.model.datatypes.String,
            value="exampleValue",
        )
    },
)
submodel_json_string = json.dumps(submodel, cls=basyx.aas.adapter.json.AASToJsonEncoder)

and then simply upload it via a PUT request to the aasServer.

Afterwards I GET the submodel again and the payload from AAS server 1.0.2 looks like this

{
    "idShort": "",
    "modelType": {
        "name": "Submodel"
    },
    "identification": {
        "id": "https://acplt.org/Simple_Submodel",
        "idType": "IRI"
    },
    "submodelElements": {
        "ExampleProperty": {
            "idShort": "ExampleProperty",
            "modelType": {
                "name": "Property"
            },
            "semanticId": {
                "keys": [
                    {
                        "type": "GlobalReference",
                        "idType": "IRI",
                        "value": "http://acplt.org/Properties/SimpleProperty",
                        "local": false
                    }
                ]
            },
            "value": "exampleValue",
            "valueType": "string"
        }
    }
}

this is a bit different from what the json serialization from python returns:

{
    "idShort": "",
    "modelType": {
        "name": "Submodel"
    },
    "identification": {
        "id": "https://acplt.org/Simple_Submodel",
        "idType": "IRI"
    },
    "submodelElements": [
        {
            "idShort": "ExampleProperty",
            "modelType": {
                "name": "Property"
            },
            "semanticId": {
                "keys": [
                    {
                        "type": "GlobalReference",
                        "idType": "IRI",
                        "value": "http://acplt.org/Properties/SimpleProperty",
                        "local": false
                    }
                ]
            },
            "value": "exampleValue",
            "valueType": "string"
        }
    ]
}

And according to my bug report in https://github.com/eclipse-basyx/basyx-python-sdk/issues/7 the AASServer is violating the spec and returning an incorrect payload. Could you verfy that?

FrankSchnicke commented 2 years ago

Many thanks for providing your report. I tried to reproduce your issue with the AAS Server 1.0.2 Version but on my end it is working as expected.

Can you provide further details? Are you using our Docker Image on Docker Hub or are you starting the AAS Server differently? Can you provide the specific rest calls, i.e., URL & payload, that you are doing?

the-nic commented 2 years ago

It is aas-server image 1.0.2 from dockerhub

the calls:

PUT http://172.29.8.193:8082/aasServer/shells/sim%2Faas%2F1220_8141_0112_0875/aas/submodels/test_submodel

{"idShort": "test_submodel", "modelType": {"name": "Submodel"}, "identification": {"id": "Alarm", "idType": "IRI"}, "submodelElements": [{"idShort": "ExampleProperty2", "modelType": {"name": "Property"}, "value": "exampleValue2", "valueType": "string"}, {"idShort": "ExampleProperty", "modelType": {"name": "Property"}, "value": "exampleValue", "valueType": "string"}]}

GET http://172.29.8.193:8082/aasServer/shells/sim%2Faas%2F1220_8141_0112_0875/aas/submodels

{"identification": {"idType": "IRI", "id": "Alarm"}, "modelType": {"name": "Submodel"}, "idShort": "test_submodel", "submodelElements": {"ExampleProperty2": {"idShort": "ExampleProperty2", "valueType": "string", "modelType": {"name": "Property"}, "value": "exampleValue2"}, "ExampleProperty": {"idShort": "ExampleProperty", "valueType": "string", "modelType": {"name": "Property"}, "value": "exampleValue"}}}

Expected a SubmodelElement in Submodel[Identifier(IRI=Alarm)], but found 'ExampleProperty2'

Expected a SubmodelElement in Submodel[Identifier(IRI=Alarm)], but found 'ExampleProperty'
FrankSchnicke commented 2 years ago

I still can't reproduce it. I'm doing the following:

docker run --name=aas -p 8081:4001 eclipsebasyx/aas-server:1.0.2

Create dummy AAS via

PUT http://localhost:8081/aasServer/shells/test

{ "hasDataSpecification": [], "asset": { "keys": [], "kind": "Instance", "identification": { "idType": "IRI", "id": "exampleAsset" }, "idShort": "exampleAssetIdShort" }, "submodels": [], "conceptDictionaries": [], "identification": { "idType": "IRI", "id": "test" }, "idShort": "HandsOnOven", "modelType": { "name": "AssetAdministrationShell" } }

Afterwards, I create your submodel using your JSON and PUT http://localhost:8081/aasServer/shells/test/aas/submodels/test_submodel

Getting it via http://localhost:8081/aasServer/shells/test/aas/submodels/test_submodel/submodel

returns exactly what I'm expecting { "identification": { "idType": "IRI", "id": "Alarm" }, "modelType": { "name": "Submodel" }, "idShort": "test_submodel", "submodelElements": [ { "idShort": "ExampleProperty2", "valueType": "string", "modelType": { "name": "Property" }, "value": "exampleValue2" }, { "idShort": "ExampleProperty", "valueType": "string", "modelType": { "name": "Property" }, "value": "exampleValue" } ] }

Are you doing anything differently?

FrankSchnicke commented 2 years ago

After further internal discussion, we could reproduce this issue. It only happens when retrieving all Submodels of an AAS, i.e. GET http://localhost:8081/aasServer/shells/test/aas/submodels/

We will address this issue in the first service release of the upcoming 1.1 release. The 1.1.1 release is projected to happen in April.

I will update this ticket when the bug is fixed. Many thanks again for pointing this out!

the-nic commented 2 years ago

Note that a very similar issue appears on modelTypes of SubmodelElementCollection.

FrankSchnicke commented 2 years ago

Can you provide a json example of what exactly is going wrong?

the-nic commented 2 years ago

Sorry, its the same as above: Instead of returning a list of elements, a dict is returned with id_short as key. Also only happens when requesting all submodels, not when requesting a specific submodel or submodel value.