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