diff --git a/src/config.xml b/src/config.xml index 97941c0..7b7b693 100644 --- a/src/config.xml +++ b/src/config.xml @@ -1,5 +1,5 @@ - +
NGSI source https://github.com/wirecloud-fiware/ngsi-source @@ -72,6 +72,18 @@ label="Query" description="Filter entities by providing a query using the Simple Query Language." default="" /> + + { handlerReceiveEntities.call(this, attrsFormat, notification.data); @@ -159,7 +175,7 @@ MashupPlatform.operator.log("Subscription created successfully (id: " + response.subscription.id + ")", MashupPlatform.log.INFO); this.subscriptionId = response.subscription.id; this.refresh_interval = setInterval(refreshNGSISubscription.bind(this), 1000 * 60 * 60 * 2); // each 2 hours - doInitialQueries.call(this, id_pattern, types, filter); + doInitialQueries.call(this, id_pattern, types, filter, attributes, metadata); }, (e) => { if (e instanceof NGSI.ProxyConnectionError) { @@ -172,7 +188,7 @@ } }; - const requestInitialData = function requestInitialData(idPattern, types, filter, attrsFormat, page) { + const requestInitialData = function requestInitialData(idPattern, types, filter, attributes, metadata, attrsFormat, page) { return this.connection.v2.listEntities( { idPattern: idPattern, @@ -181,13 +197,15 @@ keyValues: attrsFormat === "keyValues", limit: 100, offset: page * 100, - q: filter + q: filter, + attrs: attributes, + metadata: metadata } ).then( (response) => { handlerReceiveEntities.call(this, attrsFormat, response.results); if (page < 100 && (page + 1) * 100 < response.count) { - return requestInitialData.call(this, idPattern, types, filter, attrsFormat, page + 1); + return requestInitialData.call(this, idPattern, types, filter, attributes, metadata, attrsFormat, page + 1); } }, () => { diff --git a/tests/js/NGSISourceSpec.js b/tests/js/NGSISourceSpec.js index e5016b5..f455a75 100644 --- a/tests/js/NGSISourceSpec.js +++ b/tests/js/NGSISourceSpec.js @@ -30,12 +30,14 @@ type: 'operator', prefs: { 'query': '', + 'ngsi_attributes': '*', 'ngsi_entities': '', 'ngsi_id_filter': '', + 'ngsi_metadata': '*', 'ngsi_proxy': 'https://ngsiproxy.example.com', 'ngsi_server': 'https://orion.example.com', - 'ngsi_tenant': 'Tenant', 'ngsi_service_path': '/Spain/Madrid', + 'ngsi_tenant': 'Tenant', 'ngsi_update_attributes': '', 'use_owner_credentials': false, 'use_user_fiware_token': false @@ -333,6 +335,46 @@ }, 0); }); + it("connect (custom attributes)", (done) => { + MashupPlatform.prefs.set('ngsi_attributes', 'speed,location'); + MashupPlatform.prefs.set('ngsi_update_attributes', 'location'); + MashupPlatform.operator.outputs.entityOutput.connect(true); + + operator.init(); + + setTimeout(() => { + // List Entities Options + const leo = operator.connection.v2.listEntities.calls.mostRecent().args[0]; + expect(leo.attrs).toEqual("speed,location"); + + // Create Subscription Options + const cso = operator.connection.v2.createSubscription.calls.mostRecent().args[0]; + + expect(cso.notification.attrs).toEqual(["speed", "location"]); + done(); + }); + }); + + it("connect (custom metadata)", (done) => { + MashupPlatform.prefs.set('ngsi_metadata', 'unitCode,timestamp'); + MashupPlatform.prefs.set('ngsi_update_attributes', 'location'); + MashupPlatform.operator.outputs.entityOutput.connect(true); + + operator.init(); + + setTimeout(() => { + // List Entities Options + const leo = operator.connection.v2.listEntities.calls.mostRecent().args[0]; + expect(leo.metadata).toEqual("unitCode,timestamp"); + + // Create Subscription Options + const cso = operator.connection.v2.createSubscription.calls.mostRecent().args[0]; + + expect(cso.notification.metadata).toEqual(["unitCode", "timestamp"]); + done(); + }); + }); + it("connect (types + subscription)", (done) => { MashupPlatform.operator.outputs.entityOutput.connect(true); MashupPlatform.prefs.set('ngsi_entities', 'AirQualityObserved, WeatherForecast');