Skip to content

Add support for NGSI-LD valueType and more NGSI-LD sub-property types. #1723

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

Merged
merged 9 commits into from
Aug 1, 2025

Conversation

jason-fox
Copy link
Contributor

  • Update NGSI-LD processing functionality
  • Add tests
  • Update documentation.

As defined in the 1.9.1 NGSI-LD specification, there are now two mechanisms available for supporting the equivlent of NGSI-v2 type attribute holding an attribute's datatype.

The following examples show how time values (Date, Time, or DateTime) can be represented in NGSI-LD as reified
Properties. For a reified Property whose value is assigned the JSON type Date, DateTime or Time, one mechanism is to
use the Property's valueType to hold the datatype ("Date", "Datetime" or "Time"), as shown below:

{
  "id": "urn:ngsi-ld:Vehicle:B9211",
  "type": "Vehicle",
  "testedAt": {
    "type": "Property",
    "value": "2018-12-04T12:00:00Z",
    "valueType": "DateTime"
  }
}

Alternatively the data can be a structured to use the JSON-LD @value syntax structure, as shown below:

{
  "id": "urn:ngsi-ld:Vehicle:B9211",
  "type": "Vehicle",
  "testedAt": {
    "type": "Property",
    "value": {
      "@type": "DateTime",
      "@value": "2018-12-04T12:00:00Z"
    }
  }
}

This PR updates NGSI-LD processing to allow for three types of valueType processing to add datatype metadata

  • Add nothing
  • Add using valueType
  • Add using @type

The previous 1.8.1 default (and recommendation) was @type, but this should change since valueType was created to simplify value and make it queriable, The new default (for now) should be nothing, since valueType is not widely supported by context brokers yet.

Note that valueType alwayd optional - it is still possible to define attributes as Property, GeoProperty or Relationship. Furthermore the additional sub-types of Property such as JsonProperty, VocabProperty and ListProperty are also now supported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file (and the rest of similar ones) are under ngsiv2/ structure.

Maybe they are no longer used but we forgot to remove them? In that case, thanks for the clean up :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove: autocast (including env var IOTA_AUTOCAST) (#1498) was part of 4.0.0 release

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NTC

@@ -222,7 +221,7 @@ function updateEntityNgsi2(deviceData, updatedDevice, callback) {
) {
options.json[constants.TIMESTAMP_ATTRIBUTE] = {
type: constants.TIMESTAMP_TYPE_NGSI2,
value: moment()
value: new Date().toISOString()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really needed or a kind of improvement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moment.js is deprecated, or rather there are better ways of achieving the same result without the use of an unnecessary extra package. In this case Date gives us everything we need from moment.

https://momentjs.com/docs/#/-project-status/

Ideally I'd like to remove both moment and moment-timezone entirely at some point

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good :) NTC

Co-authored-by: Fermín Galán Márquez <[email protected]>
Copy link
Member

@fgalan fgalan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Let's wait for @AlvaroVega to merge this PR.

doc/admin.md Outdated
@@ -105,6 +105,7 @@ It configures the connection parameters to stablish a connection to the Context
host: '192.168.56.101',
port: '1026',
ngsiVersion: 'ld',
valueType: 'valueType',
Copy link
Member

@fgalan fgalan Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that value type is only used by NGSI-LD and taking into account that other LD-related config use the "Ld" token in the name (eg jsonLdContext, maybe it shoulb be named ldValueType?

In that case, the env var could be renamed to IOTA_CB_NGSILD_VALUE_TYPE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed b50a691
Moved to IOTA_LD_SUPPORT_DATA_TYPE with config value server.ldSupport.datatype - this aligns to the other LD only config values.

Copy link
Member

@AlvaroVega AlvaroVega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@fgalan fgalan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fgalan fgalan merged commit bd9fb18 into telefonicaid:master Aug 1, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants