11package org .gitlab4j .api ;
22
3+ import java .util .Date ;
4+ import java .util .List ;
5+
36import javax .ws .rs .core .Form ;
47import javax .ws .rs .core .MultivaluedHashMap ;
58
9+ import org .gitlab4j .api .utils .ISO8601 ;
10+
611/**
712 * This class extends the standard JAX-RS Form class to make it fluent.
813 */
@@ -27,10 +32,75 @@ public GitLabApiForm withParam(String name, Object value) throws IllegalArgument
2732 return (withParam (name , value , false ));
2833 }
2934
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+
30100 /**
31101 * Fluent method for adding query and form parameters to a get() or post() call.
32102 * If required is true and value is null, will throw an IllegalArgumentException.
33- *
103+ *
34104 * @param name the name of the field/attribute to add
35105 * @param value the value of the field/attribute to add
36106 * @param required the field is required flag
@@ -40,7 +110,6 @@ public GitLabApiForm withParam(String name, Object value) throws IllegalArgument
40110 public GitLabApiForm withParam (String name , Object value , boolean required ) throws IllegalArgumentException {
41111
42112 if (value == null ) {
43-
44113 if (required ) {
45114 throw new IllegalArgumentException (name + " cannot be empty or null" );
46115 }
0 commit comments