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