1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kns.datadictionary;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;
21 import org.kuali.rice.kns.datadictionary.exception.ClassValidationException;
22 import org.kuali.rice.kns.datadictionary.mask.Mask;
23 import org.kuali.rice.kns.lookup.valueFinder.ValueFinder;
24 import org.kuali.rice.kns.service.BusinessObjectMetaDataService;
25 import org.kuali.rice.kns.service.KNSServiceLocator;
26
27
28
29
30
31
32 public class FieldDefinition extends DataDictionaryDefinitionBase implements FieldDefinitionI {
33 private static final long serialVersionUID = -3426603523049661524L;
34
35 protected String attributeName;
36 protected boolean required = false;
37 protected boolean forceInquiry = false;
38 protected boolean noInquiry = false;
39 protected boolean noDirectInquiry = false;
40 protected boolean forceLookup = false;
41 protected boolean noLookup = false;
42 protected boolean useShortLabel = false;
43 protected String defaultValue;
44 protected Class<? extends ValueFinder> defaultValueFinderClass;
45 protected String quickfinderParameterString;
46 protected Class<? extends ValueFinder> quickfinderParameterStringBuilderClass;
47
48 protected Integer maxLength = null;
49
50 protected String displayEditMode;
51 protected Mask displayMask;
52
53 protected boolean hidden = false;
54 protected boolean readOnly = false;
55
56 protected boolean treatWildcardsAndOperatorsAsLiteral = false;
57
58 protected String alternateDisplayAttributeName;
59 protected String additionalDisplayAttributeName;
60
61 protected boolean triggerOnChange;
62 protected boolean total = false;
63
64 public FieldDefinition() {
65 }
66
67
68
69
70
71 public String getAttributeName() {
72 return attributeName;
73 }
74
75
76
77
78
79
80
81 public void setAttributeName(String attributeName) {
82 if (StringUtils.isBlank(attributeName)) {
83 throw new IllegalArgumentException("invalid (blank) attributeName");
84 }
85 this.attributeName = attributeName;
86 }
87
88
89
90
91
92 public boolean isRequired() {
93 return required;
94 }
95
96
97
98
99
100
101 public void setRequired(boolean required) {
102 this.required = required;
103 }
104
105
106
107
108
109 public boolean isForceInquiry() {
110 return forceInquiry;
111 }
112
113
114
115
116
117
118 public void setForceInquiry(boolean forceInquiry) {
119 this.forceInquiry = forceInquiry;
120 }
121
122
123
124
125 public boolean isForceLookup() {
126 return forceLookup;
127 }
128
129
130
131
132 public void setForceLookup(boolean forceLookup) {
133 this.forceLookup = forceLookup;
134 }
135
136
137
138
139 public boolean isNoInquiry() {
140 return noInquiry;
141 }
142
143
144
145
146
147 public boolean isNoDirectInquiry()
148 {
149 return noDirectInquiry;
150 }
151
152
153
154
155 public void setNoInquiry(boolean noInquiry) {
156 this.noInquiry = noInquiry;
157 }
158
159
160
161
162
163 public void setNoDirectInquiry(boolean noDirectInquiry) {
164 this.noDirectInquiry = noDirectInquiry;
165 }
166
167
168
169
170 public boolean isNoLookup() {
171 return noLookup;
172 }
173
174
175
176
177 public void setNoLookup(boolean noLookup) {
178 this.noLookup = noLookup;
179 }
180
181
182
183
184
185 public boolean isUseShortLabel() {
186 return this.useShortLabel;
187 }
188
189
190
191
192
193 public void setUseShortLabel(boolean useShortLabel) {
194 this.useShortLabel = useShortLabel;
195 }
196
197
198
199
200
201 public String getDefaultValue() {
202 return defaultValue;
203 }
204
205
206
207
208
209
210 public void setDefaultValue(String defaultValue) {
211 this.defaultValue = defaultValue;
212 }
213
214
215
216
217
218
219
220
221 public String getQuickfinderParameterString() {
222 return this.quickfinderParameterString;
223 }
224
225
226
227
228 public void setQuickfinderParameterString(String quickfinderParameterString) {
229 this.quickfinderParameterString = quickfinderParameterString;
230 }
231
232
233
234
235
236
237
238
239
240
241 public Class<? extends ValueFinder> getQuickfinderParameterStringBuilderClass() {
242 return this.quickfinderParameterStringBuilderClass;
243 }
244
245
246
247
248
249 public void setQuickfinderParameterStringBuilderClass(
250 Class<? extends ValueFinder> quickfinderParameterStringBuilderClass) {
251 if (quickfinderParameterStringBuilderClass == null) {
252 throw new IllegalArgumentException("invalid (null) quickfinderParameterStringBuilderClass");
253 }
254 this.quickfinderParameterStringBuilderClass = quickfinderParameterStringBuilderClass;
255 }
256
257
258
259
260
261
262 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
263 BusinessObjectMetaDataService boMetadataService = KNSServiceLocator.getBusinessObjectMetaDataService();
264
265 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAttributeName())) {
266 throw new AttributeValidationException("unable to find attribute '" + attributeName + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
267 }
268
269 if (StringUtils.isNotBlank(getAlternateDisplayAttributeName())) {
270 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAlternateDisplayAttributeName())) {
271 throw new AttributeValidationException("unable to find attribute named '" + getName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
272 }
273 }
274
275 if (StringUtils.isNotBlank(getAdditionalDisplayAttributeName())) {
276 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAdditionalDisplayAttributeName())) {
277 throw new AttributeValidationException("unable to find attribute named '" + getName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
278 }
279 }
280
281 if (defaultValueFinderClass != null && defaultValue != null) {
282 throw new AttributeValidationException("Both defaultValue and defaultValueFinderClass can not be specified on attribute " + getAttributeName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName());
283 }
284
285 validateQuickfinderParameters(rootBusinessObjectClass, boMetadataService);
286
287 if (forceInquiry == true && noInquiry == true) {
288 throw new AttributeValidationException("Both forceInquiry and noInquiry can not be set to true on attribute " + getAttributeName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName());
289 }
290 if (forceLookup == true && noLookup == true) {
291 throw new AttributeValidationException("Both forceLookup and noLookup can not be set to true on attribute " + getAttributeName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName());
292 }
293 }
294
295
296
297
298
299
300
301
302 private void validateQuickfinderParameters(Class rootBusinessObjectClass,
303 BusinessObjectMetaDataService boMetadataService) {
304 if (quickfinderParameterStringBuilderClass != null && quickfinderParameterString != null) {
305 throw new AttributeValidationException("Both quickfinderParameterString and quickfinderParameterStringBuilderClass can not be specified on attribute " + getAttributeName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName());
306 }
307
308
309 String quickfinderParameterStringSource = "quickfinderParameterString";
310
311 if (quickfinderParameterStringBuilderClass != null) {
312 try {
313 quickfinderParameterStringSource = "quickfinderParameterStringBuilderClass " + quickfinderParameterStringBuilderClass.getCanonicalName();
314 quickfinderParameterString = quickfinderParameterStringBuilderClass.newInstance().getValue();
315 } catch (InstantiationException e) {
316 throw new ClassValidationException("unable to create new instance of "+ quickfinderParameterStringSource +" while validating rootBusinessObjectClass '"+ rootBusinessObjectClass.getName() +"'", e);
317 } catch (IllegalAccessException e) {
318 throw new ClassValidationException("unable to create new instance of "+ quickfinderParameterStringSource +" while validating rootBusinessObjectClass '"+ rootBusinessObjectClass.getName() +"'", e);
319 }
320 }
321
322 if (!StringUtils.isEmpty(quickfinderParameterString)) {
323
324 for (String quickfinderParam : quickfinderParameterString.split(",")) {
325 if (quickfinderParam.contains("=")) {
326 String propertyName = quickfinderParam.split("=")[0];
327 RelationshipDefinition relationship = boMetadataService.getBusinessObjectRelationshipDefinition(rootBusinessObjectClass, attributeName);
328 Class targetClass = relationship.getTargetClass();
329
330
331 if (!DataDictionary.isPropertyOf(targetClass, propertyName)) {
332 throw new ClassValidationException("malformed parameter string '"+ quickfinderParameterString +"' from "+ quickfinderParameterStringSource +
333 ", '"+ propertyName +"' is not a property of "+ targetClass +"' for rootBusinessObjectClass '"+ rootBusinessObjectClass.getName() +"'");
334 }
335
336 } else {
337 throw new ClassValidationException("malformed parameter string '"+ quickfinderParameterString +"' from "+ quickfinderParameterStringSource +
338 " for rootBusinessObjectClass '"+ rootBusinessObjectClass.getName() +"'");
339 }
340 }
341 }
342 }
343
344
345
346
347
348 public String toString() {
349 return "FieldDefinition for attribute " + getAttributeName();
350 }
351
352
353 public String getName() {
354 return attributeName;
355 }
356
357
358 public String getDisplayEditMode() {
359 return displayEditMode;
360 }
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375 public void setDisplayEditMode(String displayEditMode) {
376 this.displayEditMode = displayEditMode;
377 }
378
379
380 public Mask getDisplayMask() {
381 return displayMask;
382 }
383
384
385
386
387
388
389 public void setDisplayMask(Mask displayMask) {
390 this.displayMask = displayMask;
391 }
392
393
394
395 public boolean isReadOnlyAfterAdd() {
396 return false;
397 }
398
399
400
401
402
403
404 public Integer getMaxLength() {
405 return maxLength;
406 }
407
408
409
410
411
412
413 public void setMaxLength(Integer maxLength) {
414 this.maxLength = maxLength;
415 }
416
417
418
419
420 public Class<? extends ValueFinder> getDefaultValueFinderClass() {
421 return this.defaultValueFinderClass;
422 }
423
424
425
426
427
428
429 public void setDefaultValueFinderClass(Class<? extends ValueFinder> defaultValueFinderClass) {
430 if (defaultValueFinderClass == null) {
431 throw new IllegalArgumentException("invalid (null) defaultValueFinderClass");
432 }
433 this.defaultValueFinderClass = defaultValueFinderClass;
434 }
435
436
437
438
439 public boolean isHidden() {
440 return this.hidden;
441 }
442
443
444
445
446
447
448
449
450
451
452
453
454 public void setHidden(boolean hidden) {
455 this.hidden = hidden;
456 }
457
458
459
460
461 public boolean isReadOnly() {
462 return this.readOnly;
463 }
464
465
466
467
468 public void setReadOnly(boolean readOnly) {
469 this.readOnly = readOnly;
470 }
471
472 public boolean isTriggerOnChange() {
473 return this.triggerOnChange;
474 }
475
476 public void setTriggerOnChange(boolean triggerOnChange) {
477 this.triggerOnChange = triggerOnChange;
478 }
479
480
481
482
483 public boolean isTreatWildcardsAndOperatorsAsLiteral() {
484 return this.treatWildcardsAndOperatorsAsLiteral;
485 }
486
487
488
489
490
491 public void setTreatWildcardsAndOperatorsAsLiteral(
492 boolean treatWildcardsAndOperatorsAsLiteralOnLookups) {
493 this.treatWildcardsAndOperatorsAsLiteral = treatWildcardsAndOperatorsAsLiteralOnLookups;
494 }
495
496
497 public String getAlternateDisplayAttributeName() {
498 return this.alternateDisplayAttributeName;
499 }
500
501
502 public void setAlternateDisplayAttributeName(String alternateDisplayAttributeName) {
503 this.alternateDisplayAttributeName = alternateDisplayAttributeName;
504 }
505
506
507 public String getAdditionalDisplayAttributeName() {
508 return this.additionalDisplayAttributeName;
509 }
510
511
512 public void setAdditionalDisplayAttributeName(String additionalDisplayAttributeName) {
513 this.additionalDisplayAttributeName = additionalDisplayAttributeName;
514 }
515
516
517 public boolean isTotal() {
518 return this.total;
519 }
520
521
522 public void setTotal(boolean total) {
523 this.total = total;
524 }
525
526 }