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