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