1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.field;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
22 import org.kuali.rice.krad.datadictionary.validator.ErrorReport;
23 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
24 import org.kuali.rice.krad.uif.component.BindingInfo;
25 import org.kuali.rice.krad.uif.component.MethodInvokerConfig;
26 import org.kuali.rice.krad.uif.util.CloneUtils;
27
28 import java.io.Serializable;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 @BeanTag(name = "attributeQueryConfig-bean", parent = "Uif-AttributeQueryConfig")
50 public class AttributeQuery extends UifDictionaryBeanBase implements Serializable {
51 private static final long serialVersionUID = -4569905665441735255L;
52
53 private String dataObjectClassName;
54
55 private boolean renderNotFoundMessage;
56 private String returnMessageText;
57 private String returnMessageStyleClasses;
58
59 private Map<String, String> queryFieldMapping;
60 private Map<String, String> returnFieldMapping;
61 private Map<String, String> additionalCriteria;
62
63 private List<String> sortPropertyNames;
64
65 private String queryMethodToCall;
66 private List<String> queryMethodArgumentFieldList;
67 private MethodInvokerConfig queryMethodInvokerConfig;
68
69 public AttributeQuery() {
70 renderNotFoundMessage = true;
71
72 queryFieldMapping = new HashMap<String, String>();
73 returnFieldMapping = new HashMap<String, String>();
74 additionalCriteria = new HashMap<String, String>();
75 sortPropertyNames = new ArrayList<String>();
76
77 queryMethodArgumentFieldList = new ArrayList<String>();
78 queryMethodInvokerConfig = new MethodInvokerConfig();
79 }
80
81
82
83
84
85
86
87 public void updateQueryFieldMapping(BindingInfo bindingInfo) {
88 Map<String, String> adjustedQueryFieldMapping = new HashMap<String, String>();
89 for (String fromFieldPath : getQueryFieldMapping().keySet()) {
90 String toField = getQueryFieldMapping().get(fromFieldPath);
91 String adjustedFromFieldPath = bindingInfo.getPropertyAdjustedBindingPath(fromFieldPath);
92
93 adjustedQueryFieldMapping.put(adjustedFromFieldPath, toField);
94 }
95
96 this.queryFieldMapping = adjustedQueryFieldMapping;
97 }
98
99
100
101
102
103
104
105 public void updateReturnFieldMapping(BindingInfo bindingInfo) {
106 Map<String, String> adjustedReturnFieldMapping = new HashMap<String, String>();
107 for (String fromFieldPath : getReturnFieldMapping().keySet()) {
108 String toFieldPath = getReturnFieldMapping().get(fromFieldPath);
109 String adjustedToFieldPath = bindingInfo.getPropertyAdjustedBindingPath(toFieldPath);
110
111 adjustedReturnFieldMapping.put(fromFieldPath, adjustedToFieldPath);
112 }
113
114 this.returnFieldMapping = adjustedReturnFieldMapping;
115 }
116
117
118
119
120
121
122
123 public void updateQueryMethodArgumentFieldList(BindingInfo bindingInfo) {
124 List<String> adjustedArgumentFieldList = new ArrayList<String>();
125 for (String argumentFieldPath : getQueryMethodArgumentFieldList()) {
126 String adjustedFieldPath = bindingInfo.getPropertyAdjustedBindingPath(argumentFieldPath);
127 adjustedArgumentFieldList.add(adjustedFieldPath);
128 }
129
130 this.queryMethodArgumentFieldList = adjustedArgumentFieldList;
131 }
132
133
134
135
136
137
138
139 public String getQueryFieldMappingJsString() {
140 String queryFieldMappingJs = "{";
141
142 for (String queryField : queryFieldMapping.keySet()) {
143 if (!StringUtils.equals(queryFieldMappingJs, "{")) {
144 queryFieldMappingJs += ",";
145 }
146
147 queryFieldMappingJs += "\"" + queryField + "\":\"" + queryFieldMapping.get(queryField) + "\"";
148 }
149
150 queryFieldMappingJs += "}";
151
152 return queryFieldMappingJs;
153 }
154
155
156
157
158
159
160
161 public String getReturnFieldMappingJsString() {
162 String returnFieldMappingJs = "{";
163
164 for (String fromField : returnFieldMapping.keySet()) {
165 if (!StringUtils.equals(returnFieldMappingJs, "{")) {
166 returnFieldMappingJs += ",";
167 }
168
169 returnFieldMappingJs += "\"" + returnFieldMapping.get(fromField) + "\":\"" + fromField + "\"";
170 }
171
172 returnFieldMappingJs += "}";
173
174 return returnFieldMappingJs;
175 }
176
177
178
179
180
181
182 public String getQueryMethodArgumentFieldsJsString() {
183 String queryMethodArgsJs = "{";
184
185 for (String methodArg : queryMethodArgumentFieldList) {
186 if (!StringUtils.equals(queryMethodArgsJs, "{")) {
187 queryMethodArgsJs += ",";
188 }
189
190 queryMethodArgsJs += "\"" + methodArg + "\":\"" + methodArg + "\"";
191 }
192
193 queryMethodArgsJs += "}";
194
195 return queryMethodArgsJs;
196 }
197
198
199
200
201
202
203
204
205
206 public boolean hasConfiguredMethod() {
207 boolean configuredMethod = false;
208
209 if (StringUtils.isNotBlank(getQueryMethodToCall())) {
210 configuredMethod = true;
211 } else if (getQueryMethodInvokerConfig() != null && (StringUtils.isNotBlank(
212 getQueryMethodInvokerConfig().getTargetMethod()) || StringUtils.isNotBlank(
213 getQueryMethodInvokerConfig().getStaticMethod()))) {
214 configuredMethod = true;
215 }
216
217 return configuredMethod;
218 }
219
220
221
222
223
224
225 @BeanTagAttribute(name = "dataObjectClassName")
226 public String getDataObjectClassName() {
227 return dataObjectClassName;
228 }
229
230
231
232
233
234
235 public void setDataObjectClassName(String dataObjectClassName) {
236 this.dataObjectClassName = dataObjectClassName;
237 }
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252 @BeanTagAttribute(name = "queryFieldMapping", type = BeanTagAttribute.AttributeType.MAPVALUE)
253 public Map<String, String> getQueryFieldMapping() {
254 return queryFieldMapping;
255 }
256
257
258
259
260
261
262 public void setQueryFieldMapping(Map<String, String> queryFieldMapping) {
263 this.queryFieldMapping = queryFieldMapping;
264 }
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279 @BeanTagAttribute(name = "returnFieldMapping", type = BeanTagAttribute.AttributeType.MAPVALUE)
280 public Map<String, String> getReturnFieldMapping() {
281 return returnFieldMapping;
282 }
283
284
285
286
287
288
289 public void setReturnFieldMapping(Map<String, String> returnFieldMapping) {
290 this.returnFieldMapping = returnFieldMapping;
291 }
292
293
294
295
296
297
298
299
300
301 @BeanTagAttribute(name = "additionalCriteria", type = BeanTagAttribute.AttributeType.MAPVALUE)
302 public Map<String, String> getAdditionalCriteria() {
303 return additionalCriteria;
304 }
305
306
307
308
309
310
311 public void setAdditionalCriteria(Map<String, String> additionalCriteria) {
312 this.additionalCriteria = additionalCriteria;
313 }
314
315
316
317
318
319
320
321
322
323 @BeanTagAttribute(name = "sortPropertyNames", type = BeanTagAttribute.AttributeType.LISTVALUE)
324 public List<String> getSortPropertyNames() {
325 return sortPropertyNames;
326 }
327
328
329
330
331
332
333 public void setSortPropertyNames(List<String> sortPropertyNames) {
334 this.sortPropertyNames = sortPropertyNames;
335 }
336
337
338
339
340
341
342
343 @BeanTagAttribute(name = "renderNotFoundMessage")
344 public boolean isRenderNotFoundMessage() {
345 return renderNotFoundMessage;
346 }
347
348
349
350
351
352
353 public void setRenderNotFoundMessage(boolean renderNotFoundMessage) {
354 this.renderNotFoundMessage = renderNotFoundMessage;
355 }
356
357
358
359
360
361
362 @BeanTagAttribute(name = "returnMessageText")
363 public String getReturnMessageText() {
364 return returnMessageText;
365 }
366
367
368
369
370
371
372 public void setReturnMessageText(String returnMessageText) {
373 this.returnMessageText = returnMessageText;
374 }
375
376
377
378
379
380
381
382 @BeanTagAttribute(name = "returnMessageStyleClasses")
383 public String getReturnMessageStyleClasses() {
384 return returnMessageStyleClasses;
385 }
386
387
388
389
390
391
392 public void setReturnMessageStyleClasses(String returnMessageStyleClasses) {
393 this.returnMessageStyleClasses = returnMessageStyleClasses;
394 }
395
396
397
398
399
400
401
402
403
404
405
406
407
408 @BeanTagAttribute(name = "queryMethodToCall")
409 public String getQueryMethodToCall() {
410 return queryMethodToCall;
411 }
412
413
414
415
416
417
418 public void setQueryMethodToCall(String queryMethodToCall) {
419 this.queryMethodToCall = queryMethodToCall;
420 }
421
422
423
424
425
426
427
428
429
430
431
432
433 @BeanTagAttribute(name = "queryMethodArgumentFieldList", type = BeanTagAttribute.AttributeType.LISTVALUE)
434 public List<String> getQueryMethodArgumentFieldList() {
435 return queryMethodArgumentFieldList;
436 }
437
438
439
440
441
442
443 public void setQueryMethodArgumentFieldList(List<String> queryMethodArgumentFieldList) {
444 this.queryMethodArgumentFieldList = queryMethodArgumentFieldList;
445 }
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460 @BeanTagAttribute(name = "queryMethodInvokerConfig", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
461 public MethodInvokerConfig getQueryMethodInvokerConfig() {
462 return queryMethodInvokerConfig;
463 }
464
465
466
467
468
469
470 public void setQueryMethodInvokerConfig(MethodInvokerConfig queryMethodInvokerConfig) {
471 this.queryMethodInvokerConfig = queryMethodInvokerConfig;
472 }
473
474
475
476
477 public void completeValidation(ValidationTrace tracer) {
478 tracer.addBean("AttributeQuery", ValidationTrace.NO_BEAN_ID);
479
480
481 if (getDataObjectClassName() == null
482 && getQueryMethodToCall() == null
483 && getQueryMethodInvokerConfig() == null) {
484 String currentValues[] = {"dataObjectClassName = " + getDataObjectClassName(),
485 "queryMethodToCall = " + getQueryMethodToCall(),
486 "queryMethodInvokerConfig = " + getQueryMethodInvokerConfig()};
487 tracer.createWarning(
488 "At least 1 should be set: dataObjectClass, queryMethodToCall or queryMethodInvokerConfig",
489 currentValues);
490 }
491 }
492
493
494
495
496
497
498 public <T> T copy() {
499 T copiedClass = null;
500 try {
501 copiedClass = (T) this.getClass().newInstance();
502 } catch (Exception exception) {
503 throw new RuntimeException();
504 }
505
506 copyProperties(copiedClass);
507
508 return copiedClass;
509 }
510
511
512
513
514
515
516 protected <T> void copyProperties(T attributeQuery) {
517 super.copyProperties(attributeQuery);
518 AttributeQuery attributeQueryCopy = (AttributeQuery) attributeQuery;
519
520 if (this.additionalCriteria != null) {
521 attributeQueryCopy.setAdditionalCriteria(new HashMap<String, String>(this.additionalCriteria));
522 }
523
524 attributeQueryCopy.setDataObjectClassName(this.dataObjectClassName);
525
526 if (this.queryFieldMapping != null) {
527 attributeQueryCopy.setQueryFieldMapping(new HashMap<String, String>(this.queryFieldMapping));
528 }
529
530 if (this.queryMethodArgumentFieldList != null) {
531 attributeQueryCopy.setQueryMethodArgumentFieldList(new ArrayList<String>(
532 this.queryMethodArgumentFieldList));
533 }
534
535 attributeQueryCopy.setQueryMethodToCall(this.queryMethodToCall);
536 attributeQueryCopy.setRenderNotFoundMessage(this.renderNotFoundMessage);
537
538 if (this.returnFieldMapping != null) {
539 attributeQueryCopy.setReturnFieldMapping(new HashMap<String, String>(this.returnFieldMapping));
540 }
541
542 attributeQueryCopy.setReturnMessageStyleClasses(this.returnMessageStyleClasses);
543 attributeQueryCopy.setReturnMessageText(this.returnMessageText);
544
545 if (this.sortPropertyNames != null) {
546 attributeQueryCopy.setSortPropertyNames(new ArrayList<String>(this.sortPropertyNames));
547 }
548
549 if (this.queryMethodInvokerConfig != null) {
550 ((AttributeQuery) attributeQuery).setQueryMethodInvokerConfig(CloneUtils.deepClone(
551 this.queryMethodInvokerConfig));
552 }
553 }
554 }