简体   繁体   English

NGSI更新Wirecloud中复杂实体的属性

[英]NGSI update attributes from complex entities in Wirecloud

Is it possible to update a child attribute through the updateAttributes() function from Wirecloud NGSI API ? 是否可以通过Wirecloud NGSI API的updateAttributes()函数更新子属性?

For example, a coordinate (entity.location.coords.coordinates[0]=-2.000000) in this piece of entity. 例如,此实体中的坐标(entity.location.coords.coordinates [0] =-2.000000)。

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

EDITED 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. 但是, Wirecloud使用的是NGSI API v1 ,因此,当所有属性发送到Orion或从Orion接收时, 所有属性都被视为字符串

More info: http://fiware-orion.readthedocs.io/en/master/user/structured_attribute_valued/ 更多信息: 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. 当前,无法使用WireCloud的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). 而且,据我所知,NGSI API并没有提供对结构化属性(v1和v2均未进行部分更新)的直接方法。

However, v1 of the NGSI API supports structured attribute values . 但是, NGSI API的v1支持结构化属性值 So you can make use of the updateContext method to update only one attribute (eg the coordinates attribute). 因此,您可以利用updateContext方法仅更新一个属性(例如, coordinates属性)。 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
    }
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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