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.Enumeration;
19 import java.util.HashSet;
20 import java.util.Map;
21 import java.util.Set;
22
23 import javax.servlet.http.HttpServletRequest;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.kuali.ole.sys.OLEConstants;
27 import org.kuali.rice.kns.lookup.LookupUtils;
28 import org.kuali.rice.kns.web.struts.form.KualiTableRenderFormMetadata;
29 import org.kuali.rice.kns.web.struts.form.LookupForm;
30
31
32
33
34
35 public class BalanceInquiryLookupResults extends LookupForm implements LookupResultsSelectable {
36 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BalanceInquiryLookupResults.class);
37
38 private KualiTableRenderFormMetadata tableMetadata;
39
40 private String lookupResultsSequenceNumber;
41
42
43
44
45 private int resultsActualSize;
46
47
48
49
50 private int resultsLimitedSize;
51
52
53
54
55
56 private String previouslySortedColumnIndex;
57
58
59
60
61 private int columnToSortIndex;
62
63
64
65
66
67
68 private String lookedUpCollectionName;
69
70
71
72
73 private Set<String> previouslySelectedObjectIdSet;
74
75
76
77 private Set<String> displayedObjectIdSet;
78
79
80
81 private Set<String> selectedObjectIdSet;
82
83
84
85
86 private Map<String, String> compositeObjectIdMap;
87
88 public BalanceInquiryLookupResults() {
89 tableMetadata = new KualiTableRenderFormMetadata();
90 }
91
92 protected String getMethodToCall(HttpServletRequest request) {
93 return request.getParameter(OLEConstants.DISPATCH_REQUEST_PARAMETER);
94 }
95
96
97
98
99
100
101 public void populate(HttpServletRequest request) {
102 super.populate(request);
103
104 if (StringUtils.isNotBlank(request.getParameter(OLEConstants.TableRenderConstants.VIEWED_PAGE_NUMBER))) {
105 setViewedPageNumber(Integer.parseInt(request.getParameter(OLEConstants.TableRenderConstants.VIEWED_PAGE_NUMBER)));
106 }
107 else {
108 setViewedPageNumber(0);
109 }
110
111 if (OLEConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD.equals(getMethodToCall(request))) {
112
113 setSwitchToPageNumber(-1);
114
115
116 String paramPrefix = OLEConstants.DISPATCH_REQUEST_PARAMETER + "." + OLEConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD + ".";
117 for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) {
118 String parameterName = (String) i.nextElement();
119 if (parameterName.startsWith(paramPrefix) && parameterName.endsWith(".x")) {
120 String switchToPageNumberStr = StringUtils.substringBetween(parameterName, paramPrefix, ".");
121 setSwitchToPageNumber(Integer.parseInt(switchToPageNumberStr));
122 }
123 }
124 if (getSwitchToPageNumber() == -1) {
125 throw new RuntimeException("Couldn't find page number");
126 }
127 }
128
129 if (OLEConstants.TableRenderConstants.SORT_METHOD.equals(getMethodToCall(request))) {
130 setColumnToSortIndex(-1);
131
132
133 String paramPrefix = OLEConstants.DISPATCH_REQUEST_PARAMETER + "." + OLEConstants.TableRenderConstants.SORT_METHOD + ".";
134 for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) {
135 String parameterName = (String) i.nextElement();
136 if (parameterName.startsWith(paramPrefix) && parameterName.endsWith(".x")) {
137 String columnToSortStr = StringUtils.substringBetween(parameterName, paramPrefix, ".");
138 setColumnToSortIndex(Integer.parseInt(columnToSortStr));
139 }
140 }
141 if (getColumnToSortIndex() == -1) {
142 throw new RuntimeException("Couldn't find column to sort");
143 }
144 }
145
146 setPreviouslySelectedObjectIdSet(parsePreviouslySelectedObjectIds(request));
147 setSelectedObjectIdSet(parseSelectedObjectIdSet(request));
148 setDisplayedObjectIdSet(parseDisplayedObjectIdSet(request));
149
150 setSearchUsingOnlyPrimaryKeyValues(parseSearchUsingOnlyPrimaryKeyValues(request));
151 if (isSearchUsingOnlyPrimaryKeyValues()) {
152 setPrimaryKeyFieldLabels(getLookupable().getPrimaryKeyFieldLabels());
153 }
154 }
155
156
157
158
159
160
161 public String getCompositeSelectedObjectIds() {
162 return LookupUtils.convertSetOfObjectIdsToString(getCompositeObjectIdMap().keySet());
163 }
164
165
166
167
168
169
170
171 protected Set<String> parsePreviouslySelectedObjectIds(HttpServletRequest request) {
172 String previouslySelectedObjectIds = request.getParameter(OLEConstants.MULTIPLE_VALUE_LOOKUP_PREVIOUSLY_SELECTED_OBJ_IDS_PARAM);
173 return LookupUtils.convertStringOfObjectIdsToSet(previouslySelectedObjectIds);
174 }
175
176
177
178
179
180
181
182 protected Set<String> parseSelectedObjectIdSet(HttpServletRequest request) {
183 Set<String> set = new HashSet<String>();
184
185 Enumeration paramNames = request.getParameterNames();
186 while (paramNames.hasMoreElements()) {
187 String paramName = (String) paramNames.nextElement();
188 if (paramName.startsWith(OLEConstants.MULTIPLE_VALUE_LOOKUP_SELECTED_OBJ_ID_PARAM_PREFIX) && StringUtils.isNotBlank(request.getParameter(paramName))) {
189 set.add(StringUtils.substringAfter(paramName, OLEConstants.MULTIPLE_VALUE_LOOKUP_SELECTED_OBJ_ID_PARAM_PREFIX));
190 }
191 }
192 return set;
193 }
194
195
196
197
198
199
200
201 protected Set<String> parseDisplayedObjectIdSet(HttpServletRequest request) {
202 Set<String> set = new HashSet<String>();
203
204 Enumeration paramNames = request.getParameterNames();
205 while (paramNames.hasMoreElements()) {
206 String paramName = (String) paramNames.nextElement();
207 if (paramName.startsWith(OLEConstants.MULTIPLE_VALUE_LOOKUP_DISPLAYED_OBJ_ID_PARAM_PREFIX) && StringUtils.isNotBlank(request.getParameter(paramName))) {
208 set.add(StringUtils.substringAfter(paramName, OLEConstants.MULTIPLE_VALUE_LOOKUP_DISPLAYED_OBJ_ID_PARAM_PREFIX));
209 }
210 }
211 return set;
212 }
213
214
215
216
217
218
219
220
221
222 protected boolean parseSearchUsingOnlyPrimaryKeyValues(HttpServletRequest request) {
223
224 String paramPrefix = OLEConstants.DISPATCH_REQUEST_PARAMETER + "." + getMethodToCall(request) + ".";
225 for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) {
226 String parameterName = (String) i.nextElement();
227 if (parameterName.startsWith(paramPrefix) && parameterName.endsWith(".x")) {
228 return parseSearchUsingOnlyPrimaryKeyValues(parameterName);
229 }
230 }
231
232 return false;
233 }
234
235
236
237
238
239
240
241
242 protected boolean parseSearchUsingOnlyPrimaryKeyValues(String methodToCallParam) {
243 String searchUsingOnlyPrimaryKeyValuesStr = StringUtils.substringBetween(methodToCallParam, OLEConstants.METHOD_TO_CALL_PARM12_LEFT_DEL, OLEConstants.METHOD_TO_CALL_PARM12_RIGHT_DEL);
244 if (StringUtils.isBlank(searchUsingOnlyPrimaryKeyValuesStr)) {
245 return false;
246 }
247 return Boolean.parseBoolean(searchUsingOnlyPrimaryKeyValuesStr);
248 }
249
250
251
252
253 public int getViewedPageNumber() {
254 return tableMetadata.getViewedPageNumber();
255 }
256
257
258
259
260 public void setViewedPageNumber(int pageNumberBeingViewedForMultivalueLookups) {
261 tableMetadata.setViewedPageNumber(pageNumberBeingViewedForMultivalueLookups);
262 }
263
264
265
266
267 public String getLookupResultsSequenceNumber() {
268 return lookupResultsSequenceNumber;
269 }
270
271
272
273
274 public void setLookupResultsSequenceNumber(String lookupResultSequenceNumber) {
275 this.lookupResultsSequenceNumber = lookupResultSequenceNumber;
276 }
277
278
279
280
281 public int getTotalNumberOfPages() {
282 return tableMetadata.getTotalNumberOfPages();
283 }
284
285
286
287
288 public void setTotalNumberOfPages(int totalNumberOfPages) {
289 tableMetadata.setTotalNumberOfPages(totalNumberOfPages);
290 }
291
292
293
294
295 public int getFirstRowIndex() {
296 return tableMetadata.getFirstRowIndex();
297 }
298
299
300
301
302 public void setFirstRowIndex(int firstRowIndex) {
303 tableMetadata.setFirstRowIndex(firstRowIndex);
304 }
305
306
307
308
309 public int getLastRowIndex() {
310 return tableMetadata.getLastRowIndex();
311 }
312
313
314
315
316 public void setLastRowIndex(int lastRowIndex) {
317 tableMetadata.setLastRowIndex(lastRowIndex);
318 }
319
320
321
322
323 public int getSwitchToPageNumber() {
324 return tableMetadata.getSwitchToPageNumber();
325 }
326
327
328
329
330
331
332 protected void setSwitchToPageNumber(int switchToPageNumber) {
333 tableMetadata.setSwitchToPageNumber(switchToPageNumber);
334 }
335
336
337
338
339 public Set<String> getPreviouslySelectedObjectIdSet() {
340 return previouslySelectedObjectIdSet;
341 }
342
343
344
345
346 public void setPreviouslySelectedObjectIdSet(Set<String> previouslySelectedObjectIds) {
347 this.previouslySelectedObjectIdSet = previouslySelectedObjectIds;
348 }
349
350
351
352
353 public Set<String> getSelectedObjectIdSet() {
354 return selectedObjectIdSet;
355 }
356
357
358
359
360 public void setSelectedObjectIdSet(Set<String> selectedObjectIdSet) {
361 this.selectedObjectIdSet = selectedObjectIdSet;
362 }
363
364
365
366
367 public Set<String> getDisplayedObjectIdSet() {
368 return displayedObjectIdSet;
369 }
370
371
372
373
374 public void setDisplayedObjectIdSet(Set<String> displayedObjectIdSet) {
375 this.displayedObjectIdSet = displayedObjectIdSet;
376 }
377
378
379
380
381 public Map<String, String> getCompositeObjectIdMap() {
382 return compositeObjectIdMap;
383 }
384
385
386
387
388 public void setCompositeObjectIdMap(Map<String, String> compositeObjectIdMap) {
389 this.compositeObjectIdMap = compositeObjectIdMap;
390 }
391
392
393
394
395 public int getColumnToSortIndex() {
396 return columnToSortIndex;
397 }
398
399
400
401
402 public void setColumnToSortIndex(int columnToSortIndex) {
403 this.columnToSortIndex = columnToSortIndex;
404 }
405
406
407
408
409 public String getPreviouslySortedColumnIndex() {
410 return previouslySortedColumnIndex;
411 }
412
413
414
415
416 public void setPreviouslySortedColumnIndex(String previouslySortedColumnIndex) {
417 this.previouslySortedColumnIndex = previouslySortedColumnIndex;
418 }
419
420
421
422
423
424
425
426
427 public String getLookedUpCollectionName() {
428 return lookedUpCollectionName;
429 }
430
431
432
433
434
435
436
437
438 public void setLookedUpCollectionName(String lookedUpCollectionName) {
439 this.lookedUpCollectionName = lookedUpCollectionName;
440 }
441
442
443
444
445 public int getResultsActualSize() {
446 return resultsActualSize;
447 }
448
449
450
451
452 public void setResultsActualSize(int resultsActualSize) {
453 this.resultsActualSize = resultsActualSize;
454 }
455
456
457
458
459 public int getResultsLimitedSize() {
460 return resultsLimitedSize;
461 }
462
463
464
465
466 public void setResultsLimitedSize(int resultsLimitedSize) {
467 this.resultsLimitedSize = resultsLimitedSize;
468 }
469
470
471
472
473 public void jumpToFirstPage(int listSize, int maxRowsPerPage) {
474 tableMetadata.jumpToFirstPage(listSize, maxRowsPerPage);
475 }
476
477
478
479
480 public void jumpToLastPage(int listSize, int maxRowsPerPage) {
481 tableMetadata.jumpToLastPage(listSize, maxRowsPerPage);
482 }
483
484
485
486
487 public void jumpToPage(int pageNumber, int listSize, int maxRowsPerPage) {
488 tableMetadata.jumpToPage(pageNumber, listSize, maxRowsPerPage);
489 }
490
491 }