4

I have created a rule whose "when" condition is as follows :-

when
    $map: Map(this["key1"].equals("value1")) and Map(this["key2"].equals("value2"))  
then
...

The above condition is working fine. Now how do I add multiple boolean conditions in a rule? For eg. The above rule could be summarized as : a and b so if I want to create a rule : (a and b) or c then what would be actual drl syntax for it. I am new to drools so kindly help me with the syntax of the rule (a and b) or c.

I did create a syntax

when
    $map: Reindexing((Map(this["key1"].equals("value1")) and Map(this["key2"].equals("value2"))) or  Map(this["key3"].equals("value3"))) 
then

But I got the following exception

Error Messages: Message [id=1, level=ERROR, path=mapIterationRules.drl, line=13, column=0 text=[ERR 101] Line 13:21 no viable alternative at input '(' in rule "first rule"]

Thanks

Yatin
  • 727
  • 1
  • 9
  • 40
  • What is `Reindexing` supposed to be or do? You have facts of type Map. Using a class name within a pattern using another class name isn't valid syntax. Check the documentation. – laune Jun 17 '16 at 12:24
  • Yes, we need more information about what the rule should do. Currently I'm not sure if you are checking if reindexing worked or if you want to reindex. – Toni Rikkola Jun 18 '16 at 05:40
  • Reindexing is the name of the class that has this map, I guess it has nothing to do here, i was just experimenting with the correct syntax. The "a and b" rule worked perfectly so on similar grounds, i was experimenting the syntax of "(a and b) or c" rule. And @laune so if I cannot use two class names(applogies for that) then how do I create the second rule, I tried with the rule "(Map(this["key1"].equals("value1")) and Map(this["key2"].equals("value2"))) or Map(this["key3"].equals("value3"))" but this also gave me the same error. – Yatin Jun 19 '16 at 10:35
  • Hardly the same error, possibly one with the same wording but at a different location. Don't use `and` and `or` conditional element operators if all constraints should relate to the same Map - use the constraint logical operators `||` and `&&`. Again, **check the documentation** – laune Jun 20 '16 at 16:23

1 Answers1

8

Figured out the syntax for the above rule. thanks laune and toni for the help.

here is the syntax

when
    $map: Map( this["data1"].equals("dataOutput1") ) || Map( this["data2"].equals("dataOutput2") && this["data3"].equals("dataOutput3") )

when inside the same bracket, it is not required to type the class name again.

Yatin
  • 727
  • 1
  • 9
  • 40