Uploaded image for project: 'Help-Desk'
  1. Help-Desk
  2. HELP-14905

[fiware-stackoverflow] How to avoid registrations result when query the entities filtered by a relationship

    Details

      Description

      Created question in FIWARE Q/A platform on 29-10-2018 at 12:10
      Please, ANSWER this question AT https://stackoverflow.com/questions/53044149/how-to-avoid-registrations-result-when-query-the-entities-filtered-by-a-relation

      Question:
      How to avoid registrations result when query the entities filtered by a relationship

      Description:
      I've deployed the iot stack with docker. These are the used containers:

      fiware/orion:2.0.0
      fiware/iotagent-json:1.8.0

      [other containers not involved in the issue ...]

      Documentation consulted:

      http://fiware.github.io/specifications/ngsiv2/stable/

      Step 1: I've registered the following entities on the Orion context broker:

      curl -X POST \
      http://localhost:1026/v2/op/update/ \
      -H 'Content-Type: application/json' \
      -H 'fiware-service: test' \
      -H 'fiware-servicepath: /' \
      -d '{
      "actionType": "append",
      "entities": [{
      "type": "Area",
      "id": "first:Area:001",
      "name":

      { "type": "Text", "value": "First area" }

      }, {
      "type": "Area",
      "id": "second:Area:002",
      "name":

      { "type": "Text", "value": "Second area" }

      }]
      }'

      Step 2: I've registered the following device related with the Area first:Area:001 on the IoT agent:

      curl -X POST \
      http://localhost:4041/iot/devices \
      -H 'Content-Type: application/json' \
      -H 'fiware-service: test' \
      -H 'fiware-servicepath: /' \
      -d '{
      "devices": [{
      "device_id": "device001",
      "entity_name": "first:Area:001:IoTDevice:001",
      "entity_type": "IoTDevice",
      "transport": "HTTP",
      "protocol": "IoTA-JSON",
      "endpoint": "http://context-producer:3000/iot/iot-device/device001",
      "commands": [

      { "name": "ping", "type": "command" }

      ],
      "attributes": [

      { "object_id": "c", "name": "count", "type": "Number" }

      ],
      "static_attributes": [

      { "name": "refArea", "type": "Relationship", "value": "first:Area:001" }

      ,

      { "name": "name", "type": "Text", "value": "IoT Device 001" }

      ]
      }]
      }'

      Request 1: When you perform step 2, registration-type entities are automatically generated on the Orion context broker

      curl -X GET \
      http://localhost:1026/v2/registrations/ \
      -H 'fiware-service: test' \
      -H 'fiware-servicepath: /'

      Result:

      [
      {
      "id": "5bd6dbb2bef7081490c96eb2",
      "dataProvided": {
      "entities": [

      { "id": "first:Area:001:IoTDevice:001", "type": "IoTDevice" }

      ],
      "attrs": [
      "ping"
      ]
      },
      "provider": {
      "http":

      { "url": "http://iotagent-json:4041" }

      ,
      "supportedForwardingMode": "all",
      "legacyForwarding": true
      },
      "status": "active"
      }
      ]

      Test 1: Getting the IoTDevice-type entities related with the Area first:Area:001

      curl -X GET \
      'http://localhost:1026/v2/entities?options=keyValues&q=refArea==first:Area:001' \
      -H 'fiware-service: test' \
      -H 'fiware-servicepath: /'

      OK Expected Result:

      [

      { "id": "first:Area:001:IoTDevice:001", "type": "IoTDevice", "TimeInstant": " ", "count": 0, "name": "IoT Device 001", "ping_info": " ", "ping_status": "UNKNOWN", "refArea": "first:Area:001", "ping": "" }

      ]

      Test 2: Getting the IoTDevice-type entities related with the Area second:Area:001

      curl -X GET \
      'http://localhost:1026/v2/entities?options=keyValues&q=refArea==second:Area:001' \
      -H 'fiware-service: test' \
      -H 'fiware-servicepath: /'

      ERROR unexpected Result:

      [

      { "id": "first:Area:001:IoTDevice:001", "type": "IoTDevice", "ping": "" }

      ]

      The expected result was [ ] or empty but the query returned results that seem to come from the registration-type entities. This only happens if devices with attributes of type command are inserted. For example, the ping command.

      So, How can this be avoided?

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open In Progress In Progress
        6d 18h 1 Backlog Manager 05/Nov/18 9:06 AM
        In Progress In Progress Answered Answered
        1d 2h 59m 1 Backlog Manager 06/Nov/18 12:05 PM
        Answered Answered Closed Closed
        1d 1 Backlog Manager 07/Nov/18 12:06 PM

          People

          • Assignee:
            jmcantera Jose Manuel Cantera
            Reporter:
            backlogmanager Backlog Manager
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: