iotagent-node-lib 2.26.0 → 3.1.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/.github/workflows/ci.yml +1 -0
- package/CHANGES_NEXT_RELEASE +2 -0
- package/docker-compose-dev.yml +1 -1
- package/lib/fiware-iotagent-lib.js +0 -5
- package/lib/plugins/compressTimestamp.js +2 -7
- package/lib/plugins/expressionParser.js +0 -47
- package/lib/plugins/expressionPlugin.js +6 -78
- package/lib/plugins/jexlParser.js +0 -36
- package/lib/plugins/pluginUtils.js +0 -119
- package/lib/services/ngsi/entities-NGSI-LD.js +586 -199
- package/lib/services/ngsi/entities-NGSI-v2.js +607 -297
- package/lib/services/ngsi/ngsiUtils.js +15 -22
- package/package.json +2 -2
- package/test/unit/general/config-multi-core-test.js +2 -1
- package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +2 -1
- package/test/unit/general/deviceService-test.js +2 -1
- package/test/unit/general/loglevel-api_test.js +2 -3
- package/test/unit/general/startup-test.js +2 -1
- package/test/unit/general/statistics-persistence_test.js +1 -0
- package/test/unit/general/statistics-service_test.js +1 -0
- package/test/unit/lazyAndCommands/commandRegistry_test.js +1 -0
- package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +1 -0
- package/test/unit/mongodb/mongodb-connectionoptions-test.js +1 -0
- package/test/unit/mongodb/mongodb-group-registry-test.js +1 -0
- package/test/unit/mongodb/mongodb-registry-test.js +2 -1
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin1.json +0 -5
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast10.json +1 -1
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast8.json +1 -1
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast9.json +1 -1
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +16 -15
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4.json +8 -8
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4a.json +34 -34
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin5.json +8 -8
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin6.json +0 -20
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin7.json +0 -5
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin8.json +10 -10
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +8 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +5 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -1
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextProcessTimestamp.json +4 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextTimestampOverride.json +4 -3
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +4 -3
- package/test/unit/ngsi-ld/expressions/expressionBasedTransformations-test.js +4 -6
- package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +1 -7
- package/test/unit/ngsi-ld/general/config-jsonld-contexts-test.js +2 -1
- package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +2 -1
- package/test/unit/ngsi-ld/general/deviceService-test.js +2 -1
- package/test/unit/ngsi-ld/general/https-support-test.js +2 -1
- package/test/unit/ngsi-ld/general/iotam-autoregistration-test.js +2 -1
- package/test/unit/ngsi-ld/general/startup-test.js +3 -2
- package/test/unit/ngsi-ld/lazyAndCommands/active-devices-attribute-update-test.js +2 -1
- package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +5 -7
- package/test/unit/ngsi-ld/lazyAndCommands/lazy-devices-test.js +8 -6
- package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +18 -22
- package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +2 -1
- package/test/unit/ngsi-ld/ngsiService/active-devices-test.js +2 -1
- package/test/unit/ngsi-ld/ngsiService/autocast-test.js +17 -4
- package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +2 -1
- package/test/unit/ngsi-ld/ngsiService/languageProperties-test.js +32 -34
- package/test/unit/ngsi-ld/ngsiService/staticAttributes-test.js +2 -1
- package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +2 -1
- package/test/unit/ngsi-ld/ngsiService/unsupported-endpoints-test.js +11 -15
- package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +2 -3
- package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +2 -1
- package/test/unit/ngsi-ld/plugins/compress-timestamp-plugin_test.js +2 -32
- package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +20 -19
- package/test/unit/ngsi-ld/plugins/timestamp-processing-plugin_test.js +21 -7
- package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +1 -0
- package/test/unit/ngsi-ld/provisioning/device-registration_test.js +2 -1
- package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +15 -12
- package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +1 -0
- package/test/unit/ngsi-ld/provisioning/provisionDeviceMultientity-test.js +1 -0
- package/test/unit/ngsi-ld/provisioning/removeProvisionedDevice-test.js +1 -0
- package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +1 -0
- package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +1 -0
- package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +13 -7
- package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin1.json +2 -2
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +4 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +0 -16
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +0 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +8 -8
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +42 -42
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +7 -7
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +0 -5
- package/test/unit/ngsiv2/examples/contextRequests/updateContextProcessTimestamp.json +6 -6
- package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverride.json +7 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +7 -1
- package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +2 -4
- package/test/unit/ngsiv2/expressions/expressionCombinedTransformations-test.js +4 -8
- package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +5 -9
- package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +2 -1
- package/test/unit/ngsiv2/general/deviceService-test.js +2 -1
- package/test/unit/ngsiv2/general/https-support-test.js +2 -1
- package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +2 -1
- package/test/unit/ngsiv2/general/startup-test.js +2 -1
- package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +2 -1
- package/test/unit/ngsiv2/lazyAndCommands/command-test.js +2 -1
- package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +8 -6
- package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +2 -1
- package/test/unit/ngsiv2/ngsiService/active-devices-test.js +3 -2
- package/test/unit/ngsiv2/ngsiService/autocast-test.js +2 -1
- package/test/unit/ngsiv2/ngsiService/queryDeviceInformationInCb-test.js +2 -1
- package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +2 -1
- package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +2 -1
- package/test/unit/ngsiv2/plugins/alias-plugin_test.js +2 -3
- package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +2 -5
- package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +2 -33
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +7 -16
- package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +3 -2
- package/test/unit/ngsiv2/provisioning/device-group-api-test.js +1 -0
- package/test/unit/ngsiv2/provisioning/device-group-utils-test.js +1 -0
- package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +1 -0
- package/test/unit/ngsiv2/provisioning/device-registration_test.js +2 -1
- package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +15 -12
- package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +1 -0
- package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +1 -0
- package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +1 -0
- package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +1 -0
- package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +1 -0
- package/test/unit/plugins/capture-configuration-inPlugins_test.js +2 -1
- package/test/unit/plugins/capture-provision-inPlugins_test.js +2 -1
- package/lib/plugins/addEvent.js +0 -32
- package/lib/plugins/attributeAlias.js +0 -107
- package/lib/plugins/multiEntity.js +0 -255
- package/lib/plugins/timestampProcessPlugin.js +0 -95
- package/test/unit/ngsi-ld/plugins/event-plugin_test.js +0 -116
- package/test/unit/ngsiv2/plugins/event-plugin_test.js +0 -118
- package/test/unit/ngsiv2/plugins/translation-inPlugins_test.js +0 -262
package/lib/plugins/addEvent.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2016 Telefonica Investigación y Desarrollo, S.A.U
|
|
3
|
-
*
|
|
4
|
-
* This file is part of fiware-iotagent-lib
|
|
5
|
-
*
|
|
6
|
-
* fiware-iotagent-lib is free software: you can redistribute it and/or
|
|
7
|
-
* modify it under the terms of the GNU Affero General Public License as
|
|
8
|
-
* published by the Free Software Foundation, either version 3 of the License,
|
|
9
|
-
* or (at your option) any later version.
|
|
10
|
-
*
|
|
11
|
-
* fiware-iotagent-lib is distributed in the hope that it will be useful,
|
|
12
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
14
|
-
* See the GNU Affero General Public License for more details.
|
|
15
|
-
*
|
|
16
|
-
* You should have received a copy of the GNU Affero General Public
|
|
17
|
-
* License along with fiware-iotagent-lib.
|
|
18
|
-
* If not, see http://www.gnu.org/licenses/.
|
|
19
|
-
*
|
|
20
|
-
* For those usages not covered by the GNU Affero General Public License
|
|
21
|
-
* please contact with::daniel.moranjimenez@telefonica.com
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
const pluginUtils = require('./pluginUtils');
|
|
25
|
-
const config = require('../commonConfig');
|
|
26
|
-
|
|
27
|
-
function addEvents() {
|
|
28
|
-
return new Date().toISOString();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
exports.update = pluginUtils.createUpdateFilter(addEvents, config.getConfig().eventType || 'Event');
|
|
32
|
-
exports.query = pluginUtils.identityFilter;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2015 Telefonica Investigación y Desarrollo, S.A.U
|
|
3
|
-
*
|
|
4
|
-
* This file is part of fiware-iotagent-lib
|
|
5
|
-
*
|
|
6
|
-
* fiware-iotagent-lib is free software: you can redistribute it and/or
|
|
7
|
-
* modify it under the terms of the GNU Affero General Public License as
|
|
8
|
-
* published by the Free Software Foundation, either version 3 of the License,
|
|
9
|
-
* or (at your option) any later version.
|
|
10
|
-
*
|
|
11
|
-
* fiware-iotagent-lib is distributed in the hope that it will be useful,
|
|
12
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
14
|
-
* See the GNU Affero General Public License for more details.
|
|
15
|
-
*
|
|
16
|
-
* You should have received a copy of the GNU Affero General Public
|
|
17
|
-
* License along with fiware-iotagent-lib.
|
|
18
|
-
* If not, see http://www.gnu.org/licenses/.
|
|
19
|
-
*
|
|
20
|
-
* For those usages not covered by the GNU Affero General Public License
|
|
21
|
-
* please contact with::daniel.moranjimenez@telefonica.com
|
|
22
|
-
*
|
|
23
|
-
* Modified by: Daniel Calvo - ATOS Research & Innovation
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
const utils = require('./pluginUtils');
|
|
27
|
-
/* eslint-disable no-unused-vars */
|
|
28
|
-
const logger = require('logops');
|
|
29
|
-
const context = {
|
|
30
|
-
op: 'IoTAgentNGSI.attributeAlias'
|
|
31
|
-
};
|
|
32
|
-
const ngsiUtils = require('../services/ngsi/ngsiUtils');
|
|
33
|
-
|
|
34
|
-
function extractSingleMapping(previous, current) {
|
|
35
|
-
/* jshint camelcase: false */
|
|
36
|
-
previous.direct[current.object_id] = current.name;
|
|
37
|
-
previous.types[current.object_id] = current.type;
|
|
38
|
-
previous.metadata[current.object_id] = current.metadata;
|
|
39
|
-
previous.inverse[current.name] = current.object_id; // collision using multientity
|
|
40
|
-
return previous;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Extract all the alias information for the attributes from the provisioning information provided for a device.
|
|
45
|
-
*
|
|
46
|
-
* @param {Object} typeInformation Provisioning information about the device represented by the entity.
|
|
47
|
-
* @return {{direct: {}, inverse: {}}} Object containing the direct and reverse name mappings.
|
|
48
|
-
*/
|
|
49
|
-
function extractAllMappings(typeInformation) {
|
|
50
|
-
let mappings = { direct: {}, inverse: {}, types: {}, metadata: {} };
|
|
51
|
-
|
|
52
|
-
if (typeInformation.active) {
|
|
53
|
-
mappings = typeInformation.active.reduce(extractSingleMapping, mappings);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (typeInformation.lazy) {
|
|
57
|
-
mappings = typeInformation.lazy.reduce(extractSingleMapping, mappings);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (typeInformation.commands) {
|
|
61
|
-
mappings = typeInformation.commands.reduce(extractSingleMapping, mappings);
|
|
62
|
-
}
|
|
63
|
-
return mappings;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Create a map function to apply a set of mappings to a vector of attributes.
|
|
68
|
-
*
|
|
69
|
-
* @param {Object} mappings Mappings to be applied.
|
|
70
|
-
* @return {aliasApplier} Map function that will apply the mappings to collections of objects.
|
|
71
|
-
*/
|
|
72
|
-
function applyAlias(mappings) {
|
|
73
|
-
return function aliasApplier(attribute) {
|
|
74
|
-
if (mappings.direct[attribute.name]) {
|
|
75
|
-
attribute.object_id = attribute.name;
|
|
76
|
-
attribute.metadata = mappings.metadata[attribute.name];
|
|
77
|
-
attribute.type = mappings.types[attribute.name];
|
|
78
|
-
attribute.name = mappings.direct[attribute.name];
|
|
79
|
-
}
|
|
80
|
-
return attribute;
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Filter to map attribute Ids into attribute names based on provisioning information.
|
|
86
|
-
*
|
|
87
|
-
* @param {Object} entity The entity to be modified, representing the information in a device.
|
|
88
|
-
* @param {Object} typeInformation Provisioning information about the device represented by the entity.
|
|
89
|
-
*/
|
|
90
|
-
function updateAttribute(entity, typeInformation, callback) {
|
|
91
|
-
const mappings = extractAllMappings(typeInformation);
|
|
92
|
-
|
|
93
|
-
let attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
|
|
94
|
-
attsArray = attsArray.map(applyAlias(mappings));
|
|
95
|
-
entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
|
|
96
|
-
ngsiUtils.castJsonNativeAttributes(entity);
|
|
97
|
-
|
|
98
|
-
callback(null, entity, typeInformation);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function queryAttribute(entity, typeInformation, callback) {
|
|
102
|
-
callback(null, entity, typeInformation);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
exports.update = updateAttribute;
|
|
106
|
-
exports.query = queryAttribute;
|
|
107
|
-
exports.extractAllMappings = extractAllMappings;
|
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2016 Telefonica Investigación y Desarrollo, S.A.U
|
|
3
|
-
*
|
|
4
|
-
* This file is part of fiware-iotagent-lib
|
|
5
|
-
*
|
|
6
|
-
* fiware-iotagent-lib is free software: you can redistribute it and/or
|
|
7
|
-
* modify it under the terms of the GNU Affero General Public License as
|
|
8
|
-
* published by the Free Software Foundation, either version 3 of the License,
|
|
9
|
-
* or (at your option) any later version.
|
|
10
|
-
*
|
|
11
|
-
* fiware-iotagent-lib is distributed in the hope that it will be useful,
|
|
12
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
14
|
-
* See the GNU Affero General Public License for more details.
|
|
15
|
-
*
|
|
16
|
-
* You should have received a copy of the GNU Affero General Public
|
|
17
|
-
* License along with fiware-iotagent-lib.
|
|
18
|
-
* If not, see http://www.gnu.org/licenses/.
|
|
19
|
-
*
|
|
20
|
-
* For those usages not covered by the GNU Affero General Public License
|
|
21
|
-
* please contact with::daniel.moranjimenez@telefonica.com
|
|
22
|
-
*
|
|
23
|
-
* Modified by: Daniel Calvo - ATOS Research & Innovation
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/* eslint-disable no-prototype-builtins */
|
|
27
|
-
/* eslint-disable array-callback-return */
|
|
28
|
-
|
|
29
|
-
const _ = require('underscore');
|
|
30
|
-
const constants = require('../constants');
|
|
31
|
-
const legacyParser = require('./expressionParser');
|
|
32
|
-
const jexlParser = require('./jexlParser');
|
|
33
|
-
const expressionPlugin = require('./expressionPlugin');
|
|
34
|
-
/* eslint-disable-next-line no-unused-vars */
|
|
35
|
-
const logger = require('logops');
|
|
36
|
-
/* eslint-disable-next-line no-unused-vars */
|
|
37
|
-
const context = {
|
|
38
|
-
op: 'IoTAgentNGSI.MultiEntityPlugin'
|
|
39
|
-
};
|
|
40
|
-
const utils = require('./pluginUtils');
|
|
41
|
-
/* eslint-disable-next-line no-unused-vars */
|
|
42
|
-
const aliasPlugin = require('./attributeAlias');
|
|
43
|
-
|
|
44
|
-
function hasEntityNameOrEntityType(item) {
|
|
45
|
-
return item.entity_name || item.entity_type;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Return a list of all the attributes that don't have a multientity option. It considers NGSIv2.
|
|
50
|
-
*
|
|
51
|
-
* @param {Array} originalAttrs Array of original attributes coming from the single-entity device.
|
|
52
|
-
* @param {Array} meAttributes Array of all the multientity attributes.
|
|
53
|
-
* @return {Array} List of all the attrbiutes without multientity flag.
|
|
54
|
-
*/
|
|
55
|
-
function filterOutMultientitiesNgsi2(originalAttrs, meAttributes) {
|
|
56
|
-
const result = {};
|
|
57
|
-
const meNamesList = _.pluck(meAttributes, 'name');
|
|
58
|
-
const meObjectsList = _.pluck(meAttributes, 'object_id');
|
|
59
|
-
let toBeFilteredByObj = [];
|
|
60
|
-
|
|
61
|
-
for (const att in originalAttrs) {
|
|
62
|
-
if (originalAttrs.hasOwnProperty(att)) {
|
|
63
|
-
if (!_.contains(meNamesList, att)) {
|
|
64
|
-
result[att] = originalAttrs[att];
|
|
65
|
-
}
|
|
66
|
-
if (originalAttrs[att].hasOwnProperty('multi')) {
|
|
67
|
-
let cleanAttributes = _.union([_.clone(originalAttrs[att])], originalAttrs[att].multi);
|
|
68
|
-
delete cleanAttributes[0].multi;
|
|
69
|
-
cleanAttributes = _.map(cleanAttributes, function (val) {
|
|
70
|
-
val['name'] = att;
|
|
71
|
-
return val;
|
|
72
|
-
});
|
|
73
|
-
toBeFilteredByObj = _.union(toBeFilteredByObj, cleanAttributes);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
for (const att in toBeFilteredByObj) {
|
|
79
|
-
if (!_.contains(meObjectsList, toBeFilteredByObj[att].object_id)) {
|
|
80
|
-
result[toBeFilteredByObj[att].name] = toBeFilteredByObj[att];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Generate new Context Elements for each new Entity, with the attributes of the original entity matching its
|
|
89
|
-
* entity_name. It considers Ngsiv2.
|
|
90
|
-
*
|
|
91
|
-
* @param {Object} entity The original entity
|
|
92
|
-
* @param {Array} newEntities List of the new entities that will be generated
|
|
93
|
-
* @param {Array} multiEntityAttributes List of attributes with multientity option
|
|
94
|
-
* @return {Array} List of the new Context Entities
|
|
95
|
-
*/
|
|
96
|
-
function generateNewCEsNgsi2(entity, newEntities, multiEntityAttributes) {
|
|
97
|
-
const result = [];
|
|
98
|
-
let newEntityAttributes;
|
|
99
|
-
let newEntityAttributeNames;
|
|
100
|
-
let newEntityAttributeObjectIds;
|
|
101
|
-
function filterByEntityNameandType(entityNameType) {
|
|
102
|
-
return function (item) {
|
|
103
|
-
return (
|
|
104
|
-
item.entity_name === entityNameType.entity_name &&
|
|
105
|
-
(!item.entity_type || item.entity_type === entityNameType.entity_type)
|
|
106
|
-
);
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function filterByAttributeObjectIds(entity, newEntityAttributeNames, newEntityAttributeObjectIds) {
|
|
111
|
-
const result = {};
|
|
112
|
-
for (const att in entity) {
|
|
113
|
-
if (entity.hasOwnProperty(att)) {
|
|
114
|
-
if (_.contains(newEntityAttributeNames, att)) {
|
|
115
|
-
if (entity[att].object_id && _.contains(newEntityAttributeObjectIds, entity[att].object_id)) {
|
|
116
|
-
result[att] = entity[att];
|
|
117
|
-
delete entity[att].object_id;
|
|
118
|
-
} else if (entity[att].multi) {
|
|
119
|
-
for (const j in entity[att].multi) {
|
|
120
|
-
if (
|
|
121
|
-
entity[att].multi[j].object_id &&
|
|
122
|
-
_.contains(newEntityAttributeObjectIds, entity[att].multi[j].object_id)
|
|
123
|
-
) {
|
|
124
|
-
result[att] = entity[att].multi[j];
|
|
125
|
-
delete entity[att].multi[j].object_id;
|
|
126
|
-
break; // stop in first ocurrence (#635)
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return result;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
for (let i = 0; i < newEntities.length; i++) {
|
|
137
|
-
newEntityAttributeNames = _.pluck(
|
|
138
|
-
multiEntityAttributes.filter(filterByEntityNameandType(newEntities[i])),
|
|
139
|
-
'name'
|
|
140
|
-
);
|
|
141
|
-
newEntityAttributeObjectIds = _.pluck(
|
|
142
|
-
multiEntityAttributes.filter(filterByEntityNameandType(newEntities[i])),
|
|
143
|
-
'object_id'
|
|
144
|
-
);
|
|
145
|
-
newEntityAttributes = filterByAttributeObjectIds(entity, newEntityAttributeNames, newEntityAttributeObjectIds);
|
|
146
|
-
newEntityAttributes.type = newEntities[i].entity_type;
|
|
147
|
-
newEntityAttributes.id = newEntities[i].entity_name;
|
|
148
|
-
result.push(newEntityAttributes);
|
|
149
|
-
}
|
|
150
|
-
return result;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function extractNewEntities(multiEntityAttributes, defaultType) {
|
|
154
|
-
let newEntitieswithDuplicates = multiEntityAttributes.map((elem) => {
|
|
155
|
-
return { entity_name: elem.entity_name, entity_type: elem.entity_type || defaultType };
|
|
156
|
-
});
|
|
157
|
-
let auxOverwriteTree = {};
|
|
158
|
-
for (let entityItem in newEntitieswithDuplicates) {
|
|
159
|
-
if (!auxOverwriteTree[newEntitieswithDuplicates[entityItem].entity_name]) {
|
|
160
|
-
auxOverwriteTree[newEntitieswithDuplicates[entityItem].entity_name] = {};
|
|
161
|
-
}
|
|
162
|
-
auxOverwriteTree[newEntitieswithDuplicates[entityItem].entity_name][
|
|
163
|
-
newEntitieswithDuplicates[entityItem].entity_type
|
|
164
|
-
] = null;
|
|
165
|
-
}
|
|
166
|
-
let flatNewEntities = [];
|
|
167
|
-
for (let entityItem in auxOverwriteTree) {
|
|
168
|
-
for (let typeItem in auxOverwriteTree[entityItem]) {
|
|
169
|
-
flatNewEntities.push({ entity_name: entityItem, entity_type: typeItem });
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return flatNewEntities;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Propagates the same timestamp used in entity to entities. This is needed given that timestamp processing
|
|
176
|
-
* plugin runs before multientity plugin, so we could have issues as the one described here:
|
|
177
|
-
* https://github.com/telefonicaid/iotagent-node-lib/issues/748
|
|
178
|
-
*
|
|
179
|
-
* Note that this kind of timestamp propagation only works for NGSIv2. That is intentional: NGSIv1 is
|
|
180
|
-
* deprecated so we don't want to spend effort on it.
|
|
181
|
-
*
|
|
182
|
-
* @param entity entity which is the source of timestamp
|
|
183
|
-
* @param entities array to adjust
|
|
184
|
-
*
|
|
185
|
-
*/
|
|
186
|
-
function propagateTimestamp(entity, entities) {
|
|
187
|
-
const ts = entity[constants.TIMESTAMP_ATTRIBUTE];
|
|
188
|
-
if (!ts) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
entities.map(function (en) {
|
|
193
|
-
let att;
|
|
194
|
-
// Set timestamp metadata in attributes (except TimeInstant attribute itself)
|
|
195
|
-
for (att in en && att !== constants.TIMESTAMP_ATTRIBUTE) {
|
|
196
|
-
if (en.hasOwnProperty(att) && att !== 'id' && att !== 'type') {
|
|
197
|
-
if (!en[att].metadata) {
|
|
198
|
-
en[att].metadata = {};
|
|
199
|
-
}
|
|
200
|
-
en[att].metadata[constants.TIMESTAMP_ATTRIBUTE] = ts;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
// Set timestamp attribute inm the entity itself
|
|
204
|
-
en[constants.TIMESTAMP_ATTRIBUTE] = ts;
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function updateAttribute(entity, typeInformation, callback) {
|
|
209
|
-
try {
|
|
210
|
-
logger.debug(context, 'multiEntityPlugin entity %j', entity);
|
|
211
|
-
let parser = jexlParser;
|
|
212
|
-
if (!expressionPlugin.checkJexl(typeInformation)) {
|
|
213
|
-
parser = legacyParser;
|
|
214
|
-
}
|
|
215
|
-
// The context for the JEXL expression should be the ID, TYPE, S, SS
|
|
216
|
-
let attrList = utils.getIdTypeServSubServiceFromDevice(typeInformation);
|
|
217
|
-
const attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
|
|
218
|
-
attrList = attrList.concat(attsArray);
|
|
219
|
-
const ctx = parser.extractContext(attrList);
|
|
220
|
-
let entities = [entity];
|
|
221
|
-
if (typeInformation.active) {
|
|
222
|
-
const multiEntityAttributes = typeInformation.active.filter(hasEntityNameOrEntityType);
|
|
223
|
-
for (let i in multiEntityAttributes) {
|
|
224
|
-
if (!multiEntityAttributes[i].entity_name) {
|
|
225
|
-
// Then hasEntityType and entity_name should be device.name
|
|
226
|
-
multiEntityAttributes[i].entity_name = typeInformation.name;
|
|
227
|
-
}
|
|
228
|
-
if (parser.contextAvailable(multiEntityAttributes[i].entity_name, ctx)) {
|
|
229
|
-
let entityName = parser.applyExpression(multiEntityAttributes[i].entity_name, ctx, typeInformation);
|
|
230
|
-
// An entity_name could not be null, but a result or expression could be null
|
|
231
|
-
if (entityName !== null) {
|
|
232
|
-
multiEntityAttributes[i].entity_name = entityName;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
const newEntities = extractNewEntities(multiEntityAttributes, typeInformation.type);
|
|
237
|
-
|
|
238
|
-
if (multiEntityAttributes.length > 0) {
|
|
239
|
-
let resultAttributes = filterOutMultientitiesNgsi2(entity, multiEntityAttributes);
|
|
240
|
-
const newCes = generateNewCEsNgsi2(entity, newEntities, multiEntityAttributes);
|
|
241
|
-
entities = [resultAttributes].concat(newCes);
|
|
242
|
-
propagateTimestamp(entity, entities);
|
|
243
|
-
} else {
|
|
244
|
-
entities = entity;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
callback(null, entities, typeInformation);
|
|
248
|
-
} catch (e) {
|
|
249
|
-
logger.info(context, 'multiEntityPlugin error %j procesing entity %j', e, entity);
|
|
250
|
-
callback(e);
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
exports.update = updateAttribute;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2016 Telefonica Investigación y Desarrollo, S.A.U
|
|
3
|
-
*
|
|
4
|
-
* This file is part of fiware-iotagent-lib
|
|
5
|
-
*
|
|
6
|
-
* fiware-iotagent-lib is free software: you can redistribute it and/or
|
|
7
|
-
* modify it under the terms of the GNU Affero General Public License as
|
|
8
|
-
* published by the Free Software Foundation, either version 3 of the License,
|
|
9
|
-
* or (at your option) any later version.
|
|
10
|
-
*
|
|
11
|
-
* fiware-iotagent-lib is distributed in the hope that it will be useful,
|
|
12
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
14
|
-
* See the GNU Affero General Public License for more details.
|
|
15
|
-
*
|
|
16
|
-
* You should have received a copy of the GNU Affero General Public
|
|
17
|
-
* License along with fiware-iotagent-lib.
|
|
18
|
-
* If not, see http://www.gnu.org/licenses/.
|
|
19
|
-
*
|
|
20
|
-
* For those usages not covered by the GNU Affero General Public License
|
|
21
|
-
* please contact with::daniel.moranjimenez@telefonica.com
|
|
22
|
-
*
|
|
23
|
-
* Modified by: Daniel Calvo - ATOS Research & Innovation
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/* eslint-disable no-prototype-builtins */
|
|
27
|
-
|
|
28
|
-
const errors = require('../errors');
|
|
29
|
-
const constants = require('../constants');
|
|
30
|
-
const logger = require('logops');
|
|
31
|
-
const context = {
|
|
32
|
-
op: 'IoTAgentNGSI.TimestampProcessPlugin'
|
|
33
|
-
};
|
|
34
|
-
const utils = require('./pluginUtils');
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Looks for Thinking Thing modules and parses them, updating the entity (NGSIv2) with the transformed value.
|
|
38
|
-
*
|
|
39
|
-
* @param {Object} entity NGSI Entity as it would have been sent before the plugin.
|
|
40
|
-
*/
|
|
41
|
-
function updatePluginNgsi2(entity, entityType, callback) {
|
|
42
|
-
let timestamp;
|
|
43
|
-
|
|
44
|
-
function insertMetadata(element) {
|
|
45
|
-
if (element.name !== constants.TIMESTAMP_ATTRIBUTE) {
|
|
46
|
-
const metadata = element.metadata || {};
|
|
47
|
-
metadata[constants.TIMESTAMP_ATTRIBUTE] = {
|
|
48
|
-
type: constants.TIMESTAMP_TYPE_NGSI2,
|
|
49
|
-
value: timestamp.value
|
|
50
|
-
};
|
|
51
|
-
element.metadata = metadata;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return element;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function updateSingleEntity(entity) {
|
|
58
|
-
let attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
|
|
59
|
-
|
|
60
|
-
if (entity && entity[constants.TIMESTAMP_ATTRIBUTE]) {
|
|
61
|
-
if (entity.hasOwnProperty(constants.TIMESTAMP_ATTRIBUTE)) {
|
|
62
|
-
timestamp = entity[constants.TIMESTAMP_ATTRIBUTE];
|
|
63
|
-
}
|
|
64
|
-
} else if (!entity) {
|
|
65
|
-
logger.error(context, 'Bad payload received while processing timestamps');
|
|
66
|
-
callback(new errors.WrongSyntax(entity));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (timestamp) {
|
|
70
|
-
attsArray = attsArray.map(insertMetadata);
|
|
71
|
-
}
|
|
72
|
-
timestamp = false; // reset for possible next entity
|
|
73
|
-
entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray);
|
|
74
|
-
return entity;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (entity instanceof Array) {
|
|
78
|
-
const results = entity.map(updateSingleEntity);
|
|
79
|
-
callback(null, results, entityType);
|
|
80
|
-
} else {
|
|
81
|
-
const newEntity = updateSingleEntity(entity);
|
|
82
|
-
callback(null, newEntity, entityType);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Looks for Thinking Thing modules and parses them, updating the entity with the transformed value.
|
|
88
|
-
*
|
|
89
|
-
* @param {Object} entity NGSI Entity as it would have been sent before the plugin.
|
|
90
|
-
*/
|
|
91
|
-
function updatePlugin(entity, entityType, callback) {
|
|
92
|
-
updatePluginNgsi2(entity, entityType, callback);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
exports.update = updatePlugin;
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Telefonica Investigación y Desarrollo, S.A.U
|
|
3
|
-
*
|
|
4
|
-
* This file is part of fiware-iotagent-lib
|
|
5
|
-
*
|
|
6
|
-
* fiware-iotagent-lib is free software: you can redistribute it and/or
|
|
7
|
-
* modify it under the terms of the GNU Affero General Public License as
|
|
8
|
-
* published by the Free Software Foundation, either version 3 of the License,
|
|
9
|
-
* or (at your option) any later version.
|
|
10
|
-
*
|
|
11
|
-
* fiware-iotagent-lib is distributed in the hope that it will be useful,
|
|
12
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
14
|
-
* See the GNU Affero General Public License for more details.
|
|
15
|
-
*
|
|
16
|
-
* You should have received a copy of the GNU Affero General Public
|
|
17
|
-
* License along with fiware-iotagent-lib.
|
|
18
|
-
* If not, see http://www.gnu.org/licenses/.
|
|
19
|
-
*
|
|
20
|
-
* For those usages not covered by the GNU Affero General Public License
|
|
21
|
-
* please contact with::daniel.moranjimenez@telefonica.com
|
|
22
|
-
*
|
|
23
|
-
* Modified by: Jason Fox - FIWARE Foundation
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
|
|
27
|
-
const should = require('should');
|
|
28
|
-
const logger = require('logops');
|
|
29
|
-
const nock = require('nock');
|
|
30
|
-
let contextBrokerMock;
|
|
31
|
-
const iotAgentConfig = {
|
|
32
|
-
contextBroker: {
|
|
33
|
-
host: '192.168.1.1',
|
|
34
|
-
port: '1026',
|
|
35
|
-
ngsiVersion: 'ld',
|
|
36
|
-
jsonLdContext: 'http://context.json-ld'
|
|
37
|
-
},
|
|
38
|
-
server: {
|
|
39
|
-
port: 4041
|
|
40
|
-
},
|
|
41
|
-
types: {
|
|
42
|
-
Light: {
|
|
43
|
-
commands: [],
|
|
44
|
-
type: 'Light',
|
|
45
|
-
lazy: [
|
|
46
|
-
{
|
|
47
|
-
name: 'temperature',
|
|
48
|
-
type: 'centigrades'
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
active: [
|
|
52
|
-
{
|
|
53
|
-
name: 'pressure',
|
|
54
|
-
type: 'Hgmm'
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
service: 'smartgondor',
|
|
60
|
-
subservice: 'gardens',
|
|
61
|
-
providerUrl: 'http://smartgondor.com'
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
describe('NGSI-LD - Event plugin', function () {
|
|
65
|
-
beforeEach(function (done) {
|
|
66
|
-
logger.setLevel('FATAL');
|
|
67
|
-
|
|
68
|
-
iotAgentLib.activate(iotAgentConfig, function () {
|
|
69
|
-
iotAgentLib.clearAll(function () {
|
|
70
|
-
iotAgentLib.addUpdateMiddleware(iotAgentLib.dataPlugins.addEvents.update);
|
|
71
|
-
iotAgentLib.addQueryMiddleware(iotAgentLib.dataPlugins.addEvents.query);
|
|
72
|
-
done();
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
afterEach(function (done) {
|
|
78
|
-
iotAgentLib.clearAll(function () {
|
|
79
|
-
iotAgentLib.deactivate(done);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
describe('When an update comes with an event to the plugin', function () {
|
|
83
|
-
const values = [
|
|
84
|
-
{
|
|
85
|
-
name: 'state',
|
|
86
|
-
type: 'Boolean',
|
|
87
|
-
value: 'true'
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
name: 'activation',
|
|
91
|
-
type: 'Event',
|
|
92
|
-
value: '1'
|
|
93
|
-
}
|
|
94
|
-
];
|
|
95
|
-
|
|
96
|
-
beforeEach(function () {
|
|
97
|
-
nock.cleanAll();
|
|
98
|
-
|
|
99
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
100
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
101
|
-
.post('/ngsi-ld/v1/entityOperations/upsert/?options=update', function (body) {
|
|
102
|
-
const dateRegex = /\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d.\d{3}Z/;
|
|
103
|
-
return body[0].activation.value['@value'].match(dateRegex);
|
|
104
|
-
})
|
|
105
|
-
.reply(204);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should return an entity with all its timestamps expanded to have separators', function (done) {
|
|
109
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
110
|
-
should.not.exist(error);
|
|
111
|
-
contextBrokerMock.done();
|
|
112
|
-
done();
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|