1 Reply Latest reply on Apr 17, 2010 11:58 AM by jaikiran pai

    Newbie Drools Rule-Writing Question

    Greg Zoller Newbie

      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