GroupApi.java 55.74 KiB
package org.gitlab4j.api;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
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.AccessLevel;
import org.gitlab4j.api.models.Group;
import org.gitlab4j.api.models.GroupFilter;
import org.gitlab4j.api.models.GroupProjectsFilter;
import org.gitlab4j.api.models.Member;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.Variable;
import org.gitlab4j.api.models.Visibility;
/**
 * This class implements the client side API for the GitLab groups calls.
public class GroupApi extends AbstractApi {
    public GroupApi(GitLabApi gitLabApi) {
        super(gitLabApi);
    /**
     * Get a list of groups. (As user: my groups, as admin: all groups)
     * <pre><code>GitLab Endpoint: GET /groups</code></pre>
     * @return the list of groups viewable by the authenticated user
     * @throws GitLabApiException if any exception occurs
    public List<Group> getGroups() throws GitLabApiException {
        return (getGroups(getDefaultPerPage()).all());
    /**
     * Get a list of groups (As user: my groups, as admin: all groups) and in the specified page range.
     * <pre><code>GitLab Endpoint: GET /groups</code></pre>
     * @param page the page to get
     * @param perPage the number of Group instances per page
     * @return the list of groups viewable by the authenticated userin the specified page range
     * @throws GitLabApiException if any exception occurs
    public List<Group> getGroups(int page, int perPage) throws GitLabApiException {
        Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "groups");
        return (response.readEntity(new GenericType<List<Group>>() {}));
    /**
     * Get a Pager of groups. (As user: my groups, as admin: all groups)
     * <pre><code>GitLab Endpoint: GET /groups</code></pre>
     * @param itemsPerPage the number of Group instances that will be fetched per page
     * @return the list of groups viewable by the authenticated user
     * @throws GitLabApiException if any exception occurs
    public Pager<Group> getGroups(int itemsPerPage) throws GitLabApiException {
        return (new Pager<Group>(this, Group.class, itemsPerPage, null, "groups"));
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
/** * Get a Stream of groups. (As user: my groups, as admin: all groups) * * <pre><code>GitLab Endpoint: GET /groups</code></pre> * * @return a Stream of groups viewable by the authenticated user * @throws GitLabApiException if any exception occurs */ public Stream<Group> getGroupsStream() throws GitLabApiException { return (getGroups(getDefaultPerPage()).stream()); } /** * Get all groups that match your string in their name or path. * * @param search the group name or path search criteria * @return a List containing matching Group instances * @throws GitLabApiException if any exception occurs */ public List<Group> getGroups(String search) throws GitLabApiException { return (getGroups(search, getDefaultPerPage()).all()); } /** * Get all groups that match your string in their name or path. * * @param search the group name or path search criteria * @param page the page to get * @param perPage the number of Group instances per page * @return a List containing matching Group instances * @throws GitLabApiException if any exception occurs */ public List<Group> getGroups(String search, int page, int perPage) throws GitLabApiException { Form formData = new GitLabApiForm().withParam("search", search).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage); Response response = get(Response.Status.OK, formData.asMap(), "groups"); return (response.readEntity(new GenericType<List<Group>>() {})); } /** * Get all groups that match your string in their name or path. * * @param search the group name or path search criteria * @param itemsPerPage the number of Group instances that will be fetched per page * @return a Pager containing matching Group instances * @throws GitLabApiException if any exception occurs */ public Pager<Group> getGroups(String search, int itemsPerPage) throws GitLabApiException { Form formData = new GitLabApiForm().withParam("search", search); return (new Pager<Group>(this, Group.class, itemsPerPage, formData.asMap(), "groups")); } /** * Get all groups that match your string in their name or path as a Stream. * * @param search the group name or path search criteria * @return a Stream containing matching Group instances * @throws GitLabApiException if any exception occurs */ public Stream<Group> getGroupsStream(String search) throws GitLabApiException { return (getGroups(search, getDefaultPerPage()).stream()); } /** * Get a list of visible groups for the authenticated user using the provided filter. * * <pre><code>GitLab Endpoint: GET /groups</code></pre> * * @param filter the GroupFilter to match against * @return a List&lt;Group&gt; of the matching groups * @throws GitLabApiException if any exception occurs
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
*/ public List<Group> getGroups(GroupFilter filter) throws GitLabApiException { return (getGroups(filter, getDefaultPerPage()).all()); } /** * Get a Pager of visible groups for the authenticated user using the provided filter. * * <pre><code>GitLab Endpoint: GET /groups</code></pre> * * @param filter the GroupFilter to match against * @param itemsPerPage the number of Group instances that will be fetched per page * @return a Pager containing matching Group instances * @throws GitLabApiException if any exception occurs */ public Pager<Group> getGroups(GroupFilter filter, int itemsPerPage) throws GitLabApiException { GitLabApiForm formData = filter.getQueryParams(); return (new Pager<Group>(this, Group.class, itemsPerPage, formData.asMap(), "groups")); } /** * Get a Stream of visible groups for the authenticated user using the provided filter. * * <pre><code>GitLab Endpoint: GET /groups</code></pre> * * @param filter the GroupFilter to match against * @return a Stream&lt;Group&gt; of the matching groups * @throws GitLabApiException if any exception occurs */ public Stream<Group> getGroupsStream(GroupFilter filter) throws GitLabApiException { return (getGroups(filter, getDefaultPerPage()).stream()); } /** * Get a list of visible direct subgroups in this group. * * <pre><code>GitLab Endpoint: GET /groups/:id/subgroups</code></pre> * * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required * @return a List&lt;Group&gt; containing the group's sub-groups * @throws GitLabApiException if any exception occurs * @since GitLab 10.3.0 */ public List<Group> getSubGroups(Object groupIdOrPath) throws GitLabApiException { return (getSubGroups(groupIdOrPath, getDefaultPerPage()).all()); } /** * Get a Pager of visible direct subgroups in this group. * * <pre><code>GitLab Endpoint: GET /groups/:id/subgroups</code></pre> * * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required * @param itemsPerPage the number of Group instances that will be fetched per page * @return a Pager containing matching Group instances * @throws GitLabApiException if any exception occurs * @since GitLab 10.3.0 */ public Pager<Group> getSubGroups(Object groupIdOrPath, int itemsPerPage) throws GitLabApiException { return (new Pager<Group>(this, Group.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "subgroups")); } /** * Get a Stream of visible direct subgroups in this group. * * <pre><code>GitLab Endpoint: GET /groups/:id/subgroups</code></pre> * * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required * @return a Stream&lt;Group&gt; containing the group's sub-groups * @throws GitLabApiException if any exception occurs