iotagent-node-lib 4.3.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config.js +2 -1
- package/doc/admin.md +16 -7
- package/doc/api.md +230 -45
- package/doc/requirements.txt +1 -1
- package/docker/Mosquitto/Dockerfile +1 -1
- package/lib/commonConfig.js +25 -1
- package/lib/errors.js +4 -1
- package/lib/services/devices/deviceRegistryMemory.js +1 -1
- package/lib/services/devices/deviceRegistryMongoDB.js +3 -10
- package/lib/services/devices/deviceService.js +5 -3
- package/lib/services/devices/devices-NGSI-LD.js +5 -5
- package/lib/services/devices/devices-NGSI-mixed.js +3 -3
- package/lib/services/devices/devices-NGSI-v2.js +5 -5
- package/lib/services/ngsi/entities-NGSI-LD.js +1 -1
- package/lib/services/ngsi/entities-NGSI-v2.js +324 -268
- package/lib/services/ngsi/ngsiService.js +2 -2
- package/lib/services/ngsi/subscription-NGSI-LD.js +2 -2
- package/lib/services/ngsi/subscription-NGSI-v2.js +2 -2
- package/lib/services/northBound/deviceProvisioningServer.js +5 -4
- package/lib/services/northBound/northboundServer.js +2 -2
- package/package.json +2 -2
- package/scripts/legacy_expression_tool/requirements.txt +1 -1
- package/test/functional/README.md +60 -37
- package/test/functional/testCases.js +2206 -722
- package/test/functional/testUtils.js +53 -20
- package/test/unit/examples/deviceProvisioningRequests/updateProvisionDeviceWithApikey.json +4 -0
- package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +5 -5
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +34 -2
- package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +6 -6
- package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +35 -0
|
@@ -144,9 +144,9 @@ function executeWithDeviceInformation(operationFunction) {
|
|
|
144
144
|
// For preregistered devices, augment the existing deviceInformation with selected attributes.
|
|
145
145
|
if (!callback) {
|
|
146
146
|
callback = deviceInformation;
|
|
147
|
-
typeInformation = deviceGroup || { ...config.
|
|
147
|
+
typeInformation = deviceGroup || { ...config.getConfigForTypeInformation(), ...configDeviceInfo };
|
|
148
148
|
} else {
|
|
149
|
-
typeInformation = { ...config.
|
|
149
|
+
typeInformation = { ...config.getConfigForTypeInformation(), ...deviceInformation };
|
|
150
150
|
attributeList.forEach((key) => {
|
|
151
151
|
typeInformation[key] =
|
|
152
152
|
typeInformation[key] || (deviceGroup || {})[key] || (configDeviceInfo || {})[key];
|
|
@@ -89,7 +89,7 @@ function createSubscriptionHandlerNgsiLD(device, triggers, store, callback) {
|
|
|
89
89
|
triggers
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
-
config.getRegistry().update(device, callback);
|
|
92
|
+
config.getRegistry().update(device, device, callback);
|
|
93
93
|
} else {
|
|
94
94
|
callback(null, response.headers.location);
|
|
95
95
|
}
|
|
@@ -203,7 +203,7 @@ function createUnsubscribeHandlerNgsiLD(device, id, callback) {
|
|
|
203
203
|
callback(new errors.BadRequest(body.orionError.details));
|
|
204
204
|
} else {
|
|
205
205
|
device.subscriptions.splice(device.subscriptions.indexOf(id), 1);
|
|
206
|
-
config.getRegistry().update(device, callback);
|
|
206
|
+
config.getRegistry().update(device, device, callback);
|
|
207
207
|
}
|
|
208
208
|
};
|
|
209
209
|
}
|
|
@@ -91,7 +91,7 @@ function createSubscriptionHandlerNgsi2(device, triggers, store, callback) {
|
|
|
91
91
|
triggers
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
-
config.getRegistry().update(device, callback);
|
|
94
|
+
config.getRegistry().update(device, device, callback);
|
|
95
95
|
} else {
|
|
96
96
|
callback(null, response.headers.location);
|
|
97
97
|
}
|
|
@@ -203,7 +203,7 @@ function createUnsubscribeHandlerNgsi2(device, id, callback) {
|
|
|
203
203
|
callback(new errors.BadRequest(body.orionError.details));
|
|
204
204
|
} else {
|
|
205
205
|
device.subscriptions.splice(device.subscriptions.indexOf(id), 1);
|
|
206
|
-
config.getRegistry().update(device, callback);
|
|
206
|
+
config.getRegistry().update(device, device, callback);
|
|
207
207
|
}
|
|
208
208
|
};
|
|
209
209
|
}
|
|
@@ -398,11 +398,11 @@ function handleRemoveDevices(req, res, next) {
|
|
|
398
398
|
* This middleware handles updates in the provisioning devices. The only attribute
|
|
399
399
|
*/
|
|
400
400
|
function handleUpdateDevice(req, res, next) {
|
|
401
|
-
function applyUpdatingHandler(
|
|
401
|
+
function applyUpdatingHandler(newDevice, oldDevice, callback) {
|
|
402
402
|
if (updatingHandler) {
|
|
403
|
-
updatingHandler(
|
|
403
|
+
updatingHandler(newDevice, oldDevice, callback);
|
|
404
404
|
} else {
|
|
405
|
-
callback(null,
|
|
405
|
+
callback(null, newDevice);
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
408
|
|
|
@@ -429,10 +429,11 @@ function handleUpdateDevice(req, res, next) {
|
|
|
429
429
|
isTypeOrNameUpdated = true;
|
|
430
430
|
}
|
|
431
431
|
async.waterfall(
|
|
432
|
-
[apply(applyUpdatingHandler, newDevice)],
|
|
432
|
+
[apply(applyUpdatingHandler, newDevice, device)],
|
|
433
433
|
function handleUpdating(error, newDeviceUpdated) {
|
|
434
434
|
deviceService.updateRegister(
|
|
435
435
|
newDeviceUpdated,
|
|
436
|
+
device,
|
|
436
437
|
isTypeOrNameUpdated,
|
|
437
438
|
function handleDeviceUpdate(error) {
|
|
438
439
|
if (error) {
|
|
@@ -56,8 +56,8 @@ function start(config, callback) {
|
|
|
56
56
|
northboundServer.app.set('port', config.server.port);
|
|
57
57
|
northboundServer.app.set('host', config.server.host || '0.0.0.0');
|
|
58
58
|
northboundServer.app.use(domainUtils.requestDomain);
|
|
59
|
-
northboundServer.app.use(bodyParser.json());
|
|
60
|
-
northboundServer.app.use(bodyParser.json({ type: 'application/*+json' }));
|
|
59
|
+
northboundServer.app.use(bodyParser.json({ limit: config.expressLimit }));
|
|
60
|
+
northboundServer.app.use(bodyParser.json({ type: 'application/*+json', limit: config.expressLimit }));
|
|
61
61
|
|
|
62
62
|
if (config.logLevel && config.logLevel === 'DEBUG') {
|
|
63
63
|
northboundServer.app.use(middlewares.traceRequest);
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "iotagent-node-lib",
|
|
3
3
|
"license": "AGPL-3.0-only",
|
|
4
4
|
"description": "IoT Agent library to interface with NGSI Context Broker",
|
|
5
|
-
"version": "4.
|
|
5
|
+
"version": "4.5.0",
|
|
6
6
|
"homepage": "https://github.com/telefonicaid/iotagent-node-lib",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"fiware",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"async": "2.6.4",
|
|
47
47
|
"body-parser": "~1.20.0",
|
|
48
|
-
"express": "~4.
|
|
48
|
+
"express": "~4.19.2",
|
|
49
49
|
"got": "~11.8.5",
|
|
50
50
|
"jexl": "2.3.0",
|
|
51
51
|
"jison": "0.4.18",
|
|
@@ -39,7 +39,7 @@ test cases are automatically generated. Each test case is defined as an object w
|
|
|
39
39
|
or if the `transport` element is not defined. See the "Advanced features" section for more information.
|
|
40
40
|
- `shouldName`: The name of the `IT` test case. This will be used to generate the test case name in the mocha test
|
|
41
41
|
suite.
|
|
42
|
-
- `type`: The type of the test case. This can be `single` or `multientity`. See the "Advanced features" section
|
|
42
|
+
- `type`: The type of the test case. This can be `single`, `multimeasure` or `multientity`. See the "Advanced features" section
|
|
43
43
|
for more information.
|
|
44
44
|
- `measure`: The JSON object that will be sent to the IoTA JSON measure API. This will be used to send the
|
|
45
45
|
measure. It contains the following elements:
|
|
@@ -199,41 +199,11 @@ as a batch operation (see the following example).
|
|
|
199
199
|
|
|
200
200
|
#### Multimeasures
|
|
201
201
|
|
|
202
|
-
It is also supported to test cases in which is sent more than one measure. To do so, you need to
|
|
203
|
-
|
|
204
|
-
expect the same number of NGSI requests. I.E:
|
|
202
|
+
It is also supported to test cases in which is sent more than one measure. To do so, you need to set add to the test case
|
|
203
|
+
the parameter `should.type` to the value `'multimeasure'`.
|
|
205
204
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
{
|
|
209
|
-
id: 'TheLightType2:MQTT_2',
|
|
210
|
-
type: 'TheLightType2',
|
|
211
|
-
temperature: {
|
|
212
|
-
value: 10,
|
|
213
|
-
type: 'Number'
|
|
214
|
-
},
|
|
215
|
-
status: {
|
|
216
|
-
value: false,
|
|
217
|
-
type: 'Boolean'
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
id: 'TheLightType2:MQTT_2',
|
|
222
|
-
type: 'TheLightType2',
|
|
223
|
-
temperature: {
|
|
224
|
-
value: 20,
|
|
225
|
-
type: 'Number'
|
|
226
|
-
},
|
|
227
|
-
status: {
|
|
228
|
-
value: true,
|
|
229
|
-
type: 'Boolean'
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
];
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
You also should define the measure as multimeasure. This is done by defining the `measure` JSON element as an array of
|
|
236
|
-
objects. Each object will be a measure that will be sent to the Context Broker in a different request. I.E:
|
|
205
|
+
You must define the measure as multimeasure. This is done by defining the `measure` JSON element as an array of
|
|
206
|
+
objects. I.E:
|
|
237
207
|
|
|
238
208
|
```javascript
|
|
239
209
|
measure: {
|
|
@@ -246,16 +216,69 @@ measure: {
|
|
|
246
216
|
json: [
|
|
247
217
|
{
|
|
248
218
|
s: false,
|
|
249
|
-
t:
|
|
219
|
+
t: 21
|
|
250
220
|
},
|
|
251
221
|
{
|
|
252
222
|
s: true,
|
|
253
|
-
t:
|
|
223
|
+
t: 22
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
s: false,
|
|
227
|
+
t: 23
|
|
228
|
+
}
|
|
229
|
+
]
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
And you should define the test case `expectation` as an object, following a Context Broker batch operation. I.E:
|
|
234
|
+
|
|
235
|
+
```js
|
|
236
|
+
expectation: {
|
|
237
|
+
actionType: 'append',
|
|
238
|
+
entities: [
|
|
239
|
+
{
|
|
240
|
+
id: 'TheLightType2:MQTT_2',
|
|
241
|
+
type: 'TheLightType2',
|
|
242
|
+
temperature: {
|
|
243
|
+
type: 'Number',
|
|
244
|
+
value: 21
|
|
245
|
+
},
|
|
246
|
+
status: {
|
|
247
|
+
type: 'Boolean',
|
|
248
|
+
value: false
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
id: 'TheLightType2:MQTT_2',
|
|
253
|
+
type: 'TheLightType2',
|
|
254
|
+
temperature: {
|
|
255
|
+
type: 'Number',
|
|
256
|
+
value: 22
|
|
257
|
+
},
|
|
258
|
+
status: {
|
|
259
|
+
type: 'Boolean',
|
|
260
|
+
value: true
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
id: 'TheLightType2:MQTT_2',
|
|
265
|
+
type: 'TheLightType2',
|
|
266
|
+
temperature: {
|
|
267
|
+
type: 'Number',
|
|
268
|
+
value: 23
|
|
269
|
+
},
|
|
270
|
+
status: {
|
|
271
|
+
type: 'Boolean',
|
|
272
|
+
value: false
|
|
273
|
+
}
|
|
254
274
|
}
|
|
255
275
|
]
|
|
256
276
|
}
|
|
257
277
|
```
|
|
258
278
|
|
|
279
|
+
Then, a batch request would be sent to the Context Broker containing the different measures. More information about
|
|
280
|
+
how the IoT Agent send multimeasures to the Context Broker [here](/doc/api.md#multimeasure-support).
|
|
281
|
+
|
|
259
282
|
#### Transport
|
|
260
283
|
|
|
261
284
|
The test suite supports using the internal node lib function `iotAgentLib.update`, `HTTP` or `MQTT` for measure sending.
|