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.identity.Person;
20 import org.kuali.rice.kim.api.identity.PersonService;
21 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
23 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
24 import org.kuali.rice.krad.uif.field.InputField;
25 import org.kuali.rice.krad.uif.util.ScriptUtils;
26 import org.kuali.rice.krad.uif.view.View;
27 import org.kuali.rice.krad.uif.component.Component;
28 import org.kuali.rice.krad.uif.component.MethodInvokerConfig;
29 import org.kuali.rice.krad.uif.field.AttributeQuery;
30 import org.kuali.rice.krad.uif.widget.QuickFinder;
31
32
33
34
35
36
37
38 @BeanTag(name="userControl")
39 public class UserControl extends TextControl {
40 private static final long serialVersionUID = 7468340793076585869L;
41
42 private String principalIdPropertyName;
43 private String personNamePropertyName;
44 private String personObjectPropertyName;
45
46 public UserControl() {
47 super();
48 }
49
50
51
52
53
54 @Override
55 public void performApplyModel(View view, Object model, Component parent) {
56 super.performApplyModel(view, model, parent);
57
58 if (!(parent instanceof InputField)) {
59 return;
60 }
61
62 InputField field = (InputField) parent;
63 field.getAdditionalHiddenPropertyNames().add(principalIdPropertyName);
64
65 if (!field.isReadOnly()) {
66
67 if (StringUtils.isNotBlank(personNamePropertyName)) {
68 field.getPropertyNamesForAdditionalDisplay().add(personNamePropertyName);
69 } else {
70 field.getPropertyNamesForAdditionalDisplay().add(personObjectPropertyName + ".name");
71 }
72
73
74 String idPropertyPath = field.getBindingInfo().getPropertyAdjustedBindingPath(principalIdPropertyName);
75 String onChangeScript = "setValue('" + ScriptUtils.escapeName(idPropertyPath) + "','');";
76
77 if (StringUtils.isNotBlank(getOnChangeScript())) {
78 onChangeScript = getOnChangeScript() + onChangeScript;
79 }
80 setOnChangeScript(onChangeScript);
81 }
82
83 if (field.isReadOnly() && StringUtils.isBlank(field.getReadOnlyDisplaySuffixPropertyName())) {
84 if (StringUtils.isNotBlank(personNamePropertyName)) {
85 field.setReadOnlyDisplaySuffixPropertyName(personNamePropertyName);
86 } else {
87 field.setReadOnlyDisplaySuffixPropertyName(personObjectPropertyName + ".name");
88 }
89 }
90
91
92 AttributeQuery attributeQuery = new AttributeQuery();
93
94 MethodInvokerConfig methodInvokerConfig = new MethodInvokerConfig();
95 PersonService personService = KimApiServiceLocator.getPersonService();
96 methodInvokerConfig.setTargetObject(personService);
97
98 attributeQuery.setQueryMethodInvokerConfig(methodInvokerConfig);
99 attributeQuery.setQueryMethodToCall("getPersonByPrincipalName");
100 attributeQuery.getQueryMethodArgumentFieldList().add(field.getPropertyName());
101 attributeQuery.getReturnFieldMapping().put("principalId", principalIdPropertyName);
102
103 if (StringUtils.isNotBlank(personNamePropertyName)) {
104 attributeQuery.getReturnFieldMapping().put("name", personNamePropertyName);
105 } else {
106 attributeQuery.getReturnFieldMapping().put("name", personObjectPropertyName + ".name");
107 }
108 field.setAttributeQuery(attributeQuery);
109
110
111 QuickFinder quickFinder = field.getQuickfinder();
112 if (quickFinder.isRender()) {
113 if (StringUtils.isBlank(quickFinder.getDataObjectClassName())) {
114 quickFinder.setDataObjectClassName(Person.class.getName());
115 }
116
117 if (quickFinder.getFieldConversions().isEmpty()) {
118 quickFinder.getFieldConversions().put("principalId", principalIdPropertyName);
119
120 if (StringUtils.isNotBlank(personNamePropertyName)) {
121 quickFinder.getFieldConversions().put("name", personNamePropertyName);
122 } else {
123 quickFinder.getFieldConversions().put("name", personObjectPropertyName + ".name");
124 }
125
126 quickFinder.getFieldConversions().put("principalName", field.getPropertyName());
127 }
128 }
129 }
130
131
132
133
134
135
136 @BeanTagAttribute(name="principalIdPropertyName")
137 public String getPrincipalIdPropertyName() {
138 return principalIdPropertyName;
139 }
140
141
142
143
144
145
146 public void setPrincipalIdPropertyName(String principalIdPropertyName) {
147 this.principalIdPropertyName = principalIdPropertyName;
148 }
149
150
151
152
153
154
155 @BeanTagAttribute(name="personNamePropertyName")
156 public String getPersonNamePropertyName() {
157 return personNamePropertyName;
158 }
159
160
161
162
163
164
165 public void setPersonNamePropertyName(String personNamePropertyName) {
166 this.personNamePropertyName = personNamePropertyName;
167 }
168
169
170
171
172
173
174 @BeanTagAttribute(name="personObjectPropertyName")
175 public String getPersonObjectPropertyName() {
176 return personObjectPropertyName;
177 }
178
179
180
181
182
183
184 public void setPersonObjectPropertyName(String personObjectPropertyName) {
185 this.personObjectPropertyName = personObjectPropertyName;
186 }
187 }