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 java.util.ArrayList;
20 import java.util.LinkedHashMap;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.kuali.rice.kns.datadictionary.exception.DuplicateEntryException;
26 import org.kuali.rice.kns.service.KNSServiceLocator;
27 import org.kuali.rice.kns.util.KNSConstants;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 public class LookupDefinition extends DataDictionaryDefinitionBase {
56 private static final long serialVersionUID = 6733008572890721359L;
57
58 protected String lookupableID;
59 protected String title;
60 protected String menubar;
61 protected SortDefinition defaultSort;
62
63 protected List<FieldDefinition> lookupFields = new ArrayList<FieldDefinition>();
64 protected Map<String,FieldDefinition> lookupFieldMap = new LinkedHashMap<String, FieldDefinition>();
65 protected List<FieldDefinition> resultFields = new ArrayList<FieldDefinition>();
66 protected Map<String,FieldDefinition> resultFieldMap = new LinkedHashMap<String, FieldDefinition>();
67
68 protected Integer resultSetLimit = null;
69
70 protected String extraButtonSource;
71 protected String extraButtonParams;
72
73 protected String searchIconOverride;
74
75 protected int numOfColumns;
76
77 protected HelpDefinition helpDefinition;
78 protected String helpUrl;
79
80 protected boolean translateCodes = false;
81 protected boolean disableSearchButtons = false;
82
83 public LookupDefinition() {}
84
85
86
87
88
89
90
91
92
93
94
95
96 public void setLookupableID(String lookupableID) {
97 if (lookupableID == null) {
98 throw new IllegalArgumentException("invalid (null) lookupableID");
99 }
100
101 this.lookupableID = lookupableID;
102 }
103
104
105
106
107 public String getLookupableID() {
108 return this.lookupableID;
109 }
110
111
112
113
114 public String getTitle() {
115 return title;
116 }
117
118
119
120
121
122
123
124 public void setTitle(String title) {
125 if (StringUtils.isBlank(title)) {
126 throw new IllegalArgumentException("invalid (blank) title");
127 }
128 this.title = title;
129 }
130
131
132
133
134 public boolean hasMenubar() {
135 return (menubar != null);
136 }
137
138
139
140
141 public String getMenubar() {
142 return menubar;
143 }
144
145
146
147
148
149
150
151
152
153
154 public void setMenubar(String menubar) {
155 if (StringUtils.isBlank(menubar)) {
156 throw new IllegalArgumentException("invalid (blank) menubar");
157 }
158
159 this.menubar = menubar.replace("${kr.externalizable.images.url}", KNSServiceLocator.getKualiConfigurationService().getPropertyString(KNSConstants.EXTERNALIZABLE_IMAGES_URL_KEY)).replace("${externalizable.images.url}", KNSServiceLocator.getKualiConfigurationService().getPropertyString(KNSConstants.APPLICATION_EXTERNALIZABLE_IMAGES_URL_KEY));
160 this.menubar = this.menubar.replace("${application.url}", KNSServiceLocator.getKualiConfigurationService().getPropertyString(KNSConstants.APPLICATION_URL_KEY));
161 }
162
163
164
165
166
167 public boolean hasDefaultSort() {
168 return (defaultSort != null);
169 }
170
171
172
173
174 public SortDefinition getDefaultSort() {
175 return defaultSort;
176 }
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195 public void setDefaultSort(SortDefinition defaultSort) {
196 if (defaultSort == null) {
197 throw new IllegalArgumentException("invalid (null) defaultSort");
198 }
199 this.defaultSort = defaultSort;
200 }
201
202
203
204
205
206 public List getLookupFieldNames() {
207 List fieldNames = new ArrayList();
208 fieldNames.addAll(this.lookupFieldMap.keySet());
209
210 return fieldNames;
211 }
212
213
214
215
216
217 public List<FieldDefinition> getLookupFields() {
218 return lookupFields;
219 }
220
221
222
223
224
225 public FieldDefinition getLookupField(String attributeName) {
226 return lookupFieldMap.get(attributeName);
227 }
228
229
230
231
232
233 public List<String> getResultFieldNames() {
234 List<String> fieldNames = new ArrayList<String>();
235 fieldNames.addAll(resultFieldMap.keySet());
236
237 return fieldNames;
238 }
239
240
241
242
243
244 public List<FieldDefinition> getResultFields() {
245 return resultFields;
246 }
247
248
249
250
251
252
253 public FieldDefinition getResultField(String attributeName) {
254 return resultFieldMap.get(attributeName);
255 }
256
257
258
259
260
261 public void setResultSetLimit(Integer resultSetLimit) {
262 this.resultSetLimit = resultSetLimit;
263 }
264
265
266
267
268 public boolean hasResultSetLimit() {
269 return (resultSetLimit != null);
270 }
271
272
273
274
275
276
277 public Integer getResultSetLimit() {
278 return resultSetLimit;
279 }
280
281
282
283
284
285
286 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
287 if (hasDefaultSort()) {
288 defaultSort.completeValidation(rootBusinessObjectClass, null);
289 }
290
291 for ( FieldDefinition lookupField : lookupFields ) {
292 lookupField.completeValidation(rootBusinessObjectClass, null);
293 }
294
295 for ( FieldDefinition resultField : resultFields ) {
296 resultField.completeValidation(rootBusinessObjectClass, null);
297 }
298 }
299
300
301
302
303 public boolean hasExtraButtonSource() {
304 return extraButtonSource != null;
305 }
306
307
308
309
310 public String getExtraButtonSource() {
311 return extraButtonSource;
312 }
313
314
315
316
317
318
319
320
321
322
323
324
325
326 public void setExtraButtonSource(String extraButtonSource) {
327 if (StringUtils.isBlank(extraButtonSource)) {
328 throw new IllegalArgumentException("invalid (blank) button source");
329 }
330 this.extraButtonSource = extraButtonSource;
331 }
332
333
334
335
336 public boolean hasExtraButtonParams() {
337 return extraButtonParams != null;
338 }
339
340
341
342
343 public String getExtraButtonParams() {
344 return extraButtonParams;
345 }
346
347
348
349
350
351
352
353
354
355
356
357 public void setExtraButtonParams(String extraButtonParams) {
358 this.extraButtonParams = extraButtonParams;
359 }
360
361
362
363
364
365 public boolean hasSearchIconOverride() {
366 return searchIconOverride != null;
367 }
368
369
370
371
372 public String getSearchIconOverride() {
373 return searchIconOverride;
374 }
375
376
377
378
379
380
381
382 public void setSearchIconOverride(String searchIconOverride) {
383 if (StringUtils.isBlank(searchIconOverride)) {
384 throw new IllegalArgumentException("invalid (blank) search icon override");
385 }
386 this.searchIconOverride = searchIconOverride;
387 }
388
389
390 public String toString() {
391 return "LookupDefinition '" + getTitle() + "'";
392 }
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428 public void setLookupFields(List<FieldDefinition> lookupFields) {
429 lookupFieldMap.clear();
430 for ( FieldDefinition lookupField : lookupFields ) {
431 if (lookupField == null) {
432 throw new IllegalArgumentException("invalid (null) lookupField");
433 }
434 String keyName = lookupField.getAttributeName();
435 if (lookupFieldMap.containsKey(keyName)) {
436 throw new DuplicateEntryException("duplicate lookupField entry for attribute '" + keyName + "'");
437 }
438
439 lookupFieldMap.put(keyName, lookupField);
440 }
441 this.lookupFields = lookupFields;
442 }
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462 public void setResultFields(List<FieldDefinition> resultFields) {
463 resultFieldMap.clear();
464 for ( FieldDefinition resultField : resultFields ) {
465 if (resultField == null) {
466 throw new IllegalArgumentException("invalid (null) resultField");
467 }
468
469 String keyName = resultField.getAttributeName();
470 if (resultFieldMap.containsKey(keyName)) {
471 throw new DuplicateEntryException("duplicate resultField entry for attribute '" + keyName + "'");
472 }
473
474 resultFieldMap.put(keyName, resultField);
475 }
476 this.resultFields = resultFields;
477 }
478
479
480
481
482 public int getNumOfColumns() {
483 return this.numOfColumns;
484 }
485
486
487
488
489 public void setNumOfColumns(int numOfColumns) {
490 this.numOfColumns = numOfColumns;
491 }
492
493
494
495
496 public HelpDefinition getHelpDefinition() {
497 return this.helpDefinition;
498 }
499
500
501
502
503 public void setHelpDefinition(HelpDefinition helpDefinition) {
504 this.helpDefinition = helpDefinition;
505 }
506
507
508
509
510 public String getHelpUrl() {
511 return this.helpUrl;
512 }
513
514
515
516
517 public void setHelpUrl(String helpUrl) {
518 this.helpUrl = helpUrl;
519 }
520
521 public boolean isTranslateCodes() {
522 return this.translateCodes;
523 }
524
525 public void setTranslateCodes(boolean translateCodes) {
526 this.translateCodes = translateCodes;
527 }
528
529 public boolean isDisableSearchButtons() {
530 return this.disableSearchButtons;
531 }
532
533 public void setDisableSearchButtons(boolean disableSearchButtons) {
534 this.disableSearchButtons = disableSearchButtons;
535 }
536
537 }