【问题标题】:NGSI update attributes from complex entities in WirecloudNGSI 更新 Wirecloud 中复杂实体的属性
【发布时间】:2017-01-25 01:25:46
【问题描述】:

是否可以通过 Wirecloud NGSI API 的 updateAttributes() 函数更新子属性?

例如,这块实体中的坐标 (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 ]
       }

已编辑

我自己的回答:可以通过将对象作为属性值传递。

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

但是,Wirecloud 使用的是 NGSI API v1,因此所有属性在向 Orion 发送/接收时都被视为字符串

更多信息:http://fiware-orion.readthedocs.io/en/master/user/structured_attribute_valued/

【问题讨论】:

    标签: fiware fiware-orion fiware-wirecloud


    【解决方案1】:

    目前,无法使用 WireCloud 的 NGSI API 对结构属性进行部分更改。此外,据我所知,NGSI API 没有提供直接的方法来对结构化属性进行部分更新(v1 和 v2 都没有)。

    但是,NGSI API v1 支持结构化属性值。因此,您可以使用updateContext 方法仅更新一个属性(例如coordinates 属性)。唯一需要考虑的是您必须提供完整的值,因此如果您想进行部分更改,您必须读取该值,进行部分更改并更新它。

    事实上,您几乎可以使用它。您只需要修复传递要更新的属性的方式,您应该将它们包装到一个数组中:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-22
      相关资源
      最近更新 更多