1111import  org .gitlab4j .api .models .AccessLevel ;
1212import  org .gitlab4j .api .models .Variable ;
1313import  org .gitlab4j .models .GitLabForm ;
14+ import  org .gitlab4j .models .GitLabFormValue ;
1415import  org .gitlab4j .models .utils .ISO8601 ;
1516
1617/** 
@@ -35,13 +36,33 @@ public GitLabApiForm(MultivaluedHashMap<String, String> map) {
3536    public  GitLabApiForm (int  page , int  perPage ) {
3637        super ();
3738        withParam (AbstractApi .PAGE_PARAM , page );
38-         withParam (AbstractApi .PER_PAGE_PARAM , ( Integer )  perPage );
39+         withParam (AbstractApi .PER_PAGE_PARAM , perPage );
3940    }
4041
4142    public  GitLabApiForm (GitLabForm  form ) {
4243        super ();
43-         for  (Entry <String , String > e  : form .getFormValues ().entrySet ()) {
44-             this .param (e .getKey (), e .getValue ());
44+         for  (Entry <String , GitLabFormValue > e  : form .getFormValues ().entrySet ()) {
45+             GitLabFormValue  value  = e .getValue ();
46+             switch  (value .getType ()) {
47+                 case  ACCESS_LEVEL :
48+                     withParam (e .getKey (), (AccessLevel ) value .getValue (), value .isRequired ());
49+                     break ;
50+                 case  DATE :
51+                     withParam (e .getKey (), (Date ) value .getValue (), value .isRequired ());
52+                     break ;
53+                 case  LIST :
54+                     withParam (e .getKey (), (List <?>) value .getValue (), value .isRequired ());
55+                     break ;
56+                 case  MAP :
57+                     @ SuppressWarnings ("unchecked" )
58+                     Map <String , ?> mapValue  = (Map <String , ?>) value .getValue ();
59+                     withParam (e .getKey (), mapValue , value .isRequired ());
60+                     break ;
61+                 case  OBJECT :
62+                 default :
63+                     withParam (e .getKey (), value .getValue (), value .isRequired ());
64+                     break ;
65+             }
4566        }
4667    }
4768
@@ -52,8 +73,8 @@ public GitLabApiForm(GitLabForm form) {
5273     * @param value the value of the field/attribute to add 
5374     * @return this GitLabAPiForm instance 
5475     */ 
55-     public  GitLabApiForm  withParam (String  name , Object  value ) throws   IllegalArgumentException   {
56-         return  ( withParam (name , value , false ) );
76+     public  GitLabApiForm  withParam (String  name , Object  value ) {
77+         return  withParam (name , value , false );
5778    }
5879
5980    /** 
@@ -63,8 +84,8 @@ public GitLabApiForm withParam(String name, Object value) throws IllegalArgument
6384     * @param date the value of the field/attribute to add 
6485     * @return this GitLabAPiForm instance 
6586     */ 
66-     public  GitLabApiForm  withParam (String  name , Date  date ) throws   IllegalArgumentException   {
67-         return  ( withParam (name , date , false ) );
87+     public  GitLabApiForm  withParam (String  name , Date  date ) {
88+         return  withParam (name , date , false );
6889    }
6990
7091    /** 
@@ -76,8 +97,8 @@ public GitLabApiForm withParam(String name, Date date) throws IllegalArgumentExc
7697     * @return this GitLabAPiForm instance 
7798     * @throws IllegalArgumentException if a required parameter is null or empty 
7899     */ 
79-     public  GitLabApiForm  withParam (String  name , Date  date , boolean  required ) throws   IllegalArgumentException   {
80-         return  ( withParam (name , ( date  == null  ? null  : ISO8601 .toString (date )) , required ) );
100+     public  GitLabApiForm  withParam (String  name , Date  date , boolean  required ) {
101+         return  withParam (name , date  == null  ? null  : ISO8601 .toString (date ), required );
81102    }
82103
83104    /** 
@@ -87,8 +108,8 @@ public GitLabApiForm withParam(String name, Date date, boolean required) throws
87108     * @param level the value of the field/attribute to add 
88109     * @return this GitLabAPiForm instance 
89110     */ 
90-     public  GitLabApiForm  withParam (String  name , AccessLevel  level ) throws   IllegalArgumentException   {
91-         return  ( withParam (name , level , false ) );
111+     public  GitLabApiForm  withParam (String  name , AccessLevel  level ) {
112+         return  withParam (name , level , false );
92113    }
93114
94115    /** 
@@ -100,49 +121,47 @@ public GitLabApiForm withParam(String name, AccessLevel level) throws IllegalArg
100121     * @return this GitLabAPiForm instance 
101122     * @throws IllegalArgumentException if a required parameter is null or empty 
102123     */ 
103-     public  GitLabApiForm  withParam (String  name , AccessLevel  level , boolean  required ) throws   IllegalArgumentException   {
104-         return  ( withParam (name , ( level  == null  ? null  : level .toValue ()) , required ) );
124+     public  GitLabApiForm  withParam (String  name , AccessLevel  level , boolean  required ) {
125+         return  withParam (name , level  == null  ? null  : level .toValue (), required );
105126    }
106127
107128    /** 
108129     * Fluent method for adding a List type query and form parameters to a get() or post() call. 
109130     * 
110-      * @param <T> the type contained by the List 
111131     * @param name the name of the field/attribute to add 
112132     * @param values a List containing the values of the field/attribute to add 
113133     * @return this GitLabAPiForm instance 
114134     */ 
115-     public  < T >  GitLabApiForm  withParam (String  name , List <T > values ) {
116-         return  ( withParam (name , values , false ) );
135+     public  GitLabApiForm  withParam (String  name , List <? > values ) {
136+         return  withParam (name , values , false );
117137    }
118138
119139    /** 
120140     * Fluent method for adding a List type query and form parameters to a get() or post() call. 
121141     * 
122-      * @param <T> the type contained by the List 
123142     * @param name the name of the field/attribute to add 
124143     * @param values a List containing the values of the field/attribute to add 
125144     * @param required the field is required flag 
126145     * @return this GitLabAPiForm instance 
127146     * @throws IllegalArgumentException if a required parameter is null or empty 
128147     */ 
129-     public  < T >  GitLabApiForm  withParam (String  name , List <T > values , boolean  required )  throws   IllegalArgumentException  {
148+     public  GitLabApiForm  withParam (String  name , List <? > values , boolean  required ) {
130149
131150        if  (values  == null  || values .isEmpty ()) {
132151            if  (required ) {
133152                throw  new  IllegalArgumentException (name  + " cannot be empty or null" );
134153            }
135154
136-             return  ( this ) ;
155+             return  this ;
137156        }
138157
139-         for  (T  value  : values ) {
158+         for  (Object  value  : values ) {
140159            if  (value  != null ) {
141160                this .param (name  + "[]" , value .toString ());
142161            }
143162        }
144163
145-         return  ( this ) ;
164+         return  this ;
146165    }
147166
148167    /** 
@@ -154,15 +173,14 @@ public <T> GitLabApiForm withParam(String name, List<T> values, boolean required
154173     * @return this GitLabAPiForm instance 
155174     * @throws IllegalArgumentException if a required parameter is null or empty 
156175     */ 
157-     public  GitLabApiForm  withParam (String  name , Map <String , ?> variables , boolean  required )
158-             throws  IllegalArgumentException  {
176+     public  GitLabApiForm  withParam (String  name , Map <String , ?> variables , boolean  required ) {
159177
160178        if  (variables  == null  || variables .isEmpty ()) {
161179            if  (required ) {
162180                throw  new  IllegalArgumentException (name  + " cannot be empty or null" );
163181            }
164182
165-             return  ( this ) ;
183+             return  this ;
166184        }
167185
168186        for  (Entry <String , ?> variable  : variables .entrySet ()) {
@@ -172,7 +190,7 @@ public GitLabApiForm withParam(String name, Map<String, ?> variables, boolean re
172190            }
173191        }
174192
175-         return  ( this ) ;
193+         return  this ;
176194    }
177195
178196    /** 
@@ -185,14 +203,14 @@ public GitLabApiForm withParam(String name, Map<String, ?> variables, boolean re
185203     * @return this GitLabAPiForm instance 
186204     * @throws IllegalArgumentException if a required parameter is null or empty 
187205     */ 
188-     public  GitLabApiForm  withParam (String  name , Object  value , boolean  required ) throws   IllegalArgumentException   {
206+     public  GitLabApiForm  withParam (String  name , Object  value , boolean  required ) {
189207
190208        if  (value  == null ) {
191209            if  (required ) {
192210                throw  new  IllegalArgumentException (name  + " cannot be empty or null" );
193211            }
194212
195-             return  ( this ) ;
213+             return  this ;
196214        }
197215
198216        String  stringValue  = value .toString ();
@@ -201,7 +219,7 @@ public GitLabApiForm withParam(String name, Object value, boolean required) thro
201219        }
202220
203221        this .param (name .trim (), stringValue );
204-         return  ( this ) ;
222+         return  this ;
205223    }
206224
207225    /** 
@@ -213,7 +231,7 @@ public GitLabApiForm withParam(String name, Object value, boolean required) thro
213231    public  GitLabApiForm  withParam (List <Variable > variables ) {
214232
215233        if  (variables  == null  || variables .isEmpty ()) {
216-             return  ( this ) ;
234+             return  this ;
217235        }
218236
219237        variables .forEach (v  -> {
@@ -223,6 +241,6 @@ public GitLabApiForm withParam(List<Variable> variables) {
223241            }
224242        });
225243
226-         return  ( this ) ;
244+         return  this ;
227245    }
228246}
0 commit comments