Class UserManager
- java.lang.Object
-
- com.taskadapter.redmineapi.UserManager
-
public class UserManager extends java.lang.Object
Works with Users and Groups.Obtain it via RedmineManager:
RedmineManager redmineManager = RedmineManagerFactory.createWithUserAuth(redmineURI, login, password); UserManager userManager = redmineManager.getUserManager();
Note that some operations with users require Redmine Admin privileges.Sample usage:
users = mgr.getUserManager().getUsers();
- See Also:
RedmineManager.getUserManager()
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addUserToGroup(User user, Group group)
Adds the given user to the given group.Group
createGroup(Group base)
Creates a new group.User
createUser(User user)
void
deleteGroup(Group base)
Deletes a group.void
deleteUser(java.lang.Integer userId)
User
getCurrentUser()
Group
getGroupById(int id)
Returns the group based on its id.Group
getGroupByName(java.lang.String name)
Returns the group based on its name.java.util.List<Group>
getGroups()
Load list of groups on the server.Role
getRoleById(int id)
java.util.List<Role>
getRoles()
User
getUserById(java.lang.Integer userId)
This does NOT require Admin privileges by default Redmine installation (tested with Redmine 2.0.3).java.util.List<User>
getUsers()
Load list of users from the server.ResultsWrapper<User>
getUsers(java.util.Map<java.lang.String,java.lang.String> parameters)
This method does NOT handle paging for you.void
update(Group group)
void
update(User obj)
-
-
-
Method Detail
-
getCurrentUser
public User getCurrentUser() throws RedmineException
- Returns:
- the current user logged into Redmine
- Throws:
RedmineException
-
createUser
public User createUser(User user) throws RedmineException
- Throws:
RedmineException
-
deleteUser
public void deleteUser(java.lang.Integer userId) throws RedmineException
- Parameters:
userId
- user identifier (numeric ID)- Throws:
RedmineAuthenticationException
- invalid or no API access key is used with the server, which requires authorization. Check the constructor arguments.NotFoundException
- if the user with the given id is not foundRedmineException
-
addUserToGroup
public void addUserToGroup(User user, Group group) throws RedmineException
Adds the given user to the given group.Note: "add to group" operation used to be safe (idempotent) for Redmine 2.6.x, but FAILS for Redmine 3.0.0 when executed twice on the same user. I submitted a bug: http://www.redmine.org/issues/19363
- Parameters:
user
- - The user being added.group
- - The new group of the user.- Throws:
RedmineException
- Since:
- Redmine 2.1
-
getUsers
public java.util.List<User> getUsers() throws RedmineException
Load list of users from the server.This operation requires "Redmine Administrator" permission.
This method calls Redmine with "include = memberships,groups" parameter.
- Returns:
- list of User objects
- Throws:
RedmineAuthenticationException
- invalid or no API access key is used with the server, which requires authorization. Check the constructor arguments.NotFoundException
RedmineException
-
getUsers
public ResultsWrapper<User> getUsers(java.util.Map<java.lang.String,java.lang.String> parameters) throws RedmineException
This method does NOT handle paging for you. You need to provide "offset" and "limit" parameters if you want to control paging.
Sample usage:
final Map
params = new HashMap (); params.put("name", name); final List users = userManager.getUsers(params); - Parameters:
parameters
- http parameters: key/value pairs to append to the rest api request- Returns:
- resultsWrapper with raw response from Redmine REST API
- Throws:
RedmineAuthenticationException
- invalid or no API access key is used with the server, which requires authorization. Check the constructor arguments.RedmineException
-
getUserById
public User getUserById(java.lang.Integer userId) throws RedmineException
This does NOT require Admin privileges by default Redmine installation (tested with Redmine 2.0.3).- Throws:
RedmineException
-
getGroups
public java.util.List<Group> getGroups() throws RedmineException
Load list of groups on the server.This operation requires "Redmine Administrator" permission.
- Returns:
- list of User objects
- Throws:
RedmineAuthenticationException
- invalid or no API access key is used with the server, which requires authorization. Check the constructor arguments.NotFoundException
RedmineException
-
getGroupById
public Group getGroupById(int id) throws RedmineException
Returns the group based on its id.This operation requires "Redmine Administrators" permission.
- Parameters:
id
- id of the group- Returns:
- the group
- Throws:
RedmineException
-
getGroupByName
public Group getGroupByName(java.lang.String name) throws RedmineException
Returns the group based on its name.This operation requires "Redmine Administrators" permission.
- Parameters:
name
- the name of the group- Returns:
- the group
- Throws:
RedmineException
-
createGroup
public Group createGroup(Group base) throws RedmineException
Creates a new group.This operation requires "Redmine Administrator" permission.
- Returns:
- created group.
- Throws:
RedmineException
-
deleteGroup
public void deleteGroup(Group base) throws RedmineException
Deletes a group.This operation requires "Redmine Administrator" permission.
- Throws:
RedmineException
-
getRoles
public java.util.List<Role> getRoles() throws RedmineException
- Throws:
RedmineException
-
getRoleById
public Role getRoleById(int id) throws RedmineException
- Throws:
RedmineException
-
update
public void update(User obj) throws RedmineException
- Throws:
RedmineException
-
update
public void update(Group group) throws RedmineException
- Throws:
RedmineException
-
-