[rules-users] Verify if an objects attribute exists

lnguyen mzspdrcr at gmail.com
Tue Sep 14 00:18:46 EDT 2010


Sorry here is some additional details...I hope I'm not making this sound more
complicated than it really is but I am attempting to restrict access to view
an account based on the logged in user.

public class User 
{
	private Long id;

	...
	
	private UserProfile userProfile;
    
}


public class UserProfile
{

	private Long id;

	....
	
	private User supervisor;

}


So I created a function called isUserMatching to determine if the
currentUser is looking at their own account or if their supervisor is
looking at an employees account:

function boolean isUserMatching(User user)
{
    User currentUser = (User) Component.getInstance("currentUser");

    User supervisor = (User) user.getUserProfile().getSupervisor();

    boolean result = false;	


    if(currentUser == user)
    {
        System.out.println("###################### currentUser = user is
TRUE #####");
        result = true;
    }
    else if((supervisor != null) &&
(currentUser.getId().equals(supervisor.getId())))
    {	
	System.out.println("###################### currentUser = supervisor is TRUE
#####");
        result = true;
    }
    else
    {
        System.out.println("###################### currentUser/supervisor !=
user is FALSE #####");
    }

    return result;


}

This function works as desired but not all users have a supervisor. What I'd
like to know is how can I check if a supervisor is null so that I can
prevent passing null values into functions?

Doing this "eval (isUserMatching($supervisor))" results in an runtime error
of course when there is no supervisor.
-- 
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Verify-if-an-objects-attribute-exists-tp1455073p1470638.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list