From f9d6b8a28e9853959f59c1a21bb4e97bd1167bd5 Mon Sep 17 00:00:00 2001 From: Alex Bobkov Date: Fri, 27 Oct 2017 14:08:05 +0300 Subject: [PATCH] Get active/blocked users --- src/main/java/org/gitlab4j/api/UserApi.java | 111 ++++++++++++++++++-- 1 file changed, 104 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/UserApi.java b/src/main/java/org/gitlab4j/api/UserApi.java index 7f0056088..34abcf718 100644 --- a/src/main/java/org/gitlab4j/api/UserApi.java +++ b/src/main/java/org/gitlab4j/api/UserApi.java @@ -1,14 +1,13 @@ package org.gitlab4j.api; -import java.util.List; +import org.gitlab4j.api.GitLabApi.ApiVersion; +import org.gitlab4j.api.models.SshKey; +import org.gitlab4j.api.models.User; import javax.ws.rs.core.Form; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.Response; - -import org.gitlab4j.api.GitLabApi.ApiVersion; -import org.gitlab4j.api.models.SshKey; -import org.gitlab4j.api.models.User; +import java.util.List; /** * This class provides an entry point to all the GitLab API users calls. @@ -24,7 +23,7 @@ public class UserApi extends AbstractApi { * * GET /users * - * @return a list of Users, this list will only contain the first 20 users in the system. + * @return a list of Users, this list will only contain the first 100 users in the system. * @throws GitLabApiException if any exception occurs */ public List getUsers() throws GitLabApiException { @@ -52,7 +51,7 @@ public List getUsers(int page, int perPage) throws GitLabApiException { * * GET /users * - * @param itemsPerPage the number of Project instances that will be fetched per page + * @param itemsPerPage the number of User instances that will be fetched per page * @return a Pager of User * @throws GitLabApiException if any exception occurs */ @@ -60,6 +59,104 @@ public Pager getUsers(int itemsPerPage) throws GitLabApiException { return (new Pager(this, User.class, itemsPerPage, null, "users")); } + /** + * Get a list of active users. Only returns the first page + * + * GET /users?active=true + * + * @return a list of active Users, this list will only contain the first 100 users in the system. + * @throws GitLabApiException if any exception occurs + */ + public List getActiveUsers() throws GitLabApiException{ + GitLabApiForm formData = new GitLabApiForm() + .withParam("active", true) + .withParam(PER_PAGE_PARAM, getDefaultPerPage()); + Response response = get(Response.Status.OK, formData.asMap(), "users"); + return (response.readEntity(new GenericType>() {})); + } + + /** + * Get a list of active users using the specified page and per page settings. + * + * GET /users?active=true + * + * @param page the page to get + * @param perPage the number of users per page + * @return the list of active Users in the specified range + * @throws GitLabApiException if any exception occurs + */ + public List getActiveUsers(int page, int perPage) throws GitLabApiException{ + GitLabApiForm formData = new GitLabApiForm() + .withParam("active", true) + .withParam(PAGE_PARAM, page) + .withParam(PER_PAGE_PARAM, perPage); + Response response = get(Response.Status.OK, formData.asMap(), "users"); + return (response.readEntity(new GenericType>() {})); + } + + /** + * Get a Pager of active users. + * + * GET /users?active=true + * + * @param itemsPerPage the number of active User instances that will be fetched per page + * @return a Pager of active User + * @throws GitLabApiException if any exception occurs + */ + public Pager getActiveUsers(int itemsPerPage) throws GitLabApiException{ + GitLabApiForm formData = new GitLabApiForm().withParam("active", true); + return (new Pager(this, User.class, itemsPerPage, formData.asMap(), "users")); + } + + /** + * Get a list of blocked users. Only returns the first page + * + * GET /users?blocked=true + * + * @return a list of blocked Users, this list will only contain the first 100 users in the system. + * @throws GitLabApiException if any exception occurs + */ + public List getBlockedUsers() throws GitLabApiException{ + GitLabApiForm formData = new GitLabApiForm() + .withParam("blocked", true) + .withParam(PER_PAGE_PARAM, getDefaultPerPage()); + Response response = get(Response.Status.OK, formData.asMap(), "users"); + return (response.readEntity(new GenericType>() {})); + } + + /** + * Get a list of blocked users using the specified page and per page settings. + * + * GET /users?blocked=true + * + * @param page the page to get + * @param perPage the number of users per page + * @return the list of blocked Users in the specified range + * @throws GitLabApiException if any exception occurs + */ + public List getblockedUsers(int page, int perPage) throws GitLabApiException{ + GitLabApiForm formData = new GitLabApiForm() + .withParam("blocked", true) + .withParam(PAGE_PARAM, page) + .withParam(PER_PAGE_PARAM, perPage); + Response response = get(Response.Status.OK, formData.asMap(), "users"); + return (response.readEntity(new GenericType>() {})); + } + + /** + * Get a Pager of blocked users. + * + * GET /users?blocked=true + * + * @param itemsPerPage the number of blocked User instances that will be fetched per page + * @return a Pager of blocked User + * @throws GitLabApiException if any exception occurs + */ + public Pager getBlockedUsers(int itemsPerPage) throws GitLabApiException{ + GitLabApiForm formData = new GitLabApiForm().withParam("blocked", true); + return (new Pager(this, User.class, itemsPerPage, formData.asMap(), "users")); + } + /** * Get a single user. *