From 4e583694ead625339e3e2cb7bd9177def78abe60 Mon Sep 17 00:00:00 2001 From: mapedraza <40356341+mapedraza@users.noreply.github.com> Date: Tue, 14 May 2024 15:50:24 +0200 Subject: [PATCH 1/7] add 533 --- test/functional/testCases.js | 101 +++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/test/functional/testCases.js b/test/functional/testCases.js index 9f88f75d1..da12394c6 100644 --- a/test/functional/testCases.js +++ b/test/functional/testCases.js @@ -2968,6 +2968,107 @@ const testCases = [ } ] }, + { + describeName: + '0533 - Group with explicit attrs:[ ] (empty array) + active attributes + TimeInstant attribute + static attributes + timestamp:true', + 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, + explicitAttrs: "['DateIssued']", + timestamp: true, + commands: [], + lazy: [], + attributes: [ + { + name: 'attr_a', + object_id: 'a', + type: 'Number' + }, + { + name: 'attr_b', + object_id: 'b', + type: 'Number' + }, + { + name: 'DateIssued', + object_id: 'TimeInstant', + type: 'DateTime' + }, + { + name: 'TimeInstant', + object_id: 't', + type: 'DateTime' + } + ], + static_attributes: [ + { + name: 'static_a', + type: 'Number', + value: 3 + }, + { + name: 'static_b', + type: 'Number', + value: 4 + } + ] + } + ] + }, + headers: { + 'fiware-service': globalEnv.service, + 'fiware-servicepath': globalEnv.servicePath + } + }, + should: [ + { + shouldName: + 'A - WHEN sending data and a measure called "t" (defined as TimeInstant attribte) through http IT should NOT store anything into the Context Broker (No request to CB)', + type: 'single', + measure: { + url: 'http://localhost:' + config.http.port + '/iot/json', + method: 'POST', + qs: { + i: globalEnv.deviceId, + k: globalEnv.apikey + }, + json: { + a: 3, + b: 10, + c: 11, + t: '2015-12-14T08:06:01.468Z' + } + }, + expectation: {} + }, + { + shouldName: + 'B - WHEN sending data and a measure called TimeInstant through http IT should NOT store anything into the Context Broker (No request to CB)', + type: 'single', + measure: { + url: 'http://localhost:' + config.http.port + '/iot/json', + method: 'POST', + qs: { + i: globalEnv.deviceId, + k: globalEnv.apikey + }, + json: { + a: 3, + b: 10, + c: 11, + TimeInstant: '2015-12-14T08:06:01.468Z' + } + }, + expectation: {} // No payload expected + } + ] + }, { describeName: '0540 - Group with explicit attrs: JEXL expression based on measure resulting boolean + active attributes + static attributes', From f364cc1658325d6a2258ceedfe92a37702944de3 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Fri, 17 May 2024 10:08:53 +0200 Subject: [PATCH 2/7] add test with empy array for explicitAttrs and timestamp false --- test/functional/testCases.js | 114 ++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 3 deletions(-) diff --git a/test/functional/testCases.js b/test/functional/testCases.js index da12394c6..ab5cfd4c5 100644 --- a/test/functional/testCases.js +++ b/test/functional/testCases.js @@ -2980,7 +2980,7 @@ const testCases = [ resource: '/iot/json', apikey: globalEnv.apikey, entity_type: globalEnv.entity_type, - explicitAttrs: "['DateIssued']", + explicitAttrs: '[ ]', timestamp: true, commands: [], lazy: [], @@ -3045,7 +3045,115 @@ const testCases = [ t: '2015-12-14T08:06:01.468Z' } }, - expectation: {} + expectation: { + id: 'TestType:TestDevice', + type: 'TestType', + TimeInstant: { + type: 'DateTime', + value: '2015-12-14T08:06:01.468Z' + } + } + }, + { + shouldName: + 'B - WHEN sending data and a measure called TimeInstant through http IT should NOT store anything into the Context Broker (No request to CB)', + type: 'single', + measure: { + url: 'http://localhost:' + config.http.port + '/iot/json', + method: 'POST', + qs: { + i: globalEnv.deviceId, + k: globalEnv.apikey + }, + json: { + a: 3, + b: 10, + c: 11, + TimeInstant: '2015-12-14T08:06:01.468Z' + } + }, + expectation: [] // No payload expected + } + ] + }, + { + describeName: + '0534 - Group with explicit attrs:[ ] (empty array) + active attributes + TimeInstant attribute + static attributes + timestamp:false', + 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, + explicitAttrs: '[ ]', + timestamp: false, + commands: [], + lazy: [], + attributes: [ + { + name: 'attr_a', + object_id: 'a', + type: 'Number' + }, + { + name: 'attr_b', + object_id: 'b', + type: 'Number' + }, + { + name: 'DateIssued', + object_id: 'TimeInstant', + type: 'DateTime' + }, + { + name: 'TimeInstant', + object_id: 't', + type: 'DateTime' + } + ], + static_attributes: [ + { + name: 'static_a', + type: 'Number', + value: 3 + }, + { + name: 'static_b', + type: 'Number', + value: 4 + } + ] + } + ] + }, + headers: { + 'fiware-service': globalEnv.service, + 'fiware-servicepath': globalEnv.servicePath + } + }, + should: [ + { + shouldName: + 'A - WHEN sending data and a measure called "t" (defined as TimeInstant attribte) through http IT should NOT store anything into the Context Broker (No request to CB)', + type: 'single', + measure: { + url: 'http://localhost:' + config.http.port + '/iot/json', + method: 'POST', + qs: { + i: globalEnv.deviceId, + k: globalEnv.apikey + }, + json: { + a: 3, + b: 10, + c: 11, + t: '2015-12-14T08:06:01.468Z' + } + }, + expectation: [] }, { shouldName: @@ -3065,7 +3173,7 @@ const testCases = [ TimeInstant: '2015-12-14T08:06:01.468Z' } }, - expectation: {} // No payload expected + expectation: [] // No payload expected } ] }, From 9ea5d39af63a8f0e23f5f87fbaf0834643017a97 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 6 Jun 2024 10:39:13 +0200 Subject: [PATCH 3/7] check explicitAttrs array is not empty before add timestamp as attribute --- lib/services/ngsi/entities-NGSI-v2.js | 2 +- test/functional/testCases.js | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/services/ngsi/entities-NGSI-v2.js b/lib/services/ngsi/entities-NGSI-v2.js index dc5e3b733..a02d9aa60 100644 --- a/lib/services/ngsi/entities-NGSI-v2.js +++ b/lib/services/ngsi/entities-NGSI-v2.js @@ -504,7 +504,7 @@ function sendUpdateValueNgsi2(entityName, measures, typeInformation, token, call if (typeof typeInformation.explicitAttrs === 'string') { try { explicit = jexlParser.applyExpression(typeInformation.explicitAttrs, jexlctxt, typeInformation); - if (explicit instanceof Array && mustInsertTimeInstant) { + if (explicit instanceof Array && explicit.length > 0 && mustInsertTimeInstant) { explicit.push(constants.TIMESTAMP_ATTRIBUTE); } logger.debug( diff --git a/test/functional/testCases.js b/test/functional/testCases.js index ab5cfd4c5..389d6f8ac 100644 --- a/test/functional/testCases.js +++ b/test/functional/testCases.js @@ -3045,14 +3045,7 @@ const testCases = [ t: '2015-12-14T08:06:01.468Z' } }, - expectation: { - id: 'TestType:TestDevice', - type: 'TestType', - TimeInstant: { - type: 'DateTime', - value: '2015-12-14T08:06:01.468Z' - } - } + expectation: [] }, { shouldName: From 3176f6cf595a88350a0b25ecd1097fb14c2fe18f Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 6 Jun 2024 11:24:24 +0200 Subject: [PATCH 4/7] update CNR --- CHANGES_NEXT_RELEASE | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index d04285253..5169f122e 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,3 +1,4 @@ +- Feature: do not propage TimeInstnat when explicitAttrs is empty array - Fix: update device using previous device apikey to avoid error when apikey is updated (iota-json#833) - Fix: allow send multiple measures to CB in a batch (POST /v2/op/update) and sorted by TimeInstant when possible, instead of using multiples single request (iotagent-json#825, #1612) - Fix: default express limit to 1Mb instead default 100Kb and allow change it throught a conf env var 'IOTA_EXPRESS_LIMIT' (iotagent-json#827) From 37c255e8748b033c3aeb991e78c18c5f3dae81b1 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 6 Jun 2024 12:53:56 +0200 Subject: [PATCH 5/7] update CNR --- doc/api.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/api.md b/doc/api.md index b614a2799..f2b74c59b 100644 --- a/doc/api.md +++ b/doc/api.md @@ -464,7 +464,8 @@ element. By adding the field `explicitAttrs` with `true` value to device or conf measure elements that are not defined in the mappings of device or config group, persisting only the one defined in the mappings of the provision. If `explicitAttrs` is provided both at device and config group level, the device level takes precedence. Additionally `explicitAttrs` can be used to define which measures (identified by their attribute names, not -by their object_id) defined in JSON/JEXL array will be propagated to NGSI interface. +by their object_id) defined in JSON/JEXL array will be propagated to NGSI interface. When `explicitAttrs` is an array or +and JEXL expression resulting in to Array, if this array is empty then `TimeInstant` is not propaged to CB. The different possibilities are summarized below: From b0422bd9d01751565b42153dff0948f0ac2ebf3c Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 6 Jun 2024 12:56:40 +0200 Subject: [PATCH 6/7] Update CHANGES_NEXT_RELEASE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fermín Galán Márquez --- CHANGES_NEXT_RELEASE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 5169f122e..10c4b4eb7 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,4 +1,4 @@ -- Feature: do not propage TimeInstnat when explicitAttrs is empty array +- Fix: do not propage TimeInstant when explicitAttrs is empty array (#1606) - Fix: update device using previous device apikey to avoid error when apikey is updated (iota-json#833) - Fix: allow send multiple measures to CB in a batch (POST /v2/op/update) and sorted by TimeInstant when possible, instead of using multiples single request (iotagent-json#825, #1612) - Fix: default express limit to 1Mb instead default 100Kb and allow change it throught a conf env var 'IOTA_EXPRESS_LIMIT' (iotagent-json#827) From ea2979dc4fad0afa4174a8151312331e373742a8 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 6 Jun 2024 12:56:52 +0200 Subject: [PATCH 7/7] Update doc/api.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fermín Galán Márquez --- doc/api.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/api.md b/doc/api.md index f2b74c59b..c928422d4 100644 --- a/doc/api.md +++ b/doc/api.md @@ -464,8 +464,9 @@ element. By adding the field `explicitAttrs` with `true` value to device or conf measure elements that are not defined in the mappings of device or config group, persisting only the one defined in the mappings of the provision. If `explicitAttrs` is provided both at device and config group level, the device level takes precedence. Additionally `explicitAttrs` can be used to define which measures (identified by their attribute names, not -by their object_id) defined in JSON/JEXL array will be propagated to NGSI interface. When `explicitAttrs` is an array or -and JEXL expression resulting in to Array, if this array is empty then `TimeInstant` is not propaged to CB. +by their object_id) defined in JSON/JEXL array will be propagated to NGSI interface. + +Note that when `explicitAttrs` is an array or a JEXL expression resulting in to Array, if this array is empty then `TimeInstant` is not propaged to CB. The different possibilities are summarized below: