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.services.KimApiServiceLocator; |
20 | |
import org.kuali.rice.kim.service.PersonService; |
21 | |
import org.kuali.rice.krad.uif.container.View; |
22 | |
import org.kuali.rice.krad.uif.core.Component; |
23 | |
import org.kuali.rice.krad.uif.core.MethodInvokerConfig; |
24 | |
import org.kuali.rice.krad.uif.field.AttributeField; |
25 | |
import org.kuali.rice.krad.uif.field.AttributeQuery; |
26 | |
import org.kuali.rice.krad.uif.widget.QuickFinder; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public class UserControl extends TextControl { |
35 | |
|
36 | |
private static final long serialVersionUID = 7468340793076585869L; |
37 | |
private String principalIdPropertyName; |
38 | |
private String personNamePropertyName; |
39 | |
private String personObjectPropertyName; |
40 | |
|
41 | |
public UserControl() { |
42 | 0 | super(); |
43 | 0 | } |
44 | |
|
45 | |
@Override |
46 | |
public void performApplyModel(View view, Object model, Component parent) { |
47 | 0 | super.performApplyModel(view, model, parent); |
48 | |
|
49 | 0 | if (parent instanceof AttributeField) { |
50 | 0 | AttributeField field = (AttributeField) parent; |
51 | 0 | field.getHiddenPropertyNames().add(principalIdPropertyName); |
52 | |
|
53 | 0 | if (!field.isReadOnly()) |
54 | |
{ |
55 | 0 | if (StringUtils.isNotBlank(personNamePropertyName)) { |
56 | 0 | field.getInformationalDisplayPropertyNames().add(personNamePropertyName); |
57 | |
} |
58 | |
else |
59 | |
{ |
60 | 0 | field.getInformationalDisplayPropertyNames().add(personObjectPropertyName + ".name"); |
61 | |
} |
62 | |
} |
63 | |
|
64 | 0 | if (field.isReadOnly() && StringUtils.isBlank(field.getAdditionalDisplayPropertyName())) { |
65 | 0 | field.setAdditionalDisplayPropertyName(personObjectPropertyName + ".name"); |
66 | |
} |
67 | |
|
68 | 0 | AttributeQuery attributeQuery = new AttributeQuery(); |
69 | 0 | MethodInvokerConfig methodInvokerConfig = new MethodInvokerConfig(); |
70 | 0 | PersonService personService = KimApiServiceLocator.getPersonService(); |
71 | 0 | methodInvokerConfig.setTargetObject(personService); |
72 | 0 | attributeQuery.setQueryMethodInvokerConfig(methodInvokerConfig); |
73 | 0 | attributeQuery.setQueryMethodToCall("getPersonByPrincipalName"); |
74 | 0 | attributeQuery.getQueryMethodArgumentFieldList().add(field.getPropertyName()); |
75 | 0 | attributeQuery.getReturnFieldMapping().put("principalId", principalIdPropertyName); |
76 | |
|
77 | 0 | if (StringUtils.isNotBlank(personNamePropertyName)) { |
78 | 0 | attributeQuery.getReturnFieldMapping().put("name", personNamePropertyName); |
79 | |
} |
80 | |
else { |
81 | 0 | attributeQuery.getReturnFieldMapping().put("name", personObjectPropertyName + ".name"); |
82 | |
} |
83 | |
|
84 | 0 | field.setFieldAttributeQuery(attributeQuery); |
85 | |
|
86 | 0 | QuickFinder quickFinder = field.getFieldLookup(); |
87 | |
|
88 | 0 | if (quickFinder.isRender()) { |
89 | 0 | if (StringUtils.isBlank(quickFinder.getDataObjectClassName())) { |
90 | 0 | quickFinder.setDataObjectClassName("org.kuali.rice.kim.bo.Person"); |
91 | |
} |
92 | |
|
93 | 0 | if (quickFinder.getFieldConversions().isEmpty()) { |
94 | 0 | quickFinder.getFieldConversions().put("principalId", principalIdPropertyName); |
95 | |
|
96 | 0 | if (StringUtils.isNotBlank(personNamePropertyName)) { |
97 | 0 | quickFinder.getFieldConversions().put("name", personNamePropertyName); |
98 | |
} |
99 | |
else { |
100 | 0 | quickFinder.getFieldConversions().put("name", personObjectPropertyName + ".name"); |
101 | |
} |
102 | |
|
103 | 0 | quickFinder.getFieldConversions().put("principalName", field.getPropertyName()); |
104 | |
} |
105 | |
} |
106 | |
} |
107 | 0 | } |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public String getPrincipalIdPropertyName() { |
115 | 0 | return principalIdPropertyName; |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
public void setPrincipalIdPropertyName(String principalIdPropertyName) { |
124 | 0 | this.principalIdPropertyName = principalIdPropertyName; |
125 | 0 | } |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
public String getPersonNamePropertyName() { |
133 | 0 | return personNamePropertyName; |
134 | |
} |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
public void setPersonNamePropertyName(String personNamePropertyName) { |
142 | 0 | this.personNamePropertyName = personNamePropertyName; |
143 | 0 | } |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
public String getPersonObjectPropertyName() { |
151 | 0 | return personObjectPropertyName; |
152 | |
} |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public void setPersonObjectPropertyName(String personObjectPropertyName) { |
160 | 0 | this.personObjectPropertyName = personObjectPropertyName; |
161 | 0 | } |
162 | |
} |