[jboss-user] [Beginner's Corner] - Newbie Drools Rule-Writing Question

Greg Zoller do-not-reply at jboss.com
Fri Apr 16 14:32:21 EDT 2010


Greg Zoller [http://community.jboss.org/people/gwzoller] created the discussion

"Newbie Drools Rule-Writing Question"

To view the discussion, visit: http://community.jboss.org/message/538052#538052

--------------------------------------------------------------
Hello,

I'm trying to write a drools rule for the following situation:

I have a user profile object containing a list of Strings representing the roles this user has been granted.
I need a drools rule pattern that matches true if there is an intersection between the user's roles and a list of given roles.
In Java the rule logic would be:

     ArrayList<String> okRoles = new ArrayList<String>();
     okRoles.add("Internal");
     okRoles.add("Admin");
     Profile profile = // get profile from wherever...contains list of user's roles: {"User","Internal"}
     if( okRoles.retainAll( profile.getRoles() ) == false ) {
          // successful match
     }

How can I do similar match logic in Drools?  Here's where I'm at so far:

rule "Test1"
    when
        Profile(roles in ("Internal","Admin"))
    then
        System.out.println("Found role match!");
end

This rule actually runs w/o crashing, but fails to match...presumably because getRoles() returns a list of roles and the list is not in ("ROLE_BUYER").

Any hints how I can accomplish this?

Thanks!
Greg

--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/538052#538052]

Start a new discussion in Beginner's Corner at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100416/09f8fd5e/attachment.html 


More information about the jboss-user mailing list