FIWARE / context.Orion-LD

Context Broker and CEF building block for context data management which supports both the NGSI-LD and the NGSI-v2 APIs
https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.06.01_60/gs_CIM009v010601p.pdf
GNU Affero General Public License v3.0
50 stars 42 forks source link

Response payload body is missing for batch upsert. #502

Open jason-fox opened 4 years ago

jason-fox commented 4 years ago

I make a batch create operation

curl -L -X POST 'http://localhost:1026/ngsi-ld/v1/entityOperations/create' \
-H 'Content-Type: application/json' \
-H 'Link: <http://context-provider:3000/data-models/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
-H 'Accept: application/ld+json' \
--data-raw '[
    {
      "id": "urn:ngsi-ld:TemperatureSensor:002",
      "type": "TemperatureSensor",
      "category": {
            "type": "Property",
            "value": "sensor"
      },
      "temperature": {
            "type": "Property",
            "value": 20,
            "unitCode": "CEL"
      }
    },
    {
      "id": "urn:ngsi-ld:TemperatureSensor:003",
      "type": "TemperatureSensor",
      "category": {
            "type": "Property",
            "value": "sensor"
      },
      "temperature": {
            "type": "Property",
            "value": 2,
            "unitCode": "CEL"
      }
    },
     {
      "id": "urn:ngsi-ld:TemperatureSensor:004",
      "type": "TemperatureSensor",
      "category": {
            "type": "Property",
            "value": "sensor"
      },
      "temperature": {
            "type": "Property",
            "value": 100,
            "unitCode": "CEL"
      }
    }
]'

The broker returns a payload detailing success/failure - this is CORRECT

EITHER:

{
    "@context": "http://context-provider:3000/data-models/ngsi-context.jsonld",
    "success": [
        "urn:ngsi-ld:TemperatureSensor:002",
        "urn:ngsi-ld:TemperatureSensor:003",
        "urn:ngsi-ld:TemperatureSensor:004"
    ],
    "errors": []
}

OR:

{
    "@context": "http://context-provider:3000/data-models/ngsi-context.jsonld",
    "success": [],
    "errors": [
        {
            "entityId": "urn:ngsi-ld:TemperatureSensor:002",
            "error": {
                "type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
                "title": "entity already exists",
                "status": 400
            }
        },
        {
            "entityId": "urn:ngsi-ld:TemperatureSensor:003",
            "error": {
                "type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
                "title": "entity already exists",
                "status": 400
            }
        },
        {
            "entityId": "urn:ngsi-ld:TemperatureSensor:004",
            "error": {
                "type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
                "title": "entity already exists",
                "status": 400
            }
        }
    ]
}

I now batch upsert the same entities:

curl -L -X POST 'http://localhost:1026/ngsi-ld/v1/entityOperations/upsert' \
-H 'Content-Type: application/json' \
-H 'Link: <http://context-provider:3000/data-models/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
-H 'Accept: application/ld+json' \
-H 'Cookie: _csrf=MAPTGFPcoPnewsGCWklHi4Mq' \
--data-raw '[
    {
      "id": "urn:ngsi-ld:TemperatureSensor:002",
      "type": "TemperatureSensor",
      "category": {
            "type": "Property",
            "value": "sensor"
      },
      "temperature": {
            "type": "Property",
            "value": 21,
            "unitCode": "CEL"
      }
    },
    {
      "id": "urn:ngsi-ld:TemperatureSensor:003",
      "type": "TemperatureSensor",
      "category": {
            "type": "Property",
            "value": "sensor"
      },
      "temperature": {
            "type": "Property",
            "value": 27,
            "unitCode": "CEL"
      }
    }
]'

The response is 204 no content - this is INCORRECT

According to the 1.3.1 specification: 5.6.8 Batch Entity Creation or Update (Upsert)

5.6.8.5 Output data

  • The list of Entities successfully processed (S Array).
  • The list of Entities in error (E Array).

The response payload body is missing, and the HTTP code should be altered since content should be returned.

"git_hash": "db891a72a531ef4cc037caed5b04f8fe71da6814",
"compile_time": "Thu Jul 30 13:13:23 UTC 2020"
jason-fox commented 4 years ago

The @context used in the example can be found here

kzangeli commented 4 years ago

This is a bug in the spec, I'm afraid. A clarification is needed in chapter 5. If you look further down, chapter 6.16 says the following:

204 No Content
If all entities have been successfully updated, there is no payload body in the response.

kzangeli commented 4 years ago

Keeping the issue open until the ETSI spec has been updated