简体   繁体   English

从JavaScript查询OCB(WireCloud)

[英]Querying OCB from JavaScript (WireCloud)

I'm trying to get type fields for each attribute of my entities. 我正在尝试为实体的每个属性获取类型字段。 Quering Orion and getting entities is not the problem (I do this through NGSI Source widget) but the way getting these parameters. 查询Orion并获取实体不是问题(我通过NGSI Source小部件完成此任务),而是获取这些参数的方式。

From NGSI Source (usual suscription to Orion instance): 从NGSI来源(通常为Orion实例订阅):

 var doInitialSubscription = function doInitialSubscription() {

    this.subscriptionId = null;

    this.ngsi_server = MashupPlatform.prefs.get('ngsi_server');
    this.ngsi_proxy = MashupPlatform.prefs.get('ngsi_proxy');
    this.connection = new NGSI.Connection(this.ngsi_server, {
        ngsi_proxy_url: this.ngsi_proxy
    });

    var types = MashupPlatform.prefs.get('ngsi_entities').split(new RegExp(',\\s*'));
    var entityIdList = [];
    var entityId;
    for (var i = 0; i < types.length; i++) {
        entityId = {
            id: '.*',
            type: types[i],
            isPattern: true
        };
        entityIdList.push(entityId);
    }
    var attributeList = null;
    var duration = 'PT3H';
    var throttling = null;
    var notifyConditions = [{
        'type': 'ONCHANGE',
        'condValues': MashupPlatform.prefs.get('ngsi_update_attributes').split(new RegExp(',\\s*'))
    }];
    var options = {
        flat: true,
        onNotify: handlerReceiveEntity.bind(this),
        onSuccess: function (data) {
            this.subscriptionId = data.subscriptionId;
            this.refresh_interval = setInterval(refreshNGSISubscription.bind(this), 1000 * 60 * 60 * 2);  // each 2 hours
            window.addEventListener("beforeunload", function () {
                this.connection.cancelSubscription(this.subscriptionId);
            }.bind(this));
        }.bind(this)
    };
    this.connection.createSubscription(entityIdList, attributeList, duration, throttling, notifyConditions, options);
};
 var handlerReceiveEntity = function handlerReceiveEntity(data) {
    for (var entityId in data.elements) {
        MashupPlatform.wiring.pushEvent("entityOutput", JSON.stringify(data.elements[entityId]));
    }
};

To MyWidget: 到MyWidget:

MashupPlatform.wiring.registerCallback("entityInput", function (entityString) {
    var entity;
    entity = JSON.parse(entityString);
    id = entity.id;
    type = entity.type;
    for(var attr in entity){
        attribute = entity[attr];
    }

I'm trying to code something similar to obtain the value of type fields. 我正在尝试编写类似的代码来获取类型字段的值。 How can I do that? 我怎样才能做到这一点? (I'm sure it's quite easy...) (我敢肯定这很容易...)

You cannot make use of the current NGSI source operator implementation (at least v3.0.2) if you want to get the type metadata of attributes as the NGSI source makes use of the flat option (discarding that info). 如果要获取属性的类型元数据,则不能使用当前的NGSI源操作符实现(至少v3.0.2),因为NGSI源使用flat选项(丢弃该信息)。

We are studying updating this operator to allow creating subscriptions without using the flat option. 我们正在研究更新此运算符,以允许在不使用flat选项的情况下创建订阅。 The main problem here is that other components expect the data provided by this operator being provided in the format returned when using the flat option. 这里的主要问题是其他组件期望使用flat选项时以返回的格式提供此运算符提供的数据。 I will update this answer after analysing deeper the issue. 在深入分析问题之后,我将更新此答案。

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

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