org.openmrs
Class User

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

public class User
extends BaseOpenmrsMetadata
implements java.io.Serializable

Defines a User Account in the system. This account belongs to a Person in the system, although that person may have other user accounts. Users have login credentials (username/password) and can have special user properties. User properties are just simple key-value pairs for either quick info or display specific info that needs to be persisted (like locale preferences, search options, etc)

See Also:
Serialized Form

Field Summary
static long serialVersionUID
           
 
Constructor Summary
User()
          default constructor
User(java.lang.Integer userId)
          constructor with id
User(Person person)
          constructor with person object
 
Method Summary
 void addName(PersonName name)
           
 User addRole(Role role)
          Add the given Role to the list of roles for this User
 boolean equals(java.lang.Object obj)
          Compares two objects for similarity
 java.util.Set<Role> getAllRoles()
          Returns all roles attributed to this user by expanding the role list to include the parents of the assigned roles
 java.lang.String getFamilyName()
          Get familyName on the Person this user account belongs to
 java.lang.String getFirstName()
          Deprecated. use getGivenName on Person
 java.lang.String getGivenName()
          Get givenName on the Person this user account belongs to
 java.lang.Integer getId()
           
 java.lang.String getLastName()
          Deprecated. use getFamilyName on Person
 java.util.Set<PersonName> getNames()
           
 Person getPerson()
           
 PersonName getPersonName()
           
 java.util.Collection<Privilege> getPrivileges()
          Get all privileges this user has.
 java.util.List<java.util.Locale> getProficientLocales()
          Returns a list of Locales for which the User is considered proficient.
 java.util.Set<Role> getRoles()
           
 java.lang.String getSecretQuestion()
           
 java.lang.String getSystemId()
           
 java.lang.Integer getUserId()
           
 java.lang.String getUsername()
           
 java.util.Map<java.lang.String,java.lang.String> getUserProperties()
           
 java.lang.String getUserProperty(java.lang.String prop)
          Get prop property from this user's properties.
 java.lang.String getUserProperty(java.lang.String prop, java.lang.String defaultValue)
          Get prop property from this user's properties.
 int hashCode()
          The hashcode for a user is used to index the objects in a tree
 boolean hasPrivilege(java.lang.String privilege)
          This method shouldn't be used directly.
 boolean hasRole(java.lang.String r)
          Check if this user has the given String role
 boolean hasRole(java.lang.String r, boolean ignoreSuperUser)
          Checks if this user has the given String role
 boolean isSuperUser()
          Return true if this user has all privileges
 User removeRole(Role role)
          Remove the given Role from the list of roles for this User
 void removeUserProperty(java.lang.String prop)
          Convenience method.
 User replaceSerialization(java.util.Map<?,?> sessionMap)
          If the serializer wishes, don't serialize this entire object, just the important parts
 void setId(java.lang.Integer id)
           
 void setPerson(Person person)
           
 void setPersonId(java.lang.Integer personId)
          Deprecated. see setPerson(Person)
 void setRoles(java.util.Set<Role> roles)
           
 void setSecretQuestion(java.lang.String secretQuestion)
           
 void setSystemId(java.lang.String systemId)
           
 void setUserId(java.lang.Integer userId)
           
 void setUsername(java.lang.String username)
           
 void setUserProperties(java.util.Map<java.lang.String,java.lang.String> userProperties)
           
 void setUserProperty(java.lang.String prop, java.lang.String value)
          Convenience method.
 java.lang.String toString()
           
 void validateSerialization(java.util.Map<?,?> sessionMap)
           
 
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

User

public User()
default constructor


User

public User(java.lang.Integer userId)
constructor with id


User

public User(Person person)
constructor with person object

Method Detail

isSuperUser

public boolean isSuperUser()
Return true if this user has all privileges

Returns:
true/false if this user is defined as a super user

hasPrivilege

public boolean hasPrivilege(java.lang.String privilege)
This method shouldn't be used directly. Use org.openmrs.api.context.Context#hasPrivilege so that anonymous/authenticated/proxy privileges are all included Return true if this user has the specified privilege

Parameters:
privilege -
Returns:
true/false depending on whether user has specified privilege

hasRole

public boolean hasRole(java.lang.String r)
Check if this user has the given String role

Parameters:
r - String name of a role to check
Returns:
Returns true if this user has the specified role, false otherwise

hasRole

public boolean hasRole(java.lang.String r,
                       boolean ignoreSuperUser)
Checks if this user has the given String role

Parameters:
r - String name of a role to check
ignoreSuperUser - If this is false, then this method will always return true for a superuser.
Returns:
Returns true if the user has the given role, or if ignoreSuperUser is false and the user is a superUser

getPrivileges

public java.util.Collection<Privilege> getPrivileges()
Get all privileges this user has. This delves into all of the roles that a person has, appending unique privileges

Returns:
Collection of complete Privileges this user has

equals

public boolean equals(java.lang.Object obj)
Compares two objects for similarity

Overrides:
equals in class java.lang.Object
Parameters:
obj -
Returns:
boolean true/false whether or not they are the same objects

hashCode

public int hashCode()
The hashcode for a user is used to index the objects in a tree

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

getAllRoles

public java.util.Set<Role> getAllRoles()
Returns all roles attributed to this user by expanding the role list to include the parents of the assigned roles

Returns:
all roles (inherited from parents and given) for this user

getRoles

public java.util.Set<Role> getRoles()
Returns:
Returns the roles.

setRoles

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

addRole

public User addRole(Role role)
Add the given Role to the list of roles for this User

Parameters:
role -
Returns:
Returns this user with the given role attached

removeRole

public User removeRole(Role role)
Remove the given Role from the list of roles for this User

Parameters:
role -
Returns:
this user with the given role removed

getSystemId

public java.lang.String getSystemId()
Returns:
Returns the systemId.

setSystemId

public void setSystemId(java.lang.String systemId)
Parameters:
systemId - The systemId to set.

getUserId

public java.lang.Integer getUserId()
Returns:
Returns the userId.

setUserId

public void setUserId(java.lang.Integer userId)
Parameters:
userId - The userId to set.

setPersonId

@Deprecated
public void setPersonId(java.lang.Integer personId)
Deprecated. see setPerson(Person)


getPerson

public Person getPerson()
Returns:
the person
Since:
1.6

setPerson

public void setPerson(Person person)
Parameters:
person - the person to set
Since:
1.6

getUsername

public java.lang.String getUsername()
Returns:
Returns the username.

setUsername

public void setUsername(java.lang.String username)
Parameters:
username - The username to set.

getSecretQuestion

public java.lang.String getSecretQuestion()
Returns:
Returns the secretQuestion.

setSecretQuestion

public void setSecretQuestion(java.lang.String secretQuestion)
Parameters:
secretQuestion - The secretQuestion to set.

toString

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

getUserProperties

public java.util.Map<java.lang.String,java.lang.String> getUserProperties()
Returns:
Returns the userProperties.

setUserProperties

public void setUserProperties(java.util.Map<java.lang.String,java.lang.String> userProperties)
Parameters:
userProperties - A Map of the properties to set.

setUserProperty

public void setUserProperty(java.lang.String prop,
                            java.lang.String value)
Convenience method. Adds the given property to the user's properties


removeUserProperty

public void removeUserProperty(java.lang.String prop)
Convenience method. Removes the given property from the user's properties


getUserProperty

public java.lang.String getUserProperty(java.lang.String prop)
Get prop property from this user's properties. If prop is not found in properties, return empty string

Parameters:
prop -
Returns:
property value

getUserProperty

public java.lang.String getUserProperty(java.lang.String prop,
                                        java.lang.String defaultValue)
Get prop property from this user's properties. If prop is not found in properties, return defaultValue

Parameters:
prop -
defaultValue -
Returns:
property value
See Also:
getUserProperty(java.lang.String)

addName

public void addName(PersonName name)
See Also:
Person.addName(PersonName)

getPersonName

public PersonName getPersonName()
See Also:
Person.getPersonName()

getGivenName

public java.lang.String getGivenName()
Get givenName on the Person this user account belongs to

See Also:
Person.getGivenName()

getFamilyName

public java.lang.String getFamilyName()
Get familyName on the Person this user account belongs to

See Also:
Person.getFamilyName()

getNames

public java.util.Set<PersonName> getNames()
See Also:
Person.getNames()

getFirstName

@Deprecated
public java.lang.String getFirstName()
Deprecated. use getGivenName on Person

Returns:
String user's first name

getLastName

@Deprecated
public java.lang.String getLastName()
Deprecated. use getFamilyName on Person

Returns:
String user's last name

replaceSerialization

public User replaceSerialization(java.util.Map<?,?> sessionMap)
If the serializer wishes, don't serialize this entire object, just the important parts

Parameters:
sessionMap - serialization session information
Returns:
User object to serialize
See Also:
OpenmrsUtil.isShortSerialization(Map)

validateSerialization

public void validateSerialization(java.util.Map<?,?> sessionMap)

getProficientLocales

public java.util.List<java.util.Locale> getProficientLocales()
Returns a list of Locales for which the User is considered proficient.

Returns:
List of the User's proficient locales

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