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

org.gitlab4j.api.NamespaceApi Maven / Gradle / Ivy

Go to download

GitLab4J-API (gitlab4j-api) provides a full featured Java client library for working with GitLab repositories and servers via the GitLab REST API.

There is a newer version: 6.0.0-rc.6
Show newest version
package org.gitlab4j.api;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.Response;

import org.gitlab4j.api.models.Namespace;

/**
 * This class implements the client side API for the GitLab namespace calls.
 */
public class NamespaceApi extends AbstractApi {

    public NamespaceApi(GitLabApi gitLabApi) {
        super(gitLabApi);
    }

    /**
     * Get a list of the namespaces of the authenticated user. If the user is an administrator,
     * a list of all namespaces in the GitLab instance is created.
     *
     * 
GitLab Endpoint: GET /namespaces
* * @return a List of Namespace instances * @throws GitLabApiException if any exception occurs */ public List getNamespaces() throws GitLabApiException { return (getNamespaces(getDefaultPerPage()).all()); } /** * Get a list of the namespaces of the authenticated user. If the user is an administrator, * a list of all namespaces in the GitLab instance is returned. * *
GitLab Endpoint: GET /namespaces
* * @param page the page to get * @param perPage the number of Namespace instances per page * @return a List of Namespace instances in the specified page range * @throws GitLabApiException if any exception occurs */ public List getNamespaces(int page, int perPage) throws GitLabApiException { Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "namespaces"); return (response.readEntity(new GenericType>() {})); } /** * Get a Pager of the namespaces of the authenticated user. If the user is an administrator, * a Pager of all namespaces in the GitLab instance is returned. * *
GitLab Endpoint: GET /namespaces
* * @param itemsPerPage the number of Project instances that will be fetched per page * @return a Pager of Namespace instances * @throws GitLabApiException if any exception occurs */ public Pager getNamespaces(int itemsPerPage) throws GitLabApiException { return (new Pager(this, Namespace.class, itemsPerPage, null, "namespaces")); } /** * Get a Stream of the namespaces of the authenticated user. If the user is an administrator, * a Stream of all namespaces in the GitLab instance is returned. * *
GitLab Endpoint: GET /namespaces
* * @return a Stream of Namespace instances * @throws GitLabApiException if any exception occurs */ public Stream getNamespacesStream() throws GitLabApiException { return (getNamespaces(getDefaultPerPage()).stream()); } /** * Get all namespaces that match a string in their name or path. * *
GitLab Endpoint: GET /namespaces?search=:query
* * @param query the search string * @return the Namespace List with the matching namespaces * @throws GitLabApiException if any exception occurs */ public List findNamespaces(String query) throws GitLabApiException { return (findNamespaces(query, getDefaultPerPage()).all()); } /** * Get all namespaces that match a string in their name or path in the specified page range. * *
GitLab Endpoint: GET /namespaces?search=:query
* * @param query the search string * @param page the page to get * @param perPage the number of Namespace instances per page * @return the Namespace List with the matching namespaces * @throws GitLabApiException if any exception occurs */ public List findNamespaces(String query, int page, int perPage) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm().withParam("search", query, true).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage); Response response = get(Response.Status.OK, formData.asMap(), "namespaces"); return (response.readEntity(new GenericType>() {})); } /** * Get a Pager of all namespaces that match a string in their name or path. * *
GitLab Endpoint: GET /namespaces?search=:query
* * @param query the search string * @param itemsPerPage the number of Project instances that will be fetched per page * @return a Pager of Namespace instances with the matching namespaces * @throws GitLabApiException if any exception occurs */ public Pager findNamespaces(String query, int itemsPerPage) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm().withParam("search", query, true); return (new Pager(this, Namespace.class, itemsPerPage, formData.asMap(), "namespaces")); } /** * Get all namespaces that match a string in their name or path as a Stream. * *
GitLab Endpoint: GET /namespaces?search=:query
* * @param query the search string * @return a Stream with the matching namespaces * @throws GitLabApiException if any exception occurs */ public Stream findNamespacesStream(String query) throws GitLabApiException { return (findNamespaces(query, getDefaultPerPage()).stream()); } /** * Get all details of a namespace. * *
GitLab Endpoint: GET /namespaces/:id
* * @param namespaceIdOrPath the namespace ID, path of the namespace, or a Namespace instance holding the namespace ID or path * @return the Namespace instance for the specified path * @throws GitLabApiException if any exception occurs */ public Namespace getNamespace(Object namespaceIdOrPath) throws GitLabApiException { Response response = get(Response.Status.OK, null, "namespaces", getNamespaceIdOrPath(namespaceIdOrPath)); return (response.readEntity(Namespace .class)); } /** * Get all details of a namespace as an Optional instance. * *
GitLab Endpoint: GET /namespaces/:id
* * @param namespaceIdOrPath the namespace ID, path of the namespace, or a Namespace instance holding the namespace ID or path * @return the Group for the specified group path as an Optional instance */ public Optional getOptionalNamespace(Object namespaceIdOrPath) { try { return (Optional.ofNullable(getNamespace(namespaceIdOrPath))); } catch (GitLabApiException glae) { return (GitLabApi.createOptionalFromException(glae)); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy