-1

Is there a way to identify which part of a SpEL expression trigger a rule ?

For example :

a < 10 || a > 20

I want to know if the rule is fired because a < 10 or a > 20


For example :

ExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression(rule.getExpression());
return Boolean.TRUE.equals(expression.getValue(evaluationContext, Boolean.class));

thanks to this I can know if the whole expression is true or false, in addition to this I would like to know more precisely that it has triggered the rule

marojbor
  • 191
  • 10

1 Answers1

0

It seems to me that there is no way to check it using the SPeL API. But you can modify your code (if its possible) slightly and split this expression into a list of expressions List<Expression>, so you will be able to iterate through the list of expressions and save the result of each. I hope this idea helps you somehow

Here is example code:

Map<Expression, Boolean> results = List.of(new Expression("a < 1"), new Expression("a > 20"))
    .stream()
    .collect(Collectors.toMap(Function.identity(), Expression::evaluate));
KSs
  • 420
  • 3
  • 9