JEXL expression in subject.condition #4555#4738
Conversation
4a1a886 to
018862c
Compare
Do you mean instead of ? I think we don't need |
| bool basic = false; | ||
| #endif | ||
|
|
||
| // Build JEXL evaluation contexts using entity attributes and their metadata |
There was a problem hiding this comment.
I'd suggest to do the JEXL evaluation after string filters (which is less expensive) and before than geo-evaluation (which is more expensive, as it hits de MongoDB).
| if (!result.boolValue) | ||
| { | ||
| continue; | ||
| } | ||
| } |
There was a problem hiding this comment.
In the case of the expression that evaluations to a number or string (e.g. 'a|logor 's|uppercase), isresult.boolValueset tofalse`?
There was a problem hiding this comment.
The condition was changed and tests were added with these cases
https://github.com/telefonicaid/fiware-orion/pull/4738/files#diff-f3de384894601039a5d62bd71c655eade1dbf49e023cdacce6e843279808401bR2098
| @@ -302,6 +302,8 @@ Fields: | |||
| - **expression**: an expression used to evaluate if notifications has | |||
There was a problem hiding this comment.
CHANGES_NEXT_RELEASE entry regarding the changes in this PR should be included
| @@ -5033,6 +5033,8 @@ A `condition` contains the following subfields: | |||
| | `expression` | ✓ | object| An expression composed of `q`, `mq`, `georel`, `geometry` and `coords` (see [List Entities](#list-entities-get-v2entities) operation above about this field). `expression` and sub elements (i.e. `q`) must have content, i.e. `{}` or `""` is not allowed. `georel`, `geometry` and `coords` have to be used together (i.e. "all or nothing"). Check the example using geoquery as expression [below](#create-subscription-post-v2subscriptions).| | |||
There was a problem hiding this comment.
We have a section "JEXL Support" https://github.com/telefonicaid/fiware-orion/blob/master/doc/manuals/orion-api.md#jexl-support but what it is actually describin in "JEXL Support in Custom Notifications"
I'd suggest to change this name, in the section title, in the TOC and in links (search for #jexl-support literal among directory files)
(Up to this PR, the diference was not meaninful, but now whe have JEXL support in a different place, i.e. subscription conditions, so I think is better changing the same)
| # 01. Create httpCustom sub with subject.condition.jexlExpression | ||
| # 02. Get sub, see sub with subject.condition.jexlExpression | ||
| # 03. Update sub description | ||
| # 04. Get sub, see subject.condition.jexlExpression | ||
| # 05. Update sub subject.condition.jexlExpression | ||
| # 06. see subject.condition.jexlExpression |
There was a problem hiding this comment.
I understand this .test is testing the basic CRUD of the new field. I'd suggest to add the following steps
# 07. Update subject.condition removing jexlExpression
# 08. Get sub, see now jexlExpression in subject.condition
# 09. Update subject.condition adding jexlExpression again
# 10. Get sub, see subject.condition.jexlExpression
| # 01. Create custom sub with condition.JexlExpression (A|isNaN) && (B|isNaN) | ||
| # 02. Create entity E1 with A=1 and B=2 | ||
| # 03. Update entity E1 with A=foo and B=bar | ||
| # 04. Update entity E1 with A=2.1 and B=-3.8 |
There was a problem hiding this comment.
Maybe better
| # 04. Update entity E1 with A=2.1 and B=-3.8 | |
| # 04. Update entity E1 with A=zzzz and B=-3.8 |
To have a case in which the values of both operands in && are different
| # 04. Update entity E1 with A=2.1 and B=-3.8 | ||
| # 05. Dump accumulator and see ONE notification (only for step 02: A=1, B=2) | ||
| # (the updates in steps 03 and 04 must NOT trigger notifications) |
There was a problem hiding this comment.
I'd suggest to add an additional step:
| # 04. Update entity E1 with A=2.1 and B=-3.8 | |
| # 05. Dump accumulator and see ONE notification (only for step 02: A=1, B=2) | |
| # (the updates in steps 03 and 04 must NOT trigger notifications) | |
| # 04. Update entity E1 with A=2.1 and B=-3.8 | |
| # 05. Update entity E1 with A=6.8 and B=-3.8 | |
| # 06. Dump accumulator and see TWO notification (for steps 02: A=1, B=2 and 05: A=6.8 and B=-3.8) | |
| # (the updates in steps 03 and 04 must NOT trigger notifications) |
| @@ -0,0 +1,203 @@ | |||
| # Copyright 2025 Telefonica Investigacion y Desarrollo, S.A.U | |||
There was a problem hiding this comment.
I'd suggest to add a variant of this test in a new .test in which only one of the attributes comes in the notification (e.g. A) and the other is an existing one in the entity (e.g. B).
| @@ -0,0 +1,203 @@ | |||
| # Copyright 2025 Telefonica Investigacion y Desarrollo, S.A.U | |||
There was a problem hiding this comment.
I'd suggest to add a variant of this test in a new .test in which only one of the attributes comes in the notification (e.g. A) and the other is an existing one in the entity (e.g. B).
Co-authored-by: Fermín Galán Márquez <fgalan@users.noreply.github.com>
…thub.com:telefonicaid/fiware-orion into feature/4555_jexlexpression_in_subject_condition
Clarified notification triggering rules and expressions in the documentation.
Co-authored-by: Fermín Galán Márquez <fgalan@users.noreply.github.com>
...n_in_subject_condition/jexl_expression_in_condition_sum_eq3_mixed_update_existing_attrs.test
Outdated
Show resolved
Hide resolved
...n_in_subject_condition/jexl_expression_in_condition_sum_eq3_mixed_update_existing_attrs.test
Outdated
Show resolved
Hide resolved
...n_in_subject_condition/jexl_expression_in_condition_sum_eq3_mixed_update_existing_attrs.test
Outdated
Show resolved
Hide resolved
fgalan
left a comment
There was a problem hiding this comment.
LGTM (except for a small typo in one of the .test files)
…tion/jexl_expression_in_condition_sum_eq3_mixed_update_existing_attrs.test Co-authored-by: Fermín Galán Márquez <fgalan@users.noreply.github.com>
…tion/jexl_expression_in_condition_sum_eq3_mixed_update_existing_attrs.test Co-authored-by: Fermín Galán Márquez <fgalan@users.noreply.github.com>
…tion/jexl_expression_in_condition_sum_eq3_mixed_update_existing_attrs.test Co-authored-by: Fermín Galán Márquez <fgalan@users.noreply.github.com>
|
@fisuda this PR does some modifications to .md English files. It would be great if you could sync the Japanese translation, please. |
|
I sent the PR #4739. |
(JP) JEXL expression in subject.condition (#4738)
Issue #4555
@fgalan
So far, the
JexlExpressionfield does not use macros. Should we add support for them?