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