0 Replies Latest reply on Aug 25, 2009 11:02 AM by Juan Ignacio Sánchez Lara

    Avoiding verbose rules

    Juan Ignacio Sánchez Lara Apprentice

      I'm using Drools to perform security authorization checks at my application. I'm doing something like this:




      global User currentUser
      
      rule PersonFromTheSameCountry
      when
          modify: PermissionCheck(target == person, action == "modify")
          eval(person.getCountry().getId().equals(currentUser.getCountry().getId())
      then
          modify.grant();
      end
      




      This works perfectly when nothing is null, but, for example, if the current user hasn't a Country assigned, it fails because of the nullity. I know I can workaround this with additional checks:





      eval(currentUser.getCountry() != null)






      But this becomes too verbose when there're three or more entities. Is there any other way to express this?