Use Of memberOf operator with drools templates

25 views
Skip to first unread message

Samyak jain

unread,
Jan 11, 2023, 12:58:15 PM1/11/23
to drools...@googlegroups.com
Hi,
I am trying to build rules from the data stored in the database, till now we are using drools-workbench to create rules, there we are using guided decision tables and decision table spreadsheets to create rules. Recently  I read about creating rules using drools templates and databases. I wanted to give it a try. I was able to create and execute rules for basic operators like equalTo, notEqualTo, GreaterThan etc:. But I am not able to do the same for IN Operator.
While searching on the internet I found that memberOf operator can be used to check in condition but I am not able to create rules for it.

For example i am not able to create highlighted part of following condition

 order : order( appName == "UBER" , userType == "EMP" , nodeId in ( "428129", "1342633", "560186" )

I am referring this blog to do so
https://itfromhell.net/2017/10/25/creating-rules-dynamically-with-drools/

Can someone help me with this?

Also let me know if any information is needed.

Thanks 
Samyak

aas...@gmail.com

unread,
Jan 12, 2023, 1:32:07 AM1/12/23
to Drools Usage
Hi Samyak!

You could try the regular .contains() method of Java collections, something like this:

 order : order( appName == "UBER" , userType == "EMP" , Arrays.asList( "428129", "1342633", "560186").contains( nodeId ) )

I suggest first creating the rules manually and keeping them in the filesystem.
Once you are sure the rules work as expected then you could rewrite them
so that the rules are created dynamically or using a spreadsheet decision table.

Be aware that Drools Rule Template (mentioned in the article you linked) is deprecated (source)

Juhan

P.S. I have a video course about spreadsheet decision tables and creating Drools rules dynamically
using Freemarker templates, something that you might want to check out:

Samyak jain

unread,
Jan 18, 2023, 12:05:17 AM1/18/23
to Drools Usage
thanks, this worked.
sure will look into this tutorial.
regards
Samyak
Reply all
Reply to author
Forward
0 new messages