From 54fb27a424bd52d2238dc04a55005e8f99249fb3 Mon Sep 17 00:00:00 2001 From: Guillaume Odile <146841815+GuillaumeOd@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:17:10 +0100 Subject: [PATCH 1/3] fix: attribute loss when updating entity --- CHANGES_NEXT_RELEASE | 1 + lib/services/ngsi/entities-NGSI-v2.js | 2 +- test/functional/testCases.js | 29 +++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index e69de29bb..051ef991d 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -0,0 +1 @@ +- Fix attribute loss during device update when both name and object_id are defined by filtering only object_id (#1660) diff --git a/lib/services/ngsi/entities-NGSI-v2.js b/lib/services/ngsi/entities-NGSI-v2.js index e180e607a..d39dbedb7 100644 --- a/lib/services/ngsi/entities-NGSI-v2.js +++ b/lib/services/ngsi/entities-NGSI-v2.js @@ -467,7 +467,7 @@ function sendUpdateValueNgsi2(entityName, originMeasures, originTypeInformation, } //remove measures that has been shadowed by an alias (some may be left and managed later) //Maybe we must filter object_id if there is name == object_id - measures = measures.filter((item) => item.name !== currentAttr.object_id && item.name !== currentAttr.name); + measures = measures.filter((item) => item.name !== currentAttr.object_id); if ( currentAttr.expression !== undefined && diff --git a/test/functional/testCases.js b/test/functional/testCases.js index b2f850aa5..1411165cf 100644 --- a/test/functional/testCases.js +++ b/test/functional/testCases.js @@ -542,6 +542,16 @@ const testCases = [ object_id: '.1.0.0.1', name: 'psBatteryVoltage', type: 'Number' + }, + { + object_id: 'fdt', + name: 'fireDetectionThreshold', + type: 'Number' + }, + { + object_id: 'fireDetectionThreshold3', + name: 'fireDetectionThreshold3', + type: 'Number' } ], static_attributes: [] @@ -556,7 +566,7 @@ const testCases = [ should: [ { shouldName: - 'A - WHEN sending defined object_ids with special format names (measures) through http IT should send measures to Context Broker preserving value types, name mappings and metadatas', + 'A - WHEN sending defined object_ids with special format names in attributes through http IT should send measures to Context Broker preserving value types, name mappings and metadatas', type: 'single', measure: { url: 'http://localhost:' + config.http.port + '/iot/json', @@ -567,7 +577,10 @@ const testCases = [ }, json: { a: false, - '.1.0.0.1': 23.5 + '.1.0.0.1': 23.5, + fdt: 10, + fireDetectionThreshold2: 20, + fireDetectionThreshold3: 30 } }, expectation: { @@ -586,6 +599,18 @@ const testCases = [ psBatteryVoltage: { type: 'Number', value: 23.5 + }, + fireDetectionThreshold: { + type: 'Number', + value: 10 + }, + fireDetectionThreshold2: { + type: 'Text', + value: 20 + }, + fireDetectionThreshold3: { + type: 'Number', + value: 30 } } } From 6ad4e387fe91218258e9ea77e98e7e2008e05e7a Mon Sep 17 00:00:00 2001 From: edwinvautier Date: Mon, 7 Jul 2025 14:21:13 +0200 Subject: [PATCH 2/3] test: add dedicated test for special named attr --- test/functional/testCases.js | 76 +++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/test/functional/testCases.js b/test/functional/testCases.js index 1411165cf..d5ccaac63 100644 --- a/test/functional/testCases.js +++ b/test/functional/testCases.js @@ -542,16 +542,6 @@ const testCases = [ object_id: '.1.0.0.1', name: 'psBatteryVoltage', type: 'Number' - }, - { - object_id: 'fdt', - name: 'fireDetectionThreshold', - type: 'Number' - }, - { - object_id: 'fireDetectionThreshold3', - name: 'fireDetectionThreshold3', - type: 'Number' } ], static_attributes: [] @@ -566,7 +556,7 @@ const testCases = [ should: [ { shouldName: - 'A - WHEN sending defined object_ids with special format names in attributes through http IT should send measures to Context Broker preserving value types, name mappings and metadatas', + 'A - WHEN sending defined object_ids with special format names (measures) through http IT should send measures to Context Broker preserving value types, name mappings and metadatas', type: 'single', measure: { url: 'http://localhost:' + config.http.port + '/iot/json', @@ -577,10 +567,7 @@ const testCases = [ }, json: { a: false, - '.1.0.0.1': 23.5, - fdt: 10, - fireDetectionThreshold2: 20, - fireDetectionThreshold3: 30 + '.1.0.0.1': 23.5 } }, expectation: { @@ -599,7 +586,66 @@ const testCases = [ psBatteryVoltage: { type: 'Number', value: 23.5 + } + } + } + ] + }, + { + describeName: '0021c - Simple group with active attributes with special names in object_id', + provision: { + url: 'http://localhost:' + config.iota.server.port + '/iot/services', + method: 'POST', + json: { + services: [ + { + resource: '/iot/json', + apikey: globalEnv.apikey, + entity_type: globalEnv.entity_type, + commands: [], + lazy: [], + attributes: [ + { + object_id: 'fdt', + name: 'fireDetectionThreshold', + type: 'Number' + }, + { + object_id: 'fireDetectionThreshold3', + name: 'fireDetectionThreshold3', + type: 'Number' + } + ], + static_attributes: [] + } + ] + }, + headers: { + 'fiware-service': globalEnv.service, + 'fiware-servicepath': globalEnv.servicePath + } + }, + should: [ + { + shouldName: + 'A - WHEN sending defined object_ids with special format names in attributes through http IT should send measures to Context Broker preserving value types, name mappings and metadatas', + type: 'single', + measure: { + url: 'http://localhost:' + config.http.port + '/iot/json', + method: 'POST', + qs: { + i: globalEnv.deviceId, + k: globalEnv.apikey }, + json: { + fdt: 10, + fireDetectionThreshold2: 20, + fireDetectionThreshold3: 30 + } + }, + expectation: { + id: globalEnv.entity_name, + type: globalEnv.entity_type, fireDetectionThreshold: { type: 'Number', value: 10 From d07fcffa2b758bbb9b9496d3d239ae1b206b4dc4 Mon Sep 17 00:00:00 2001 From: edwinvautier Date: Tue, 9 Sep 2025 10:09:04 +0200 Subject: [PATCH 3/3] test: test case did not cover the fix --- test/functional/testCases.js | 38 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/test/functional/testCases.js b/test/functional/testCases.js index d5ccaac63..7dec4b0a4 100644 --- a/test/functional/testCases.js +++ b/test/functional/testCases.js @@ -606,14 +606,18 @@ const testCases = [ lazy: [], attributes: [ { - object_id: 'fdt', - name: 'fireDetectionThreshold', - type: 'Number' + name: 'mainDoorEvent', + type: 'Boolean' }, { - object_id: 'fireDetectionThreshold3', - name: 'fireDetectionThreshold3', - type: 'Number' + name: 'psSMDUHPower14', + type: 'Text', + object_id: '.1.3.6.1.4.1.6302.2.1.2.17.1.1.15.1702' + }, + { + name: 'psSMDUHPower17', + type: 'Number', + object_id: '.1.3.6.1.4.1.6302.2.1.2.17.1.1.18.1702' } ], static_attributes: [] @@ -638,25 +642,25 @@ const testCases = [ k: globalEnv.apikey }, json: { - fdt: 10, - fireDetectionThreshold2: 20, - fireDetectionThreshold3: 30 + '.1.3.6.1.4.1.6302.2.1.2.17.1.1.18.1702': 3, + mainDoorEvent: 1, + psSMDUHPower14: 2 } }, expectation: { id: globalEnv.entity_name, type: globalEnv.entity_type, - fireDetectionThreshold: { + mainDoorEvent: { + type: 'Boolean', + value: 1 + }, + psSMDUHPower17: { type: 'Number', - value: 10 + value: 3 }, - fireDetectionThreshold2: { + psSMDUHPower14: { type: 'Text', - value: 20 - }, - fireDetectionThreshold3: { - type: 'Number', - value: 30 + value: 2 } } }