1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.kuali.rice.kns.uif.widget; |
12 | |
|
13 | |
import java.util.HashMap; |
14 | |
import java.util.List; |
15 | |
import java.util.Map; |
16 | |
|
17 | |
import org.apache.commons.lang.StringUtils; |
18 | |
import org.kuali.rice.kns.bo.BusinessObjectRelationship; |
19 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
20 | |
import org.kuali.rice.kns.uif.UifParameters; |
21 | |
import org.kuali.rice.kns.uif.container.View; |
22 | |
import org.kuali.rice.kns.uif.core.Component; |
23 | |
import org.kuali.rice.kns.uif.field.ActionField; |
24 | |
import org.kuali.rice.kns.uif.field.AttributeField; |
25 | |
import org.kuali.rice.kns.uif.util.ViewModelUtils; |
26 | |
import org.kuali.rice.kns.util.KNSUtils; |
27 | |
import org.kuali.rice.kns.util.WebUtils; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public class QuickFinder extends WidgetBase { |
35 | |
private static final long serialVersionUID = 3302390972815386785L; |
36 | |
|
37 | |
|
38 | |
private String baseLookupUrl; |
39 | |
private String dataObjectClassName; |
40 | |
private String viewName; |
41 | |
|
42 | |
private String referencesToRefresh; |
43 | |
|
44 | |
private Map<String, String> fieldConversions; |
45 | |
private Map<String, String> lookupParameters; |
46 | |
|
47 | |
|
48 | |
private String readOnlySearchFields; |
49 | |
|
50 | |
private Boolean hideReturnLink; |
51 | |
private Boolean supressActions; |
52 | |
private Boolean autoSearch; |
53 | |
private Boolean lookupCriteriaEnabled; |
54 | |
private Boolean supplementalActionsEnabled; |
55 | |
private Boolean disableSearchButtons; |
56 | |
private Boolean headerBarEnabled; |
57 | |
private Boolean showMaintenanceLinks; |
58 | |
|
59 | |
private ActionField quickfinderActionField; |
60 | |
|
61 | |
public QuickFinder() { |
62 | 0 | super(); |
63 | |
|
64 | 0 | fieldConversions = new HashMap<String, String>(); |
65 | 0 | lookupParameters = new HashMap<String, String>(); |
66 | 0 | } |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
@Override |
73 | |
public void performFinalize(View view, Object model, Component parent) { |
74 | 0 | super.performFinalize(view, model, parent); |
75 | |
|
76 | 0 | if (!isRender()) { |
77 | 0 | return; |
78 | |
} |
79 | |
|
80 | 0 | AttributeField field = (AttributeField) parent; |
81 | |
|
82 | |
|
83 | |
|
84 | 0 | if (StringUtils.isBlank(dataObjectClassName)) { |
85 | 0 | BusinessObjectRelationship relationship = getRelationshipForField(view, model, field); |
86 | |
|
87 | |
|
88 | 0 | if (relationship == null) { |
89 | 0 | setRender(false); |
90 | 0 | return; |
91 | |
} |
92 | |
|
93 | 0 | dataObjectClassName = relationship.getRelatedClass().getName(); |
94 | |
|
95 | 0 | if ((fieldConversions == null) || fieldConversions.isEmpty()) { |
96 | 0 | generateFieldConversions(field, relationship); |
97 | |
} |
98 | |
|
99 | 0 | if ((lookupParameters == null) || lookupParameters.isEmpty()) { |
100 | 0 | generateLookupParameters(field, relationship); |
101 | |
} |
102 | |
} |
103 | |
|
104 | 0 | quickfinderActionField.addActionParameter(UifParameters.BASE_LOOKUP_URL, baseLookupUrl); |
105 | 0 | quickfinderActionField.addActionParameter(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClassName); |
106 | |
|
107 | 0 | if (!fieldConversions.isEmpty()) { |
108 | 0 | quickfinderActionField.addActionParameter(UifParameters.CONVERSION_FIELDS, |
109 | |
WebUtils.buildMapParameterString(fieldConversions)); |
110 | |
} |
111 | |
|
112 | 0 | if (!lookupParameters.isEmpty()) { |
113 | 0 | quickfinderActionField.addActionParameter(UifParameters.LOOKUP_PARAMETERS, |
114 | |
WebUtils.buildMapParameterString(lookupParameters)); |
115 | |
} |
116 | |
|
117 | 0 | addActionParameterIfNotNull(UifParameters.VIEW_NAME, viewName); |
118 | 0 | addActionParameterIfNotNull(UifParameters.READ_ONLY_FIELDS, readOnlySearchFields); |
119 | 0 | addActionParameterIfNotNull(UifParameters.HIDE_RETURN_LINK, hideReturnLink); |
120 | 0 | addActionParameterIfNotNull(UifParameters.SUPRESS_ACTIONS, supressActions); |
121 | 0 | addActionParameterIfNotNull(UifParameters.REFERENCES_TO_REFRESH, referencesToRefresh); |
122 | 0 | addActionParameterIfNotNull(UifParameters.AUTO_SEARCH, autoSearch); |
123 | 0 | addActionParameterIfNotNull(UifParameters.LOOKUP_CRITERIA_ENABLED, lookupCriteriaEnabled); |
124 | 0 | addActionParameterIfNotNull(UifParameters.SUPPLEMENTAL_ACTIONS_ENABLED, supplementalActionsEnabled); |
125 | 0 | addActionParameterIfNotNull(UifParameters.DISABLE_SEARCH_BUTTONS, disableSearchButtons); |
126 | 0 | addActionParameterIfNotNull(UifParameters.HEADER_BAR_ENABLED, headerBarEnabled); |
127 | 0 | addActionParameterIfNotNull(UifParameters.SHOW_MAINTENANCE_LINKS, showMaintenanceLinks); |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | 0 | } |
133 | |
|
134 | |
protected void addActionParameterIfNotNull(String parameterName, Object parameterValue) { |
135 | 0 | if ((parameterValue != null) && StringUtils.isNotBlank(parameterValue.toString())) { |
136 | 0 | quickfinderActionField.addActionParameter(parameterName, parameterValue.toString()); |
137 | |
} |
138 | 0 | } |
139 | |
|
140 | |
protected BusinessObjectRelationship getRelationshipForField(View view, Object model, AttributeField field) { |
141 | 0 | String propertyName = field.getBindingInfo().getBindingName(); |
142 | |
|
143 | |
|
144 | 0 | Object parentObject = ViewModelUtils.getParentObjectForMetadata(view, model, field); |
145 | 0 | Class<?> parentObjectClass = null; |
146 | 0 | if (parentObject != null) { |
147 | 0 | parentObjectClass = parentObject.getClass(); |
148 | |
} |
149 | |
|
150 | |
|
151 | 0 | return KNSServiceLocatorWeb.getDataObjectMetaDataService().getDataObjectRelationship(parentObject, |
152 | |
parentObjectClass, propertyName, "", true, true, false); |
153 | |
} |
154 | |
|
155 | |
protected void generateFieldConversions(AttributeField field, BusinessObjectRelationship relationship) { |
156 | 0 | String parentObjectPath = ViewModelUtils.getParentObjectPath(field); |
157 | |
|
158 | 0 | fieldConversions = new HashMap<String, String>(); |
159 | 0 | for (Map.Entry<String, String> entry : relationship.getParentToChildReferences().entrySet()) { |
160 | 0 | String fromField = entry.getValue(); |
161 | 0 | String toField = entry.getKey(); |
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | 0 | if (StringUtils.isNotBlank(parentObjectPath)) { |
168 | 0 | if (field.getBindingInfo().isBindToMap()) { |
169 | 0 | toField = parentObjectPath + "['" + toField + "']"; |
170 | |
} |
171 | |
else { |
172 | 0 | toField = parentObjectPath + "." + toField; |
173 | |
} |
174 | |
} |
175 | |
|
176 | 0 | fieldConversions.put(fromField, toField); |
177 | 0 | } |
178 | 0 | } |
179 | |
|
180 | |
protected void generateLookupParameters(AttributeField field, BusinessObjectRelationship relationship) { |
181 | 0 | String parentObjectPath = ViewModelUtils.getParentObjectPath(field); |
182 | |
|
183 | 0 | lookupParameters = new HashMap<String, String>(); |
184 | 0 | for (Map.Entry<String, String> entry : relationship.getParentToChildReferences().entrySet()) { |
185 | 0 | String fromField = entry.getKey(); |
186 | 0 | String toField = entry.getValue(); |
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | 0 | if (relationship.getUserVisibleIdentifierKey() == null |
193 | |
|| relationship.getUserVisibleIdentifierKey().equals(fromField)) { |
194 | 0 | if (StringUtils.isNotBlank(parentObjectPath)) { |
195 | 0 | if (field.getBindingInfo().isBindToMap()) { |
196 | 0 | fromField = parentObjectPath + "['" + fromField + "']"; |
197 | |
} |
198 | |
else { |
199 | 0 | fromField = parentObjectPath + "." + fromField; |
200 | |
} |
201 | |
} |
202 | |
|
203 | 0 | lookupParameters.put(fromField, toField); |
204 | |
} |
205 | 0 | } |
206 | 0 | } |
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
@Override |
212 | |
public List<Component> getNestedComponents() { |
213 | 0 | List<Component> components = super.getNestedComponents(); |
214 | |
|
215 | 0 | components.add(quickfinderActionField); |
216 | |
|
217 | 0 | return components; |
218 | |
} |
219 | |
|
220 | |
public String getBaseLookupUrl() { |
221 | 0 | return this.baseLookupUrl; |
222 | |
} |
223 | |
|
224 | |
public void setBaseLookupUrl(String baseLookupUrl) { |
225 | 0 | this.baseLookupUrl = baseLookupUrl; |
226 | 0 | } |
227 | |
|
228 | |
public String getDataObjectClassName() { |
229 | 0 | return this.dataObjectClassName; |
230 | |
} |
231 | |
|
232 | |
public void setDataObjectClassName(String dataObjectClassName) { |
233 | 0 | this.dataObjectClassName = dataObjectClassName; |
234 | 0 | } |
235 | |
|
236 | |
public String getViewName() { |
237 | 0 | return this.viewName; |
238 | |
} |
239 | |
|
240 | |
public void setViewName(String viewName) { |
241 | 0 | this.viewName = viewName; |
242 | 0 | } |
243 | |
|
244 | |
public String getReferencesToRefresh() { |
245 | 0 | return this.referencesToRefresh; |
246 | |
} |
247 | |
|
248 | |
public void setReferencesToRefresh(String referencesToRefresh) { |
249 | 0 | this.referencesToRefresh = referencesToRefresh; |
250 | 0 | } |
251 | |
|
252 | |
public Map<String, String> getFieldConversions() { |
253 | 0 | return this.fieldConversions; |
254 | |
} |
255 | |
|
256 | |
public void setFieldConversions(Map<String, String> fieldConversions) { |
257 | 0 | this.fieldConversions = fieldConversions; |
258 | 0 | } |
259 | |
|
260 | |
public Map<String, String> getLookupParameters() { |
261 | 0 | return this.lookupParameters; |
262 | |
} |
263 | |
|
264 | |
public void setLookupParameters(Map<String, String> lookupParameters) { |
265 | 0 | this.lookupParameters = lookupParameters; |
266 | 0 | } |
267 | |
|
268 | |
public String getReadOnlySearchFields() { |
269 | 0 | return this.readOnlySearchFields; |
270 | |
} |
271 | |
|
272 | |
public void setReadOnlySearchFields(String readOnlySearchFields) { |
273 | 0 | this.readOnlySearchFields = readOnlySearchFields; |
274 | 0 | } |
275 | |
|
276 | |
public Boolean getHideReturnLink() { |
277 | 0 | return this.hideReturnLink; |
278 | |
} |
279 | |
|
280 | |
public void setHideReturnLink(Boolean hideReturnLink) { |
281 | 0 | this.hideReturnLink = hideReturnLink; |
282 | 0 | } |
283 | |
|
284 | |
public Boolean getSupressActions() { |
285 | 0 | return this.supressActions; |
286 | |
} |
287 | |
|
288 | |
public void setSupressActions(Boolean supressActions) { |
289 | 0 | this.supressActions = supressActions; |
290 | 0 | } |
291 | |
|
292 | |
public Boolean getAutoSearch() { |
293 | 0 | return this.autoSearch; |
294 | |
} |
295 | |
|
296 | |
public void setAutoSearch(Boolean autoSearch) { |
297 | 0 | this.autoSearch = autoSearch; |
298 | 0 | } |
299 | |
|
300 | |
public Boolean getLookupCriteriaEnabled() { |
301 | 0 | return this.lookupCriteriaEnabled; |
302 | |
} |
303 | |
|
304 | |
public void setLookupCriteriaEnabled(Boolean lookupCriteriaEnabled) { |
305 | 0 | this.lookupCriteriaEnabled = lookupCriteriaEnabled; |
306 | 0 | } |
307 | |
|
308 | |
public Boolean getSupplementalActionsEnabled() { |
309 | 0 | return this.supplementalActionsEnabled; |
310 | |
} |
311 | |
|
312 | |
public void setSupplementalActionsEnabled(Boolean supplementalActionsEnabled) { |
313 | 0 | this.supplementalActionsEnabled = supplementalActionsEnabled; |
314 | 0 | } |
315 | |
|
316 | |
public Boolean getDisableSearchButtons() { |
317 | 0 | return this.disableSearchButtons; |
318 | |
} |
319 | |
|
320 | |
public void setDisableSearchButtons(Boolean disableSearchButtons) { |
321 | 0 | this.disableSearchButtons = disableSearchButtons; |
322 | 0 | } |
323 | |
|
324 | |
public Boolean getHeaderBarEnabled() { |
325 | 0 | return this.headerBarEnabled; |
326 | |
} |
327 | |
|
328 | |
public void setHeaderBarEnabled(Boolean headerBarEnabled) { |
329 | 0 | this.headerBarEnabled = headerBarEnabled; |
330 | 0 | } |
331 | |
|
332 | |
public Boolean getShowMaintenanceLinks() { |
333 | 0 | return this.showMaintenanceLinks; |
334 | |
} |
335 | |
|
336 | |
public void setShowMaintenanceLinks(Boolean showMaintenanceLinks) { |
337 | 0 | this.showMaintenanceLinks = showMaintenanceLinks; |
338 | 0 | } |
339 | |
|
340 | |
public ActionField getQuickfinderActionField() { |
341 | 0 | return this.quickfinderActionField; |
342 | |
} |
343 | |
|
344 | |
public void setQuickfinderActionField(ActionField quickfinderActionField) { |
345 | 0 | this.quickfinderActionField = quickfinderActionField; |
346 | 0 | } |
347 | |
|
348 | |
} |