org.openmrs
Class Role

java.lang.Object
  extended by org.openmrs.BaseOpenmrsObject
      extended by org.openmrs.BaseOpenmrsMetadata
          extended by org.openmrs.Role
All Implemented Interfaces:
java.io.Serializable, Auditable, OpenmrsMetadata, OpenmrsObject, Retireable

public class Role
extends BaseOpenmrsMetadata
implements java.io.Serializable

A Role is just an aggregater of Privileges. Users contain a number of roles (Users DO NOT contain any privileges directly) Roles can be grouped by inheriting other roles. If a user is given Role A that inherits from Role B, the user has all rights/abilities for both Role A's privileges and for Role B's privileges.

See Also:
Privilege, Serialized Form

Field Summary
static long serialVersionUID
           
 
Constructor Summary
Role()
          default constructor
Role(java.lang.String role)
          constructor with id
Role(java.lang.String role, java.lang.String description)
          constructor with all database required properties
 
Method Summary
 void addPrivilege(Privilege privilege)
          Adds the given Privilege to the list of privileges
 boolean equals(java.lang.Object obj)
           
 java.util.Set<Role> getAllParentRoles()
          Recursive (if need be) method to return all parent roles of this role
 java.lang.Integer getId()
           
 java.util.Set<Role> getInheritedRoles()
           
 java.util.Set<Privilege> getPrivileges()
           
 java.lang.String getRole()
           
 int hashCode()
           
 boolean hasPrivilege(java.lang.String privilegeName)
          Looks for the given privilegeName privilege name in this roles privileges.
 boolean inheritsRoles()
          Convenience method to test whether or not this role extends/ inherits from any other roles
 java.util.Set<Role> recurseOverParents(java.util.Set<Role> children)
          Returns the full set of roles be looping over inherited roles.
 void removePrivilege(Privilege privilege)
          Removes the given Privilege from the list of privileges
 void setId(java.lang.Integer id)
           
 void setInheritedRoles(java.util.Set<Role> inheritedRoles)
           
 void setPrivileges(java.util.Set<Privilege> privileges)
           
 void setRole(java.lang.String role)
           
 java.lang.String toString()
           
 
Methods inherited from class org.openmrs.BaseOpenmrsMetadata
getChangedBy, getCreator, getDateChanged, getDateCreated, getDateRetired, getDescription, getName, getRetired, getRetiredBy, getRetireReason, isRetired, setChangedBy, setCreator, setDateChanged, setDateCreated, setDateRetired, setDescription, setName, setRetired, setRetiredBy, setRetireReason
 
Methods inherited from class org.openmrs.BaseOpenmrsObject
getUuid, setUuid
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.openmrs.OpenmrsObject
getUuid, setUuid
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

Role

public Role()
default constructor


Role

public Role(java.lang.String role)
constructor with id


Role

public Role(java.lang.String role,
            java.lang.String description)
constructor with all database required properties

Method Detail

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

getPrivileges

public java.util.Set<Privilege> getPrivileges()
Returns:
Returns the privileges.

setPrivileges

public void setPrivileges(java.util.Set<Privilege> privileges)
Parameters:
privileges - The privileges to set.

addPrivilege

public void addPrivilege(Privilege privilege)
Adds the given Privilege to the list of privileges

Parameters:
privilege - Privilege to add

removePrivilege

public void removePrivilege(Privilege privilege)
Removes the given Privilege from the list of privileges

Parameters:
privilege - Privilege to remove

getRole

public java.lang.String getRole()
Returns:
Returns the role.

setRole

public void setRole(java.lang.String role)
Parameters:
role - The role to set.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

hasPrivilege

public boolean hasPrivilege(java.lang.String privilegeName)
Looks for the given privilegeName privilege name in this roles privileges. This method does not recurse through the inherited roles

Parameters:
privilegeName - String name of a privilege
Returns:
true/false whether this role has the given privilege
Expected behavior:
return false if not found, return true if found, not fail given null parameter, return true for any privilegeName if super user

getInheritedRoles

public java.util.Set<Role> getInheritedRoles()
Returns:
Returns the inheritedRoles.

setInheritedRoles

public void setInheritedRoles(java.util.Set<Role> inheritedRoles)
Parameters:
inheritedRoles - The inheritedRoles to set.

inheritsRoles

public boolean inheritsRoles()
Convenience method to test whether or not this role extends/ inherits from any other roles

Returns:
true/false whether this role inherits from other roles

getAllParentRoles

public java.util.Set<Role> getAllParentRoles()
Recursive (if need be) method to return all parent roles of this role

Returns:
Return this role's parents

recurseOverParents

public java.util.Set<Role> recurseOverParents(java.util.Set<Role> children)
Returns the full set of roles be looping over inherited roles. Duplicate roles are dropped.

Parameters:
children - Roles already looped over
Returns:
Set Current and inherited roles

getId

public java.lang.Integer getId()
Specified by:
getId in interface OpenmrsObject
Returns:
id - The unique Identifier for the object
Since:
1.5
See Also:
OpenmrsObject.getId()

setId

public void setId(java.lang.Integer id)
Specified by:
setId in interface OpenmrsObject
Parameters:
id - - The unique Identifier for the object
Since:
1.5
See Also:
OpenmrsObject.setId(java.lang.Integer)

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change