1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web.struts.form;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.kns.lookup.HtmlData;
20 import org.kuali.rice.kns.lookup.LookupUtils;
21 import org.kuali.rice.kns.util.PagingBannerUtils;
22 import org.kuali.rice.krad.util.KRADConstants;
23
24 import javax.servlet.http.HttpServletRequest;
25 import java.util.Enumeration;
26 import java.util.HashSet;
27 import java.util.Map;
28 import java.util.Set;
29
30
31
32
33
34
35
36
37 @Deprecated
38 public class MultipleValueLookupForm extends LookupForm {
39 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MultipleValueLookupForm.class);
40
41 private KualiTableRenderFormMetadata tableMetadata;
42
43 private String lookupResultsSequenceNumber;
44
45
46
47
48 @Override
49 public void addRequiredNonEditableProperties(){
50 super.addRequiredNonEditableProperties();
51 registerRequiredNonEditableProperty(KRADConstants.LOOKUP_RESULTS_SEQUENCE_NUMBER);
52 registerRequiredNonEditableProperty(KRADConstants.LOOKED_UP_COLLECTION_NAME);
53 }
54
55
56
57
58 private int resultsActualSize;
59
60
61
62
63
64 private int resultsLimitedSize;
65
66
67
68
69
70 private String previouslySortedColumnIndex;
71
72
73
74
75 private int columnToSortIndex;
76
77
78
79
80
81
82 private String lookedUpCollectionName;
83
84
85
86
87 private Set<String> previouslySelectedObjectIdSet;
88
89
90
91 private Set<String> displayedObjectIdSet;
92
93
94
95 private Set<String> selectedObjectIdSet;
96
97
98
99 private Map<String, String> compositeObjectIdMap;
100
101 public MultipleValueLookupForm() {
102 tableMetadata = new KualiTableRenderFormMetadata();
103 setHtmlDataType(HtmlData.INPUT_HTML_DATA_TYPE);
104 }
105
106 @Override
107 public void populate(HttpServletRequest request) {
108 super.populate(request);
109
110 if (StringUtils.isNotBlank(request.getParameter(KRADConstants.TableRenderConstants.VIEWED_PAGE_NUMBER))) {
111 setViewedPageNumber(Integer.parseInt(request.getParameter(KRADConstants.TableRenderConstants.VIEWED_PAGE_NUMBER)));
112 }
113 else {
114 setViewedPageNumber(0);
115 }
116
117 if (KRADConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD.equals(getMethodToCall())) {
118 final String paramPrefix = KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + KRADConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD + ".";
119 setSwitchToPageNumber(PagingBannerUtils.getNumbericalValueAfterPrefix(paramPrefix, request.getParameterNames()));
120 if (getSwitchToPageNumber() == -1) {
121 throw new RuntimeException("Couldn't find page number");
122 }
123 }
124
125 if (KRADConstants.TableRenderConstants.SORT_METHOD.equals(getMethodToCall())) {
126 final String paramPrefix = KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + KRADConstants.TableRenderConstants.SORT_METHOD + ".";
127 setColumnToSortIndex(
128 PagingBannerUtils.getNumbericalValueAfterPrefix(paramPrefix, request.getParameterNames()));
129 if (getColumnToSortIndex() == -1) {
130 throw new RuntimeException("Couldn't find column to sort");
131 }
132 }
133
134 setPreviouslySelectedObjectIdSet(parsePreviouslySelectedObjectIds(request));
135 setSelectedObjectIdSet(parseSelectedObjectIdSet(request));
136 setDisplayedObjectIdSet(parseDisplayedObjectIdSet(request));
137
138 setSearchUsingOnlyPrimaryKeyValues(parseSearchUsingOnlyPrimaryKeyValues(request));
139 if (isSearchUsingOnlyPrimaryKeyValues()) {
140 setPrimaryKeyFieldLabels(getLookupable().getPrimaryKeyFieldLabels());
141 }
142 }
143
144
145
146
147
148
149
150 public String getCompositeSelectedObjectIds() {
151 return LookupUtils.convertSetOfObjectIdsToString(getCompositeObjectIdMap().keySet());
152 }
153
154 protected Set<String> parsePreviouslySelectedObjectIds(HttpServletRequest request) {
155 String previouslySelectedObjectIds = request.getParameter(KRADConstants.MULTIPLE_VALUE_LOOKUP_PREVIOUSLY_SELECTED_OBJ_IDS_PARAM);
156 return LookupUtils.convertStringOfObjectIdsToSet(previouslySelectedObjectIds);
157 }
158
159 protected Set<String> parseSelectedObjectIdSet(HttpServletRequest request) {
160 Set<String> set = new HashSet<String>();
161
162 Enumeration paramNames = request.getParameterNames();
163 while (paramNames.hasMoreElements()) {
164 String paramName = (String) paramNames.nextElement();
165 if (paramName.startsWith(KRADConstants.MULTIPLE_VALUE_LOOKUP_SELECTED_OBJ_ID_PARAM_PREFIX) && StringUtils.isNotBlank(request.getParameter(paramName))) {
166 set.add(StringUtils.substringAfter(paramName, KRADConstants.MULTIPLE_VALUE_LOOKUP_SELECTED_OBJ_ID_PARAM_PREFIX));
167 }
168 }
169 return set;
170 }
171
172 protected Set<String> parseDisplayedObjectIdSet(HttpServletRequest request) {
173 Set<String> set = new HashSet<String>();
174
175 Enumeration paramNames = request.getParameterNames();
176 while (paramNames.hasMoreElements()) {
177 String paramName = (String) paramNames.nextElement();
178 if (paramName.startsWith(KRADConstants.MULTIPLE_VALUE_LOOKUP_DISPLAYED_OBJ_ID_PARAM_PREFIX) && StringUtils.isNotBlank(request.getParameter(paramName))) {
179 set.add(StringUtils.substringAfter(paramName, KRADConstants.MULTIPLE_VALUE_LOOKUP_DISPLAYED_OBJ_ID_PARAM_PREFIX));
180 }
181 }
182 return set;
183 }
184
185
186
187
188
189
190
191
192
193
194 protected boolean parseSearchUsingOnlyPrimaryKeyValues(HttpServletRequest request) {
195
196 String paramPrefix = KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + getMethodToCall() + ".";
197 for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) {
198 String parameterName = (String) i.nextElement();
199 if (parameterName.startsWith(paramPrefix) && parameterName.endsWith(".x")) {
200 return parseSearchUsingOnlyPrimaryKeyValues(parameterName);
201 }
202 }
203
204 return false;
205 }
206
207
208
209
210
211
212
213
214
215
216 protected boolean parseSearchUsingOnlyPrimaryKeyValues(String methodToCallParam) {
217 String searchUsingOnlyPrimaryKeyValuesStr = StringUtils.substringBetween(methodToCallParam, KRADConstants.METHOD_TO_CALL_PARM12_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM12_RIGHT_DEL);
218 if (StringUtils.isBlank(searchUsingOnlyPrimaryKeyValuesStr)) {
219 return false;
220 }
221 return Boolean.parseBoolean(searchUsingOnlyPrimaryKeyValuesStr);
222 }
223
224 public int getViewedPageNumber() {
225 return tableMetadata.getViewedPageNumber();
226 }
227
228 public void setViewedPageNumber(int pageNumberBeingViewedForMultivalueLookups) {
229 tableMetadata.setViewedPageNumber(pageNumberBeingViewedForMultivalueLookups);
230 }
231
232 public String getLookupResultsSequenceNumber() {
233 return lookupResultsSequenceNumber;
234 }
235
236 public void setLookupResultsSequenceNumber(String lookupResultSequenceNumber) {
237 this.lookupResultsSequenceNumber = lookupResultSequenceNumber;
238 }
239
240 public int getTotalNumberOfPages() {
241 return tableMetadata.getTotalNumberOfPages();
242 }
243
244 public void setTotalNumberOfPages(int totalNumberOfPages) {
245 tableMetadata.setTotalNumberOfPages(totalNumberOfPages);
246 }
247
248 public int getFirstRowIndex() {
249 return tableMetadata.getFirstRowIndex();
250 }
251
252 public void setFirstRowIndex(int firstRowIndex) {
253 tableMetadata.setFirstRowIndex(firstRowIndex);
254 }
255
256 public int getLastRowIndex() {
257 return tableMetadata.getLastRowIndex();
258 }
259
260 public void setLastRowIndex(int lastRowIndex) {
261 tableMetadata.setLastRowIndex(lastRowIndex);
262 }
263
264 public int getSwitchToPageNumber() {
265 return tableMetadata.getSwitchToPageNumber();
266 }
267
268 protected void setSwitchToPageNumber(int switchToPageNumber) {
269 tableMetadata.setSwitchToPageNumber(switchToPageNumber);
270 }
271
272 public Set<String> getPreviouslySelectedObjectIdSet() {
273 return previouslySelectedObjectIdSet;
274 }
275
276 public void setPreviouslySelectedObjectIdSet(Set<String> previouslySelectedObjectIds) {
277 this.previouslySelectedObjectIdSet = previouslySelectedObjectIds;
278 }
279
280 public Set<String> getSelectedObjectIdSet() {
281 return selectedObjectIdSet;
282 }
283
284 public void setSelectedObjectIdSet(Set<String> selectedObjectIdSet) {
285 this.selectedObjectIdSet = selectedObjectIdSet;
286 }
287
288 public Set<String> getDisplayedObjectIdSet() {
289 return displayedObjectIdSet;
290 }
291
292 public void setDisplayedObjectIdSet(Set<String> displayedObjectIdSet) {
293 this.displayedObjectIdSet = displayedObjectIdSet;
294 }
295
296 public Map<String, String> getCompositeObjectIdMap() {
297 return compositeObjectIdMap;
298 }
299
300 public void setCompositeObjectIdMap(Map<String, String> compositeObjectIdMap) {
301 this.compositeObjectIdMap = compositeObjectIdMap;
302 }
303
304 public int getColumnToSortIndex() {
305 return columnToSortIndex;
306 }
307
308 public void setColumnToSortIndex(int columnToSortIndex) {
309 this.columnToSortIndex = columnToSortIndex;
310 }
311
312 public String getPreviouslySortedColumnIndex() {
313 return previouslySortedColumnIndex;
314 }
315
316 public void setPreviouslySortedColumnIndex(String previouslySortedColumnIndex) {
317 this.previouslySortedColumnIndex = previouslySortedColumnIndex;
318 }
319
320
321
322
323
324
325
326
327 public String getLookedUpCollectionName() {
328 return lookedUpCollectionName;
329 }
330
331
332
333
334
335
336
337
338 public void setLookedUpCollectionName(String lookedUpCollectionName) {
339 this.lookedUpCollectionName = lookedUpCollectionName;
340 }
341
342 public int getResultsActualSize() {
343 return resultsActualSize;
344 }
345
346 public void setResultsActualSize(int resultsActualSize) {
347 this.resultsActualSize = resultsActualSize;
348 }
349
350 public int getResultsLimitedSize() {
351 return resultsLimitedSize;
352 }
353
354 public void setResultsLimitedSize(int resultsLimitedSize) {
355 this.resultsLimitedSize = resultsLimitedSize;
356 }
357
358 public void jumpToFirstPage(int listSize, int maxRowsPerPage) {
359 tableMetadata.jumpToFirstPage(listSize, maxRowsPerPage);
360 }
361
362 public void jumpToLastPage(int listSize, int maxRowsPerPage) {
363 tableMetadata.jumpToLastPage(listSize, maxRowsPerPage);
364 }
365
366 public void jumpToPage(int pageNumber, int listSize, int maxRowsPerPage) {
367 tableMetadata.jumpToPage(pageNumber, listSize, maxRowsPerPage);
368 }
369 }