Commit 87ed3c85 authored by Greg Messner's avatar Greg Messner
Browse files

Mods for new LicenseApi (#443).

parent 932c6bba
package org.gitlab4j.api;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.models.License;
/**
* This class provides an entry point to all the GitLab API license calls.
* @see <a href="https://docs.gitlab.com/ce/api/license.html">License API</a>
*/
public class LicenseApi extends AbstractApi {
public LicenseApi(GitLabApi gitLabApi) {
super(gitLabApi);
}
/**
* Retrieve information about the current license.
*
* <pre><code>GitLab Endpoint: GET /license</code></pre>
*
* @return a License instance holding info about the current license
* @throws GitLabApiException if any exception occurs
*/
public License getLicense() throws GitLabApiException {
Response response = get(Response.Status.OK, null, "license");
return (response.readEntity(License.class));
}
/**
* Retrieve information about the current license as the value of an Optional.
*
* <pre><code>GitLab Endpoint: GET /license</code></pre>
*
* @return the current license as the value of an Optional.
*/
public Optional<License> getOptionalLicense() {
try {
return (Optional.ofNullable(getLicense()));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/**
* Retrieve information about all licenses.
*
* <pre><code>GitLab Endpoint: GET /licenses</code></pre>
*
* @return a List of License instances
* @throws GitLabApiException if any exception occurs
*/
public List<License> getAllLicenses() throws GitLabApiException {
return (getAllLicenses(getDefaultPerPage()).all());
}
/**
* Get a Stream of all licenses.
*
<pre><code>GitLab Endpoint: GET /licenses</code></pre>
*
* @return a Stream of License instances
* @throws GitLabApiException if any exception occurs
*/
public Stream<License> getAllLicensesStream() throws GitLabApiException {
return (getAllLicenses(getDefaultPerPage()).stream());
}
/**
* Get a Pager of all licenses.
*
* <pre><code>GitLab Endpoint: GET /licenses</code></pre>
*
* @param itemsPerPage the number of LicenseTemplate instances that will be
* fetched per page
* @return a Pager of license template
* @throws GitLabApiException if any exception occurs
*/
public Pager<License> getAllLicenses(int itemsPerPage) throws GitLabApiException {
return (new Pager<License>(this, License.class, itemsPerPage, null, "licenses"));
}
/**
* Add a new license.
*
* <pre><code>GitLab Endpoint: POST /license</code></pre>
*
* @param licenseString the license string for the license
* @return a License instance for the added license
* @throws GitLabApiException if any exception occurs
*/
public License addLicense(String licenseString) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("license", licenseString, true);
Response response = post(Response.Status.CREATED, formData, "license");
return (response.readEntity(License.class));
}
/**
* Deletes a license.
*
* <pre><code>GitLab Endpoint: DELETE /license/:id</code></pre>
*
* @param licenseId the ID of the license to delete
* @return a License instance for the delete license
* @throws GitLabApiException if any exception occurs
*/
public License deleteLicense(Integer licenseId) throws GitLabApiException {
Response response = delete(Response.Status.OK, null, "license", licenseId);
return (response.readEntity(License.class));
}
}
\ No newline at end of file
......@@ -10,8 +10,7 @@ import org.gitlab4j.api.models.LicenseTemplate;
/**
* This class provides an entry point to all the GitLab API licenses calls.
@see <a href="https://docs.gitlab.com/ce/api/templates/licenses.html">Licenses API</a>
* @see <a href="https://docs.gitlab.com/ce/api/templates/licenses.html">Licenses API</a>
*/
public class LicenseTemplatesApi extends AbstractApi {
......@@ -24,7 +23,7 @@ public class LicenseTemplatesApi extends AbstractApi {
*
* <pre><code>GitLab Endpoint: GET /templates/licenses</code></pre>
*
* @return a list of LicenseTemplate instances
* @return a List of LicenseTemplate instances
* @throws GitLabApiException if any exception occurs
*/
public List<LicenseTemplate> getLicenseTemplates() throws GitLabApiException {
......@@ -36,7 +35,7 @@ public class LicenseTemplatesApi extends AbstractApi {
*
* <pre><code>GitLab Endpoint: GET /templates/licenses</code></pre>
*
* @return a list of LicenseTemplate instances
* @return a Stream of LicenseTemplate instances
* @throws GitLabApiException if any exception occurs
*/
public Stream<LicenseTemplate> getLicenseTemplatesStream() throws GitLabApiException {
......@@ -49,7 +48,7 @@ public class LicenseTemplatesApi extends AbstractApi {
* <pre><code>GitLab Endpoint: GET /templates/licenses</code></pre>
*
* @param itemsPerPage the number of LicenseTemplate instances that will be fetched per page
* @return a Pager of license template
* @return a Pager of LicenseTemplate instances
* @throws GitLabApiException if any exception occurs
*/
public Pager<LicenseTemplate> getLicenseTemplates(int itemsPerPage) throws GitLabApiException {
......@@ -61,7 +60,7 @@ public class LicenseTemplatesApi extends AbstractApi {
*
* <pre><code>GitLab Endpoint: GET /templates/licenses?popular=true</code></pre>
*
* @return a list of popular LicenseTemplate instances
* @return a List of popular LicenseTemplate instances
* @throws GitLabApiException if any exception occurs
*/
public List<LicenseTemplate> getPopularLicenseTemplates() throws GitLabApiException {
......@@ -87,7 +86,7 @@ public class LicenseTemplatesApi extends AbstractApi {
*
* @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 license template
* @return a Pager of LicenseTemplate instances
* @throws GitLabApiException if any exception occurs
*/
public Pager<LicenseTemplate> getLicenseTemplates(Boolean popular, int itemsPerPage) throws GitLabApiException {
......@@ -116,7 +115,6 @@ public class LicenseTemplatesApi extends AbstractApi {
*
* @param key The key of the license template
* @return a single license template as the value of an Optional.
* @throws GitLabApiException if any exception occurs
*/
public Optional<LicenseTemplate> getOptionalLicenseTemplate(String key) {
try {
......
package org.gitlab4j.api.models;
import java.util.Date;
import java.util.Map;
import org.gitlab4j.api.utils.JacksonJson;
public class License {
private Integer id;
private String plan;
private Date createdAt;
private Date startsAt;
private Date expiresAt;
private Integer historicalMax;
private Boolean expired;
private Integer overage;
private Integer userLimit;
private Integer activeUsers;
private Map<String, String> licensee;
private Map<String, Integer> addOns;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getPlan() {
return plan;
}
public void setPlan(String plan) {
this.plan = plan;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getStartsAt() {
return startsAt;
}
public void setStartsAt(Date startsAt) {
this.startsAt = startsAt;
}
public Date getExpiresAt() {
return expiresAt;
}
public void setExpiresAt(Date expiresAt) {
this.expiresAt = expiresAt;
}
public Integer getHistoricalMax() {
return historicalMax;
}
public void setHistoricalMax(Integer historicalMax) {
this.historicalMax = historicalMax;
}
public Boolean getExpired() {
return expired;
}
public void setExpired(Boolean expired) {
this.expired = expired;
}
public Integer getOverage() {
return overage;
}
public void setOverage(Integer overage) {
this.overage = overage;
}
public Integer getUserLimit() {
return userLimit;
}
public void setUserLimit(Integer userLimit) {
this.userLimit = userLimit;
}
public Integer getActiveUsers() {
return activeUsers;
}
public void setActiveUsers(Integer activeUsers) {
this.activeUsers = activeUsers;
}
public Map<String, String> getLicensee() {
return licensee;
}
public void setLicensee(Map<String, String> licensee) {
this.licensee = licensee;
}
public Map<String, Integer> getAddOns() {
return addOns;
}
public void setAddOns(Map<String, Integer> addOns) {
this.addOns = addOns;
}
@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment