| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krad.datadictionary; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.ClassUtils; |
| 19 | |
import org.apache.commons.lang.StringUtils; |
| 20 | |
import org.apache.log4j.Logger; |
| 21 | |
import org.kuali.rice.core.api.uif.DataType; |
| 22 | |
import org.kuali.rice.core.api.util.ClassLoaderUtils; |
| 23 | |
import org.kuali.rice.core.web.format.Formatter; |
| 24 | |
import org.kuali.rice.krad.datadictionary.control.ControlDefinition; |
| 25 | |
import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException; |
| 26 | |
import org.kuali.rice.krad.datadictionary.exception.ClassValidationException; |
| 27 | |
import org.kuali.rice.krad.datadictionary.validation.ValidationPattern; |
| 28 | |
import org.kuali.rice.krad.datadictionary.validation.capability.CaseConstrainable; |
| 29 | |
import org.kuali.rice.krad.datadictionary.validation.capability.Formatable; |
| 30 | |
import org.kuali.rice.krad.datadictionary.validation.capability.HierarchicallyConstrainable; |
| 31 | |
import org.kuali.rice.krad.datadictionary.validation.capability.LengthConstrainable; |
| 32 | |
import org.kuali.rice.krad.datadictionary.validation.capability.MustOccurConstrainable; |
| 33 | |
import org.kuali.rice.krad.datadictionary.validation.capability.PrerequisiteConstrainable; |
| 34 | |
import org.kuali.rice.krad.datadictionary.validation.capability.RangeConstrainable; |
| 35 | |
import org.kuali.rice.krad.datadictionary.validation.capability.ValidCharactersConstrainable; |
| 36 | |
import org.kuali.rice.krad.datadictionary.validation.constraint.CaseConstraint; |
| 37 | |
import org.kuali.rice.krad.datadictionary.validation.constraint.LookupConstraint; |
| 38 | |
import org.kuali.rice.krad.datadictionary.validation.constraint.MustOccurConstraint; |
| 39 | |
import org.kuali.rice.krad.datadictionary.validation.constraint.PrerequisiteConstraint; |
| 40 | |
import org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersConstraint; |
| 41 | |
import org.kuali.rice.krad.keyvalues.KeyValuesFinder; |
| 42 | |
import org.kuali.rice.krad.uif.control.Control; |
| 43 | |
import org.kuali.rice.krad.util.ObjectUtils; |
| 44 | |
|
| 45 | |
import java.util.List; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
public class AttributeDefinition extends AttributeDefinitionBase implements CaseConstrainable, PrerequisiteConstrainable, Formatable, HierarchicallyConstrainable, MustOccurConstrainable, LengthConstrainable, RangeConstrainable, ValidCharactersConstrainable { |
| 55 | |
private static final long serialVersionUID = -2490613377818442742L; |
| 56 | |
|
| 57 | 0 | protected Boolean forceUppercase = Boolean.FALSE; |
| 58 | |
|
| 59 | |
protected DataType dataType; |
| 60 | |
|
| 61 | |
protected Integer minLength; |
| 62 | |
protected Integer maxLength; |
| 63 | |
protected Boolean unique; |
| 64 | |
|
| 65 | |
protected String exclusiveMin; |
| 66 | |
protected String inclusiveMax; |
| 67 | |
|
| 68 | |
@Deprecated |
| 69 | |
protected ValidationPattern validationPattern; |
| 70 | |
|
| 71 | |
protected ControlDefinition control; |
| 72 | |
|
| 73 | |
|
| 74 | |
protected Control controlField; |
| 75 | |
|
| 76 | |
protected String formatterClass; |
| 77 | |
|
| 78 | |
protected AttributeSecurity attributeSecurity; |
| 79 | |
|
| 80 | |
protected Boolean dynamic; |
| 81 | |
|
| 82 | |
|
| 83 | |
protected String customValidatorClass; |
| 84 | |
protected ValidCharactersConstraint validCharactersConstraint; |
| 85 | |
protected CaseConstraint caseConstraint; |
| 86 | |
protected List<PrerequisiteConstraint> dependencyConstraints; |
| 87 | |
protected List<MustOccurConstraint> mustOccurConstraints; |
| 88 | |
protected LookupConstraint lookupDefinition; |
| 89 | |
|
| 90 | |
protected String lookupContextPath; |
| 91 | |
|
| 92 | |
|
| 93 | |
protected String childEntryName; |
| 94 | |
|
| 95 | |
private KeyValuesFinder optionsFinder; |
| 96 | |
|
| 97 | |
protected String alternateDisplayAttributeName; |
| 98 | |
protected String additionalDisplayAttributeName; |
| 99 | |
|
| 100 | |
|
| 101 | 0 | public AttributeDefinition() { |
| 102 | |
|
| 103 | 0 | } |
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
public void setForceUppercase(Boolean forceUppercase) { |
| 110 | 0 | this.forceUppercase = forceUppercase; |
| 111 | 0 | } |
| 112 | |
|
| 113 | |
public Boolean getForceUppercase() { |
| 114 | 0 | return this.forceUppercase; |
| 115 | |
} |
| 116 | |
|
| 117 | |
@Override |
| 118 | |
public Integer getMaxLength() { |
| 119 | 0 | return maxLength; |
| 120 | |
} |
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
public void setMaxLength(Integer maxLength) { |
| 127 | 0 | this.maxLength = maxLength; |
| 128 | 0 | } |
| 129 | |
|
| 130 | |
@Override |
| 131 | |
public String getExclusiveMin() { |
| 132 | 0 | return exclusiveMin; |
| 133 | |
} |
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
public void setExclusiveMin(String exclusiveMin) { |
| 141 | 0 | this.exclusiveMin = exclusiveMin; |
| 142 | 0 | } |
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
@Override |
| 152 | |
public String getInclusiveMax() { |
| 153 | 0 | return inclusiveMax; |
| 154 | |
} |
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
public void setInclusiveMax(String inclusiveMax) { |
| 164 | 0 | this.inclusiveMax = inclusiveMax; |
| 165 | 0 | } |
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
public boolean hasValidationPattern() { |
| 171 | 0 | return (validationPattern != null); |
| 172 | |
} |
| 173 | |
|
| 174 | |
public ValidationPattern getValidationPattern() { |
| 175 | 0 | return this.validationPattern; |
| 176 | |
} |
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
public void setValidationPattern(ValidationPattern validationPattern) { |
| 216 | 0 | this.validationPattern = validationPattern; |
| 217 | |
|
| 218 | |
|
| 219 | 0 | } |
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
public ControlDefinition getControl() { |
| 226 | 0 | return control; |
| 227 | |
} |
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | |
public void setControl(ControlDefinition control) { |
| 270 | 0 | if (control == null) { |
| 271 | 0 | throw new IllegalArgumentException("invalid (null) control"); |
| 272 | |
} |
| 273 | 0 | this.control = control; |
| 274 | 0 | } |
| 275 | |
|
| 276 | |
public boolean hasFormatterClass() { |
| 277 | 0 | return (formatterClass != null); |
| 278 | |
} |
| 279 | |
|
| 280 | |
@Override |
| 281 | |
public String getFormatterClass() { |
| 282 | 0 | return formatterClass; |
| 283 | |
} |
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | |
public void setFormatterClass(String formatterClass) { |
| 293 | 0 | if (formatterClass == null) { |
| 294 | 0 | throw new IllegalArgumentException("invalid (null) formatterClass"); |
| 295 | |
} |
| 296 | 0 | this.formatterClass = formatterClass; |
| 297 | 0 | } |
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
@Override |
| 306 | |
public void completeValidation(Class<?> rootObjectClass, Class<?> otherObjectClass) { |
| 307 | |
try { |
| 308 | 0 | if (!DataDictionary.isPropertyOf(rootObjectClass, getName())) { |
| 309 | 0 | throw new AttributeValidationException("property '" + getName() + "' is not a property of class '" |
| 310 | |
+ rootObjectClass.getName() + "' (" + "" + ")"); |
| 311 | |
} |
| 312 | |
|
| 313 | |
|
| 314 | 0 | if (getControl() == null && getControlField() == null) { |
| 315 | 0 | throw new AttributeValidationException("property '" + getName() + "' in class '" |
| 316 | |
+ rootObjectClass.getName() + " does not have a control defined"); |
| 317 | |
} |
| 318 | |
|
| 319 | 0 | if(getControl() != null) { |
| 320 | 0 | getControl().completeValidation(rootObjectClass, otherObjectClass); |
| 321 | |
} |
| 322 | |
|
| 323 | 0 | if (attributeSecurity != null) { |
| 324 | 0 | attributeSecurity.completeValidation(rootObjectClass, otherObjectClass); |
| 325 | |
} |
| 326 | |
|
| 327 | 0 | if (validationPattern != null) { |
| 328 | 0 | validationPattern.completeValidation(); |
| 329 | |
} |
| 330 | |
|
| 331 | 0 | if (formatterClass != null) { |
| 332 | |
try { |
| 333 | 0 | Class formatterClassObject = ClassUtils.getClass(ClassLoaderUtils.getDefaultClassLoader(), |
| 334 | |
getFormatterClass()); |
| 335 | 0 | if (!Formatter.class.isAssignableFrom(formatterClassObject)) { |
| 336 | 0 | throw new ClassValidationException("formatterClass is not a valid instance of " |
| 337 | |
+ Formatter.class.getName() + " instead was: " + formatterClassObject.getName()); |
| 338 | |
} |
| 339 | |
} |
| 340 | 0 | catch (ClassNotFoundException e) { |
| 341 | 0 | throw new ClassValidationException("formatterClass could not be found: " + getFormatterClass(), e); |
| 342 | 0 | } |
| 343 | |
} |
| 344 | |
} |
| 345 | 0 | catch (RuntimeException ex) { |
| 346 | 0 | Logger.getLogger(getClass()).error( |
| 347 | |
"Unable to validate attribute " + rootObjectClass + "." + getName() + ": " + ex.getMessage(), ex); |
| 348 | 0 | throw ex; |
| 349 | 0 | } |
| 350 | 0 | } |
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | |
@Override |
| 356 | |
public String toString() { |
| 357 | 0 | return "AttributeDefinition for attribute " + getName(); |
| 358 | |
} |
| 359 | |
|
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
public AttributeSecurity getAttributeSecurity() { |
| 364 | 0 | return this.attributeSecurity; |
| 365 | |
} |
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | |
|
| 371 | |
public void setAttributeSecurity(AttributeSecurity attributeSecurity) { |
| 372 | 0 | this.attributeSecurity = attributeSecurity; |
| 373 | 0 | } |
| 374 | |
|
| 375 | |
public boolean hasAttributeSecurity() { |
| 376 | 0 | return (attributeSecurity != null); |
| 377 | |
} |
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
|
| 382 | |
|
| 383 | |
|
| 384 | |
@Override |
| 385 | |
public void afterPropertiesSet() throws Exception { |
| 386 | 0 | if (StringUtils.isEmpty(name)) { |
| 387 | 0 | throw new RuntimeException("blank name for bean: " + id); |
| 388 | |
} |
| 389 | 0 | } |
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
public Boolean getUnique() { |
| 395 | 0 | return this.unique; |
| 396 | |
} |
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
|
| 402 | |
public void setUnique(Boolean unique) { |
| 403 | 0 | this.unique = unique; |
| 404 | 0 | } |
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | |
|
| 412 | |
|
| 413 | |
public Control getControlField() { |
| 414 | 0 | return this.controlField; |
| 415 | |
} |
| 416 | |
|
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
|
| 422 | |
public void setControlField(Control controlField) { |
| 423 | 0 | this.controlField = controlField; |
| 424 | 0 | } |
| 425 | |
|
| 426 | |
|
| 427 | |
|
| 428 | |
|
| 429 | |
public Integer getMinLength() { |
| 430 | 0 | return this.minLength; |
| 431 | |
} |
| 432 | |
|
| 433 | |
|
| 434 | |
|
| 435 | |
|
| 436 | |
public void setMinLength(Integer minLength) { |
| 437 | 0 | this.minLength = minLength; |
| 438 | 0 | } |
| 439 | |
|
| 440 | |
|
| 441 | |
|
| 442 | |
|
| 443 | |
@Override |
| 444 | |
public DataType getDataType() { |
| 445 | 0 | return this.dataType; |
| 446 | |
} |
| 447 | |
|
| 448 | |
|
| 449 | |
|
| 450 | |
|
| 451 | |
public void setDataType(DataType dataType) { |
| 452 | 0 | this.dataType = dataType; |
| 453 | 0 | } |
| 454 | |
|
| 455 | |
public void setDataType(String dataType) { |
| 456 | 0 | this.dataType = DataType.valueOf(dataType); |
| 457 | 0 | } |
| 458 | |
|
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
public String getCustomValidatorClass() { |
| 463 | 0 | return this.customValidatorClass; |
| 464 | |
} |
| 465 | |
|
| 466 | |
|
| 467 | |
|
| 468 | |
|
| 469 | |
public void setCustomValidatorClass(String customValidatorClass) { |
| 470 | 0 | this.customValidatorClass = customValidatorClass; |
| 471 | 0 | } |
| 472 | |
|
| 473 | |
|
| 474 | |
|
| 475 | |
|
| 476 | |
@Override |
| 477 | |
public ValidCharactersConstraint getValidCharactersConstraint() { |
| 478 | 0 | return this.validCharactersConstraint; |
| 479 | |
} |
| 480 | |
|
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
public void setValidCharactersConstraint(ValidCharactersConstraint validCharactersConstraint) { |
| 485 | 0 | this.validCharactersConstraint = validCharactersConstraint; |
| 486 | 0 | } |
| 487 | |
|
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | |
@Override |
| 492 | |
public CaseConstraint getCaseConstraint() { |
| 493 | 0 | return this.caseConstraint; |
| 494 | |
} |
| 495 | |
|
| 496 | |
|
| 497 | |
|
| 498 | |
|
| 499 | |
public void setCaseConstraint(CaseConstraint caseConstraint) { |
| 500 | 0 | this.caseConstraint = caseConstraint; |
| 501 | 0 | } |
| 502 | |
|
| 503 | |
|
| 504 | |
|
| 505 | |
|
| 506 | |
@Override |
| 507 | |
public List<PrerequisiteConstraint> getPrerequisiteConstraints() { |
| 508 | 0 | return this.dependencyConstraints; |
| 509 | |
} |
| 510 | |
|
| 511 | |
|
| 512 | |
|
| 513 | |
|
| 514 | |
public void setPrerequisiteConstraints(List<PrerequisiteConstraint> dependencyConstraints) { |
| 515 | 0 | this.dependencyConstraints = dependencyConstraints; |
| 516 | 0 | } |
| 517 | |
|
| 518 | |
|
| 519 | |
|
| 520 | |
|
| 521 | |
@Override |
| 522 | |
public List<MustOccurConstraint> getMustOccurConstraints() { |
| 523 | 0 | return this.mustOccurConstraints; |
| 524 | |
} |
| 525 | |
|
| 526 | |
|
| 527 | |
|
| 528 | |
|
| 529 | |
public void setMustOccurConstraints(List<MustOccurConstraint> mustOccurConstraints) { |
| 530 | 0 | this.mustOccurConstraints = mustOccurConstraints; |
| 531 | 0 | } |
| 532 | |
|
| 533 | |
|
| 534 | |
|
| 535 | |
|
| 536 | |
public LookupConstraint getLookupDefinition() { |
| 537 | 0 | return this.lookupDefinition; |
| 538 | |
} |
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
public void setLookupDefinition(LookupConstraint lookupDefinition) { |
| 544 | 0 | this.lookupDefinition = lookupDefinition; |
| 545 | 0 | } |
| 546 | |
|
| 547 | |
|
| 548 | |
|
| 549 | |
|
| 550 | |
public String getLookupContextPath() { |
| 551 | 0 | return this.lookupContextPath; |
| 552 | |
} |
| 553 | |
|
| 554 | |
|
| 555 | |
|
| 556 | |
|
| 557 | |
public void setLookupContextPath(String lookupContextPath) { |
| 558 | 0 | this.lookupContextPath = lookupContextPath; |
| 559 | 0 | } |
| 560 | |
|
| 561 | |
|
| 562 | |
|
| 563 | |
|
| 564 | |
public String getChildEntryName() { |
| 565 | 0 | return this.childEntryName; |
| 566 | |
} |
| 567 | |
|
| 568 | |
|
| 569 | |
|
| 570 | |
|
| 571 | |
public void setChildEntryName(String childEntryName) { |
| 572 | 0 | this.childEntryName = childEntryName; |
| 573 | 0 | } |
| 574 | |
|
| 575 | |
|
| 576 | |
|
| 577 | |
|
| 578 | |
|
| 579 | |
|
| 580 | |
|
| 581 | |
|
| 582 | |
|
| 583 | |
|
| 584 | |
|
| 585 | |
public KeyValuesFinder getOptionsFinder() { |
| 586 | 0 | return this.optionsFinder; |
| 587 | |
} |
| 588 | |
|
| 589 | |
|
| 590 | |
|
| 591 | |
|
| 592 | |
|
| 593 | |
|
| 594 | |
public void setOptionsFinder(KeyValuesFinder optionsFinder) { |
| 595 | 0 | this.optionsFinder = optionsFinder; |
| 596 | 0 | } |
| 597 | |
|
| 598 | |
|
| 599 | |
|
| 600 | |
|
| 601 | |
|
| 602 | |
|
| 603 | |
|
| 604 | |
public void setOptionsFinderClass(Class<? extends KeyValuesFinder> optionsFinderClass) { |
| 605 | 0 | this.optionsFinder = ObjectUtils.newInstance(optionsFinderClass); |
| 606 | 0 | } |
| 607 | |
|
| 608 | |
public void setAdditionalDisplayAttributeName(String additionalDisplayAttributeName) { |
| 609 | 0 | this.additionalDisplayAttributeName = additionalDisplayAttributeName; |
| 610 | 0 | } |
| 611 | |
|
| 612 | |
public String getAdditionalDisplayAttributeName() { |
| 613 | 0 | return this.additionalDisplayAttributeName; |
| 614 | |
} |
| 615 | |
|
| 616 | |
public void setAlternateDisplayAttributeName(String alternateDisplayAttributeName) { |
| 617 | 0 | this.alternateDisplayAttributeName = alternateDisplayAttributeName; |
| 618 | 0 | } |
| 619 | |
|
| 620 | |
public String getAlternateDisplayAttributeName() { |
| 621 | 0 | return this.alternateDisplayAttributeName; |
| 622 | |
} |
| 623 | |
|
| 624 | |
} |