1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.web.struts;
17
18 import java.util.HashMap;
19 import java.util.Iterator;
20 import java.util.Map;
21 import java.util.StringTokenizer;
22
23 import javax.servlet.http.HttpServletRequest;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.kuali.ole.gl.GeneralLedgerConstants;
27 import org.kuali.ole.gl.businessobject.Entry;
28 import org.kuali.ole.sys.OLEConstants;
29 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
30 import org.kuali.ole.sys.businessobject.lookup.LookupableSpringContext;
31 import org.kuali.ole.sys.context.SpringContext;
32 import org.kuali.rice.kns.lookup.Lookupable;
33 import org.kuali.rice.kns.service.BusinessObjectDictionaryService;
34 import org.kuali.rice.kns.web.struts.form.LookupForm;
35 import org.kuali.rice.kns.web.ui.Field;
36 import org.kuali.rice.kns.web.ui.Row;
37 import org.kuali.rice.krad.bo.BusinessObject;
38
39
40
41
42 public class BalanceInquiryForm extends LookupForm {
43 private static final long serialVersionUID = 1L;
44
45 private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(BalanceInquiryForm.class);
46
47 private String formKey;
48 private String backLocation;
49 private Map fields;
50 private String lookupableImplServiceName;
51 private String conversionFields;
52 private Map fieldConversions;
53 private String businessObjectClassName;
54 private Lookupable lookupable;
55 private Lookupable pendingEntryLookupable;
56 private boolean hideReturnLink = false;
57
58
59
60
61
62
63
64
65
66
67
68 public void populate(HttpServletRequest request) {
69 super.populate(request);
70
71 try {
72 if (StringUtils.isBlank(request.getParameter(OLEConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME)) && StringUtils.isBlank(getLookupableImplServiceName())) {
73
74
75 String localBusinessObjectClassName = request.getParameter(OLEConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE);
76 setBusinessObjectClassName(localBusinessObjectClassName);
77
78 if (StringUtils.isBlank(localBusinessObjectClassName)) {
79 LOG.error("Business object class not passed to lookup.");
80 throw new RuntimeException("Business object class not passed to lookup.");
81 }
82
83
84 String lookupImplID = SpringContext.getBean(BusinessObjectDictionaryService.class).getLookupableID(Class.forName(localBusinessObjectClassName));
85 if (lookupImplID == null) {
86 lookupImplID = "lookupable";
87 }
88
89 setLookupableImplServiceName(lookupImplID);
90 }
91 setLookupable(LookupableSpringContext.getLookupable(getLookupableImplServiceName()));
92
93 if (getLookupable() == null) {
94 LOG.error("Lookup impl not found for lookup impl name " + getLookupableImplServiceName());
95 throw new RuntimeException("Lookup impl not found for lookup impl name " + getLookupableImplServiceName());
96 }
97
98
99 if (Entry.class.getName().equals(getBusinessObjectClassName())) {
100 setPendingEntryLookupable(LookupableSpringContext.getLookupable(GeneralLedgerConstants.LookupableBeanKeys.PENDING_ENTRY));
101 }
102
103 if (request.getParameter(OLEConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME) != null) {
104 setLookupableImplServiceName(request.getParameter(OLEConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME));
105 }
106
107
108 if (request.getAttribute(OLEConstants.DOC_FORM_KEY) != null && StringUtils.isBlank(this.getFormKey())) {
109 setFormKey((String) request.getAttribute(OLEConstants.DOC_FORM_KEY));
110 }
111 else if (request.getParameter(OLEConstants.DOC_FORM_KEY) != null && StringUtils.isBlank(this.getFormKey())) {
112 setFormKey(request.getParameter(OLEConstants.DOC_FORM_KEY));
113 }
114
115 if (request.getParameter(OLEConstants.RETURN_LOCATION_PARAMETER) != null) {
116 setBackLocation(request.getParameter(OLEConstants.RETURN_LOCATION_PARAMETER));
117 }
118 if (request.getParameter(OLEConstants.CONVERSION_FIELDS_PARAMETER) != null) {
119 setConversionFields(request.getParameter(OLEConstants.CONVERSION_FIELDS_PARAMETER));
120 }
121
122
123 getLookupable().setBusinessObjectClass((Class<? extends BusinessObject>)Class.forName(getBusinessObjectClassName()));
124 if (null != getPendingEntryLookupable()) {
125 getPendingEntryLookupable().setBusinessObjectClass(GeneralLedgerPendingEntry.class);
126 }
127
128 Map fieldValues = new HashMap();
129 Map formFields = getFields();
130 Class boClass = Class.forName(getBusinessObjectClassName());
131 for (Iterator iter = getLookupable().getRows().iterator(); iter.hasNext();) {
132 Row row = (Row) iter.next();
133
134 for (Iterator iterator = row.getFields().iterator(); iterator.hasNext();) {
135 Field field = (Field) iterator.next();
136
137
138 if (formFields != null && formFields.containsKey(field.getPropertyName())) {
139 field.setPropertyValue(formFields.get(field.getPropertyName()));
140 }
141
142
143 if (request.getParameter(field.getPropertyName()) != null) {
144 field.setPropertyValue(request.getParameter(field.getPropertyName()));
145 }
146
147
148 field.setPropertyValue(org.kuali.rice.krad.lookup.LookupUtils.forceUppercase(boClass, field.getPropertyName(), field.getPropertyValue()));
149
150 fieldValues.put(field.getPropertyName(), field.getPropertyValue());
151 }
152 }
153 if (getLookupable().checkForAdditionalFields(fieldValues)) {
154 for (Iterator iter = getLookupable().getRows().iterator(); iter.hasNext();) {
155 Row row = (Row) iter.next();
156
157 for (Iterator iterator = row.getFields().iterator(); iterator.hasNext();) {
158 Field field = (Field) iterator.next();
159
160
161 if (formFields != null && formFields.containsKey(field.getPropertyName())) {
162 field.setPropertyValue(formFields.get(field.getPropertyName()));
163 }
164
165
166 if (request.getParameter(field.getPropertyName()) != null) {
167 field.setPropertyValue(request.getParameter(field.getPropertyName()));
168 }
169 fieldValues.put(field.getPropertyName(), field.getPropertyValue());
170 }
171 }
172 }
173 fieldValues.put(OLEConstants.DOC_FORM_KEY, this.getFormKey());
174 fieldValues.put(OLEConstants.BACK_LOCATION, this.getBackLocation());
175
176 this.setFields(fieldValues);
177
178 Map fieldConversionMap = new HashMap();
179 if (StringUtils.isNotEmpty(this.getConversionFields())) {
180 if (this.getConversionFields().indexOf(",") > 0) {
181 StringTokenizer token = new StringTokenizer(this.getConversionFields(), ",");
182 while (token.hasMoreTokens()) {
183 String element = token.nextToken();
184 fieldConversionMap.put(element.substring(0, element.indexOf(":")), element.substring(element.indexOf(":") + 1));
185 }
186 }
187 else {
188 fieldConversionMap.put(this.getConversionFields().substring(0, this.getConversionFields().indexOf(":")), this.getConversionFields().substring(this.getConversionFields().indexOf(":") + 1));
189 }
190 }
191 setFieldConversions(fieldConversionMap);
192 getLookupable().setFieldConversions(fieldConversionMap);
193 if (null != getPendingEntryLookupable()) {
194 getPendingEntryLookupable().setFieldConversions(fieldConversionMap);
195 }
196 }
197 catch (ClassNotFoundException e) {
198 LOG.error("Business Object class " + getBusinessObjectClassName() + " not found");
199 throw new RuntimeException("Business Object class " + getBusinessObjectClassName() + " not found", e);
200 }
201 }
202
203
204
205
206 public String getLookupableImplServiceName() {
207 return lookupableImplServiceName;
208 }
209
210
211
212
213 public void setLookupableImplServiceName(String lookupableImplServiceName) {
214 this.lookupableImplServiceName = lookupableImplServiceName;
215 }
216
217
218
219
220
221 public String getBackLocation() {
222 return backLocation;
223 }
224
225
226
227
228 public void setBackLocation(String backLocation) {
229 this.backLocation = backLocation;
230 }
231
232
233
234
235 public String getFormKey() {
236 return formKey;
237 }
238
239
240
241
242 public void setFormKey(String formKey) {
243 this.formKey = formKey;
244 }
245
246
247
248
249 public Map getFields() {
250 return fields;
251 }
252
253
254
255
256 public void setFields(Map fields) {
257 this.fields = fields;
258 }
259
260
261
262
263
264 public String getConversionFields() {
265 return conversionFields;
266 }
267
268
269
270
271 public void setConversionFields(String conversionFields) {
272 this.conversionFields = conversionFields;
273 }
274
275
276
277
278 public Map getFieldConversions() {
279 return fieldConversions;
280 }
281
282
283
284
285 public void setFieldConversions(Map fieldConversions) {
286 this.fieldConversions = fieldConversions;
287 }
288
289
290
291
292 public String getBusinessObjectClassName() {
293 return businessObjectClassName;
294 }
295
296
297
298
299 public void setBusinessObjectClassName(String businessObjectClassName) {
300 this.businessObjectClassName = businessObjectClassName;
301 }
302
303
304
305
306
307 public Lookupable getLookupable() {
308 return lookupable;
309 }
310
311
312
313
314
315 public void setLookupable(Lookupable lookupable) {
316 this.lookupable = lookupable;
317 }
318
319
320
321
322
323 public boolean isHideReturnLink() {
324 return hideReturnLink;
325 }
326
327
328
329
330
331 public void setHideReturnLink(boolean hideReturnLink) {
332 this.hideReturnLink = hideReturnLink;
333 }
334
335
336
337
338
339 public void setPendingEntryLookupable(Lookupable pendingEntryLookupable) {
340 this.pendingEntryLookupable = pendingEntryLookupable;
341 }
342
343
344
345
346
347 public Lookupable getPendingEntryLookupable() {
348 return this.pendingEntryLookupable;
349 }
350 }