View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.demo.uif.form;
17  
18  import org.kuali.rice.core.api.util.type.KualiDecimal;
19  import org.springframework.web.multipart.MultipartFile;
20  
21  import java.io.Serializable;
22  import java.text.SimpleDateFormat;
23  import java.util.ArrayList;
24  import java.util.Arrays;
25  import java.util.Calendar;
26  import java.util.Date;
27  import java.util.HashMap;
28  import java.util.List;
29  import java.util.Map;
30  
31  /**
32   * For test view purposes only
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class UITestObject implements Serializable {
37      private static final long serialVersionUID = -7525378097732916411L;
38  
39      private String field1;
40      private String field2;
41      private String field3;
42      private String field4;
43      private String field5;
44      private String field6;
45      private String field7;
46      private String field8;
47  
48      private String travelAccountAttributeName;
49  
50      private String dollar1;
51      private String dollar2;
52      private String dollar3;
53      private String dollar4;
54      private String dollar5;
55      private String dollar6;
56      private String dollar7;
57      private String dollar8;
58  
59      private KualiDecimal feeAmount;
60  
61      private static int count = 0;
62      private Integer int1 = 1;
63      private Integer int2 = 2;
64      private Integer int3 = 3;
65  
66      private boolean bfield;
67      private boolean bfield2;
68  
69      private List<String> stringList = Arrays.asList("String1", "String2", "String3");
70  
71      private Date date1;
72      private String date1Str;
73  
74      static int skipCount2 = 0;
75      private Date date2;
76  
77      private MultipartFile fileUpload;
78  
79      // private String fileUploadName;
80  
81      private UITestObject innerObject;
82  
83      private Map<String, Object> remoteFieldValuesMap;
84  
85      private List<UITestObject> subList = new ArrayList<UITestObject>();
86  
87      public UITestObject() {
88          remoteFieldValuesMap = new HashMap<String, Object>();
89          remoteFieldValuesMap.put("remoteField1", "Apple");
90          remoteFieldValuesMap.put("remoteField2", "Banana");
91          remoteFieldValuesMap.put("remoteField3", true);
92          remoteFieldValuesMap.put("remoteField4", "Fruit");
93  
94          int1 = ++count;
95          int3 = int1 * int2;
96  
97          feeAmount = new KualiDecimal(int1);
98  
99          // populate date1 and date1Str
100         try {
101             Calendar cal = Calendar.getInstance();
102             cal.set(2010, 1, 1);
103             long offset = cal.getTime().getTime();
104             cal.set(2014, 1, 1);
105             long end = cal.getTime().getTime();
106             long diff = end - offset + 1;
107             date1 = new Date(offset + (long) (Math.random() * diff));
108             date1Str = new SimpleDateFormat("MM/dd/yyyy").format(date1);
109         } catch (Exception e) {
110             e.printStackTrace();
111         }
112 
113         // populate date2
114         skipCount2++;
115         // every fifth date leave blank
116         if (skipCount2 % 5 != 0 && date2 == null) {
117             try {
118                 Calendar cal = Calendar.getInstance();
119                 cal.set(2010, 1, 1);
120                 long offset = cal.getTime().getTime();
121                 cal.set(2014, 1, 1);
122                 long end = cal.getTime().getTime();
123                 long diff = end - offset + 1;
124                 date2 = new Date(offset + (long) (Math.random() * diff));
125             } catch (Exception e) {
126                 e.printStackTrace();
127             }
128         }
129     }
130 
131     public UITestObject(String field1, String field2, String field3, String field4) {
132         this();
133 
134         this.field1 = field1;
135         this.field2 = field2;
136         this.field3 = field3;
137         this.field4 = field4;
138 
139         this.dollar1 = setCurrency(field1);
140         this.dollar2 = setCurrency(field2);
141         this.dollar3 = setCurrency(field3);
142         this.dollar4 = setCurrency(field4);
143     }
144 
145     public UITestObject(String field1, String field2, String field3, String field4, String field5, String field6) {
146         this(field1, field2, field3, field4);
147 
148         this.field5 = field5;
149         this.field6 = field6;
150         this.dollar5 = setCurrency(field5);
151         this.dollar6 = setCurrency(field6);
152     }
153 
154     public UITestObject(String field1, String field2, String field3, String field4, String field5, String field6,
155             String field7, String field8) {
156         this(field1, field2, field3, field4, field5, field6);
157 
158         this.field7 = field7;
159         this.field8 = field8;
160         this.dollar7 = setCurrency(field7);
161         this.dollar8 = setCurrency(field8);
162     }
163 
164     public UITestObject(String field1, String field2, String field3, String field4, UITestObject innerObject) {
165         this(field1, field2, field3, field4);
166 
167         this.innerObject = innerObject;
168     }
169 
170     private boolean isInteger(String input) {
171         try {
172             Integer.parseInt(input);
173             return true;
174         }
175         catch (NumberFormatException e) {
176             return false;
177         }
178     }
179 
180     private String setCurrency(String field) {
181         if (field != null && field.length() > 0 && isInteger(field)) {
182             if (!field.contains("$")) {
183                 field = "$" + field ;
184             }
185             if (!field.contains(".00")) {
186                 field = field + ".00";
187             }
188         }
189         return field;
190     }
191 
192     private String unsetCurrency(String field){
193         field = field.replace("$","");
194         field = field.replace(".00","");
195         return field;
196     }
197 
198     public String getField1() {
199         return this.field1;
200     }
201 
202     public void setField1(String field1) {
203         this.field1 = field1;
204     }
205 
206     public String getField2() {
207         return this.field2;
208     }
209 
210     public void setField2(String field2) {
211         this.field2 = field2;
212     }
213 
214     public String getField3() {
215         return this.field3;
216     }
217 
218     public void setField3(String field3) {
219         this.field3 = field3;
220     }
221 
222     public String getField4() {
223         return this.field4;
224     }
225 
226     public void setField4(String field4) {
227         this.field4 = field4;
228     }
229 
230     public String getField5() {
231         return field5;
232     }
233 
234     public void setField5(String field5) {
235         this.field5 = field5;
236     }
237 
238     public String getField6() {
239         return field6;
240     }
241 
242     public void setField6(String field6) {
243         this.field6 = field6;
244     }
245 
246     public String getField7() {
247         return field7;
248     }
249 
250     public void setField7(String field7) {
251         this.field7 = field7;
252     }
253 
254     public String getField8() {
255         return field8;
256     }
257 
258     public void setField8(String field8) {
259         this.field8 = field8;
260     }
261 
262     public String getTravelAccountAttributeName() {
263         if (travelAccountAttributeName == null) {
264             return "number";
265         }
266         return travelAccountAttributeName;
267     }
268 
269     public void setTravelAccountAttributeName(String travelAccountAttributeName) {
270         this.travelAccountAttributeName = travelAccountAttributeName;
271     }
272 
273     public String getDollar1() {
274         return dollar1;
275     }
276 
277     public void setDollar1(String dollar1) {
278         this.field1 = unsetCurrency(dollar1);
279         this.dollar1 = setCurrency(dollar1);
280     }
281 
282     public String getDollar2() {
283         return dollar2;
284     }
285 
286     public void setDollar2(String dollar2) {
287         this.field2 = unsetCurrency(dollar2);
288         this.dollar2 = setCurrency(dollar2);
289     }
290 
291     public String getDollar3() {
292         return dollar3;
293     }
294 
295     public void setDollar3(String dollar3) {
296         this.field3 = unsetCurrency(dollar3);
297         this.dollar3 = setCurrency(dollar3);
298     }
299 
300     public String getDollar4() {
301         return dollar4;
302     }
303 
304     public void setDollar4(String dollar4) {
305         this.field4 = unsetCurrency(dollar4);
306         this.dollar4 = setCurrency(dollar4);
307     }
308 
309     public String getDollar5() {
310         return dollar5;
311     }
312 
313     public void setDollar5(String dollar5) {
314         this.field5 = unsetCurrency(dollar5);
315         this.dollar5 = setCurrency(dollar5);
316     }
317 
318     public String getDollar6() {
319         return dollar6;
320     }
321 
322     public void setDollar6(String dollar6) {
323         this.field6 = unsetCurrency(dollar6);
324         this.dollar6 = setCurrency(dollar6);
325     }
326 
327     public String getDollar7() {
328         return dollar7;
329     }
330 
331     public void setDollar7(String dollar7) {
332         this.field7 = unsetCurrency(dollar7);
333         this.dollar7 = setCurrency(dollar7);
334     }
335 
336     public String getDollar8() {
337         return dollar8;
338     }
339 
340     public void setDollar8(String dollar8) {
341         this.field8 = unsetCurrency(dollar8);
342         this.dollar8 = setCurrency(dollar8);
343     }
344 
345     public KualiDecimal getFeeAmount() {
346         return feeAmount;
347     }
348 
349     public void setFeeAmount(KualiDecimal feeAmount) {
350         this.feeAmount = feeAmount;
351     }
352 
353     public MultipartFile getFileUpload() {
354         return fileUpload;
355     }
356 
357     public void setFileUpload(MultipartFile fileUpload) {
358         this.fileUpload = fileUpload;
359         // this.fileUploadName = fileUpload.getOriginalFilename();
360     }
361 
362     //    public String getFileUploadName() {
363     //        return fileUploadName;
364     //    }
365     //
366     //    public void setFileUploadName(String fileUploadName) {
367     //        this.fileUploadName = fileUploadName;
368     //    }
369 
370     public List<UITestObject> getSubList() {
371         return subList;
372     }
373 
374     public void setSubList(List<UITestObject> subList) {
375         this.subList = subList;
376     }
377 
378     public Map<String, Object> getRemoteFieldValuesMap() {
379         return remoteFieldValuesMap;
380     }
381 
382     public void setRemoteFieldValuesMap(Map<String, Object> remoteFieldValuesMap) {
383         this.remoteFieldValuesMap = remoteFieldValuesMap;
384     }
385 
386     public boolean isBfield() {
387         return bfield;
388     }
389 
390     public void setBfield(boolean bfield) {
391         this.bfield = bfield;
392     }
393 
394     public boolean isBfield2() {
395         return bfield2;
396     }
397 
398     public void setBfield2(boolean bfield2) {
399         this.bfield2 = bfield2;
400     }
401 
402     @Override
403     public String toString() {
404         return "" + field1 + field2 + field3 + field4;
405     }
406 
407     public List<String> getStringList() {
408         return stringList;
409     }
410 
411     public void setStringList(List<String> stringList) {
412         this.stringList = stringList;
413     }
414 
415     public UITestObject getInnerObject() {
416         return innerObject;
417     }
418 
419     public void setInnerObject(UITestObject innerObject) {
420         this.innerObject = innerObject;
421     }
422 
423     public void setInputField1(String field) {
424         field1 = field;
425     }
426 
427     public String getInputField1() {
428         return field1;
429     }
430 
431     public void setInputField2(String field) {
432         field2 = field;
433     }
434 
435     public String getInputField2() {
436         return field2;
437     }
438 
439     public void setInputField3(String field) {
440         field3 = field;
441     }
442 
443     public String getInputField3() {
444         return field3;
445     }
446 
447     public void setInputField4(String field) {
448         field4 = field;
449     }
450 
451     public String getInputField4() {
452         return field4;
453     }
454 
455     public Integer getInt1() {
456         return int1;
457     }
458 
459     public void setInt1(Integer int1) {
460         this.int1 = int1;
461     }
462 
463     public Integer getInt2() {
464         return int2;
465     }
466 
467     public void setInt2(Integer int2) {
468         this.int2 = int2;
469     }
470 
471     public Integer getInt3() {
472         return int3;
473     }
474 
475     public void setInt3(Integer int3) {
476         this.int3 = int3;
477     }
478 
479     public Date getDate1() {
480         return date1;
481     }
482 
483     public void setDate1(Date date1) {
484         this.date1 = date1;
485     }
486 
487     public String getDate1Str() {
488         return date1Str;
489     }
490 
491     public void setDate1Str(String date1Str) {
492         this.date1Str = date1Str;
493     }
494 
495     public Date getDate2() {
496         return date2;
497     }
498 
499     public void setDate2(Date date2) {
500         this.date2 = date2;
501     }
502 
503     // add static method to be used in library
504     static public String getStaticData() {
505         return "test";
506     }
507 }
508