001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.demo.uif.form; 017 018import org.kuali.rice.core.api.util.type.KualiDecimal; 019import org.springframework.web.multipart.MultipartFile; 020 021import java.io.Serializable; 022import java.text.SimpleDateFormat; 023import java.util.ArrayList; 024import java.util.Arrays; 025import java.util.Calendar; 026import java.util.Date; 027import java.util.HashMap; 028import java.util.List; 029import java.util.Map; 030 031/** 032 * For test view purposes only 033 * 034 * @author Kuali Rice Team (rice.collab@kuali.org) 035 */ 036public class UITestObject implements Serializable { 037 private static final long serialVersionUID = -7525378097732916411L; 038 039 private String field1; 040 private String field2; 041 private String field3; 042 private String field4; 043 private String field5; 044 private String field6; 045 private String field7; 046 private String field8; 047 048 private String travelAccountAttributeName; 049 050 private String dollar1; 051 private String dollar2; 052 private String dollar3; 053 private String dollar4; 054 private String dollar5; 055 private String dollar6; 056 private String dollar7; 057 private String dollar8; 058 059 private KualiDecimal feeAmount; 060 061 private static int count = 0; 062 private Integer int1 = 1; 063 private Integer int2 = 2; 064 private Integer int3 = 3; 065 066 private boolean bfield; 067 private boolean bfield2; 068 069 private List<String> stringList = Arrays.asList("String1", "String2", "String3"); 070 071 private Date date1; 072 private String date1Str; 073 074 static int skipCount2 = 0; 075 private Date date2; 076 077 private MultipartFile fileUpload; 078 079 // private String fileUploadName; 080 081 private UITestObject innerObject; 082 083 private Map<String, Object> remoteFieldValuesMap; 084 085 private List<UITestObject> subList = new ArrayList<UITestObject>(); 086 087 public UITestObject() { 088 remoteFieldValuesMap = new HashMap<String, Object>(); 089 remoteFieldValuesMap.put("remoteField1", "Apple"); 090 remoteFieldValuesMap.put("remoteField2", "Banana"); 091 remoteFieldValuesMap.put("remoteField3", true); 092 remoteFieldValuesMap.put("remoteField4", "Fruit"); 093 094 int1 = ++count; 095 int3 = int1 * int2; 096 097 feeAmount = new KualiDecimal(int1); 098 099 // 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