eclipse-basyx / basyx-java-server-sdk

MIT License
59 stars 47 forks source link

[BUG] Patch Submodel with ValueOnly values not possible #487

Closed empwilli closed 1 month ago

empwilli commented 1 month ago

Describe the bug Updating submodels via ValueOnly JSON documents with the PATCH verb fails with "Bad Request: Failed to read request". The endpoint accepts a list of SubmodelElements in JSON schema representation instead.

To Reproduce

  1. Run eclipsebasyx/aas-environment container with --env _JAVA_OPTIONS=-Dlogging.level.org.springframework=TRACE
  2. Create a submodel JSON description.
{
  "modelType": "Submodel",
  "kind": "Template",
  "id": "test",
  "submodelElements": [
    {
      "idShort": "MaxRotationSpeed",
      "category": "PARAMETER",
      "kind": "Instance",
      "semanticId": {
        "type": "ModelReference",
        "keys": [
          {
            "type": "ConceptDescription",
            "value": "0173-1#02-BAA120#008"
          }
        ]
      },
      "modelType": "Property",
      "valueType": "xs:int",
      "value": "5000"
    }
  ]
}
  1. Create a new /submodels resource from the submodel JSON. The newly created resource will be available under /submodels/dGVzdA==:
    curl -X POST http://localhost:8081/submodels -H "Content-Type: application/json" -d @submodel.json
  2. Download ValueOnly representation for the submodel:
    curl -X GET 'http://localhost:8081/submodels/dGVzdA==/$value' > data.json
  3. Optionally modify the data.json file and reupload it:
    curl -X PATCH 'http://localhost:8081/submodels/dGVzdA==/$value' -H "Content-Type: application/json" -d @data.json -v

Result:

{"type":"about:blank","title":"Bad Request","status":400,"detail":"Failed to read request","instance":"/submodels/dGVzdA==/$value"}                                                                                                                                               
docker logs aas-env

...
2024-10-10T08:40:58.214Z TRACE 1 --- [AAS Environment] [nio-8081-exec-8] o.s.web.servlet.DispatcherServlet        : PATCH "/submodels/dGVzdA==/$value", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
2024-10-10T08:40:58.215Z TRACE 1 --- [AAS Environment] [nio-8081-exec-8] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'submodelRepositoryApiHTTPController'
2024-10-10T08:40:58.215Z TRACE 1 --- [AAS Environment] [nio-8081-exec-8] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.eclipse.digitaltwin.basyx.submodelrepository.http.SubmodelRepositoryApiHTTPController#patchSubmodelByIdValueOnly(Base64UrlEncodedIdentifier, List, String)
2024-10-10T08:40:58.216Z DEBUG 1 --- [AAS Environment] [nio-8081-exec-8] o.s.web.method.HandlerMethod             : Could not resolve parameter [1] in public org.springframework.http.ResponseEntity<java.lang.Void> org.eclipse.digitaltwin.basyx.submodelrepository.http.SubmodelRepositoryApiHTTPController.patchSubmodelByIdValueOnly(org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier,java.util.List<org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement>,java.lang.String): JSON parse error: Could not resolve subtype of [simple type, class org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement]: missing type id property 'modelType'
2024-10-10T08:40:58.217Z DEBUG 1 --- [AAS Environment] [nio-8081-exec-8] .m.m.a.ExceptionHandlerExceptionResolver : Using @ExceptionHandler org.eclipse.digitaltwin.basyx.http.BaSyxExceptionHandler#handleException(Exception, WebRequest)
2024-10-10T08:40:58.217Z TRACE 1 --- [AAS Environment] [nio-8081-exec-8] o.s.web.method.HandlerMethod             : Arguments: [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Could not resolve subtype of [simple type, class org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement]: missing type id property 'modelType', ServletWebRequest: uri=/submodels/dGVzdA==/$value;client=172.23.0.1]
...
  1. Create JSON schema formatted list of SubmodelElements:
[{"modelType":"Property","value":"1234","valueType":"xs:int","idShort":"MaxRotationSpeed"}]
  1. Upload JSON formatted list:
curl -X PATCH 'http://localhost:8081/submodels/dGVzdA==/$value' -H "Content-Type: application/json" -d @json_schema_list.json

Result:

curl -X GET 'http://localhost:8081/submodels/dGVzdA==/$value'                                                     
{"MaxRotationSpeed":"1234"}%             

Expected behavior The PATCH operation with ValueOnly data should be processed correctly and update the stored submodel.

BaSyx:

Docker images: eclipsebasyx/aas-environment:2.0.0-milestone-04 and eclipsebasyx/aas-environment:2.0.0-SNAPSHOT

Used Asset Administration files (.aasx/.json/.xml) See examples above.

System (please complete the following information):

aaronzi commented 1 month ago

Hello @empwilli,

please have a look at this issue: https://github.com/eclipse-basyx/basyx-java-server-sdk/issues/408 Your issue seems to be describing the same problem. Hope this helps.