From 6c079951887be5435e584f117b8aa937e126aaf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Wed, 10 Jul 2024 11:53:44 +0200 Subject: [PATCH 01/10] ADD jexl_transformation_substring.test test case --- .../jexl_transformation_substring.test | 234 ++++++++++++++++++ 1 file changed, 234 insertions(+) create mode 100644 test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_substring.test diff --git a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_substring.test b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_substring.test new file mode 100644 index 0000000000..bd9f96db3e --- /dev/null +++ b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_substring.test @@ -0,0 +1,234 @@ +# Copyright 2024 Telefonica Investigacion y Desarrollo, S.A.U +# +# This file is part of Orion Context Broker. +# +# Orion Context Broker is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Orion Context Broker is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. +# +# For those usages not covered by this license please contact with +# iot_support at tid dot es + +# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh +# JEXL_EXPR_FLAVOUR - to mark the test has to execute only when contextBroker includes jexl-expr flavour + +--NAME-- +JEXL expression substring specific cases + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# +# 01. Create custom sub with custom expression A=S|substring(0,2), B=S|substring(3,5), C=S|substring(3,50), D=S|substring(5,3) +# 02. Create entity E with S=X1:X2 +# 03. Update entity E with S=Y1:Y2 +# 04. Dump accumulator and see notifications (A=X1,B=X2,C=null,D=null) (A=Y1,B=Y2,C=null,D=null) +# + + +echo "01. Create custom sub with custom expression A=S|substring(0,2), B=S|substring(3,5), C=S|substring(3,50), D=S|substring(5,3)" +echo "============================================================================================================================" +payload='{ + "subject": { + "entities": [ + { + "id" : "E", + "type": "T" + } + ] + }, + "notification": { + "httpCustom": { + "url": "http://127.0.0.1:'${LISTENER_PORT}'/notify", + "ngsi": { + "A": { + "value": "${S|substring(0,2)}", + "type": "Calculated" + }, + "B": { + "value": "${S|substring(3,5)}", + "type": "Calculated" + }, + "C": { + "value": "${S|substring(3,50)}", + "type": "Calculated" + }, + "D": { + "value": "${S|substring(5,3)}", + "type": "Calculated" + } + } + }, + "attrs": [ "A", "B", "C", "D" ] + } +}' +orionCurl --url /v2/subscriptions --payload "$payload" +echo +echo + + +echo "02. Create entity E with S=X1:X2" +echo "================================" +payload='{ + "id": "E", + "type": "T", + "S": { + "value": "X1:X2", + "type": "Text" + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "03. Update entity E with S=Y1:Y2" +echo "================================" +payload='{ + "S": { + "value": "Y1:Y2", + "type": "Text" + } +}' +orionCurl --url /v2/entities/E/attrs --payload "$payload" +echo +echo + + +echo "04. Dump accumulator and see notifications (E1/T1 A:1, E2/T2 A:2)" +echo "=================================================================" +accumulatorDump +echo +echo + + +--REGEXPECT-- +01. Create custom sub with custom expression A=S|substring(0,2), B=S|substring(3,5), C=S|substring(3,50), D=S|substring(5,3) +============================================================================================================================ +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/subscriptions/REGEX([0-9a-f]{24}) +Content-Length: 0 + + + +02. Create entity E with S=X1:X2 +================================ +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/entities/E?type=T +Content-Length: 0 + + + +03. Update entity E with S=Y1:Y2 +================================ +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +04. Dump accumulator and see notifications (E1/T1 A:1, E2/T2 A:2) +================================================================= +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: x +User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) +Ngsiv2-Attrsformat: normalized +Host: 127.0.0.1:REGEX(\d+) +Accept: application/json +Content-Type: application/json; charset=utf-8 +Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 + +{ + "data": [ + { + "A": { + "metadata": {}, + "type": "Calculated", + "value": "X1" + }, + "B": { + "metadata": {}, + "type": "Calculated", + "value": "X2" + }, + "C": { + "metadata": {}, + "type": "Calculated", + "value": null + }, + "D": { + "metadata": {}, + "type": "Calculated", + "value": null + }, + "id": "E", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: x +User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) +Ngsiv2-Attrsformat: normalized +Host: 127.0.0.1:REGEX(\d+) +Accept: application/json +Content-Type: application/json; charset=utf-8 +Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 + +{ + "data": [ + { + "A": { + "metadata": {}, + "type": "Calculated", + "value": "Y1" + }, + "B": { + "metadata": {}, + "type": "Calculated", + "value": "Y2" + }, + "C": { + "metadata": {}, + "type": "Calculated", + "value": null + }, + "D": { + "metadata": {}, + "type": "Calculated", + "value": null + }, + "id": "E", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= + + +--TEARDOWN-- +brokerStop CB +dbDrop CB +accumulatorStop From 7280faa5faa2e8aefa7615bdbd6f481cce23201b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Wed, 10 Jul 2024 13:11:56 +0200 Subject: [PATCH 02/10] FIX substring transformation docu --- doc/manuals/orion-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manuals/orion-api.md b/doc/manuals/orion-api.md index 1c1bbc1961..b1431b8e93 100644 --- a/doc/manuals/orion-api.md +++ b/doc/manuals/orion-api.md @@ -2684,7 +2684,7 @@ foo bar #### substring -Returns a substring between two positions. +Returns a substring between two positions or `null` in case of wrong parameters (eg. final position is longer than string, final position is leeser than initial position, etc.) Extra arguments: * Initial position From e430828a1d621d2aa7f6cf9554a3bfeb5e2c1bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Wed, 10 Jul 2024 13:12:16 +0200 Subject: [PATCH 03/10] FIX step cjexl version --- ci/deb/build.sh | 2 +- docker/Dockerfile | 2 +- docker/Dockerfile.alpine | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/deb/build.sh b/ci/deb/build.sh index 6202177dbb..1bc9150e16 100755 --- a/ci/deb/build.sh +++ b/ci/deb/build.sh @@ -175,7 +175,7 @@ rm -Rf /tmp/builder || true && mkdir -p /tmp/builder/{db1,db2,db,bu} if [ -z "${REPO_ACCESS_TOKEN}" ]; then echo "Builder: no REPO_ACCESS_TOKEN, skipping cjexl lib download" else - bash /opt/fiware-orion/get_cjexl.sh 0.3.0 $REPO_ACCESS_TOKEN + bash /opt/fiware-orion/get_cjexl.sh 0.4.0 $REPO_ACCESS_TOKEN fi if [ -n "${branch}" ]; then diff --git a/docker/Dockerfile b/docker/Dockerfile index 73d0501729..aac4d0b52f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -102,7 +102,7 @@ RUN --mount=type=secret,id=repo_token,dst=/run/secrets/repo_token \ git clone https://github.com/${GIT_NAME}/fiware-orion && \ cd fiware-orion && \ git checkout ${GIT_REV_ORION} && \ - bash get_cjexl.sh 0.3.0 $(cat /run/secrets/repo_token) && \ + bash get_cjexl.sh 0.4.0 $(cat /run/secrets/repo_token) && \ make && \ make install && \ # reduce size of installed binaries diff --git a/docker/Dockerfile.alpine b/docker/Dockerfile.alpine index 552b903108..884c9cf1ef 100644 --- a/docker/Dockerfile.alpine +++ b/docker/Dockerfile.alpine @@ -108,7 +108,7 @@ RUN --mount=type=secret,id=repo_token,dst=/run/secrets/repo_token \ git clone https://github.com/${GIT_NAME}/fiware-orion && \ cd fiware-orion && \ git checkout ${GIT_REV_ORION} && \ - bash get_cjexl.sh 0.3.0 $(cat /run/secrets/repo_token) && \ + bash get_cjexl.sh 0.4.0 $(cat /run/secrets/repo_token) && \ # patch bash and mktemp statement in build script, as in alpine is slightly different sed -i 's/mktemp \/tmp\/compileInfo.h.XXXX/mktemp/g' scripts/build/compileInfo.sh && \ sed -i 's/bash/ash/g' scripts/build/compileInfo.sh && \ From 132e364f4d291366bfd80c8823adbbae54513904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Thu, 1 Aug 2024 10:43:01 +0200 Subject: [PATCH 04/10] ADD 4004 new cases --- .../jexl_transformation_full.test | 46 +++- .../jexl_transformation_substring.test | 4 +- ...l_transformation_time_transformations.test | 214 +++++++++++++++++ ...mation_time_transformations_datetimes.test | 215 ++++++++++++++++++ 4 files changed, 475 insertions(+), 4 deletions(-) create mode 100644 test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations.test create mode 100644 test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations_datetimes.test diff --git a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_full.test b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_full.test index 12646463e7..10ba03a673 100644 --- a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_full.test +++ b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_full.test @@ -81,7 +81,10 @@ payload='{ "AA", "AB", "AC", - "AD" + "AD", + "AE", + "AF", + "AG" ], "httpCustom": { "url": "http://127.0.0.1:'${LISTENER_PORT}'/notify", @@ -205,6 +208,18 @@ payload='{ "AD": { "type": "Number", "value": "${AD|len}" + }, + "AE": { + "type": "Number", + "value": "${AE|now}" + }, + "AF": { + "type": "Text", + "value": "${AF|toIsoString}" + }, + "AG": { + "type": "Number", + "value": "${AG|getTime}" } } } @@ -344,6 +359,18 @@ payload='{ "AD": { "type": "StructuredValue", "value": [1, 2, 3] + }, + "AE": { + "type": "Number", + "value": 0 + }, + "AF": { + "type": "Number", + "value": 1722500129 + }, + "AG": { + "type": "Number", + "value": "1979-11-13T18:01:14+00:00" } }' orionCurl --url /v2/entities --payload "$payload" @@ -383,7 +410,7 @@ Content-Length: 0 ================================================== POST http://127.0.0.1:REGEX(\d+)/notify Fiware-Servicepath: / -Content-Length: 1627 +Content-Length: 1809 User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) Ngsiv2-Attrsformat: normalized Host: 127.0.0.1:REGEX(\d+) @@ -422,6 +449,21 @@ Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 "type": "Number", "value": 3 }, + "AE": { + "metadata": {}, + "type": "Number", + "value": REGEX(\d+) + }, + "AF": { + "metadata": {}, + "type": "Text", + "value": "2024-08-01T08:15:29+00:00" + }, + "AG": { + "metadata": {}, + "type": "Number", + "value": 311364074 + }, "B": { "metadata": {}, "type": "Text", diff --git a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_substring.test b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_substring.test index bd9f96db3e..d2e40950f3 100644 --- a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_substring.test +++ b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_substring.test @@ -148,7 +148,7 @@ Fiware-Correlator: REGEX([0-9a-f\-]{36}) ================================================================= POST http://127.0.0.1:REGEX(\d+)/notify Fiware-Servicepath: / -Content-Length: x +Content-Length: 288 User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) Ngsiv2-Attrsformat: normalized Host: 127.0.0.1:REGEX(\d+) @@ -188,7 +188,7 @@ Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 ======================================= POST http://127.0.0.1:REGEX(\d+)/notify Fiware-Servicepath: / -Content-Length: x +Content-Length: 288 User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) Ngsiv2-Attrsformat: normalized Host: 127.0.0.1:REGEX(\d+) diff --git a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations.test b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations.test new file mode 100644 index 0000000000..e5aedcdf6f --- /dev/null +++ b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations.test @@ -0,0 +1,214 @@ +# Copyright 2024 Telefonica Investigacion y Desarrollo, S.A.U +# +# This file is part of Orion Context Broker. +# +# Orion Context Broker is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Orion Context Broker is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. +# +# For those usages not covered by this license please contact with +# iot_support at tid dot es + +# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh +# JEXL_EXPR_FLAVOUR - to mark the test has to execute only when contextBroker includes jexl-expr flavour + +--NAME-- +JEXL expression time transformation specific cases + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# +# 01. Create custom sub with custom expression S=A|getTime|toIsoString, T=B|toIsoString|getTime +# 02. Create entity E with A=2060-02-04T23:28:10+00:00, B=1722501038 +# 03. Update entity E with A=2040-03-12T21:04:13+00:00, B=122501038 +# 04. Dump accumulator and see notifications (S=2060-02-04T23:28:10+00:00, T=1722501038) (S=2040-03-12T21:04:13+00:00, T=122501038) +# + + +echo "01. Create custom sub with custom expression S=A|getTime|toIsoString, T=B|toIsoString|getTime" +echo "=============================================================================================" +payload='{ + "subject": { + "entities": [ + { + "id" : "E", + "type": "T" + } + ] + }, + "notification": { + "httpCustom": { + "url": "http://127.0.0.1:'${LISTENER_PORT}'/notify", + "ngsi": { + "S": { + "value": "${A|getTime|toIsoString}", + "type": "Calculated" + }, + "T": { + "value": "${B|toIsoString|getTime}", + "type": "Calculated" + } + } + }, + "attrs": [ "S", "T" ] + } +}' +orionCurl --url /v2/subscriptions --payload "$payload" +echo +echo + + +echo "02. Create entity E with A=2060-02-04T23:28:10+00:00, B=1722501038" +echo "==================================================================" +payload='{ + "id": "E", + "type": "T", + "A": { + "value": "2060-02-04T23:28:10+00:00", + "type": "Text" + }, + "B": { + "value": 1722501038, + "type": "Number" + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "03. Update entity E with A=2040-03-12T21:04:13+00:00, B=122501038" +echo "=================================================================" +payload='{ + "A": { + "value": "2040-03-12T21:04:13+00:00", + "type": "Text" + }, + "B": { + "value": 122501038, + "type": "Number" + } +}' +orionCurl --url /v2/entities/E/attrs --payload "$payload" +echo +echo + + +echo "04. Dump accumulator and see notifications (S=2060-02-04T23:28:10+00:00, T=1722501038) (S=2040-03-12T21:04:13+00:00, T=122501038)" +echo "=================================================================================================================================" +accumulatorDump +echo +echo + + +--REGEXPECT-- +01. Create custom sub with custom expression S=A|getTime|toIsoString, T=B|toIsoString|getTime +============================================================================================= +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/subscriptions/REGEX([0-9a-f]{24}) +Content-Length: 0 + + + +02. Create entity E with A=2060-02-04T23:28:10+00:00, B=1722501038 +================================================================== +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/entities/E?type=T +Content-Length: 0 + + + +03. Update entity E with A=2040-03-12T21:04:13+00:00, B=122501038 +================================================================= +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +04. Dump accumulator and see notifications (S=2060-02-04T23:28:10+00:00, T=1722501038) (S=2040-03-12T21:04:13+00:00, T=122501038) +================================================================================================================================= +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 211 +User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) +Ngsiv2-Attrsformat: normalized +Host: 127.0.0.1:REGEX(\d+) +Accept: application/json +Content-Type: application/json; charset=utf-8 +Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 + +{ + "data": [ + { + "S": { + "metadata": {}, + "type": "Calculated", + "value": "2060-02-04T23:28:10+00:00" + }, + "T": { + "metadata": {}, + "type": "Calculated", + "value": 1722501038 + }, + "id": "E", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 210 +User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) +Ngsiv2-Attrsformat: normalized +Host: 127.0.0.1:REGEX(\d+) +Accept: application/json +Content-Type: application/json; charset=utf-8 +Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 + +{ + "data": [ + { + "S": { + "metadata": {}, + "type": "Calculated", + "value": "2040-03-12T21:04:13+00:00" + }, + "T": { + "metadata": {}, + "type": "Calculated", + "value": 122501038 + }, + "id": "E", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= + + +--TEARDOWN-- +brokerStop CB +dbDrop CB +accumulatorStop diff --git a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations_datetimes.test b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations_datetimes.test new file mode 100644 index 0000000000..4166851546 --- /dev/null +++ b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations_datetimes.test @@ -0,0 +1,215 @@ +# Copyright 2024 Telefonica Investigacion y Desarrollo, S.A.U +# +# This file is part of Orion Context Broker. +# +# Orion Context Broker is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Orion Context Broker is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. +# +# For those usages not covered by this license please contact with +# iot_support at tid dot es + +# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh +# JEXL_EXPR_FLAVOUR - to mark the test has to execute only when contextBroker includes jexl-expr flavour + +--NAME-- +JEXL expression time transformation specific cases + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# Same test as jexl_transformation_time_transformations but using "DateTime" instead of "Text" for A attribute +# +# 01. Create custom sub with custom expression S=A|getTime|toIsoString, T=B|toIsoString|getTime +# 02. Create entity E with A=2060-02-04T23:28:10+00:00, B=1722501038 +# 03. Update entity E with A=2040-03-12T21:04:13+00:00, B=122501038 +# 04. Dump accumulator and see notifications (S=2060-02-04T23:28:10+00:00, T=1722501038) (S=2040-03-12T21:04:13+00:00, T=122501038) +# + + +echo "01. Create custom sub with custom expression S=A|getTime|toIsoString, T=B|toIsoString|getTime" +echo "=============================================================================================" +payload='{ + "subject": { + "entities": [ + { + "id" : "E", + "type": "T" + } + ] + }, + "notification": { + "httpCustom": { + "url": "http://127.0.0.1:'${LISTENER_PORT}'/notify", + "ngsi": { + "S": { + "value": "${A|getTime|toIsoString}", + "type": "Calculated" + }, + "T": { + "value": "${B|toIsoString|getTime}", + "type": "Calculated" + } + } + }, + "attrs": [ "S", "T" ] + } +}' +orionCurl --url /v2/subscriptions --payload "$payload" +echo +echo + + +echo "02. Create entity E with A=2060-02-04T23:28:10+00:00, B=1722501038" +echo "==================================================================" +payload='{ + "id": "E", + "type": "T", + "A": { + "value": "2060-02-04T23:28:10+00:00", + "type": "DateTime" + }, + "B": { + "value": 1722501038, + "type": "Number" + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "03. Update entity E with A=2040-03-12T21:04:13+00:00, B=122501038" +echo "=================================================================" +payload='{ + "A": { + "value": "2040-03-12T21:04:13+00:00", + "type": "DateTime" + }, + "B": { + "value": 122501038, + "type": "Number" + } +}' +orionCurl --url /v2/entities/E/attrs --payload "$payload" +echo +echo + + +echo "04. Dump accumulator and see notifications (S=2060-02-04T23:28:10+00:00, T=1722501038) (S=2040-03-12T21:04:13+00:00, T=122501038)" +echo "=================================================================================================================================" +accumulatorDump +echo +echo + + +--REGEXPECT-- +01. Create custom sub with custom expression S=A|getTime|toIsoString, T=B|toIsoString|getTime +============================================================================================= +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/subscriptions/REGEX([0-9a-f]{24}) +Content-Length: 0 + + + +02. Create entity E with A=2060-02-04T23:28:10+00:00, B=1722501038 +================================================================== +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/entities/E?type=T +Content-Length: 0 + + + +03. Update entity E with A=2040-03-12T21:04:13+00:00, B=122501038 +================================================================= +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +04. Dump accumulator and see notifications (S=2060-02-04T23:28:10+00:00, T=1722501038) (S=2040-03-12T21:04:13+00:00, T=122501038) +================================================================================================================================= +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 211 +User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) +Ngsiv2-Attrsformat: normalized +Host: 127.0.0.1:REGEX(\d+) +Accept: application/json +Content-Type: application/json; charset=utf-8 +Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 + +{ + "data": [ + { + "S": { + "metadata": {}, + "type": "Calculated", + "value": "2060-02-04T23:28:10+00:00" + }, + "T": { + "metadata": {}, + "type": "Calculated", + "value": 1722501038 + }, + "id": "E", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 210 +User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) +Ngsiv2-Attrsformat: normalized +Host: 127.0.0.1:REGEX(\d+) +Accept: application/json +Content-Type: application/json; charset=utf-8 +Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 + +{ + "data": [ + { + "S": { + "metadata": {}, + "type": "Calculated", + "value": "2040-03-12T21:04:13+00:00" + }, + "T": { + "metadata": {}, + "type": "Calculated", + "value": 122501038 + }, + "id": "E", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= + + +--TEARDOWN-- +brokerStop CB +dbDrop CB +accumulatorStop From 33966a9c27dc72a50c5ef367930beeba97d089ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Thu, 1 Aug 2024 11:29:06 +0200 Subject: [PATCH 05/10] ADD Changelog entry --- Changelog | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Changelog b/Changelog index 5b5d5ef154..9ba2453185 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +- Upgrafe cjexl version from 0.3.0 to 0.4.0 (new transformations: now, getTime and toIsoString) + 4.0.0 (June 6th, 2024) - Add: JEXL expression support in custom notification macro replacement (using cjexl 0.3.0) (#4004) @@ -148,11 +150,11 @@ 3.5.0 (January 28th, 2022) -- Fix: avoid duplicated attributes and metadata in arrays in POST /v2/subscriptions and PATCH /v2/subscriptions/{subId} (#2101) -- Fix: $each usage with $push operator to add several items to array (#744) -- Fix: allow HTTPS certificates larger than 2048 bytes (#4012) -- Fix: DateTime attribute macro rendering in custom notifications was numeric instead of ISO8601 (#3894) -- Fix: buffer overflow problem in logs subsystem for from= field, causing crash in some cases (#3884) +- Fix: avoid duplicated attributes and metadata in arrays in POST /v2/subscriptions and PATCH /v2/subscriptions/{subId} (#2101) +- Fix: $each usage with $push operator to add several items to array (#744) +- Fix: allow HTTPS certificates larger than 2048 bytes (#4012) +- Fix: DateTime attribute macro rendering in custom notifications was numeric instead of ISO8601 (#3894) +- Fix: buffer overflow problem in logs subsystem for from= field, causing crash in some cases (#3884) 3.4.0 (December 14th, 2021) From 862804e36826d4379551e88f84f140854bc3ba46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Thu, 1 Aug 2024 12:15:37 +0200 Subject: [PATCH 06/10] ADD doc about new transformations --- Changelog | 2 +- doc/manuals/orion-api.md | 64 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 9ba2453185..01d1808f6d 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,4 @@ -- Upgrafe cjexl version from 0.3.0 to 0.4.0 (new transformations: now, getTime and toIsoString) +- Upgrade cjexl version from 0.3.0 to 0.4.0 (new transformations: now, getTime and toIsoString) 4.0.0 (June 6th, 2024) diff --git a/doc/manuals/orion-api.md b/doc/manuals/orion-api.md index b1431b8e93..fe6cd30b3e 100644 --- a/doc/manuals/orion-api.md +++ b/doc/manuals/orion-api.md @@ -108,6 +108,9 @@ - [`keys`](#keys) - [`arrSum`](#arrsum) - [`arrAvg`](#arravg) + - [`now`](#now) + - [`toIsoString`](#toisostring) + - [`getTime](#gettime) - [Failsafe cases](#failsafe-cases) - [Known limitations](#known-limitations) - [Oneshot Subscriptions](#oneshot-subscriptions) @@ -3146,6 +3149,67 @@ results in 3 ``` +#### now + +Returns the current time (plus a number of seconds specified as argument) as seconds since Unix epoch time. + +Extra arguments: none + +Example (being current time August 1st, 2024 at 9:31:02): + +``` +0|new +``` + +results in + +``` +1722504662 +``` + +It can be checked at https://www.epochconverter.com that time corresponds to August 1st, 2024 at 9:31:02 + +#### toIsoString + +Returns the [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) corresponding to a given timestamp (as seconds since Unix epoch time) passed as argument. + +Extra arguments: none + +Example (being context `{"c": 1720606949}`): + +``` +c|toIsoString +``` + +results in + +``` +"2024-07-10T10:22:29+00:00" +``` + +It can be checked at https://www.epochconverter.com that 1720606949 corresponds to 2024-07-10T10:22:29+00:00 + + +#### getTime + +Returns the timestamp (as seconds since Unix epoch time) correspoding to the [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) passed as argument. + +Extra arguments: none + +Example (being context `{"c": "2024-07-10T10:22:29+00:00"}`): + +``` +c|getTime +``` + +results in + +``` +1720606949 +``` + +It can be checked at https://www.epochconverter.com that 1720606949 corresponds to 2024-07-10T10:22:29+00:00 + ### Failsafe cases As failsafe behaviour, evaluation returns `null` in the following cases: From 3446a1ad828c05946c66791bcc72da8e2c348ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Thu, 1 Aug 2024 12:16:01 +0200 Subject: [PATCH 07/10] Update doc/manuals/orion-api.md --- doc/manuals/orion-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manuals/orion-api.md b/doc/manuals/orion-api.md index fe6cd30b3e..0a49543307 100644 --- a/doc/manuals/orion-api.md +++ b/doc/manuals/orion-api.md @@ -110,7 +110,7 @@ - [`arrAvg`](#arravg) - [`now`](#now) - [`toIsoString`](#toisostring) - - [`getTime](#gettime) + - [`getTime`](#gettime) - [Failsafe cases](#failsafe-cases) - [Known limitations](#known-limitations) - [Oneshot Subscriptions](#oneshot-subscriptions) From b4156bfac6fb9a0bcc078991e8a3878a0641f941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Thu, 1 Aug 2024 12:18:13 +0200 Subject: [PATCH 08/10] FIX changelog --- CHANGES_NEXT_RELEASE | 1 + Changelog | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 656f28c5a6..1ba267525a 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,4 +1,5 @@ - Fix: custom notification ngsi patching evaluation priority based in evalPriority builtin metadata (#4556) - Fix: wrong date values should not allowed in subscription's expires field (#4541) - Fix: do not raise DB alarm in case of wrong GeoJSON in client request +- Upgrade cjexl version from 0.3.0 to 0.4.0 (new transformations: now, getTime and toIsoString) - Upgrade Debian version from 12.4 to 12.6 in Dockerfile \ No newline at end of file diff --git a/Changelog b/Changelog index 01d1808f6d..4e6d6ab5bf 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,3 @@ -- Upgrade cjexl version from 0.3.0 to 0.4.0 (new transformations: now, getTime and toIsoString) - 4.0.0 (June 6th, 2024) - Add: JEXL expression support in custom notification macro replacement (using cjexl 0.3.0) (#4004) From 99a2752ce31e672dd36af6ef089cced9acb141d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Thu, 1 Aug 2024 12:19:05 +0200 Subject: [PATCH 09/10] FIX Changelog file encoding --- Changelog | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Changelog b/Changelog index 4e6d6ab5bf..5b5d5ef154 100644 --- a/Changelog +++ b/Changelog @@ -148,11 +148,11 @@ 3.5.0 (January 28th, 2022) -- Fix: avoid duplicated attributes and metadata in arrays in POST /v2/subscriptions and PATCH /v2/subscriptions/{subId} (#2101) -- Fix: $each usage with $push operator to add several items to array (#744) -- Fix: allow HTTPS certificates larger than 2048 bytes (#4012) -- Fix: DateTime attribute macro rendering in custom notifications was numeric instead of ISO8601 (#3894) -- Fix: buffer overflow problem in logs subsystem for from= field, causing crash in some cases (#3884) +- Fix: avoid duplicated attributes and metadata in arrays in POST /v2/subscriptions and PATCH /v2/subscriptions/{subId} (#2101) +- Fix: $each usage with $push operator to add several items to array (#744) +- Fix: allow HTTPS certificates larger than 2048 bytes (#4012) +- Fix: DateTime attribute macro rendering in custom notifications was numeric instead of ISO8601 (#3894) +- Fix: buffer overflow problem in logs subsystem for from= field, causing crash in some cases (#3884) 3.4.0 (December 14th, 2021) From 32703aa6040c9af5bb68eba4f5b8b0ab77f86aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Thu, 1 Aug 2024 12:25:44 +0200 Subject: [PATCH 10/10] Update doc/manuals/orion-api.md Co-authored-by: mapedraza <40356341+mapedraza@users.noreply.github.com> --- doc/manuals/orion-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manuals/orion-api.md b/doc/manuals/orion-api.md index 0a49543307..374da2024a 100644 --- a/doc/manuals/orion-api.md +++ b/doc/manuals/orion-api.md @@ -3158,7 +3158,7 @@ Extra arguments: none Example (being current time August 1st, 2024 at 9:31:02): ``` -0|new +0|now ``` results in