All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.taskadapter.redmineapi.UserManager Maven / Gradle / Ivy

Go to download

Free open-source Java API for Redmine and Chiliproject bug/task management systems. This project was originally a part of Task Adapter application (http://www.taskadapter.com) and then was open-sourced.

The newest version!
package com.taskadapter.redmineapi;

import com.taskadapter.redmineapi.bean.Group;
import com.taskadapter.redmineapi.bean.Role;
import com.taskadapter.redmineapi.bean.User;
import com.taskadapter.redmineapi.internal.DirectObjectsSearcher;
import com.taskadapter.redmineapi.internal.RequestParam;
import com.taskadapter.redmineapi.internal.ResultsWrapper;
import com.taskadapter.redmineapi.internal.Transport;
import org.apache.http.message.BasicNameValuePair;

import java.util.List;
import java.util.Map;

/**
 * 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 RedmineManager#getUserManager() */ public class UserManager { private final Transport transport; UserManager(Transport transport) { this.transport = transport; } /** * @return the current user logged into Redmine */ public User getCurrentUser() throws RedmineException { return transport.getCurrentUser(); } /** * DEPRECATED. use user.create() instead. */ @Deprecated public User createUser(User user) throws RedmineException { return user.create(); } /** * DEPRECATED. use user.delete() instead * * @param 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. * @throws NotFoundException if the user with the given id is not found */ @Deprecated public void deleteUser(Integer userId) throws RedmineException { transport.deleteObject(User.class, Integer.toString(userId)); } /** * DEPRECATED. use user.addToGroup() */ @Deprecated public void addUserToGroup(User user, Group group) throws RedmineException { transport.addUserToGroup(user.getId(), group.getId()); } /** * Load list of users from the server. *

This operation requires "Redmine Administrator" permission. *

* This method calls Redmine with "include = memberships,groups" parameter. * * @return list of User objects * @throws RedmineAuthenticationException invalid or no API access key is used with the server, which * requires authorization. Check the constructor arguments. * @throws NotFoundException * @throws RedmineException */ public List getUsers() throws RedmineException { return transport.getObjectsList(User.class, new RequestParam( "include", "memberships,groups")); } /** *

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);
     
* * @param parameters http parameters: key/value pairs to append to the rest api request * @return 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. * @throws RedmineException */ public ResultsWrapper getUsers(Map parameters) throws RedmineException { return DirectObjectsSearcher.getObjectsListNoPaging(transport, parameters, User.class); } /** * This does NOT require Admin privileges by default Redmine installation (tested with Redmine 2.0.3). */ public User getUserById(Integer userId) throws RedmineException { return transport.getObject(User.class, userId, new RequestParam( "include", "memberships,groups")); } /** * Load list of groups on the server. *

This operation requires "Redmine Administrator" permission. * * @return list of User objects * @throws RedmineAuthenticationException invalid or no API access key is used with the server, which * requires authorization. Check the constructor arguments. * @throws NotFoundException * @throws RedmineException */ public List getGroups() throws RedmineException { return transport.getObjectsList(Group.class); } /** * Returns the group based on its id. *

* This operation requires "Redmine Administrators" permission. * * @param id id of the group * @return the group * @throws RedmineException */ public Group getGroupById(int id) throws RedmineException { return transport.getObject(Group.class, id); } /** * Returns the group based on its name. *

* This operation requires "Redmine Administrators" permission. * * @param name * the name of the group * @return the group * @throws RedmineException */ public Group getGroupByName(String name) throws RedmineException { return transport.getObject(Group.class, name); } /** * DEPRECATED. use group.create() * * Creates a new group. *

This operation requires "Redmine Administrator" permission. * @return created group. * @throws RedmineException */ @Deprecated public Group createGroup(Group base) throws RedmineException { return transport.addObject(base); } /** * Deletes a group. *

This operation requires "Redmine Administrator" permission. */ @Deprecated public void deleteGroup(Group base) throws RedmineException { transport.deleteObject(Group.class, base.getId().toString()); } public List getRoles() throws RedmineException { return transport.getObjectsList(Role.class); } public Role getRoleById(int id) throws RedmineException { return transport.getObject(Role.class, id); } @Deprecated public void update(User obj) throws RedmineException { transport.updateObject(obj); } @Deprecated public void update(Group group) throws RedmineException { transport.updateObject(group); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy