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