0
votes

MY rule condition and action is defined as below. I am getting compilation error. In rule condition I am specified the left and right values as 'abc' and 'xyz' which values are stored in a MAP of Me object. When I am using the me.getVariableValues('abc') in action part then its working fine. But, when I want to use same me.getVariableValues('abc') in condition then I am getting below compilation error.

Error while creating rule package - [139,0]: unknown:139:0 mismatched token: [@463,2378:2383='me',<7>,139:0]; expecting type RIGHT_PAREN[140,37]: unknown:140:37 Unexpected token ')'[140,39]: unknown:140:39 Unexpected token 'abc'

rule "rule"

when

me: Me()

getValue(me.getVariableValues(),${condition.leftVariableCode}) ${condition.operator} getValue(me.getVariableValues(),${condition.rightVariableCode})

then

me.addVariableValue("$action.output.variableCode", me.getVariableValue("$action.firstInput.VariableCode") $action.operator me.getVariableValue("$action.secondInput.VariableCode"));

end

1
Absolutely broken syntax starting with "getValue". It looks like some templating code. - What are you trying to do? - laune
Hi Laune, thanks for immediate response, Here I am trying to compare the values in a Map based on the condition defined in rule. DRL string generation is defined in velocity file. The map saved in memory and I want to two values of map. please let me know give me sample code two compare two values in a map. - pramagouni
The DRL code as shown is absolutely broken. Where is the Map? How is class Me defined? - laune
Here is the class Me public class Me{ // Variable Details Map<String, Integer> variableValues = new HashMap<String, Integer>(); public Map<String, Integer> getVariableValues() { return variableValues; } public void addVariableValue(String variableCode, Integer count){ if (count < 0) count = 0; this.variableValues.put(variableCode, count); } public Integer getVariableValue(String variableCode){ Integer value = this.variableValues.get(variableCode); return value == null? 0 : value; } } - pramagouni

1 Answers

0
votes

A correct rule with the given declaration of class Me would be

Me( $vv: variableValues )
Map( this["key"] == 42 ) from $vv

or

Me( $vv: variableValues )
Map( this["foo"] < this["bar"] ) from $vv

If you have posted a velocity template, then it is broken.

If you have posted the result after expanding a template, both the template and your expansion mechanism are broken.