1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.control;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.kim.api.group.Group;
20 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
23 import org.kuali.rice.krad.uif.view.View;
24 import org.kuali.rice.krad.uif.component.Component;
25 import org.kuali.rice.krad.uif.field.InputField;
26
27 import java.util.HashMap;
28 import java.util.Map;
29
30
31
32
33
34
35
36 @BeanTag(name = "kimGroupControl-bean", parent = "Uif-KimGroupControl")
37 public class GroupControl extends TextControl implements FilterableLookupCriteriaControl {
38 private static final long serialVersionUID = 5598459655735440981L;
39
40 private String namespaceCodePropertyName;
41 private String groupIdPropertyName;
42
43 public GroupControl() {
44 super();
45 }
46
47 @Override
48 public void performApplyModel(View view, Object model, Component parent) {
49 super.performApplyModel(view, model, parent);
50
51 if (!(parent instanceof InputField)) {
52 return;
53 }
54
55 InputField field = (InputField) parent;
56
57 if (StringUtils.isNotBlank(groupIdPropertyName)) {
58 field.getAdditionalHiddenPropertyNames().add(groupIdPropertyName);
59 }
60
61 if (StringUtils.isBlank(field.getQuickfinder().getDataObjectClassName())) {
62 field.getQuickfinder().setDataObjectClassName("org.kuali.rice.kim.impl.group.GroupBo");
63 }
64
65 if (field.getQuickfinder().getFieldConversions().isEmpty()) {
66 if (StringUtils.isNotBlank(groupIdPropertyName)) {
67 field.getQuickfinder().getFieldConversions().put("id", groupIdPropertyName);
68 }
69
70 field.getQuickfinder().getFieldConversions().put("name", field.getPropertyName());
71
72 if (StringUtils.isNotBlank(namespaceCodePropertyName)) {
73 field.getQuickfinder().getFieldConversions().put("namespaceCode", namespaceCodePropertyName);
74 }
75 }
76
77 if (field.getQuickfinder().getLookupParameters().isEmpty()) {
78 if (StringUtils.isNotBlank(namespaceCodePropertyName)) {
79 field.getQuickfinder().getLookupParameters().put(namespaceCodePropertyName, "namespaceCode");
80 }
81 }
82 }
83
84
85
86
87
88
89 @BeanTagAttribute(name="namespaceCodePropertyName")
90 public String getNamespaceCodePropertyName() {
91 return namespaceCodePropertyName;
92 }
93
94
95
96
97
98
99 public void setNamespaceCodePropertyName(String namespaceCodePropertyName) {
100 this.namespaceCodePropertyName = namespaceCodePropertyName;
101 }
102
103
104
105
106
107
108 @BeanTagAttribute(name="groupIdPropertyName")
109 public String getGroupIdPropertyName() {
110 return groupIdPropertyName;
111 }
112
113
114
115
116
117
118 public void setGroupIdPropertyName(String groupIdPropertyName) {
119 this.groupIdPropertyName = groupIdPropertyName;
120 }
121
122
123
124
125 @Override
126 public Map<String, String> filterSearchCriteria(String propertyName, Map<String, String> searchCriteria) {
127 Map<String, String> filteredSearchCriteria = new HashMap<String, String>(searchCriteria);
128
129
130
131
132 String groupName = searchCriteria.get(propertyName);
133 String groupNamespaceCd = searchCriteria.get(namespaceCodePropertyName);
134 if (StringUtils.isNotBlank(groupName) && StringUtils.isNotBlank(groupNamespaceCd)) {
135 Group group = KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(groupNamespaceCd,groupName);
136 if( group == null) {
137 return null;
138 } else {
139 filteredSearchCriteria.put(groupIdPropertyName, group.getId());
140 }
141 }
142
143
144 filteredSearchCriteria.remove(propertyName);
145 filteredSearchCriteria.remove(namespaceCodePropertyName);
146
147 return filteredSearchCriteria;
148 }
149 }