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

[fiware-stackoverflow] Non-Primitive Values from a Registered Content Provider are not showing a value

    Details

      Description

      Created question in FIWARE Q/A platform on 20-04-2018 at 17:04
      Please, ANSWER this question AT https://stackoverflow.com/questions/49945250/non-primitive-values-from-a-registered-content-provider-are-not-showing-a-value

      Question:
      Non-Primitive Values from a Registered Content Provider are not showing a value

      Description:
      I'm using the /v2/registrations endpoint to register a content provider with the legacyForwarding flag being set. Therefore my Content Provider is offering the v1/queryContext endpoint

      When I am returning a simple value (Integer, String etc.) such as a temperature the data is added to the context correctly:

      {
      "contextResponses": [
      {
      "contextElement": {
      "attributes": [

      { "name": "temperature", "type": "Number", "value": 27 }

      ],
      "id": "urn:ngsi-ld:Store:001",
      "isPattern": "false",
      "type": "Store"
      },
      "statusCode":

      { "code": "200", "reasonPhrase": "OK" }

      }
      ]
      }

      However when trying to return an array of strings as shown from a Context Provider.

      {
      "contextResponses": [
      {
      "contextElement": {
      "attributes": [

      { "name": "tweets", "type": "Array", "value": [ "String 1", "String 2" ] }

      ],
      "id": "urn:ngsi-ld:Store:002",
      "isPattern": "false",
      "type": "Store"
      },
      "statusCode":

      { "code": "200", "reasonPhrase": "OK" }

      }
      ]
      }

      I can see the request being sent in the log and I can retrieve the following entity:

      {
      "id": "urn:ngsi-ld:Store:002",
      "type": "Store",
      "address": {
      "type": "PostalAddress",
      "value": "",
      "metadata": {}
      },
      "location": {
      "type": "geo:json",
      "value": "",
      "metadata": {}
      },
      "name": {
      "type": "Text",
      "value": "Checkpoint Markt",
      "metadata": {}
      },
      "tweets": {
      "type": "Array",
      "value": "",
      "metadata": {}
      }
      }

      As you can see the "tweets" value is blank, but the attribute exists and the type has been successfully received.

      My question is how should I return an Array or an Object as a value from a Content Provider so that Orion is able to display the data received correctly?

        Activity

        Hide
        backlogmanager Backlog Manager added a comment -

        2018-04-20 18:05|CREATED monitor | # answers= 0, accepted answer= False

        Show
        backlogmanager Backlog Manager added a comment - 2018-04-20 18:05|CREATED monitor | # answers= 0, accepted answer= False
        Hide
        jmcantera Jose Manuel Cantera added a comment -

        Hi Veronika,

        That’s a question from Jason, that should be responded by the Orion Developers but I think is better to assign it to Jason. Please could you add an account for Jason in Jira and reassign this issue to him?

        Jason, probably would need to provide a functest to Ken, in cc showing what is failing.

        Ken, Jason, please could liaise to solve this?

        Thanks,

        Best

        Show
        jmcantera Jose Manuel Cantera added a comment - Hi Veronika, That’s a question from Jason, that should be responded by the Orion Developers but I think is better to assign it to Jason. Please could you add an account for Jason in Jira and reassign this issue to him? Jason, probably would need to provide a functest to Ken, in cc showing what is failing. Ken, Jason, please could liaise to solve this? Thanks, Best
        Hide
        fw.ext.user FW External User added a comment -

        The issue is easy to reproduce within the https://github.com/Fiware/tutorials.Context-Providers <https://github.com/Fiware/tutorials.Context-Providers> GitRepo

        1. Pull repository
        2. Run ./services stop; ./services create; ./services start;
        3. Run the following cUrl commands: - Context Provider is usually localhost:3000. Orion localhost:1026

        Check Random Data Generator is Running
        curl -X GET \
        'http://context-provider/proxy/random/health'

        Check Random Data Generator is returning a valid NGSI Array Response
        curl -X POST \
        'http://context-provider/proxy/random/array/temperature/queryContext' \
        -H 'Cache-Control: no-cache' \
        -H 'Content-Type: application/json' \
        -H 'Postman-Token: b48df54e-7b3a-4406-814b-b978949c4060' \
        -d '{
        "entities": [

        { "type": "Store", "isPattern": "false", "id": "urn:ngsi-ld:Store:001" }

        ],
        "attributes": [
        "temperature"
        ]
        }'

        Register Random Data Generator as a Context Provider
        curl -X POST \
        'http://orion/v2/registrations' \
        -H 'Cache-Control: no-cache' \
        -H 'Content-Type: application/json' \
        -H 'Postman-Token: 43ff9fdf-2584-4db9-9b95-bec256fdb7dc' \
        -d '{
        "description": "Current Customer Count",
        "dataProvided": {
        "entities": [

        { "id": "urn:ngsi-ld:Store:001", "type": "Store" }

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

        { "url": "http://context-provider:3000/proxy/random/array/customerCount" }

        ,
        "legacyForwarding": true
        }
        }'

        Query for Data
        curl -X GET \
        'http://orion/v2/entities/urn:ngsi-ld:Store:001'

        The customerCount has a value of “” - I would expect an array of Lorem Ipsum entries.

        Show
        fw.ext.user FW External User added a comment - The issue is easy to reproduce within the https://github.com/Fiware/tutorials.Context-Providers < https://github.com/Fiware/tutorials.Context-Providers > GitRepo 1. Pull repository 2. Run ./services stop; ./services create; ./services start; 3. Run the following cUrl commands: - Context Provider is usually localhost:3000. Orion localhost:1026 Check Random Data Generator is Running curl -X GET \ 'http:// context-provider /proxy/random/health' Check Random Data Generator is returning a valid NGSI Array Response curl -X POST \ 'http:// context-provider /proxy/random/array/temperature/queryContext' \ -H 'Cache-Control: no-cache' \ -H 'Content-Type: application/json' \ -H 'Postman-Token: b48df54e-7b3a-4406-814b-b978949c4060' \ -d '{ "entities": [ { "type": "Store", "isPattern": "false", "id": "urn:ngsi-ld:Store:001" } ], "attributes": [ "temperature" ] }' Register Random Data Generator as a Context Provider curl -X POST \ 'http:// orion /v2/registrations' \ -H 'Cache-Control: no-cache' \ -H 'Content-Type: application/json' \ -H 'Postman-Token: 43ff9fdf-2584-4db9-9b95-bec256fdb7dc' \ -d '{ "description": "Current Customer Count", "dataProvided": { "entities": [ { "id": "urn:ngsi-ld:Store:001", "type": "Store" } ], "attrs": [ "customerCount" ] }, "provider": { "http": { "url": "http://context-provider:3000/proxy/random/array/customerCount" } , "legacyForwarding": true } }' Query for Data curl -X GET \ 'http:// orion /v2/entities/urn:ngsi-ld:Store:001' The customerCount has a value of “” - I would expect an array of Lorem Ipsum entries.
        Hide
        fw.ext.user FW External User added a comment -

        Actually I’ve discovered the issue is worse than I thought.

        If I have an Entity with an existing object attribute in Orion (e.g.Postal Address)
        And then I add in *any* field into the context (e.g. a Number for temperature) then the Object attribute appears as "" when the Entity is requested:

        e.g.:

        curl -X POST \
        'http://localhost:1026/v2/op/update' \
        -H 'Content-Type: application/json' \
        -g -d '{
        "actionType": "APPEND",
        "entities": [
        {
        "id":"urn:ngsi-ld:Store:004","type":"Store",
        "address":{"type":"PostalAddress","value":{"streetAddress":"Panoramastraße 1A","addressRegion":"Berlin","addressLocality":"Mitte","postalCode":"10178"}},
        "location":{"type":"geo:json","value":{"type":"Point","coordinates":[13.4094,52.5208]}},
        "name":

        {"type":"Text","value":"Tower Trödelmarkt"}

        }
        ]
        }’

        curl -X POST \
        'http://localhost:1026/v2/registrations' \
        -H 'Cache-Control: no-cache' \
        -H 'Content-Type: application/json' \
        -d '{
        "description": "Relative Humidity Context Source",
        "dataProvided": {
        "entities": [

        { "id": "urn:ngsi-ld:Store:004", "type": "Store" }

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

        { "url": "http://context-provider:3000/proxy/random/number/temperature" }

        ,
        "legacyForwarding": true
        }
        }’

        curl -X GET \
        'http://localhost:1026/v2/entities/urn:ngsi-ld:Store:004'

        Response:

        {
        "id": "urn:ngsi-ld:Store:004",
        "type": "Store",
        "address": {
        "type": "PostalAddress",
        "value": "",
        "metadata": {}
        },
        "location": {
        "type": "geo:json",
        "value": "",
        "metadata": {}
        },
        "name": {
        "type": "Text",
        "value": "Tower Trödelmarkt",
        "metadata": {}
        },
        "temperature": {
        "type": "Number",
        "value": "29",
        "metadata": {}
        }
        }

        Postal Address has disappeared.

        I would add this to the JIRA ticket, but I don’t have a log-in.

        Regards,

        Jason.

        Show
        fw.ext.user FW External User added a comment - Actually I’ve discovered the issue is worse than I thought. If I have an Entity with an existing object attribute in Orion (e.g.Postal Address) And then I add in * any * field into the context (e.g. a Number for temperature) then the Object attribute appears as "" when the Entity is requested: e.g.: curl -X POST \ 'http://localhost:1026/v2/op/update' \ -H 'Content-Type: application/json' \ -g -d '{ "actionType": "APPEND", "entities": [ { "id":"urn:ngsi-ld:Store:004","type":"Store", "address":{"type":"PostalAddress","value":{"streetAddress":"Panoramastraße 1A","addressRegion":"Berlin","addressLocality":"Mitte","postalCode":"10178"}}, "location":{"type":"geo:json","value":{"type":"Point","coordinates": [13.4094,52.5208] }}, "name": {"type":"Text","value":"Tower Trödelmarkt"} } ] }’ curl -X POST \ 'http://localhost:1026/v2/registrations' \ -H 'Cache-Control: no-cache' \ -H 'Content-Type: application/json' \ -d '{ "description": "Relative Humidity Context Source", "dataProvided": { "entities": [ { "id": "urn:ngsi-ld:Store:004", "type": "Store" } ], "attrs": [ "temperature" ] }, "provider": { "http": { "url": "http://context-provider:3000/proxy/random/number/temperature" } , "legacyForwarding": true } }’ curl -X GET \ 'http://localhost:1026/v2/entities/urn:ngsi-ld:Store:004' Response: { "id": "urn:ngsi-ld:Store:004", "type": "Store", "address": { "type": "PostalAddress", "value": "", "metadata": {} }, "location": { "type": "geo:json", "value": "", "metadata": {} }, "name": { "type": "Text", "value": "Tower Trödelmarkt", "metadata": {} }, "temperature": { "type": "Number", "value": "29", "metadata": {} } } Postal Address has disappeared. I would add this to the JIRA ticket, but I don’t have a log-in. Regards, Jason.
        Hide
        jason.fox Jason Fox added a comment - - edited

        Taking advice from Ken Zangelin (Telefónica I+D)

        Show
        jason.fox Jason Fox added a comment - - edited Taking advice from Ken Zangelin (Telefónica I+D) I have created issue: [ https://github.com/telefonicaid/fiware-orion/issues/3162 ] I have branched fiware/orion: https://github.com/jason-fox/fiware-orion/tree/feature/3162-func-test I have attempted to create a functional test : https://github.com/jason-fox/fiwre-orion/blob/feature/3162-func-test/test/functionalTest/cases/3162_context_providers_legacy_non_primitive/query_for_arrays.test + I have no idea if it will run (since I didn’t find out how to invoke the tests) + The test is expected to fail on points 06, 08 and 09 since arrays aren’t being returned. I have created a pull request: https://github.com/telefonicaid/fiware-orion/pull/3163
        Hide
        jason.fox Jason Fox added a comment -

        This appears to be an Orion bug rather than a Stack Overflow issue.

        Bug ticket raised here.

        Once the bug is fixed I will self-answer my question on Stack Overflow

        Show
        jason.fox Jason Fox added a comment - This appears to be an Orion bug rather than a Stack Overflow issue. Bug ticket raised here . Once the bug is fixed I will self-answer my question on Stack Overflow

          People

          • Assignee:
            jason.fox Jason Fox
            Reporter:
            backlogmanager Backlog Manager
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: