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