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
2c208a09
Commit
2c208a09
authored
Jun 26, 2018
by
Greg Messner
Browse files
Added support for Date and List form params (#202).
parent
c8ccbaa7
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/GitLabApiForm.java
View file @
2c208a09
package
org.gitlab4j.api
;
package
org.gitlab4j.api
;
import
java.util.Date
;
import
java.util.List
;
import
javax.ws.rs.core.Form
;
import
javax.ws.rs.core.Form
;
import
javax.ws.rs.core.MultivaluedHashMap
;
import
javax.ws.rs.core.MultivaluedHashMap
;
import
org.gitlab4j.api.utils.ISO8601
;
/**
/**
* This class extends the standard JAX-RS Form class to make it fluent.
* This class extends the standard JAX-RS Form class to make it fluent.
*/
*/
...
@@ -27,10 +32,75 @@ public class GitLabApiForm extends Form {
...
@@ -27,10 +32,75 @@ public class GitLabApiForm extends Form {
return
(
withParam
(
name
,
value
,
false
));
return
(
withParam
(
name
,
value
,
false
));
}
}
/**
* Fluent method for adding Date query and form parameters to a get() or post() call.
*
* @param name the name of the field/attribute to add
* @param date the value of the field/attribute to add
* @return this GitLabAPiForm instance
*/
public
GitLabApiForm
withParam
(
String
name
,
Date
date
)
throws
IllegalArgumentException
{
return
(
withParam
(
name
,
date
,
false
));
}
/**
* Fluent method for adding Date query and form parameters to a get() or post() call.
*
* @param name the name of the field/attribute to add
* @param date the value of the field/attribute to add
* @param required the field is required flag
* @return this GitLabAPiForm instance
* @throws IllegalArgumentException if a required parameter is null or empty
*/
public
GitLabApiForm
withParam
(
String
name
,
Date
date
,
boolean
required
)
throws
IllegalArgumentException
{
return
(
withParam
(
name
,
(
date
==
null
?
null
:
ISO8601
.
toString
(
date
)),
required
));
}
/**
* Fluent method for adding a List type query and form parameters to a get() or post() call.
*
* @param <T> the type contained by the List
* @param name the name of the field/attribute to add
* @param values a List containing the values of the field/attribute to add
* @return this GitLabAPiForm instance
*/
public
<
T
>
GitLabApiForm
withParam
(
String
name
,
List
<
T
>
values
)
{
return
(
withParam
(
name
,
values
,
false
));
}
/**
* Fluent method for adding a List type query and form parameters to a get() or post() call.
*
* @param <T> the type contained by the List
* @param name the name of the field/attribute to add
* @param values a List containing the values of the field/attribute to add
* @param required the field is required flag
* @return this GitLabAPiForm instance
* @throws IllegalArgumentException if a required parameter is null or empty
*/
public
<
T
>
GitLabApiForm
withParam
(
String
name
,
List
<
T
>
values
,
boolean
required
)
throws
IllegalArgumentException
{
if
(
values
==
null
||
values
.
isEmpty
())
{
if
(
required
)
{
throw
new
IllegalArgumentException
(
name
+
" cannot be empty or null"
);
}
return
(
this
);
}
for
(
T
value
:
values
)
{
if
(
value
!=
null
)
{
this
.
param
(
name
+
"[]"
,
value
.
toString
());
}
}
return
(
this
);
}
/**
/**
* Fluent method for adding query and form parameters to a get() or post() call.
* Fluent method for adding query and form parameters to a get() or post() call.
* If required is true and value is null, will throw an IllegalArgumentException.
* If required is true and value is null, will throw an IllegalArgumentException.
*
*
* @param name the name of the field/attribute to add
* @param name the name of the field/attribute to add
* @param value the value of the field/attribute to add
* @param value the value of the field/attribute to add
* @param required the field is required flag
* @param required the field is required flag
...
@@ -40,7 +110,6 @@ public class GitLabApiForm extends Form {
...
@@ -40,7 +110,6 @@ public class GitLabApiForm extends Form {
public
GitLabApiForm
withParam
(
String
name
,
Object
value
,
boolean
required
)
throws
IllegalArgumentException
{
public
GitLabApiForm
withParam
(
String
name
,
Object
value
,
boolean
required
)
throws
IllegalArgumentException
{
if
(
value
==
null
)
{
if
(
value
==
null
)
{
if
(
required
)
{
if
(
required
)
{
throw
new
IllegalArgumentException
(
name
+
" cannot be empty or null"
);
throw
new
IllegalArgumentException
(
name
+
" cannot be empty or null"
);
}
}
...
...
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