org.openmrs.api.impl
Class UserServiceImpl

java.lang.Object
  extended by org.openmrs.api.impl.BaseOpenmrsService
      extended by org.openmrs.api.impl.UserServiceImpl
All Implemented Interfaces:
OpenmrsService, UserService

public class UserServiceImpl
extends BaseOpenmrsService
implements UserService

Default implementation of the user service. This class should not be used on its own. The current OpenMRS implementation should be fetched from the Context

See Also:
UserService, Context

Field Summary
protected  UserDAO dao
           
 
Constructor Summary
UserServiceImpl()
           
 
Method Summary
 void changeHashedPassword(User user, java.lang.String hashedPassword, java.lang.String salt)
          Changes the current user's password directly.
 void changePassword(java.lang.String pw, java.lang.String pw2)
          Changes the current user's password.
 void changePassword(User u, java.lang.String pw)
          Changes the user's password ** Restricted to Super User access**
 void changeQuestionAnswer(java.lang.String pw, java.lang.String q, java.lang.String a)
          Changes the current user's secret question and answer.
 void changeQuestionAnswer(User u, java.lang.String question, java.lang.String answer)
          Changes the passed user's secret question and answer.
 User createUser(User user, java.lang.String password)
          Deprecated.  
 void deleteUser(User user)
          Deprecated.  
 java.util.List<User> findUsers(java.lang.String name, java.util.List<java.lang.String> roles, boolean includeVoided)
          Deprecated.  
 java.util.List<User> findUsers(java.lang.String givenName, java.lang.String familyName, boolean includeVoided)
          Deprecated.  
 java.lang.String generateSystemId()
          Generates system ids based on the following algorithm scheme: user_id-check digit
 java.util.List<Privilege> getAllPrivileges()
          Returns all privileges currently possible for any User
 java.util.List<Role> getAllRoles()
          Returns all roles currently possible for any User
 java.util.List<User> getAllUsers()
          Returns all users in the system
 java.util.List<User> getAllUsers(java.util.List<Role> roles, boolean includeVoided)
          Deprecated.  
 java.util.List<Role> getInheritingRoles(Role role)
          Deprecated.  
 Privilege getPrivilege(java.lang.String p)
          Returns Privilege in the system with given String privilege
 Privilege getPrivilegeByUuid(java.lang.String uuid)
          Get Privilege by its UUID
 java.util.List<Privilege> getPrivileges()
          Deprecated.  
 Role getRole(java.lang.String r)
          Returns role object with given string role
 Role getRoleByUuid(java.lang.String uuid)
          Get Role by its UUID
 java.util.List<Role> getRoles()
          Deprecated.  
 User getUser(java.lang.Integer userId)
          Get user by internal user identifier.
 User getUserByUsername(java.lang.String username)
          Get user by username (user's login identifier)
 User getUserByUuid(java.lang.String uuid)
          Get user by the given uuid.
 java.util.List<User> getUsers()
          Deprecated.  
 java.util.List<User> getUsers(java.lang.String nameSearch, java.util.List<Role> roles, boolean includeVoided)
          Return a user if any part of the search matches first/last/system id and the user has one at least one of the given roles assigned to them
 java.util.List<User> getUsersByName(java.lang.String givenName, java.lang.String familyName, boolean includeVoided)
          Search for a list of users by exact first name and last name.
 java.util.List<User> getUsersByPerson(Person person, boolean includeRetired)
          Get all user accounts that belong to a given person.
 java.util.List<User> getUsersByRole(Role role)
          Get users by role granted
 void grantUserRole(User user, Role role)
          Deprecated.  
 boolean hasDuplicateUsername(User user)
          true/false if username or systemId is already in db in username or system_id columns
 boolean isSecretAnswer(User u, java.lang.String answer)
          Compares answer against the user's secret answer.
 void purgePrivilege(Privilege privilege)
          Completely remove a privilege from the database
 void purgeRole(Role role)
          Complete remove a role from the database
 void purgeUser(User user)
          Completely remove a location from the database (not reversible).
 void purgeUser(User user, boolean cascade)
          Completely remove a user from the database (not reversible).
 User removeUserProperty(User user, java.lang.String key)
          Removes the property denoted by key from the user's properties.
 User retireUser(User user, java.lang.String reason)
          Deactive a user account so that it can no longer log in.
 void revokeUserRole(User user, Role role)
          Deprecated.  
 Privilege savePrivilege(Privilege privilege)
          Save the given privilege in the database
 Role saveRole(Role role)
          Save the given role in the database
 User saveUser(User user, java.lang.String password)
          Saves a user to the database.
 void setUserDAO(UserDAO dao)
           
 User setUserProperty(User user, java.lang.String key, java.lang.String value)
          Adds the key/value pair to the given user.
 User unretireUser(User user)
          Clears retired flag for a user.
 User unvoidUser(User user)
          Clear voided flag for user (equivalent to an "undelete" or Lazarus Effect for user)
 void updateUser(User user)
          Deprecated. replaced by saveUser(User, String)
 User voidUser(User user, java.lang.String reason)
          Mark user as voided (effectively deleting user without removing their data — since anything the user touched in the database will still have their internal identifier and point to the voided user for historical tracking purposes.
 
Methods inherited from class org.openmrs.api.impl.BaseOpenmrsService
onShutdown, onStartup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.openmrs.api.OpenmrsService
onShutdown, onStartup
 

Field Detail

dao

protected UserDAO dao
Constructor Detail

UserServiceImpl

public UserServiceImpl()
Method Detail

setUserDAO

public void setUserDAO(UserDAO dao)

createUser

public User createUser(User user,
                       java.lang.String password)
                throws APIException
Deprecated. 

Specified by:
createUser in interface UserService
Throws:
APIException
See Also:
UserService.createUser(org.openmrs.User, java.lang.String)

saveUser

public User saveUser(User user,
                     java.lang.String password)
              throws APIException
Description copied from interface: UserService
Saves a user to the database.

Specified by:
saveUser in interface UserService
Returns:
a User object
Throws:
APIException
See Also:
UserService.saveUser(org.openmrs.User, java.lang.String)

getUser

public User getUser(java.lang.Integer userId)
             throws APIException
Description copied from interface: UserService
Get user by internal user identifier.

Specified by:
getUser in interface UserService
Parameters:
userId - internal identifier
Returns:
requested user
Throws:
APIException
See Also:
UserService.getUser(java.lang.Integer)

getUserByUsername

public User getUserByUsername(java.lang.String username)
                       throws APIException
Description copied from interface: UserService
Get user by username (user's login identifier)

Specified by:
getUserByUsername in interface UserService
Parameters:
username - user's identifier used for authentication
Returns:
requested user
Throws:
APIException
See Also:
UserService.getUserByUsername(java.lang.String)

hasDuplicateUsername

public boolean hasDuplicateUsername(User user)
                             throws APIException
Description copied from interface: UserService
true/false if username or systemId is already in db in username or system_id columns

Specified by:
hasDuplicateUsername in interface UserService
Parameters:
user - User to compare
Returns:
boolean
Throws:
APIException
See Also:
UserService.hasDuplicateUsername(org.openmrs.User)

getUsersByRole

public java.util.List<User> getUsersByRole(Role role)
                                    throws APIException
Description copied from interface: UserService
Get users by role granted

Specified by:
getUsersByRole in interface UserService
Parameters:
role - Role that the Users must have to be returned
Returns:
users with requested role
Throws:
APIException
See Also:
UserService.getUsersByRole(org.openmrs.Role)

updateUser

public void updateUser(User user)
                throws APIException
Deprecated. replaced by saveUser(User, String)

Description copied from interface: UserService
Save changes to given user to the database.

Specified by:
updateUser in interface UserService
Throws:
APIException
See Also:
UserService.updateUser(org.openmrs.User)

grantUserRole

public void grantUserRole(User user,
                          Role role)
                   throws APIException
Deprecated. 

Description copied from interface: UserService
Use should be UserService.saveUser(user.addRole(role))

Specified by:
grantUserRole in interface UserService
Throws:
APIException
See Also:
UserService.grantUserRole(org.openmrs.User, org.openmrs.Role)

revokeUserRole

public void revokeUserRole(User user,
                           Role role)
                    throws APIException
Deprecated. 

Description copied from interface: UserService
Use UserService.saveUser(user.removeRole(role))

Specified by:
revokeUserRole in interface UserService
Throws:
APIException
See Also:
UserService.revokeUserRole(org.openmrs.User, org.openmrs.Role)

voidUser

public User voidUser(User user,
                     java.lang.String reason)
              throws APIException
Description copied from interface: UserService
Mark user as voided (effectively deleting user without removing their data — since anything the user touched in the database will still have their internal identifier and point to the voided user for historical tracking purposes.

Specified by:
voidUser in interface UserService
Returns:
the given user voided out
Throws:
APIException
See Also:
UserService.voidUser(org.openmrs.User, java.lang.String)

retireUser

public User retireUser(User user,
                       java.lang.String reason)
                throws APIException
Description copied from interface: UserService
Deactive a user account so that it can no longer log in.

Specified by:
retireUser in interface UserService
Throws:
APIException
See Also:
UserService.retireUser(org.openmrs.User, java.lang.String)

unvoidUser

public User unvoidUser(User user)
                throws APIException
Description copied from interface: UserService
Clear voided flag for user (equivalent to an "undelete" or Lazarus Effect for user)

Specified by:
unvoidUser in interface UserService
Returns:
the given user unvoided
Throws:
APIException
See Also:
UserService.unvoidUser(org.openmrs.User)

unretireUser

public User unretireUser(User user)
                  throws APIException
Description copied from interface: UserService
Clears retired flag for a user.

Specified by:
unretireUser in interface UserService
Throws:
APIException
See Also:
UserService.unretireUser(org.openmrs.User)

deleteUser

public void deleteUser(User user)
                throws APIException
Deprecated. 

Specified by:
deleteUser in interface UserService
Throws:
APIException
See Also:
UserService.deleteUser(org.openmrs.User)

getUsers

public java.util.List<User> getUsers()
                              throws APIException
Deprecated. 

Specified by:
getUsers in interface UserService
Throws:
APIException
See Also:
UserService.getUsers()

getAllUsers

public java.util.List<User> getAllUsers()
                                 throws APIException
Description copied from interface: UserService
Returns all users in the system

Specified by:
getAllUsers in interface UserService
Returns:
Global list of users
Throws:
APIException
See Also:
UserService.getAllUsers()

getPrivileges

public java.util.List<Privilege> getPrivileges()
                                        throws APIException
Deprecated. 

Specified by:
getPrivileges in interface UserService
Throws:
APIException
See Also:
UserService.getPrivileges()

getAllPrivileges

public java.util.List<Privilege> getAllPrivileges()
                                           throws APIException
Description copied from interface: UserService
Returns all privileges currently possible for any User

Specified by:
getAllPrivileges in interface UserService
Returns:
Global list of privileges
Throws:
APIException
See Also:
UserService.getAllPrivileges()

getPrivilege

public Privilege getPrivilege(java.lang.String p)
                       throws APIException
Description copied from interface: UserService
Returns Privilege in the system with given String privilege

Specified by:
getPrivilege in interface UserService
Returns:
Privilege
Throws:
APIException
See Also:
UserService.getPrivilege(java.lang.String)

purgePrivilege

public void purgePrivilege(Privilege privilege)
                    throws APIException
Description copied from interface: UserService
Completely remove a privilege from the database

Specified by:
purgePrivilege in interface UserService
Parameters:
privilege - Privilege to delete
Throws:
APIException
See Also:
UserService.purgePrivilege(org.openmrs.Privilege)

savePrivilege

public Privilege savePrivilege(Privilege privilege)
                        throws APIException
Description copied from interface: UserService
Save the given privilege in the database

Specified by:
savePrivilege in interface UserService
Parameters:
privilege - Privilege to update
Returns:
the saved privilege
Throws:
APIException
See Also:
UserService.savePrivilege(org.openmrs.Privilege)

getRoles

public java.util.List<Role> getRoles()
                              throws APIException
Deprecated. 

Specified by:
getRoles in interface UserService
Throws:
APIException
See Also:
UserService.getRoles()

getAllRoles

public java.util.List<Role> getAllRoles()
                                 throws APIException
Description copied from interface: UserService
Returns all roles currently possible for any User

Specified by:
getAllRoles in interface UserService
Returns:
Global list of roles
Throws:
APIException
See Also:
UserService.getAllRoles()

getInheritingRoles

public java.util.List<Role> getInheritingRoles(Role role)
                                        throws APIException
Deprecated. 

Specified by:
getInheritingRoles in interface UserService
Throws:
APIException
See Also:
UserService.getInheritingRoles(org.openmrs.Role)

getRole

public Role getRole(java.lang.String r)
             throws APIException
Description copied from interface: UserService
Returns role object with given string role

Specified by:
getRole in interface UserService
Returns:
Role object for specified string
Throws:
APIException
See Also:
UserService.getRole(java.lang.String)

purgeRole

public void purgeRole(Role role)
               throws APIException
Description copied from interface: UserService
Complete remove a role from the database

Specified by:
purgeRole in interface UserService
Parameters:
role - Role to delete from the database
Throws:
APIException
See Also:
UserService.purgeRole(org.openmrs.Role)

saveRole

public Role saveRole(Role role)
              throws APIException
Description copied from interface: UserService
Save the given role in the database

Specified by:
saveRole in interface UserService
Parameters:
role - Role to update
Returns:
the saved role
Throws:
APIException
See Also:
UserService.saveRole(org.openmrs.Role)

changePassword

public void changePassword(User u,
                           java.lang.String pw)
                    throws APIException
Description copied from interface: UserService
Changes the user's password ** Restricted to Super User access**

Specified by:
changePassword in interface UserService
Parameters:
u - user
pw - new password
Throws:
APIException
See Also:
UserService.changePassword(org.openmrs.User, java.lang.String)

changePassword

public void changePassword(java.lang.String pw,
                           java.lang.String pw2)
                    throws APIException
Description copied from interface: UserService
Changes the current user's password.

Specified by:
changePassword in interface UserService
Parameters:
pw - current password
pw2 - new password
Throws:
APIException
See Also:
UserService.changePassword(java.lang.String, java.lang.String)

changeHashedPassword

public void changeHashedPassword(User user,
                                 java.lang.String hashedPassword,
                                 java.lang.String salt)
                          throws APIException
Description copied from interface: UserService
Changes the current user's password directly. This is most useful if migrating users from other systems and you want to retain the existing passwords. This method will simply save the passed hashed password and salt directly to the database.

Specified by:
changeHashedPassword in interface UserService
Parameters:
user - the user whose password you want to change
hashedPassword - - the already hashed password to store
salt - - the salt which should be used with this hashed password
Throws:
APIException
See Also:
UserService.changeHashedPassword(User, String, String)

changeQuestionAnswer

public void changeQuestionAnswer(User u,
                                 java.lang.String question,
                                 java.lang.String answer)
                          throws APIException
Description copied from interface: UserService
Changes the passed user's secret question and answer.

Specified by:
changeQuestionAnswer in interface UserService
Parameters:
u - User to change
Throws:
APIException
See Also:
UserService.changeQuestionAnswer(User, String, String)

changeQuestionAnswer

public void changeQuestionAnswer(java.lang.String pw,
                                 java.lang.String q,
                                 java.lang.String a)
Description copied from interface: UserService
Changes the current user's secret question and answer.

Specified by:
changeQuestionAnswer in interface UserService
Parameters:
pw - user's password
q - question
a - answer
See Also:
UserService.changeQuestionAnswer(java.lang.String, java.lang.String, java.lang.String)

isSecretAnswer

public boolean isSecretAnswer(User u,
                              java.lang.String answer)
Description copied from interface: UserService
Compares answer against the user's secret answer.

Specified by:
isSecretAnswer in interface UserService
Parameters:
u - user
See Also:
UserService.isSecretAnswer(org.openmrs.User, java.lang.String)

findUsers

public java.util.List<User> findUsers(java.lang.String name,
                                      java.util.List<java.lang.String> roles,
                                      boolean includeVoided)
Deprecated. 

Specified by:
findUsers in interface UserService
See Also:
UserService.findUsers(String, List, boolean)

findUsers

public java.util.List<User> findUsers(java.lang.String givenName,
                                      java.lang.String familyName,
                                      boolean includeVoided)
Deprecated. 

Specified by:
findUsers in interface UserService
See Also:
UserService.findUsers(String, String, boolean)

getUsersByName

public java.util.List<User> getUsersByName(java.lang.String givenName,
                                           java.lang.String familyName,
                                           boolean includeVoided)
                                    throws APIException
Description copied from interface: UserService
Search for a list of users by exact first name and last name.

Specified by:
getUsersByName in interface UserService
Returns:
List object of users matching criteria
Throws:
APIException
See Also:
UserService.getUsersByName(java.lang.String, java.lang.String, boolean)

getUsersByPerson

public java.util.List<User> getUsersByPerson(Person person,
                                             boolean includeRetired)
                                      throws APIException
Description copied from interface: UserService
Get all user accounts that belong to a given person.

Specified by:
getUsersByPerson in interface UserService
Returns:
all user accounts that belong to person, including retired ones if specified
Throws:
APIException
See Also:
UserService.getUsersByPerson(org.openmrs.Person, boolean)

getAllUsers

public java.util.List<User> getAllUsers(java.util.List<Role> roles,
                                        boolean includeVoided)
Deprecated. 

Specified by:
getAllUsers in interface UserService
See Also:
UserService.getAllUsers(List, boolean)

getUsers

public java.util.List<User> getUsers(java.lang.String nameSearch,
                                     java.util.List<Role> roles,
                                     boolean includeVoided)
                              throws APIException
Description copied from interface: UserService
Return a user if any part of the search matches first/last/system id and the user has one at least one of the given roles assigned to them

Specified by:
getUsers in interface UserService
Parameters:
nameSearch - string to compare to the beginning of user's given/middle/family/family2 names
roles - all the Roles the user must contain
includeVoided - true/false whether to include voided users
Returns:
list of users matching the given attributes
Throws:
APIException
See Also:
UserService.getUsers(java.lang.String, java.util.List, boolean)

setUserProperty

public User setUserProperty(User user,
                            java.lang.String key,
                            java.lang.String value)
Description copied from interface: UserService
Adds the key/value pair to the given user.

Implementations of this method should handle privileges

Specified by:
setUserProperty in interface UserService
Returns:
the user that was passed in and added to
See Also:
UserService.setUserProperty(User, String, String)

removeUserProperty

public User removeUserProperty(User user,
                               java.lang.String key)
Description copied from interface: UserService
Removes the property denoted by key from the user's properties. Implementations of this method should handle privileges

Specified by:
removeUserProperty in interface UserService
Returns:
the user that was passed in and removed from
See Also:
UserService.removeUserProperty(org.openmrs.User, java.lang.String)

generateSystemId

public java.lang.String generateSystemId()
Generates system ids based on the following algorithm scheme: user_id-check digit

Specified by:
generateSystemId in interface UserService
Returns:
new system id
See Also:
UserService.generateSystemId()

purgeUser

public void purgeUser(User user)
               throws APIException
Description copied from interface: UserService
Completely remove a location from the database (not reversible). This method delegates to #purgeLocation(location, boolean) method.

Specified by:
purgeUser in interface UserService
Parameters:
user - the User to remove from the database.
Throws:
APIException
See Also:
UserService.purgeUser(org.openmrs.User)

purgeUser

public void purgeUser(User user,
                      boolean cascade)
               throws APIException
Description copied from interface: UserService
Completely remove a user from the database (not reversible). This is a delete from the database. This is included for troubleshooting and low-level system administration. Ideally, this method should never be called — Users should be voided and not deleted altogether (since many foreign key constraints depend on users, deleting a user would require deleting all traces, and any historical trail would be lost). This method only clears user roles and attempts to delete the user record. If the user has been included in any other parts of the database (through a foreign key), the attempt to delete the user will violate foreign key constraints and fail.

Specified by:
purgeUser in interface UserService
cascade - true to delete associated content
Throws:
APIException
See Also:
UserService.purgeUser(org.openmrs.User, boolean)

getPrivilegeByUuid

public Privilege getPrivilegeByUuid(java.lang.String uuid)
                             throws APIException
Description copied from interface: UserService
Get Privilege by its UUID

Specified by:
getPrivilegeByUuid in interface UserService
Returns:
Throws:
APIException
See Also:
UserService.getPrivilegeByUuid(java.lang.String)

getRoleByUuid

public Role getRoleByUuid(java.lang.String uuid)
                   throws APIException
Description copied from interface: UserService
Get Role by its UUID

Specified by:
getRoleByUuid in interface UserService
Returns:
Throws:
APIException
See Also:
UserService.getRoleByUuid(java.lang.String)

getUserByUuid

public User getUserByUuid(java.lang.String uuid)
                   throws APIException
Description copied from interface: UserService
Get user by the given uuid.

Specified by:
getUserByUuid in interface UserService
Returns:
Throws:
APIException
See Also:
UserService.getUserByUuid(java.lang.String)

OpenMRS-1.7.x

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