简体   繁体   中英

NGSI update attributes from complex entities in Wirecloud

Is it possible to update a child attribute through the updateAttributes() function from Wirecloud NGSI API ?

For example, a coordinate (entity.location.coords.coordinates[0]=-2.000000) in this piece of entity.

   "attrNames": [ "A1", "A2", "position" ],
   "creDate": 1389376081,
   "modDate": 1389376244,
   "location": {
       "attrName": "position",
       "coords": {
           "type": "Point",
           "coordinates": [ -3.691944, 40.418889 ]
       }

EDITED

My own answer: It is possible by passing an object as value of the attribute.

ngsi.updateAttributes([
                    {
                        'entity': {'id': "entity-id"},
                        'attributes':[{ 
                          "name":"location","contextValue": {
                               "attrName": "position",
                               "coords": {
                                     "type": "Point",
                                     "coordinates": [ -2.000000, 40.418889 ]
                               }
                          } 
                        }]  
                    }
                ], {
                    onSuccess: onUpdateAttributesSuccess,
                    onFailure: onUpdateAttributesFail
                }
            );

However, Wirecloud is using NGSI API v1 , therefore all attributes are treated as strings when they are sent/received to/from Orion.

More info: http://fiware-orion.readthedocs.io/en/master/user/structured_attribute_valued/

Currently, it's not possible to make partial changes into an structure attribute using the WireCloud's NGSI API. Moreover, as far as I know, the NGSI API doesn't provide a direct way for making partial updates into structured attributes (neither v1 nor v2).

However, v1 of the NGSI API supports structured attribute values . So you can make use of the updateContext method to update only one attribute (eg the coordinates attribute). The only thing to take into account it's that you will have to provide the full value, so if you want to make a partial change you have to read the value, make the partial change and update it.

In fact, you almost have it working. You only have to fix the way you are passing the attributes to update, you should wrap them into an array:

ngsi.updateAttributes([{
        "entity": {"id": "entity-id"},
        "attributes": [
            {
                "name": "location",
                "contextValue": {
                    "attrName": "position",
                    "coords": {
                        "type": "Point",
                        "coordinates": [-2.000000, 40.418889]
                    }
                }
            }
        ]
    }],
    {
        onSuccess: onUpdateAttributesSuccess,
        onFailure: onUpdateAttributesFail
    }
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM