1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.web.struts.action; |
17 | |
|
18 | |
import java.io.IOException; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Collection; |
21 | |
import java.util.Collections; |
22 | |
import java.util.HashMap; |
23 | |
import java.util.List; |
24 | |
import java.util.Map; |
25 | |
import java.util.Properties; |
26 | |
import java.util.Set; |
27 | |
|
28 | |
import javax.servlet.ServletException; |
29 | |
import javax.servlet.http.HttpServletRequest; |
30 | |
import javax.servlet.http.HttpServletResponse; |
31 | |
|
32 | |
import org.apache.commons.beanutils.BeanComparator; |
33 | |
import org.apache.commons.lang.StringUtils; |
34 | |
import org.apache.struts.action.ActionForm; |
35 | |
import org.apache.struts.action.ActionForward; |
36 | |
import org.apache.struts.action.ActionMapping; |
37 | |
import org.kuali.rice.core.util.RiceConstants; |
38 | |
import org.kuali.rice.kns.lookup.CollectionIncomplete; |
39 | |
import org.kuali.rice.kns.lookup.LookupResultsService; |
40 | |
import org.kuali.rice.kns.lookup.LookupUtils; |
41 | |
import org.kuali.rice.kns.lookup.Lookupable; |
42 | |
import org.kuali.rice.kns.lookup.HtmlData.InputHtmlData; |
43 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
44 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
45 | |
import org.kuali.rice.kns.service.SequenceAccessorService; |
46 | |
import org.kuali.rice.kns.util.GlobalVariables; |
47 | |
import org.kuali.rice.kns.util.KNSConstants; |
48 | |
import org.kuali.rice.kns.util.UrlFactory; |
49 | |
import org.kuali.rice.kns.web.struts.form.MultipleValueLookupForm; |
50 | |
import org.kuali.rice.kns.web.ui.Column; |
51 | |
import org.kuali.rice.kns.web.ui.ResultRow; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | 0 | public class KualiMultipleValueLookupAction extends KualiLookupAction implements KualiTableRenderAction { |
57 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiMultipleValueLookupAction.class); |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public static final int DEFAULT_MAX_ROWS_PER_PAGE = 50; |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
@Override |
79 | |
public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
80 | 0 | MultipleValueLookupForm multipleValueLookupForm = (MultipleValueLookupForm) form; |
81 | |
|
82 | |
|
83 | 0 | String methodToCall = findMethodToCall(form, request); |
84 | 0 | if (methodToCall.equalsIgnoreCase("search")) { |
85 | 0 | GlobalVariables.getUserSession().removeObjectsByPrefix(KNSConstants.SEARCH_METHOD); |
86 | |
} |
87 | |
|
88 | 0 | Lookupable kualiLookupable = multipleValueLookupForm.getLookupable(); |
89 | 0 | if (kualiLookupable == null) { |
90 | 0 | LOG.error("Lookupable is null."); |
91 | 0 | throw new RuntimeException("Lookupable is null."); |
92 | |
} |
93 | |
|
94 | 0 | Collection displayList = new ArrayList(); |
95 | 0 | ArrayList<ResultRow> resultTable = new ArrayList<ResultRow>(); |
96 | |
|
97 | |
|
98 | 0 | kualiLookupable.validateSearchParameters(multipleValueLookupForm.getFields()); |
99 | |
|
100 | 0 | boolean bounded = true; |
101 | |
|
102 | 0 | displayList = performMultipleValueLookup(multipleValueLookupForm, resultTable, getMaxRowsPerPage(multipleValueLookupForm), bounded); |
103 | 0 | if (kualiLookupable.isSearchUsingOnlyPrimaryKeyValues()) { |
104 | 0 | multipleValueLookupForm.setSearchUsingOnlyPrimaryKeyValues(true); |
105 | 0 | multipleValueLookupForm.setPrimaryKeyFieldLabels(kualiLookupable.getPrimaryKeyFieldLabels()); |
106 | |
} |
107 | |
else { |
108 | 0 | multipleValueLookupForm.setSearchUsingOnlyPrimaryKeyValues(false); |
109 | 0 | multipleValueLookupForm.setPrimaryKeyFieldLabels(KNSConstants.EMPTY_STRING); |
110 | |
} |
111 | |
|
112 | |
|
113 | |
|
114 | 0 | if ( displayList instanceof CollectionIncomplete ){ |
115 | 0 | request.setAttribute("reqSearchResultsActualSize", ((CollectionIncomplete) displayList).getActualSizeIfTruncated()); |
116 | |
} else { |
117 | 0 | request.setAttribute("reqSearchResultsActualSize", displayList.size() ); |
118 | |
} |
119 | |
|
120 | 0 | request.setAttribute("reqSearchResults", resultTable); |
121 | |
|
122 | |
|
123 | |
|
124 | 0 | if ( displayList instanceof CollectionIncomplete ){ |
125 | 0 | multipleValueLookupForm.setResultsActualSize((int) ((CollectionIncomplete) displayList).getActualSizeIfTruncated().longValue()); |
126 | |
} else { |
127 | 0 | multipleValueLookupForm.setResultsActualSize(displayList.size()); |
128 | |
} |
129 | |
|
130 | |
|
131 | 0 | multipleValueLookupForm.setResultsLimitedSize(resultTable.size()); |
132 | |
|
133 | 0 | if (request.getParameter(KNSConstants.SEARCH_LIST_REQUEST_KEY) != null) { |
134 | 0 | GlobalVariables.getUserSession().removeObject(request.getParameter(KNSConstants.SEARCH_LIST_REQUEST_KEY)); |
135 | |
} |
136 | 0 | request.setAttribute(KNSConstants.SEARCH_LIST_REQUEST_KEY, GlobalVariables.getUserSession().addObjectWithGeneratedKey(resultTable, KNSConstants.SEARCH_LIST_KEY_PREFIX)); |
137 | |
|
138 | 0 | request.getParameter(KNSConstants.REFRESH_CALLER); |
139 | |
|
140 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
141 | |
} |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
@Override |
154 | |
public ActionForward switchToPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
155 | 0 | MultipleValueLookupForm multipleValueLookupForm = (MultipleValueLookupForm) form; |
156 | 0 | List<ResultRow> resultTable = switchToPage(multipleValueLookupForm, getMaxRowsPerPage(multipleValueLookupForm)); |
157 | 0 | request.setAttribute("reqSearchResults", resultTable); |
158 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
159 | |
} |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
@Override |
177 | |
public ActionForward sort(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
178 | 0 | MultipleValueLookupForm multipleValueLookupForm = (MultipleValueLookupForm) form; |
179 | 0 | List<ResultRow> resultTable = sort(multipleValueLookupForm, getMaxRowsPerPage(multipleValueLookupForm)); |
180 | 0 | request.setAttribute("reqSearchResults", resultTable); |
181 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
182 | |
} |
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
public ActionForward prepareToReturnSelectedResults(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
195 | 0 | MultipleValueLookupForm multipleValueLookupForm = (MultipleValueLookupForm) form; |
196 | 0 | if (StringUtils.isBlank(multipleValueLookupForm.getLookupResultsSequenceNumber())) { |
197 | |
|
198 | 0 | return prepareToReturnNone(mapping, form, request, response); |
199 | |
} |
200 | |
|
201 | 0 | prepareToReturnSelectedResultBOs(multipleValueLookupForm); |
202 | |
|
203 | |
|
204 | 0 | Properties parameters = new Properties(); |
205 | 0 | parameters.put(KNSConstants.LOOKUP_RESULTS_BO_CLASS_NAME, multipleValueLookupForm.getBusinessObjectClassName()); |
206 | 0 | parameters.put(KNSConstants.LOOKUP_RESULTS_SEQUENCE_NUMBER, multipleValueLookupForm.getLookupResultsSequenceNumber()); |
207 | 0 | parameters.put(KNSConstants.DOC_FORM_KEY, multipleValueLookupForm.getFormKey()); |
208 | 0 | parameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.RETURN_METHOD_TO_CALL); |
209 | 0 | parameters.put(KNSConstants.REFRESH_CALLER, KNSConstants.MULTIPLE_VALUE); |
210 | 0 | parameters.put(KNSConstants.ANCHOR, multipleValueLookupForm.getLookupAnchor()); |
211 | 0 | parameters.put(KNSConstants.LOOKED_UP_COLLECTION_NAME, multipleValueLookupForm.getLookedUpCollectionName()); |
212 | 0 | if(multipleValueLookupForm.getDocNum() != null){ |
213 | 0 | parameters.put(KNSConstants.DOC_NUM, multipleValueLookupForm.getDocNum()); |
214 | |
} |
215 | |
|
216 | |
|
217 | 0 | String backUrl = UrlFactory.parameterizeUrl(multipleValueLookupForm.getBackLocation(), parameters); |
218 | 0 | return new ActionForward(backUrl, true); |
219 | |
} |
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
public ActionForward selectAll(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
231 | 0 | MultipleValueLookupForm multipleValueLookupForm = (MultipleValueLookupForm) form; |
232 | 0 | List<ResultRow> resultTable = selectAll(multipleValueLookupForm, getMaxRowsPerPage(multipleValueLookupForm)); |
233 | 0 | request.setAttribute("reqSearchResults", resultTable); |
234 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
235 | |
} |
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
public ActionForward unselectAll(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
248 | 0 | MultipleValueLookupForm multipleValueLookupForm = (MultipleValueLookupForm) form; |
249 | 0 | List<ResultRow> resultTable = unselectAll(multipleValueLookupForm, getMaxRowsPerPage(multipleValueLookupForm)); |
250 | 0 | request.setAttribute("reqSearchResults", resultTable); |
251 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
252 | |
} |
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
@Override |
260 | |
public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
261 | 0 | return prepareToReturnNone(mapping, form, request, response); |
262 | |
} |
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
public ActionForward prepareToReturnNone(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
275 | 0 | MultipleValueLookupForm multipleValueLookupForm = (MultipleValueLookupForm) form; |
276 | 0 | prepareToReturnNone(multipleValueLookupForm); |
277 | |
|
278 | |
|
279 | 0 | Properties parameters = new Properties(); |
280 | 0 | parameters.put(KNSConstants.DOC_FORM_KEY, multipleValueLookupForm.getFormKey()); |
281 | 0 | parameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.RETURN_METHOD_TO_CALL); |
282 | 0 | parameters.put(KNSConstants.REFRESH_CALLER, KNSConstants.MULTIPLE_VALUE); |
283 | 0 | parameters.put(KNSConstants.ANCHOR, multipleValueLookupForm.getLookupAnchor()); |
284 | 0 | if(multipleValueLookupForm.getDocNum() != null){ |
285 | 0 | parameters.put(KNSConstants.DOC_NUM, multipleValueLookupForm.getDocNum()); |
286 | |
} |
287 | 0 | String backUrl = UrlFactory.parameterizeUrl(multipleValueLookupForm.getBackLocation(), parameters); |
288 | 0 | return new ActionForward(backUrl, true); |
289 | |
} |
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
public ActionForward export(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
303 | 0 | MultipleValueLookupForm multipleValueLookupForm = (MultipleValueLookupForm) form; |
304 | 0 | List<ResultRow> resultTable = prepareToExport(multipleValueLookupForm); |
305 | 0 | request.setAttribute("reqSearchResults", resultTable); |
306 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
307 | |
} |
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
protected Collection performMultipleValueLookup(MultipleValueLookupForm multipleValueLookupForm, List<ResultRow> resultTable, int maxRowsPerPage, boolean bounded) { |
320 | 0 | Lookupable lookupable = multipleValueLookupForm.getLookupable(); |
321 | 0 | Collection displayList = lookupable.performLookup(multipleValueLookupForm, resultTable, bounded); |
322 | |
|
323 | 0 | List defaultSortColumns = lookupable.getDefaultSortColumns(); |
324 | 0 | if (defaultSortColumns != null && !defaultSortColumns.isEmpty() && resultTable != null && !resultTable.isEmpty()) { |
325 | |
|
326 | 0 | String firstSortColumn = (String) defaultSortColumns.get(0); |
327 | |
|
328 | |
|
329 | 0 | int firstSortColumnIdx = -1; |
330 | 0 | List<Column> columnsForFirstResultRow = resultTable.get(0).getColumns(); |
331 | 0 | for (int i = 0; i < columnsForFirstResultRow.size(); i++) { |
332 | 0 | if (StringUtils.equals(firstSortColumn, columnsForFirstResultRow.get(i).getPropertyName())) { |
333 | 0 | firstSortColumnIdx = i; |
334 | 0 | break; |
335 | |
} |
336 | |
} |
337 | 0 | multipleValueLookupForm.setColumnToSortIndex(firstSortColumnIdx); |
338 | 0 | } |
339 | |
else { |
340 | |
|
341 | 0 | multipleValueLookupForm.setColumnToSortIndex(-1); |
342 | |
} |
343 | |
|
344 | |
|
345 | 0 | multipleValueLookupForm.jumpToFirstPage(resultTable.size(), maxRowsPerPage); |
346 | |
|
347 | 0 | SequenceAccessorService sas = KNSServiceLocator.getSequenceAccessorService(); |
348 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber(KNSConstants.LOOKUP_RESULTS_SEQUENCE); |
349 | 0 | String lookupResultsSequenceNumber = nextSeq.toString(); |
350 | 0 | multipleValueLookupForm.setLookupResultsSequenceNumber(lookupResultsSequenceNumber); |
351 | |
try { |
352 | 0 | LookupResultsService lookupResultsService = KNSServiceLocatorWeb.getLookupResultsService(); |
353 | 0 | lookupResultsService.persistResultsTable(lookupResultsSequenceNumber, resultTable, |
354 | |
GlobalVariables.getUserSession().getPerson().getPrincipalId()); |
355 | |
} |
356 | 0 | catch (Exception e) { |
357 | 0 | LOG.error("error occured trying to persist multiple lookup results", e); |
358 | 0 | throw new RuntimeException("error occured trying to persist multiple lookup results"); |
359 | 0 | } |
360 | |
|
361 | |
|
362 | 0 | multipleValueLookupForm.setCompositeObjectIdMap(new HashMap<String, String>()); |
363 | |
|
364 | 0 | return displayList; |
365 | |
} |
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
protected List<ResultRow> switchToPage(MultipleValueLookupForm multipleValueLookupForm, int maxRowsPerPage) { |
374 | 0 | String lookupResultsSequenceNumber = multipleValueLookupForm.getLookupResultsSequenceNumber(); |
375 | |
|
376 | 0 | List<ResultRow> resultTable = null; |
377 | |
try { |
378 | 0 | resultTable = KNSServiceLocatorWeb.getLookupResultsService().retrieveResultsTable(lookupResultsSequenceNumber, GlobalVariables.getUserSession().getPerson().getPrincipalId()); |
379 | |
} |
380 | 0 | catch (Exception e) { |
381 | 0 | LOG.error("error occured trying to retrieve multiple lookup results", e); |
382 | 0 | throw new RuntimeException("error occured trying to retrieve multiple lookup results"); |
383 | 0 | } |
384 | |
|
385 | 0 | multipleValueLookupForm.jumpToPage(multipleValueLookupForm.getSwitchToPageNumber(), resultTable.size(), maxRowsPerPage); |
386 | |
|
387 | 0 | multipleValueLookupForm.setColumnToSortIndex(Integer.parseInt(multipleValueLookupForm.getPreviouslySortedColumnIndex())); |
388 | 0 | multipleValueLookupForm.setCompositeObjectIdMap(LookupUtils.generateCompositeSelectedObjectIds(multipleValueLookupForm.getPreviouslySelectedObjectIdSet(), |
389 | |
multipleValueLookupForm.getDisplayedObjectIdSet(), multipleValueLookupForm.getSelectedObjectIdSet())); |
390 | 0 | return resultTable; |
391 | |
} |
392 | |
|
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
protected List<ResultRow> sort(MultipleValueLookupForm multipleValueLookupForm, int maxRowsPerPage) { |
401 | 0 | String lookupResultsSequenceNumber = multipleValueLookupForm.getLookupResultsSequenceNumber(); |
402 | |
|
403 | 0 | LookupResultsService lookupResultsService = KNSServiceLocatorWeb.getLookupResultsService(); |
404 | |
|
405 | 0 | List<ResultRow> resultTable = null; |
406 | |
try { |
407 | 0 | resultTable = lookupResultsService.retrieveResultsTable(lookupResultsSequenceNumber, GlobalVariables.getUserSession().getPerson().getPrincipalId()); |
408 | |
} |
409 | 0 | catch (Exception e) { |
410 | 0 | LOG.error("error occured trying to retrieve multiple lookup results", e); |
411 | 0 | throw new RuntimeException("error occured trying to retrieve multiple lookup results"); |
412 | 0 | } |
413 | |
|
414 | 0 | int columnToSortOn = multipleValueLookupForm.getColumnToSortIndex(); |
415 | 0 | int columnCurrentlySortedOn = Integer.parseInt(multipleValueLookupForm.getPreviouslySortedColumnIndex()); |
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | 0 | if (columnToSortOn == columnCurrentlySortedOn) { |
421 | |
|
422 | 0 | Collections.reverse(resultTable); |
423 | |
} |
424 | |
else { |
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | 0 | Collections.sort(resultTable, new BeanComparator("columns[" + columnToSortOn + "].propertyValue", LookupUtils.findBestValueComparatorForColumn(resultTable, columnToSortOn))); |
430 | |
} |
431 | |
|
432 | |
|
433 | |
try { |
434 | 0 | lookupResultsService.persistResultsTable(lookupResultsSequenceNumber, resultTable, |
435 | |
GlobalVariables.getUserSession().getPerson().getPrincipalId()); |
436 | |
} |
437 | 0 | catch (Exception e) { |
438 | 0 | LOG.error("error occured trying to persist multiple lookup results", e); |
439 | 0 | throw new RuntimeException("error occured trying to persist multiple lookup results"); |
440 | 0 | } |
441 | |
|
442 | |
|
443 | 0 | multipleValueLookupForm.jumpToFirstPage(resultTable.size(), maxRowsPerPage); |
444 | |
|
445 | 0 | multipleValueLookupForm.setCompositeObjectIdMap(LookupUtils.generateCompositeSelectedObjectIds(multipleValueLookupForm.getPreviouslySelectedObjectIdSet(), |
446 | |
multipleValueLookupForm.getDisplayedObjectIdSet(), multipleValueLookupForm.getSelectedObjectIdSet())); |
447 | 0 | return resultTable; |
448 | |
} |
449 | |
|
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
protected void prepareToReturnSelectedResultBOs(MultipleValueLookupForm multipleValueLookupForm) { |
457 | 0 | String lookupResultsSequenceNumber = multipleValueLookupForm.getLookupResultsSequenceNumber(); |
458 | 0 | if (StringUtils.isBlank(lookupResultsSequenceNumber)) { |
459 | |
|
460 | 0 | return; |
461 | |
} |
462 | 0 | Map<String, String> compositeObjectIdMap = LookupUtils.generateCompositeSelectedObjectIds(multipleValueLookupForm.getPreviouslySelectedObjectIdSet(), |
463 | |
multipleValueLookupForm.getDisplayedObjectIdSet(), multipleValueLookupForm.getSelectedObjectIdSet()); |
464 | 0 | Set<String> compositeObjectIds = compositeObjectIdMap.keySet(); |
465 | |
try { |
466 | 0 | LookupResultsService lookupResultsService = KNSServiceLocatorWeb.getLookupResultsService(); |
467 | 0 | lookupResultsService.persistSelectedObjectIds(lookupResultsSequenceNumber, compositeObjectIds, |
468 | |
GlobalVariables.getUserSession().getPerson().getPrincipalId()); |
469 | |
} |
470 | 0 | catch (Exception e) { |
471 | 0 | LOG.error("error occured trying to retrieve selected multiple lookup results", e); |
472 | 0 | throw new RuntimeException("error occured trying to retrieve selected multiple lookup results"); |
473 | 0 | } |
474 | 0 | } |
475 | |
|
476 | |
|
477 | |
|
478 | |
|
479 | |
|
480 | |
|
481 | |
protected void prepareToReturnNone(MultipleValueLookupForm multipleValueLookupForm) { |
482 | 0 | String lookupResultsSequenceNumber = multipleValueLookupForm.getLookupResultsSequenceNumber(); |
483 | |
try { |
484 | 0 | if (StringUtils.isNotBlank(lookupResultsSequenceNumber)) { |
485 | |
|
486 | 0 | LookupResultsService lookupResultsService = KNSServiceLocatorWeb.getLookupResultsService(); |
487 | 0 | lookupResultsService.clearPersistedLookupResults(lookupResultsSequenceNumber); |
488 | 0 | multipleValueLookupForm.setLookupResultsSequenceNumber(null); |
489 | |
} |
490 | |
} |
491 | 0 | catch (Exception e) { |
492 | |
|
493 | 0 | LOG.error("error occured trying to clear lookup results seq nbr " + lookupResultsSequenceNumber, e); |
494 | 0 | } |
495 | 0 | } |
496 | |
|
497 | |
|
498 | |
|
499 | |
|
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | |
|
505 | |
|
506 | |
protected List<ResultRow> prepareToExport(MultipleValueLookupForm multipleValueLookupForm) { |
507 | 0 | String lookupResultsSequenceNumber = multipleValueLookupForm.getLookupResultsSequenceNumber(); |
508 | |
|
509 | 0 | List<ResultRow> resultTable = null; |
510 | |
try { |
511 | 0 | LookupResultsService lookupResultsService = KNSServiceLocatorWeb.getLookupResultsService(); |
512 | 0 | resultTable = lookupResultsService.retrieveResultsTable(lookupResultsSequenceNumber, GlobalVariables.getUserSession().getPerson().getPrincipalId()); |
513 | |
} |
514 | 0 | catch (Exception e) { |
515 | 0 | LOG.error("error occured trying to export multiple lookup results", e); |
516 | 0 | throw new RuntimeException("error occured trying to export multiple lookup results"); |
517 | 0 | } |
518 | 0 | return resultTable; |
519 | |
} |
520 | |
|
521 | |
|
522 | |
|
523 | |
|
524 | |
|
525 | |
|
526 | |
|
527 | |
|
528 | |
protected List<ResultRow> selectAll(MultipleValueLookupForm multipleValueLookupForm, int maxRowsPerPage) { |
529 | 0 | String lookupResultsSequenceNumber = multipleValueLookupForm.getLookupResultsSequenceNumber(); |
530 | |
|
531 | 0 | List<ResultRow> resultTable = null; |
532 | |
try { |
533 | 0 | LookupResultsService lookupResultsService = KNSServiceLocatorWeb.getLookupResultsService(); |
534 | 0 | resultTable = lookupResultsService.retrieveResultsTable(lookupResultsSequenceNumber, GlobalVariables.getUserSession().getPerson().getPrincipalId()); |
535 | |
} |
536 | 0 | catch (Exception e) { |
537 | 0 | LOG.error("error occured trying to export multiple lookup results", e); |
538 | 0 | throw new RuntimeException("error occured trying to export multiple lookup results"); |
539 | 0 | } |
540 | |
|
541 | 0 | Map<String, String> selectedObjectIds = new HashMap<String, String>(); |
542 | 0 | for (ResultRow row : resultTable) { |
543 | 0 | String objId = row.getObjectId(); |
544 | 0 | InputHtmlData returnUrl = (InputHtmlData) row.getReturnUrlHtmlData(); |
545 | 0 | returnUrl.setChecked(InputHtmlData.CHECKBOX_CHECKED_VALUE); |
546 | 0 | row.setReturnUrl(returnUrl.constructCompleteHtmlTag()); |
547 | 0 | if(objId != null){ |
548 | 0 | selectedObjectIds.put(objId, objId); |
549 | |
} |
550 | 0 | } |
551 | |
|
552 | 0 | multipleValueLookupForm.jumpToPage(multipleValueLookupForm.getViewedPageNumber(), resultTable.size(), maxRowsPerPage); |
553 | 0 | multipleValueLookupForm.setColumnToSortIndex(Integer.parseInt(multipleValueLookupForm.getPreviouslySortedColumnIndex())); |
554 | 0 | multipleValueLookupForm.setCompositeObjectIdMap(selectedObjectIds); |
555 | |
|
556 | 0 | return resultTable; |
557 | |
} |
558 | |
|
559 | |
@Override |
560 | |
public ActionForward clearValues(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { |
561 | 0 | MultipleValueLookupForm multipleValueLookupForm = (MultipleValueLookupForm) form; |
562 | |
|
563 | |
|
564 | 0 | prepareToReturnNone(multipleValueLookupForm); |
565 | |
|
566 | 0 | return super.clearValues(mapping, form, request, response); |
567 | |
} |
568 | |
|
569 | |
|
570 | |
|
571 | |
|
572 | |
|
573 | |
|
574 | |
|
575 | |
protected List<ResultRow> unselectAll(MultipleValueLookupForm multipleValueLookupForm, int maxRowsPerPage) { |
576 | 0 | String lookupResultsSequenceNumber = multipleValueLookupForm.getLookupResultsSequenceNumber(); |
577 | |
|
578 | 0 | List<ResultRow> resultTable = null; |
579 | |
try { |
580 | 0 | LookupResultsService lookupResultsService = KNSServiceLocatorWeb.getLookupResultsService(); |
581 | 0 | resultTable = lookupResultsService.retrieveResultsTable(lookupResultsSequenceNumber, GlobalVariables.getUserSession().getPerson().getPrincipalId()); |
582 | |
} |
583 | 0 | catch (Exception e) { |
584 | 0 | LOG.error("error occured trying to export multiple lookup results", e); |
585 | 0 | throw new RuntimeException("error occured trying to export multiple lookup results"); |
586 | 0 | } |
587 | |
|
588 | 0 | Map<String, String> selectedObjectIds = new HashMap<String, String>(); |
589 | |
|
590 | |
|
591 | 0 | multipleValueLookupForm.jumpToPage(multipleValueLookupForm.getViewedPageNumber(), resultTable.size(), maxRowsPerPage); |
592 | 0 | multipleValueLookupForm.setColumnToSortIndex(Integer.parseInt(multipleValueLookupForm.getPreviouslySortedColumnIndex())); |
593 | 0 | multipleValueLookupForm.setCompositeObjectIdMap(selectedObjectIds); |
594 | |
|
595 | 0 | return resultTable; |
596 | |
} |
597 | |
|
598 | |
|
599 | |
|
600 | |
|
601 | |
|
602 | |
|
603 | |
|
604 | |
|
605 | |
|
606 | |
|
607 | |
|
608 | |
|
609 | |
|
610 | |
|
611 | |
protected int getMaxRowsPerPage(MultipleValueLookupForm multipleValueLookupForm) { |
612 | 0 | Integer appMaxRowsPerPage = LookupUtils.getApplicationMaximumSearchResulsPerPageForMultipleValueLookups(); |
613 | 0 | if (appMaxRowsPerPage == null) { |
614 | 0 | LOG.warn("Couldn't find application results per page for MV lookups. Using default of " + DEFAULT_MAX_ROWS_PER_PAGE); |
615 | 0 | appMaxRowsPerPage = new Integer(DEFAULT_MAX_ROWS_PER_PAGE); |
616 | |
} |
617 | 0 | return appMaxRowsPerPage; |
618 | |
} |
619 | |
} |
620 | |
|