Skip to content

Commit

Permalink
Merge pull request #4561 from telefonicaid/feature/4004_more_transfor…
Browse files Browse the repository at this point in the history
…mations

ADD new transformations
  • Loading branch information
mapedraza authored Jun 3, 2024
2 parents 50fa2bb + d2f8caf commit e46e3c4
Show file tree
Hide file tree
Showing 7 changed files with 501 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- Add: JEXL expression support in custom notification macro replacement (using cjexl 0.2.0) (#4004)
- Add: JEXL expression support in custom notification macro replacement (using cjexl 0.3.0) (#4004)
- Add: expression context build and evaluation counters in timing section in GET /statistics (#4004)
- Fix: use null for non existing attributes in custom covered notifications macro substitution (instead of empty string) to make behaviour more consistent (#4004)
- Fix: use null for non existing attributes in macro substitution applied to "paylaod" field (instead of empty string) to make behaviour more consistent (#4004)
Expand Down
2 changes: 1 addition & 1 deletion ci/deb/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.2.0 $REPO_ACCESS_TOKEN
bash /opt/fiware-orion/get_cjexl.sh 0.3.0 $REPO_ACCESS_TOKEN
fi

if [ -n "${branch}" ]; then
Expand Down
147 changes: 141 additions & 6 deletions doc/manuals/orion-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,34 @@
- [`uppercase`](#uppercase)
- [`lowercase`](#lowercase)
- [`split`](#split)
- [`indexOf`](#indexOf)
- [`indexOf`](#indexof)
- [`len`](#len)
- [`trim`](#trim)
- [`substring`](#substring)
- [`includes`](#includes)
- [`isNaN`](#isNaN)
- [`parseInt`](#parseInt)
- [`parseFloat`](#parseFloat)
- [`parseInt`](#parseint)
- [`parseFloat`](#parsefloat)
- [`typeOf`](#typeOf)
- [`toString`](#toString)
- [`toString`](#tostring)
- [`toJson`](#tojson)
- [`floor`](#floor)
- [`ceil`](#ceil)
- [`round`](#round)
- [`toFixed`](#toFixed)
- [`toFixed`](#tofixed)
- [`log`](#log)
- [`log10`](#log10)
- [`log2`](#log2)
- [`sqrt`](#sqrt)
- [`replaceStr`](#replaceStr)
- [`replaceStr`](#replacestr)
- [`replaceRegex`](#replaceregex)
- [`matchRegex`](#matchregex)
- [`mapper`](#mapper)
- [`thMapper`](#thmapper)
- [`values`](#values)
- [`keys`](#keys)
- [`arrSum`](#arrsum)
- [`arrAvg`](#arravg)
- [Failsafe cases](#failsafe-cases)
- [Known limitations](#known-limitations)
- [Oneshot Subscriptions](#oneshot-subscriptions)
Expand Down Expand Up @@ -2775,6 +2782,24 @@ results in
"23"
```

#### toJson

Convert the input string to a JSON document. If the string is not a valid JSON, it returns `null`.

Extra arguments: none.

Example (being context `{"c": "[1,2]"}`):

```
c|toJson
```

results in

```
[1, 2]
```

#### floor

Return the closest lower integer of a given number.
Expand Down Expand Up @@ -2939,6 +2964,44 @@ results in
"fuubar"
```

#### replaceRegex

Replace tokens matching a given regex in an input string by another string.

Extra arguments:
* Regex to match tokens to replace
* Destination string to replace

Example (being context `{"c": "aba1234aba786aba"}`):

```
c|replaceRegex('\d+','X')
```

results in

```
"abaXabaXaba"
```

#### matchRegex

Returns an array of tokens matching a given regular expression in input string. In the case of invalid regex, it returns `null`. If no matches are found, it returns the empty array (`[]`).

Extra arguments: regular expression.

Example (being context `{"c": "abc1234fgh897hyt"}`):

```
c|matchRegex('\d+`)
```

results in

```
["1234, "897"]]
```

#### mapper

Returns a value among several choices based in one to one mapping. This function is based in an array of *values* and an array of *choices* (which length is exactly the same). Thus, if the input value is equal to the *i*-th item of *values*, then *i*-th item of *choices* is returned.
Expand Down Expand Up @@ -2983,6 +3046,78 @@ results in
"medium"
```

#### values

Returns an array with the values of the keys of a given object (or `null` if input is not an object).

Extra arguments: none

Example (being context `{"c": {"x": 1, "y": "foo"}}`):

```
c|values
```

results in

```
[1,"foo"]
```

#### keys

Returns an array with the keys of a given object (or `null` if input is not an object).

Extra arguments: none

Example (being context `{"c": {"x": 1, "y": "foo"}}`):

```
c|keys
```

results in

```
["x","y"]
```

#### arrSum

Returns the sum of the elements of an array (or `null` if the input in an array or the array containts some not numberic item).

Extra arguments: none

Example (being context `{"c": [1, 5]}`):

```
c|arrSum
```

results in

```
6
```

#### arrAvg

Returns the average of the elements of an array (or `null` if the input in an array or the array containts some not numberic item).

Extra arguments: none

Example (being context `{"c": [1, 5]}`):

```
c|arrAvg
```

results in

```
3
```

### Failsafe cases

As failsafe behaviour, evaluation returns `null` in the following cases:
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ RUN \
git clone https://github.com/${GIT_NAME}/fiware-orion && \
cd fiware-orion && \
git checkout ${GIT_REV_ORION} && \
bash get_cjexl.sh 0.2.0 ${REPO_ACCESS_TOKEN} && \
bash get_cjexl.sh 0.3.0 ${REPO_ACCESS_TOKEN} && \
make && \
make install && \
# reduce size of installed binaries
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ RUN \
git clone https://github.com/${GIT_NAME}/fiware-orion && \
cd fiware-orion && \
git checkout ${GIT_REV_ORION} && \
bash get_cjexl.sh 0.2.0 ${REPO_ACCESS_TOKEN} && \
bash get_cjexl.sh 0.3.0 ${REPO_ACCESS_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 && \
Expand Down
Loading

0 comments on commit e46e3c4

Please sign in to comment.