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 java.io.Serializable;
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.rice.kim.api.group.Group;
24 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
25 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
26 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
27 import org.kuali.rice.krad.uif.field.InputField;
28 import org.kuali.rice.krad.uif.util.ComponentFactory;
29 import org.kuali.rice.krad.uif.util.LifecycleElement;
30 import org.kuali.rice.krad.uif.widget.QuickFinder;
31
32
33
34
35
36
37
38 @BeanTag(name = "kimGroupControl", parent = "Uif-KimGroupControl")
39 public class GroupControl extends TextControlBase implements FilterableLookupCriteriaControl {
40 private static final long serialVersionUID = 5598459655735440981L;
41
42 private String namespaceCodePropertyName;
43 private String groupIdPropertyName;
44
45 public GroupControl() {
46 super();
47 }
48
49 @Override
50 public void performApplyModel(Object model, LifecycleElement parent) {
51 super.performApplyModel(model, parent);
52
53 if (!(parent instanceof InputField)) {
54 return;
55 }
56
57 InputField field = (InputField) parent;
58
59 if (StringUtils.isNotBlank(groupIdPropertyName)) {
60 field.getAdditionalHiddenPropertyNames().add(groupIdPropertyName);
61 }
62
63 buildGroupQuickfinder(model, field);
64 }
65
66 protected void buildGroupQuickfinder(Object model, InputField field) {
67 QuickFinder quickFinder = field.getQuickfinder();
68
69
70 if (!field.isEnableAutoQuickfinder()) {
71 return;
72 }
73
74 if (quickFinder == null) {
75 quickFinder = ComponentFactory.getQuickFinder();
76 field.setQuickfinder(quickFinder);
77 }
78
79 if (field.getQuickfinder() != null) {
80 if (StringUtils.isBlank(field.getQuickfinder().getDataObjectClassName())) {
81 field.getQuickfinder().setDataObjectClassName("org.kuali.rice.kim.impl.group.GroupBo");
82 }
83
84 if (field.getQuickfinder().getFieldConversions().isEmpty()) {
85 if (StringUtils.isNotBlank(groupIdPropertyName)) {
86 field.getQuickfinder().getFieldConversions().put("id", groupIdPropertyName);
87 }
88
89 field.getQuickfinder().getFieldConversions().put("name", field.getPropertyName());
90
91 if (StringUtils.isNotBlank(namespaceCodePropertyName)) {
92 field.getQuickfinder().getFieldConversions().put("namespaceCode", namespaceCodePropertyName);
93 }
94 }
95
96 if (field.getQuickfinder().getLookupParameters().isEmpty()) {
97 if (StringUtils.isNotBlank(namespaceCodePropertyName)) {
98 field.getQuickfinder().getLookupParameters().put(namespaceCodePropertyName, "namespaceCode");
99 }
100 }
101 }
102 }
103
104
105
106
107 @Override
108 public Map<String, String> filterSearchCriteria(String propertyName, Map<String, String> searchCriteria, FilterableLookupCriteriaControlPostData postData) {
109 Map<String, String> filteredSearchCriteria = new HashMap<String, String>(searchCriteria);
110
111 GroupControlPostData groupControlPostData = (GroupControlPostData) postData;
112
113
114
115
116 String groupName = searchCriteria.get(propertyName);
117 String groupNamespaceCd = searchCriteria.get(groupControlPostData.getNamespaceCodePropertyName());
118 if (StringUtils.isNotBlank(groupName) && StringUtils.isNotBlank(groupNamespaceCd)) {
119 Group group = KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(groupNamespaceCd,groupName);
120 if( group == null) {
121 return null;
122 } else {
123 filteredSearchCriteria.put(groupControlPostData.getGroupIdPropertyName(), group.getId());
124 }
125 }
126
127
128 filteredSearchCriteria.remove(propertyName);
129 filteredSearchCriteria.remove(groupControlPostData.getNamespaceCodePropertyName());
130
131 return filteredSearchCriteria;
132 }
133
134
135
136
137
138
139 @BeanTagAttribute
140 public String getNamespaceCodePropertyName() {
141 return namespaceCodePropertyName;
142 }
143
144
145
146
147
148
149 public void setNamespaceCodePropertyName(String namespaceCodePropertyName) {
150 this.namespaceCodePropertyName = namespaceCodePropertyName;
151 }
152
153
154
155
156
157
158 @BeanTagAttribute
159 public String getGroupIdPropertyName() {
160 return groupIdPropertyName;
161 }
162
163
164
165
166
167
168 public void setGroupIdPropertyName(String groupIdPropertyName) {
169 this.groupIdPropertyName = groupIdPropertyName;
170 }
171
172
173
174
175 @Override
176 public GroupControlPostData getPostData(String propertyName) {
177 return new GroupControlPostData(propertyName, this);
178 }
179
180
181
182
183 public static class GroupControlPostData implements FilterableLookupCriteriaControlPostData, Serializable {
184
185 private static final long serialVersionUID = -1859777965985379673L;
186
187 private String propertyName;
188
189 private String namespaceCodePropertyName;
190 private String groupIdPropertyName;
191
192
193
194
195
196
197
198 public GroupControlPostData(String propertyName, GroupControl groupControl) {
199 this.propertyName = propertyName;
200 this.namespaceCodePropertyName = groupControl.getNamespaceCodePropertyName();
201 this.groupIdPropertyName = groupControl.getGroupIdPropertyName();
202 }
203
204
205
206
207 @Override
208 public Class<? extends FilterableLookupCriteriaControl> getControlClass() {
209 return GroupControl.class;
210 }
211
212
213
214
215 @Override
216 public String getPropertyName() {
217 return propertyName;
218 }
219
220
221
222
223 public String getNamespaceCodePropertyName() {
224 return namespaceCodePropertyName;
225 }
226
227
228
229
230 public String getGroupIdPropertyName() {
231 return groupIdPropertyName;
232 }
233
234 }
235
236 }