Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
87ed3c85
Commit
87ed3c85
authored
Oct 01, 2019
by
Greg Messner
Browse files
Mods for new LicenseApi (#443).
parent
932c6bba
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/LicenseApi.java
0 → 100644
View file @
87ed3c85
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
src/main/java/org/gitlab4j/api/LicenseTemplatesApi.java
View file @
87ed3c85
...
...
@@ -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
l
ist of LicenseTemplate instances
* @return a
L
ist 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
l
icense
t
emplate
* @return a Pager of
L
icense
T
emplate
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
l
ist of popular LicenseTemplate instances
* @return a
L
ist 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
l
icense
t
emplate
* @return a Pager of
L
icense
T
emplate
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
{
...
...
src/main/java/org/gitlab4j/api/models/License.java
0 → 100644
View file @
87ed3c85
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
));
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment