org.gitlab4j.api.LicenseTemplatesApi Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gitlab4j-api Show documentation
Show all versions of gitlab4j-api Show documentation
GitLab4J-API (gitlab4j-api) provides a full featured Java client library for working with GitLab repositories and servers via the GitLab REST API.
package org.gitlab4j.api;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import jakarta.ws.rs.core.Response;
import org.gitlab4j.api.models.LicenseTemplate;
/**
* This class provides an entry point to all the GitLab API licenses calls.
* @see Licenses API
*/
public class LicenseTemplatesApi extends AbstractApi {
public LicenseTemplatesApi(GitLabApi gitLabApi) {
super(gitLabApi);
}
/**
* Get a List of all license templates.
*
* GitLab Endpoint: GET /templates/licenses
*
* @return a List of LicenseTemplate instances
* @throws GitLabApiException if any exception occurs
*/
public List getLicenseTemplates() throws GitLabApiException {
return (getLicenseTemplates(false, getDefaultPerPage()).all());
}
/**
* Get a Stream of all license templates.
*
* GitLab Endpoint: GET /templates/licenses
*
* @return a Stream of LicenseTemplate instances
* @throws GitLabApiException if any exception occurs
*/
public Stream getLicenseTemplatesStream() throws GitLabApiException {
return (getLicenseTemplates(false, getDefaultPerPage()).stream());
}
/**
* Get a Pager of all license templates.
*
* GitLab Endpoint: GET /templates/licenses
*
* @param itemsPerPage the number of LicenseTemplate instances that will be fetched per page
* @return a Pager of LicenseTemplate instances
* @throws GitLabApiException if any exception occurs
*/
public Pager getLicenseTemplates(int itemsPerPage) throws GitLabApiException {
return (getLicenseTemplates(false, itemsPerPage));
}
/**
* Get a List of popular license templates.
*
* GitLab Endpoint: GET /templates/licenses?popular=true
*
* @return a List of popular LicenseTemplate instances
* @throws GitLabApiException if any exception occurs
*/
public List getPopularLicenseTemplates() throws GitLabApiException {
return (getLicenseTemplates(true, getDefaultPerPage()).all());
}
/**
* Get a Stream of popular license templates.
*
* GitLab Endpoint: GET /templates/licenses?popular=true
*
* @return a Stream of popular LicenseTemplate instances
* @throws GitLabApiException if any exception occurs
*/
public Stream getPopularLicenseTemplatesStream() throws GitLabApiException {
return (getLicenseTemplates(true, getDefaultPerPage()).stream());
}
/**
* Get a Pager of license templates.
*
* GitLab Endpoint: GET /templates/licenses
*
* @param popular if true, returns only popular licenses.
* @param itemsPerPage the number of LicenseTemplate instances that will be fetched per page
* @return a Pager of LicenseTemplate instances
* @throws GitLabApiException if any exception occurs
*/
public Pager getLicenseTemplates(Boolean popular, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("popular", popular);
return (new Pager(this, LicenseTemplate.class, itemsPerPage, formData.asMap(), "templates", "licenses"));
}
/**
* Get a single license template.
*
* GitLab Endpoint: GET /templates/licenses/:key
*
* @param key The key of the license template
* @return a LicenseTemplate instance
* @throws GitLabApiException if any exception occurs
*/
public LicenseTemplate getLicenseTemplate(String key) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "licenses", key);
return (response.readEntity(LicenseTemplate.class));
}
/**
* Get a single license template as the value of an Optional.
*
* GitLab Endpoint: GET /templates/licenses/:key
*
* @param key The key of the license template
* @return a single license template as the value of an Optional.
*/
public Optional getOptionalLicenseTemplate(String key) {
try {
return (Optional.ofNullable(getLicenseTemplate(key)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy