Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NGSI patch is not properly working when apply to "id" or "type" macro substitution from a number value. #4462

Closed
danielvillalbamota opened this issue Dec 21, 2023 · 2 comments
Labels
Milestone

Comments

@danielvillalbamota
Copy link
Collaborator

Bug description

NGSI patch is not properly working when apply to "id" or "type" macro substitution from a number value.

  • Orion version: 3.10.0-next

How to reproduce it
Steps to reproduce the behavior (as an example)

  1. Create following subscription:
curl --location 'http://host:1026/v2/subscriptions' \
--header 'Fiware-Service: service' \
--header 'Fiware-ServicePath: /servicepath' \
--header 'X-Auth-Token: gA...' \
--header 'Content-Type: application/json' \
--data '{
  "description": "ngsi patch id and type",
  "status": "active",
  "subject": {
    "entities": [
      {
        "idPattern": ".*",
        "type": "ExampleType"
      }
    ],
    "condition": {
      "attrs": [
        "TimeInstant"
      ],
      "alterationTypes": [
        "entityUpdate",
        "entityCreate",
        "entityDelete"
      ]
    }
  },
  "notification": {
    "attrs": [
      "externalId",
	  "TimeInstant"
    ],
    "onlyChangedAttrs": false,
    "attrsFormat": "normalized",
    "httpCustom": {
      "url": "https://host",
      "ngsi": {
        "id": "${externalId}",
	"type": "${externalId}"
      }
    }
  }
}'
  1. Create an entity this way:
    curl -iX POST 'http://localhost:1026/v2/entities' \
    -H 'Content-Type: application/json' \
    -d '
      {
    "id": "exampleId2",
    "type": "ExampleType",
    "TimeInstant": {
      "type": "DateTime",
      "value": "2023-07-01T09:06:15.000Z",
      "metadata": {}
    },
    "externalId": {
      "type": "Number",
      "value": 12,
      "metadata": {}
    }
  }'
  1. See error in the request response

The payload of the notification is:

{
    "subscriptionId": "6584....",
    "data": [
        {
            "id": "",
            "type": "Thing",
            "externalId": {
                "type": "Number",
                "value": 12,
                "metadata": {}
            },
            "TimeInstant": {
                "type": "DateTime",
                "value": "2023-07-01T09:07:15.000Z",
                "metadata": {}
            }
        }
    ]
}

Notice: the "id" value is an empty string and the "type": "Thing".

Expected behavior
A solution for this macro replacement would be to "stringify" the number to be applied to the id's and type's value.

Additional information

Additionaly, I have tried with a externalId's value as 102 and the behaviour is different getting a notification as:

{
    "subscriptionId": "6584...",
    "data": [
        {
            "id": "0",
            "type": "0",
            "externalId": {
                "type": "Number",
                "value": 102,
                "metadata": {}
            },
            "TimeInstant": {
                "type": "DateTime",
                "value": "2023-07-01T09:08:15.000Z",
                "metadata": {}
            }
        }
    ]
}

Where "id" neither "type" are properly parsed or "stringified".

@fgalan
Copy link
Member

fgalan commented Jan 12, 2024

PR #4468

@danielvillalbamota
Copy link
Collaborator Author

PR #4468

Tested and working. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants