1
1
package org .gitlab4j .api ;
2
2
3
+ import java .util .Date ;
4
+ import java .util .List ;
5
+
3
6
import javax .ws .rs .core .Form ;
4
7
import javax .ws .rs .core .MultivaluedHashMap ;
5
8
9
+ import org .gitlab4j .api .utils .ISO8601 ;
10
+
6
11
/**
7
12
* This class extends the standard JAX-RS Form class to make it fluent.
8
13
*/
@@ -27,10 +32,75 @@ public GitLabApiForm withParam(String name, Object value) throws IllegalArgument
27
32
return (withParam (name , value , false ));
28
33
}
29
34
35
+ /**
36
+ * Fluent method for adding Date query and form parameters to a get() or post() call.
37
+ *
38
+ * @param name the name of the field/attribute to add
39
+ * @param date the value of the field/attribute to add
40
+ * @return this GitLabAPiForm instance
41
+ */
42
+ public GitLabApiForm withParam (String name , Date date ) throws IllegalArgumentException {
43
+ return (withParam (name , date , false ));
44
+ }
45
+
46
+ /**
47
+ * Fluent method for adding Date query and form parameters to a get() or post() call.
48
+ *
49
+ * @param name the name of the field/attribute to add
50
+ * @param date the value of the field/attribute to add
51
+ * @param required the field is required flag
52
+ * @return this GitLabAPiForm instance
53
+ * @throws IllegalArgumentException if a required parameter is null or empty
54
+ */
55
+ public GitLabApiForm withParam (String name , Date date , boolean required ) throws IllegalArgumentException {
56
+ return (withParam (name , (date == null ? null : ISO8601 .toString (date )), required ));
57
+ }
58
+
59
+ /**
60
+ * Fluent method for adding a List type query and form parameters to a get() or post() call.
61
+ *
62
+ * @param <T> the type contained by the List
63
+ * @param name the name of the field/attribute to add
64
+ * @param values a List containing the values of the field/attribute to add
65
+ * @return this GitLabAPiForm instance
66
+ */
67
+ public <T > GitLabApiForm withParam (String name , List <T > values ) {
68
+ return (withParam (name , values , false ));
69
+ }
70
+
71
+ /**
72
+ * Fluent method for adding a List type query and form parameters to a get() or post() call.
73
+ *
74
+ * @param <T> the type contained by the List
75
+ * @param name the name of the field/attribute to add
76
+ * @param values a List containing the values of the field/attribute to add
77
+ * @param required the field is required flag
78
+ * @return this GitLabAPiForm instance
79
+ * @throws IllegalArgumentException if a required parameter is null or empty
80
+ */
81
+ public <T > GitLabApiForm withParam (String name , List <T > values , boolean required ) throws IllegalArgumentException {
82
+
83
+ if (values == null || values .isEmpty ()) {
84
+ if (required ) {
85
+ throw new IllegalArgumentException (name + " cannot be empty or null" );
86
+ }
87
+
88
+ return (this );
89
+ }
90
+
91
+ for (T value : values ) {
92
+ if (value != null ) {
93
+ this .param (name + "[]" , value .toString ());
94
+ }
95
+ }
96
+
97
+ return (this );
98
+ }
99
+
30
100
/**
31
101
* Fluent method for adding query and form parameters to a get() or post() call.
32
102
* If required is true and value is null, will throw an IllegalArgumentException.
33
- *
103
+ *
34
104
* @param name the name of the field/attribute to add
35
105
* @param value the value of the field/attribute to add
36
106
* @param required the field is required flag
@@ -40,7 +110,6 @@ public GitLabApiForm withParam(String name, Object value) throws IllegalArgument
40
110
public GitLabApiForm withParam (String name , Object value , boolean required ) throws IllegalArgumentException {
41
111
42
112
if (value == null ) {
43
-
44
113
if (required ) {
45
114
throw new IllegalArgumentException (name + " cannot be empty or null" );
46
115
}
0 commit comments