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