001package org.kuali.ole.describe.controller; 002 003import org.apache.commons.collections.CollectionUtils; 004import org.apache.commons.lang.StringUtils; 005import org.apache.log4j.Logger; 006import org.kuali.ole.OLEConstants; 007import org.kuali.ole.describe.bo.OleWorkHoldingsDocument; 008import org.kuali.ole.describe.bo.SearchResultDisplayFields; 009import org.kuali.ole.describe.bo.SearchResultDisplayRow; 010import org.kuali.ole.describe.form.*; 011import org.kuali.ole.describe.form.GlobalEditForm; 012import org.kuali.ole.docstore.common.client.DocstoreClientLocator; 013import org.kuali.ole.docstore.common.document.config.DocFieldConfig; 014import org.kuali.ole.docstore.common.document.config.DocFormatConfig; 015import org.kuali.ole.docstore.common.document.config.DocTypeConfig; 016import org.kuali.ole.docstore.common.document.config.DocumentSearchConfig; 017import org.kuali.ole.docstore.common.document.content.enums.DocFormat; 018import org.kuali.ole.docstore.common.search.*; 019import org.kuali.ole.docstore.model.enums.DocType; 020import org.kuali.ole.sys.context.SpringContext; 021import org.kuali.rice.kim.api.permission.PermissionService; 022import org.kuali.rice.kim.api.services.KimApiServiceLocator; 023import org.kuali.rice.krad.service.KRADServiceLocator; 024import org.kuali.rice.krad.uif.UifParameters; 025import org.kuali.rice.krad.util.GlobalVariables; 026import org.kuali.rice.krad.util.KRADConstants; 027import org.kuali.rice.krad.web.controller.UifControllerBase; 028import org.kuali.rice.krad.web.form.UifFormBase; 029import org.springframework.stereotype.Controller; 030import org.springframework.validation.BindingResult; 031import org.springframework.web.bind.annotation.ModelAttribute; 032import org.springframework.web.bind.annotation.RequestMapping; 033import org.springframework.web.multipart.MultipartFile; 034import org.springframework.web.servlet.ModelAndView; 035 036import javax.servlet.http.HttpServletRequest; 037import javax.servlet.http.HttpServletResponse; 038import java.io.BufferedReader; 039import java.io.InputStream; 040import java.io.InputStreamReader; 041import java.util.*; 042 043/** 044 * Created with IntelliJ IDEA. 045 * User: srirams 046 * Date: 2/21/14 047 * Time: 6:34 PM 048 * To change this template use File | Settings | File Templates. 049 */ 050@Controller 051@RequestMapping(value = "/globaleditController") 052public class GlobalEditController extends OLESearchController { 053 054 private static final Logger LOG = Logger.getLogger(GlobalEditController.class); 055 private DocstoreClientLocator docstoreClientLocator; 056 private String eResourceId; 057 private int totalRecCount; 058 private String tokenId; 059 private int start; 060 private int pageSize; 061 062 DocumentSearchConfig documentSearchConfig = DocumentSearchConfig.getDocumentSearchConfig(); 063 064 public DocstoreClientLocator getDocstoreClientLocator() { 065 if (null == docstoreClientLocator) { 066 return SpringContext.getBean(DocstoreClientLocator.class); 067 } 068 return docstoreClientLocator; 069 } 070 071 @Override 072 protected UifFormBase createInitialForm(HttpServletRequest request) { 073 GlobalEditForm globalEditForm = new GlobalEditForm(); 074 globalEditForm.setDocType("holdings"); 075 return globalEditForm; 076 } 077 078 @Override 079 @RequestMapping(params = "methodToCall=start") 080 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 081 HttpServletRequest request, HttpServletResponse response) { 082 this.start = 0; 083 GlobalEditForm globalEditForm = (GlobalEditForm) form; 084 globalEditForm.getSearchConditions().clear(); 085 boolean viewGlobalEditDispMessageFlag=false; 086 087 SearchCondition searchCondition = new SearchCondition(); 088 searchCondition.setOperator("AND"); 089 globalEditForm.getSearchConditions().add(searchCondition); 090 GlobalVariables.getMessageMap().getInfoMessages().clear(); 091 globalEditForm.setViewGlobalEditFlag(false); 092 globalEditForm.setStart(0); 093 094 if (globalEditForm.getSearchResultDisplayRowList() != null && globalEditForm.getSearchResultDisplayRowList().size() > 0) { 095 globalEditForm.getSearchResultDisplayRowList().clear(); 096 } 097 if (globalEditForm.getGlobalEditMap() != null && globalEditForm.getGlobalEditMap().size() > 0) { 098 globalEditForm.getGlobalEditMap().clear(); 099 } 100 if (globalEditForm.getDocType() == null) { 101 globalEditForm.setDocType("bibliographic"); 102 } 103 if (globalEditForm.getSearchType() != null && globalEditForm.getSearchType().equalsIgnoreCase("Import")) { 104 globalEditForm.setSearchFlag(false); 105 } else { 106 globalEditForm.setSearchFlag(true); 107 globalEditForm.setSearchType("search"); 108 } 109 if (StringUtils.isEmpty(globalEditForm.getFieldType())) { 110 globalEditForm.setFieldType("LocalId"); 111 } 112 113 if (globalEditForm.getSearchParams() != null) { 114 globalEditForm.getSearchParams().getSearchConditions().clear(); 115 globalEditForm.getSearchParams().getSearchResultFields().clear(); 116 } 117 globalEditForm.setMatchedCount(0); 118 globalEditForm.setUnMatchedRecords(""); 119 globalEditForm.setTotalRecords(0); 120 globalEditForm.setUnMatchedCount(0); 121 globalEditForm.setSelectedFileName(""); 122 globalEditForm.setViewGlobalEditDispMessageFlag(viewGlobalEditDispMessageFlag); 123 globalEditForm.setGlobalEditRecords(null); 124 globalEditForm.getGlobalEditMap().clear(); 125 globalEditForm.setSelectAll(false); 126 List<Integer> pageSizes = documentSearchConfig.getPageSizes(); 127 if(!pageSizes.isEmpty() || pageSizes.size() > 0) { 128 globalEditForm.setPageSize(pageSizes.get(0)); 129 } 130 GlobalVariables.getMessageMap().clearErrorMessages(); 131 boolean hasPermission = canGloballyEdit(GlobalVariables.getUserSession().getPrincipalId()); 132 if (!hasPermission) { 133 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION); 134 return super.navigate(globalEditForm, result, request, response); 135 } 136 return navigate(globalEditForm, result, request, response); 137 } 138 139 @Override 140 @RequestMapping(params = "methodToCall=search") 141 public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 142 HttpServletRequest request, HttpServletResponse response) { 143 LOG.info("*** GlobalEditController - Inside Search Method ***"); 144 GlobalEditForm globalEditForm = (GlobalEditForm) form; 145 boolean hasPermission = canGloballyEdit(GlobalVariables.getUserSession().getPrincipalId()); 146 if (!hasPermission) { 147 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION); 148 return super.navigate(globalEditForm, result, request, response); 149 } 150 searchDocstoreData(globalEditForm, request); 151 return super.navigate(globalEditForm, result, request, response); 152 } 153 154 @RequestMapping(params = "methodToCall=load") 155 public ModelAndView load(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 156 HttpServletRequest request, HttpServletResponse response) throws Exception { 157 GlobalEditForm globalEditForm = (GlobalEditForm) form; 158 boolean viewGlobalEditDispMessageFlag = false; 159 boolean hasPermission = canGloballyEdit(GlobalVariables.getUserSession().getPrincipalId()); 160 if (!hasPermission) { 161 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION); 162 return super.navigate(globalEditForm, result, request, response); 163 } 164 GlobalVariables.getMessageMap().getInfoMessages().clear(); 165 setShowPageSizeEntries(globalEditForm); 166 List<String> inputData = new ArrayList<>(); 167 String fileName = null; 168 MultipartFile file = globalEditForm.getFile(); 169 if (file != null && (file.getContentType().equalsIgnoreCase("application/octet-stream") || 170 file.getContentType().equalsIgnoreCase("text/plain") || 171 file.getOriginalFilename().endsWith(".txt"))) { 172 fileName = file.getOriginalFilename(); 173 BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream())); 174 for (String line; (line = reader.readLine()) != null; ) { 175 inputData.add(line); 176 } 177 } else { 178 //GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_GLOBAL_SEARCH_MESSAGE); 179 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_FILE_NOT_FOUND); 180 return navigate(globalEditForm, result, request, response); 181 } 182 183 List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>(); 184 if (inputData.size() > 0) { 185 SearchParams searchParams = null; 186 List<SearchCondition> searchConditions = null; 187 String docType = globalEditForm.getDocType(); 188 searchConditions = new ArrayList<>(); 189 searchParams = new SearchParams(); 190 for (String id : inputData) { 191 if (StringUtils.isNotEmpty(id)) { 192 if (globalEditForm.getFieldType().equalsIgnoreCase("Barcode")) { 193 if (DocType.HOLDINGS.getCode().equals(globalEditForm.getDocType())) { 194 searchConditions.add(searchParams.buildSearchCondition("NONE", searchParams.buildSearchField("item", "ItemBarcode_display", id), "OR")); 195 } else { 196 searchConditions.add(searchParams.buildSearchCondition("NONE", searchParams.buildSearchField(docType, "ItemBarcode_display", id), "OR")); 197 } 198 } else { 199 searchConditions.add(searchParams.buildSearchCondition("NONE", searchParams.buildSearchField(globalEditForm.getDocType(), "LocalId_display", id), "OR")); 200 } 201 } 202 } 203 if (globalEditForm.getFieldType() != null && globalEditForm.getFieldType().equalsIgnoreCase("Barcode") && DocType.HOLDINGS.getCode().equals(globalEditForm.getDocType())) { 204 searchParams.getSearchConditions().addAll(searchConditions); 205 searchResultDisplayRows = getSearchResults(searchParams, globalEditForm); 206 Set<String> holdingsIdList = new HashSet(); 207 for (SearchResultDisplayRow searchResultDisplayRow : searchResultDisplayRows) { 208 holdingsIdList.add(searchResultDisplayRow.getHoldingsIdentifier()); 209 } 210 for (String id : holdingsIdList) { 211 searchConditions.add(searchParams.buildSearchCondition("NONE", searchParams.buildSearchField(docType, "LocalId_display", id), "OR")); 212 } 213 searchParams.getSearchConditions().addAll(searchConditions); 214 searchResultDisplayRows = getSearchResults(searchParams, globalEditForm); 215 } 216 217 searchParams.getSearchConditions().addAll(searchConditions); 218 searchResultDisplayRows = getSearchResults(searchParams, globalEditForm); 219 } 220 List<String> listFromDB = new ArrayList<>(); 221 //List<String> matchedList = new ArrayList<>(); 222 List<String> unMatchedList = new ArrayList<>(); 223 if (inputData.size() > 0) { 224 viewGlobalEditDispMessageFlag = true; 225 if (searchResultDisplayRows.size() > 0) { 226 for (SearchResultDisplayRow searchResultDisplayRow : searchResultDisplayRows) { 227 if ("Barcode".equals(globalEditForm.getFieldType())) { 228 listFromDB.add(searchResultDisplayRow.getBarcode()); 229 } else { 230 listFromDB.add(searchResultDisplayRow.getLocalId()); 231 } 232 } 233 } 234 } 235 236 for (int i = 0; i < inputData.size(); i++) { 237 if (!listFromDB.contains(inputData.get(i))) { 238 //matchedList.add(listFromDB.get(i)); 239 unMatchedList.add(inputData.get(i)); 240 } 241 } 242 243 StringBuffer stringBuffer = new StringBuffer(); 244 StringBuffer stringBuffer1 =new StringBuffer(); 245 List<String> stringList = new ArrayList<>(); 246 if(unMatchedList.size()>0){ 247 for (int i = 0; i < unMatchedList.size(); i++) { 248 stringList.add(unMatchedList.get(i)); 249 if (stringList.size() > 0 && stringList.size() <= 5) { 250 stringBuffer.append(unMatchedList.get(i)); 251 stringBuffer.append(","); 252 } else { 253 stringBuffer1.append("....."); 254 } 255 256 } 257 stringBuffer = stringBuffer.deleteCharAt(stringBuffer.length() - 1); 258 } 259 stringBuffer = stringBuffer.append(stringBuffer1); 260 globalEditForm.setUnMatchedRecords(stringBuffer.toString()); 261 globalEditForm.setUnMatchedCount(unMatchedList.size()); 262 globalEditForm.setMatchedCount(listFromDB.size()); 263 globalEditForm.setSelectedFileName(fileName); 264 globalEditForm.setTotalRecords(inputData.size()); 265 globalEditForm.setViewGlobalEditDispMessageFlag(viewGlobalEditDispMessageFlag); 266 267 268 globalEditForm.setSearchResultDisplayRowList(searchResultDisplayRows); 269 if (searchResultDisplayRows.size() == 0) { 270 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_GLOBAL_SEARCH_MESSAGE); 271 } 272 273 return navigate(globalEditForm, result, request, response); 274 } 275 276 private List<SearchResultDisplayRow> getSearchResults(SearchParams searchParams, GlobalEditForm globalEditForm) throws Exception { 277 List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>(); 278 searchParams.setStartIndex(this.start); 279 for (SearchCondition searchCondition : searchParams.getSearchConditions()) { 280 if (searchCondition.getSearchField() == null) { 281 searchCondition.setSearchField(new SearchField()); 282 } 283 //added comment for Global edit change for searching barcode through hodlings. 284 if (!"holdings".equals(globalEditForm.getDocType())) { 285 searchCondition.getSearchField().setDocType(globalEditForm.getDocType()); 286 } 287 } 288 if (!globalEditForm.isMoreFacets()) { 289 searchParams.getFacetFields().clear(); 290 Set<String> facetFields = getFacetFields(globalEditForm.getDocType()); 291 searchParams.getFacetFields().addAll(facetFields); 292 searchParams.setFacetLimit(documentSearchConfig.getFacetPageSizeShort()); 293 } 294 globalEditForm.setFacetLimit(documentSearchConfig.getFacetPageSizeShort() - 1); 295 SearchResponse searchResponse = null; 296 globalEditForm.setSearchResultDisplayFields(getDisplayFields(globalEditForm)); 297 searchParams.buildSearchParams(searchParams, globalEditForm.getDocType()); 298 //added comment for Global edit change for searching barcode through hodlings 299 if ("holdings".equals(globalEditForm.getDocType())) { 300 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ItemBarcode_display")); 301 } 302 303 try { 304 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams); 305 } catch (Exception e) { 306 LOG.error("Exception : ", e); 307 } 308 globalEditForm.setSearchResultDisplayFields(getDisplayFields(globalEditForm)); 309 globalEditForm.setSearchResponse(searchResponse); 310 for (SearchResult searchResult : searchResponse.getSearchResults()) { 311 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow(); 312 if (org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode().equalsIgnoreCase(globalEditForm.getDocType())) { 313 searchResultDisplayRow.buildBibSearchResultField(searchResult.getSearchResultFields(), eResourceId); 314 } else if (org.kuali.ole.docstore.common.document.content.enums.DocType.HOLDINGS.getCode().equals(globalEditForm.getDocType())) { 315 searchResultDisplayRow.buildHoldingSearchResultField(searchResult.getSearchResultFields()); 316 } else if (org.kuali.ole.docstore.common.document.content.enums.DocType.EHOLDINGS.getCode().equals(globalEditForm.getDocType())) { 317 searchResultDisplayRow.buildEHoldingSearchResultField(searchResult.getSearchResultFields()); 318 } else if (org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode().equals(globalEditForm.getDocType())) { 319 searchResultDisplayRow.buildItemSearchResultField(searchResult.getSearchResultFields()); 320 } 321 searchResultDisplayRows.add(searchResultDisplayRow); 322 } 323 globalEditForm.setSearchResultDisplayRowList(searchResultDisplayRows); 324 if (searchResponse != null && searchResponse.getFacetResult() != null) { 325 globalEditForm.setFacetResultFields(searchResponse.getFacetResult().getFacetResultFields()); 326 } 327 if (searchResultDisplayRows.size() == 0) { 328 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE); 329 } 330 setPageNextPreviousAndEntriesInfo(globalEditForm); 331 if (searchResponse != null && searchResponse.getFacetResult() != null) { 332 globalEditForm.setFacetResultFields(searchResponse.getFacetResult().getFacetResultFields()); 333 } 334 return globalEditForm.getSearchResultDisplayRowList(); 335 } 336 337 338 @RequestMapping(params = "methodToCall=viewGlobalEditRecords") 339 public ModelAndView viewGlobalEditRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 340 HttpServletRequest request, HttpServletResponse response) { 341 GlobalEditForm globalEditForm = (GlobalEditForm) form; 342 GlobalVariables.getMessageMap().getInfoMessages().clear(); 343 if (globalEditForm.getGlobalEditRecords().size() == 0) { 344 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, OLEConstants.GLOBAL_EDIT_VIEW_RECORDS_MESSAGE); 345 } else { 346 globalEditForm.setViewGlobalEditFlag(true); 347 for (SearchResultDisplayRow searchResultDisplayRow : globalEditForm.getGlobalEditRecords()) { 348 searchResultDisplayRow.setSelect(false); 349 } 350 } 351 352 return navigate(globalEditForm, result, request, response); 353 } 354 355 @RequestMapping(params = "methodToCall=addGlobalEditRecords") 356 public ModelAndView addGlobalEditRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 357 HttpServletRequest request, HttpServletResponse response) { 358 GlobalEditForm globalEditForm = (GlobalEditForm) form; 359 GlobalVariables.getMessageMap().getInfoMessages().clear(); 360 if (globalEditForm.getSearchResultDisplayRowList() == null || globalEditForm.getSearchResultDisplayRowList().size() == 0) { 361 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, OLEConstants.DESCRIBE_GLOBAL_SEARCH_MESSAGE); 362 return navigate(globalEditForm, result, request, response); 363 } 364 boolean selectFlag = false; 365 List<SearchResultDisplayRow> searchResultDisplayRows = globalEditForm.getGlobalEditRecords(); 366 Map<String, SearchResultDisplayRow> searchResultDisplayRowMap = globalEditForm.getGlobalEditMap(); 367 int pageSize = globalEditForm.getPageSize(); 368 if (globalEditForm.isSelectAll()) { 369 globalEditForm.setPageSize(globalEditForm.getTotalRecords()); 370 searchDocstoreData(globalEditForm, request); 371 globalEditForm.setPageSize(pageSize); 372 super.setPageNextPreviousAndEntriesInfo(globalEditForm); 373 } 374 for (SearchResultDisplayRow searchResultDisplayRow : globalEditForm.getSearchResultDisplayRowList()) { 375 if (globalEditForm.isSelectAll() || searchResultDisplayRow.isSelect()) { 376 if ((globalEditForm.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode()) 377 || globalEditForm.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode())) && 378 !searchResultDisplayRowMap.containsKey(searchResultDisplayRow.getLocalId())) { 379 selectFlag = true; 380 searchResultDisplayRow.setDocType(globalEditForm.getDocType()); 381 //globalEditForm.getGlobalEditRecords().add(searchResultDisplayRow); 382 searchResultDisplayRows.add(searchResultDisplayRow); 383 searchResultDisplayRowMap.put(searchResultDisplayRow.getLocalId(), searchResultDisplayRow); 384 } else if (globalEditForm.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && 385 !searchResultDisplayRowMap.containsKey(searchResultDisplayRow.getItemIdentifier())) { 386 selectFlag = true; 387 searchResultDisplayRows.add(searchResultDisplayRow); 388 searchResultDisplayRow.setDocType(globalEditForm.getDocType()); 389 //globalEditForm.getGlobalEditRecords().add(searchResultDisplayRow); 390 searchResultDisplayRowMap.put(searchResultDisplayRow.getItemIdentifier(), searchResultDisplayRow); 391 } 392 } 393 } 394 if (!selectFlag) { 395 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, OLEConstants.GLOBAL_EDIT_ADD_RECORDS_MESSAGE); 396 } 397 return navigate(globalEditForm, result, request, response); 398 } 399 400 @RequestMapping(params = "methodToCall=globalEdit") 401 public ModelAndView globalEdit(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 402 HttpServletRequest request, HttpServletResponse response) throws Exception { 403 GlobalEditForm globalEditForm = (GlobalEditForm) form; 404 GlobalVariables.getMessageMap().getInfoMessages().clear(); 405 List<SearchResultDisplayRow> searchResultDisplayRowList = globalEditForm.getGlobalEditRecords(); 406 Iterator<SearchResultDisplayRow> iterator = searchResultDisplayRowList.iterator(); 407 List<String> ids = new ArrayList(); 408 while (iterator.hasNext()) { 409 SearchResultDisplayRow searchResultDisplayRow = iterator.next(); 410 if (searchResultDisplayRow.getDocType() != null && (searchResultDisplayRow.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode()) 411 || searchResultDisplayRow.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()))) { 412 ids.add(searchResultDisplayRow.getHoldingsIdentifier()); 413 } else if (searchResultDisplayRow.getDocType() != null && searchResultDisplayRow.getDocType().equalsIgnoreCase(DocType.ITEM.getCode())) { 414 ids.add(searchResultDisplayRow.getItemIdentifier()); 415 } 416 } 417 request.getSession().setAttribute("Ids", ids); 418 return navigate(globalEditForm, result, request, response); 419 } 420 421 @RequestMapping(params = "methodToCall=close") 422 public ModelAndView close(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 423 HttpServletRequest request, HttpServletResponse response) { 424 GlobalEditForm globalEditForm = (GlobalEditForm) form; 425 globalEditForm.setViewGlobalEditFlag(false); 426// globalEditForm.getGlobalEditRecords().clear(); 427// globalEditForm.getGlobalEditMap().clear(); 428// globalEditForm.getSearchResultDisplayRowList().clear(); 429 globalEditForm.setSelectAll(false); 430 globalEditForm.getSearchConditions().clear(); 431 globalEditForm.getSearchConditions().addAll(globalEditForm.getSearchParams().getSearchConditions()); 432 return navigate(globalEditForm, result, request, response); 433 } 434 435 @RequestMapping(params = "methodToCall=globalClear") 436 public ModelAndView globalClear(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 437 HttpServletRequest request, HttpServletResponse response) throws Exception { 438 GlobalEditForm globalEditForm = (GlobalEditForm) form; 439 if (globalEditForm.getGlobalEditRecords().size() > 0) { 440 globalEditForm.getGlobalEditRecords().clear(); 441 } 442 return navigate(globalEditForm, result, request, response); 443 } 444 445 public SearchResultDisplayFields getDisplayFields(GlobalEditForm globalEditForm) { 446 SearchResultDisplayFields searchResultDisplayFields = new SearchResultDisplayFields(); 447 searchResultDisplayFields.buildSearchResultDisplayFields(documentSearchConfig.getDocTypeConfigs(), globalEditForm.getDocType()); 448 return searchResultDisplayFields; 449 } 450 451 private void setShowPageSizeEntries(GlobalEditForm globalEditForm) { 452 super.setShowPageSizeEntries(globalEditForm); 453 } 454 455 private boolean canGloballyEdit(String principalId) { 456 PermissionService service = KimApiServiceLocator.getPermissionService(); 457 return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.GLOBAL_EDIT_PERMISSION); 458 } 459 460 /** 461 * This method clears the Search criteria and the search Results. 462 * 463 * @param form 464 * @param result 465 * @param request 466 * @param response 467 * @return 468 */ 469 470 @Override 471 @RequestMapping(params = "methodToCall=clear") 472 public ModelAndView clear(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 473 HttpServletRequest request, HttpServletResponse response) { 474 LOG.debug("Inside the clear method"); 475 GlobalEditForm globalEditForm = (GlobalEditForm) form; 476 /* List<SearchCondition> searchConditions = globalEditForm.getSearchParams().getSearchConditions(); 477 searchConditions.add(new SearchCondition());*/ 478 globalEditForm.setFile(null); 479 globalEditForm.getGlobalEditRecords().clear(); 480 globalEditForm.getGlobalEditMap().clear(); 481 globalEditForm.setSearchResultDisplayFields(new SearchResultDisplayFields()); 482 globalEditForm.setMessage(null); 483 globalEditForm.setHoldingsList(null); 484 globalEditForm.setItemList(null); 485 globalEditForm.setPageSize(10); 486 globalEditForm.setPreviousFlag(false); 487 globalEditForm.setNextFlag(false); 488 globalEditForm.setCallNumberBrowseText(""); 489 globalEditForm.setSelectAll(false); 490 globalEditForm.setSearchParams(new SearchParams()); 491 if (globalEditForm.getSearchResultDisplayRowList() != null && globalEditForm.getSearchResultDisplayRowList().size() > 0) { 492 globalEditForm.getSearchResultDisplayRowList().clear(); 493 } 494 if (globalEditForm.getSearchParams() != null && globalEditForm.getSearchParams().getFacetFields() != null) { 495 globalEditForm.getSearchParams().getFacetFields().clear(); 496 } 497 if (globalEditForm.getFacetResultFields() != null) { 498 globalEditForm.getFacetResultFields().clear(); 499 } 500 return start(globalEditForm, result, request, response); 501 } 502 503 @RequestMapping(params = "methodToCall=removeFromList") 504 public ModelAndView removeFromList(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 505 HttpServletRequest request, HttpServletResponse response) { 506 GlobalEditForm globalEditForm = (GlobalEditForm) form; 507 List<SearchResultDisplayRow> rowsListToRemove = new ArrayList<>(); 508// Map<String, SearchResultDisplayRow> globalEditMap = globalEditForm.getGlobalEditMap(); 509 for (SearchResultDisplayRow searchResultDisplayRow : globalEditForm.getGlobalEditRecords()) { 510 if (searchResultDisplayRow.isSelect()) { 511 searchResultDisplayRow.setSelect(false); 512 rowsListToRemove.add(searchResultDisplayRow); 513 globalEditForm.getGlobalEditMap().remove(searchResultDisplayRow.getLocalId()); 514 } 515 } 516 globalEditForm.getGlobalEditRecords().removeAll(rowsListToRemove); 517 return navigate(globalEditForm, result, request, response); 518 } 519}