aaron
aaron

Reputation: 23

Is there a standardized way to migrate FIWARE NGSI-LD entity representations to NGSI-v2?

I already found this script by the FIWARE-Community, which converts an NGSI-v2 normalized representation into an NGSI-LD representation.

Is there something similar for the opposite direction? I am aware that most of the steps can be done backwards. However, I am not sure about the usual procedure for converting back the "type": "Property" nodes.

E.g given an NGSI-v2 entity representation:

{
    "id": "Store:001",
    "type": "Store",
    "name": {
        "type": "Text",
        "value": "Checkpoint Markt"
    }
}

Running the script on this will lead to:

{
    "@context": [
        https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"
    ],
    "id": "urn:ngsi-ld:Store:Store:001",
    "type": "Store",
    "name": {
        "type": "Property,
        "value": "Checkpoint Markt"
    }
}

So in this case it is quite difficult to convert the "type": "Property" node back to "type": "Text".

But given the following NGSI-v2 entity representation:

{
    "type": "Store",
    "id": "Store:002",
    "address": {
        "type": "PostalAddress",
        "value": {
            "streetAddress": "Friedrichstraße 44",
            "addressRegion": "Berlin",
            "addressLocality": "Kreuzberg",
            "postalCode": "10969"
        }
    }
}

will be converted to:

{
    "@context": [
        https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"
    ],
    "id": "urn:ngsi-ld:Store:Store:002",
    "type": "Store",
    "address": {
        "type": "Property",
        "value": {
            "streetAddress": "Friedrichstra\u00dfe 44",
            "addressRegion": "Berlin",
            "addressLocality": "Kreuzberg",
            "postalCode": "10969",
            "type": "PostalAddress"
        }
    }
}

This is caused by a special case in the script:

if attr['type'] == 'PostalAddress':
    ld_attr['value']['type'] = 'PostalAddress'

Wouldn't it be possible to extend all converted attributes with such a "type": _-pair in their value? Or is there a reason that this is restricted in the code to the type "PostalAddress" only? Otherwise, is there any norm for converting back these "type": "Property" nodes?

Upvotes: 2

Views: 340

Answers (2)

Jose Manuel Cantera
Jose Manuel Cantera

Reputation: 853

It is not a good idea to convert from NGSI-LD to NGSIv2.

NGSI-LD >> NGSIv2 ... It could be the case you may need to transform from NGSIv2 to NGSI-LD so that you are more interoperable, but the other way round ... you may need to rethink if that is sensible ...

Upvotes: 0

fgalan
fgalan

Reputation: 12294

I'm not an expert in NGSI-LD but the conversion for this particular case could be solved this way:

  • If the Property has a type within its value then use it for the attribute type in NGSIv2 (as in the "PostalAddress" case you show)
  • If the Property hasn't any type within its value then use as attribute type the default type specified in NGSIv2 specification "Partial Representations" section. For instance, if value is "Checkpoint Markt" (which is a string) then attribute type in NGSIv2 will correspond to "Text".

Upvotes: 2

Related Questions