1 package org.kuali.ole.describe.controller;
2
3 import org.apache.commons.collections.CollectionUtils;
4 import org.apache.commons.lang.StringUtils;
5 import org.apache.log4j.Logger;
6 import org.kuali.ole.OLEConstants;
7 import org.kuali.ole.describe.bo.OleWorkHoldingsDocument;
8 import org.kuali.ole.describe.bo.SearchResultDisplayFields;
9 import org.kuali.ole.describe.bo.SearchResultDisplayRow;
10 import org.kuali.ole.describe.form.*;
11 import org.kuali.ole.describe.form.GlobalEditForm;
12 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
13 import org.kuali.ole.docstore.common.document.config.DocFieldConfig;
14 import org.kuali.ole.docstore.common.document.config.DocFormatConfig;
15 import org.kuali.ole.docstore.common.document.config.DocTypeConfig;
16 import org.kuali.ole.docstore.common.document.config.DocumentSearchConfig;
17 import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
18 import org.kuali.ole.docstore.common.search.*;
19 import org.kuali.ole.docstore.model.enums.DocType;
20 import org.kuali.ole.sys.context.SpringContext;
21 import org.kuali.rice.kim.api.permission.PermissionService;
22 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
23 import org.kuali.rice.krad.service.KRADServiceLocator;
24 import org.kuali.rice.krad.uif.UifParameters;
25 import org.kuali.rice.krad.util.GlobalVariables;
26 import org.kuali.rice.krad.util.KRADConstants;
27 import org.kuali.rice.krad.web.controller.UifControllerBase;
28 import org.kuali.rice.krad.web.form.UifFormBase;
29 import org.springframework.stereotype.Controller;
30 import org.springframework.validation.BindingResult;
31 import org.springframework.web.bind.annotation.ModelAttribute;
32 import org.springframework.web.bind.annotation.RequestMapping;
33 import org.springframework.web.multipart.MultipartFile;
34 import org.springframework.web.servlet.ModelAndView;
35
36 import javax.servlet.http.HttpServletRequest;
37 import javax.servlet.http.HttpServletResponse;
38 import java.io.BufferedReader;
39 import java.io.InputStream;
40 import java.io.InputStreamReader;
41 import java.util.*;
42
43
44
45
46
47
48
49
50 @Controller
51 @RequestMapping(value = "/globaleditController")
52 public class GlobalEditController extends OLESearchController {
53
54 private static final Logger LOG = Logger.getLogger(GlobalEditController.class);
55 private DocstoreClientLocator docstoreClientLocator;
56 private String eResourceId;
57 private int totalRecCount;
58 private String tokenId;
59 private int start;
60 private int pageSize;
61
62 DocumentSearchConfig documentSearchConfig = DocumentSearchConfig.getDocumentSearchConfig();
63
64 public DocstoreClientLocator getDocstoreClientLocator() {
65 if (null == docstoreClientLocator) {
66 return SpringContext.getBean(DocstoreClientLocator.class);
67 }
68 return docstoreClientLocator;
69 }
70
71 @Override
72 protected UifFormBase createInitialForm(HttpServletRequest request) {
73 GlobalEditForm globalEditForm = new GlobalEditForm();
74 globalEditForm.setDocType("holdings");
75 return globalEditForm;
76 }
77
78 @Override
79 @RequestMapping(params = "methodToCall=start")
80 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
81 HttpServletRequest request, HttpServletResponse response) {
82 this.start = 0;
83 GlobalEditForm globalEditForm = (GlobalEditForm) form;
84 globalEditForm.getSearchConditions().clear();
85 boolean viewGlobalEditDispMessageFlag=false;
86 SearchCondition searchCondition = new SearchCondition();
87 SearchField searchField = new SearchField();
88 searchField.setFieldName("any");
89 searchField.setDocType(globalEditForm.getDocType());
90 searchCondition.setSearchField(searchField);
91 searchCondition.setOperator("AND");
92 globalEditForm.getSearchConditions().add(searchCondition);
93 GlobalVariables.getMessageMap().getInfoMessages().clear();
94 globalEditForm.setViewGlobalEditFlag(false);
95 globalEditForm.setStart(0);
96
97 if (globalEditForm.getSearchResultDisplayRowList() != null && globalEditForm.getSearchResultDisplayRowList().size() > 0) {
98 globalEditForm.getSearchResultDisplayRowList().clear();
99 }
100 if (globalEditForm.getGlobalEditMap() != null && globalEditForm.getGlobalEditMap().size() > 0) {
101 globalEditForm.getGlobalEditMap().clear();
102 }
103 if (globalEditForm.getDocType() == null) {
104 globalEditForm.setDocType("bibliographic");
105 }
106 if (globalEditForm.getSearchType() != null && globalEditForm.getSearchType().equalsIgnoreCase("Import")) {
107 globalEditForm.setSearchFlag(false);
108 } else {
109 globalEditForm.setSearchFlag(true);
110 globalEditForm.setSearchType("search");
111 }
112 if (StringUtils.isEmpty(globalEditForm.getFieldType())) {
113 globalEditForm.setFieldType("LocalId");
114 }
115
116 if (globalEditForm.getSearchParams() != null) {
117 globalEditForm.getSearchParams().getSearchConditions().clear();
118 globalEditForm.getSearchParams().getSearchResultFields().clear();
119 }
120 globalEditForm.setMatchedCount(0);
121 globalEditForm.setUnMatchedRecords("");
122 globalEditForm.setTotalRecords(0);
123 globalEditForm.setUnMatchedCount(0);
124 globalEditForm.setSelectedFileName("");
125 globalEditForm.setViewGlobalEditDispMessageFlag(viewGlobalEditDispMessageFlag);
126 globalEditForm.setGlobalEditRecords(null);
127 globalEditForm.getGlobalEditMap().clear();
128 globalEditForm.setSelectAll(false);
129 List<Integer> pageSizes = documentSearchConfig.getPageSizes();
130 if(!pageSizes.isEmpty() || pageSizes.size() > 0) {
131 globalEditForm.setPageSize(pageSizes.get(0));
132 }
133 GlobalVariables.getMessageMap().clearErrorMessages();
134 boolean hasPermission = canGloballyEdit(GlobalVariables.getUserSession().getPrincipalId());
135 if (!hasPermission) {
136 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
137 return super.navigate(globalEditForm, result, request, response);
138 }
139 return navigate(globalEditForm, result, request, response);
140 }
141
142 @Override
143 @RequestMapping(params = "methodToCall=search")
144 public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
145 HttpServletRequest request, HttpServletResponse response) {
146 LOG.info("*** GlobalEditController - Inside Search Method ***");
147 GlobalEditForm globalEditForm = (GlobalEditForm) form;
148 boolean hasPermission = canGloballyEdit(GlobalVariables.getUserSession().getPrincipalId());
149 if (!hasPermission) {
150 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
151 return super.navigate(globalEditForm, result, request, response);
152 }
153 searchDocstoreData(globalEditForm, request);
154 return super.navigate(globalEditForm, result, request, response);
155 }
156
157 @RequestMapping(params = "methodToCall=load")
158 public ModelAndView load(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
159 HttpServletRequest request, HttpServletResponse response) throws Exception {
160 GlobalEditForm globalEditForm = (GlobalEditForm) form;
161 boolean viewGlobalEditDispMessageFlag = false;
162 boolean hasPermission = canGloballyEdit(GlobalVariables.getUserSession().getPrincipalId());
163 if (!hasPermission) {
164 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
165 return super.navigate(globalEditForm, result, request, response);
166 }
167 GlobalVariables.getMessageMap().getInfoMessages().clear();
168 setShowPageSizeEntries(globalEditForm);
169 List<String> inputData = new ArrayList<>();
170 String fileName = null;
171 MultipartFile file = globalEditForm.getFile();
172 if (file != null && (file.getContentType().equalsIgnoreCase("application/octet-stream") ||
173 file.getContentType().equalsIgnoreCase("text/plain") ||
174 file.getOriginalFilename().endsWith(".txt"))) {
175 fileName = file.getOriginalFilename();
176 BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream()));
177 for (String line; (line = reader.readLine()) != null; ) {
178 inputData.add(line);
179 }
180 } else {
181
182 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_FILE_NOT_FOUND);
183 return navigate(globalEditForm, result, request, response);
184 }
185
186 List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>();
187 if (inputData.size() > 0) {
188 SearchParams searchParams = null;
189 List<SearchCondition> searchConditions = null;
190 String docType = globalEditForm.getDocType();
191 searchConditions = new ArrayList<>();
192 searchParams = new SearchParams();
193 for (String id : inputData) {
194 if (StringUtils.isNotEmpty(id)) {
195 if (globalEditForm.getFieldType().equalsIgnoreCase("Barcode")) {
196 if (DocType.HOLDINGS.getCode().equals(globalEditForm.getDocType())) {
197 searchConditions.add(searchParams.buildSearchCondition("NONE", searchParams.buildSearchField("item", "ItemBarcode_display", id), "OR"));
198 } else {
199 searchConditions.add(searchParams.buildSearchCondition("NONE", searchParams.buildSearchField(docType, "ItemBarcode_display", id), "OR"));
200 }
201 } else {
202 searchConditions.add(searchParams.buildSearchCondition("NONE", searchParams.buildSearchField(globalEditForm.getDocType(), "LocalId_display", id), "OR"));
203 }
204 }
205 }
206 if (globalEditForm.getFieldType() != null && globalEditForm.getFieldType().equalsIgnoreCase("Barcode") && DocType.HOLDINGS.getCode().equals(globalEditForm.getDocType())) {
207 searchParams.getSearchConditions().addAll(searchConditions);
208 searchResultDisplayRows = getSearchResults(searchParams, globalEditForm);
209 Set<String> holdingsIdList = new HashSet();
210 for (SearchResultDisplayRow searchResultDisplayRow : searchResultDisplayRows) {
211 holdingsIdList.add(searchResultDisplayRow.getHoldingsIdentifier());
212 }
213 for (String id : holdingsIdList) {
214 searchConditions.add(searchParams.buildSearchCondition("NONE", searchParams.buildSearchField(docType, "LocalId_display", id), "OR"));
215 }
216 searchParams.getSearchConditions().addAll(searchConditions);
217 searchResultDisplayRows = getSearchResults(searchParams, globalEditForm);
218 }
219
220 searchParams.getSearchConditions().addAll(searchConditions);
221 searchResultDisplayRows = getSearchResults(searchParams, globalEditForm);
222 }
223 List<String> listFromDB = new ArrayList<>();
224
225 List<String> unMatchedList = new ArrayList<>();
226 if (inputData.size() > 0) {
227 viewGlobalEditDispMessageFlag = true;
228 if (searchResultDisplayRows.size() > 0) {
229 for (SearchResultDisplayRow searchResultDisplayRow : searchResultDisplayRows) {
230 if ("Barcode".equals(globalEditForm.getFieldType())) {
231 listFromDB.add(searchResultDisplayRow.getBarcode());
232 } else {
233 listFromDB.add(searchResultDisplayRow.getLocalId());
234 }
235 }
236 }
237 }
238
239 for (int i = 0; i < inputData.size(); i++) {
240 if (!listFromDB.contains(inputData.get(i))) {
241
242 unMatchedList.add(inputData.get(i));
243 }
244 }
245
246 StringBuffer stringBuffer = new StringBuffer();
247 StringBuffer stringBuffer1 =new StringBuffer();
248 List<String> stringList = new ArrayList<>();
249 if(unMatchedList.size()>0){
250 for (int i = 0; i < unMatchedList.size(); i++) {
251 stringList.add(unMatchedList.get(i));
252 if (stringList.size() > 0 && stringList.size() <= 5) {
253 stringBuffer.append(unMatchedList.get(i));
254 stringBuffer.append(",");
255 } else {
256 stringBuffer1.append(".....");
257 }
258
259 }
260 stringBuffer = stringBuffer.deleteCharAt(stringBuffer.length() - 1);
261 }
262 stringBuffer = stringBuffer.append(stringBuffer1);
263 globalEditForm.setUnMatchedRecords(stringBuffer.toString());
264 globalEditForm.setUnMatchedCount(unMatchedList.size());
265 globalEditForm.setMatchedCount(listFromDB.size());
266 globalEditForm.setSelectedFileName(fileName);
267 globalEditForm.setTotalRecords(inputData.size());
268 globalEditForm.setViewGlobalEditDispMessageFlag(viewGlobalEditDispMessageFlag);
269
270
271 globalEditForm.setSearchResultDisplayRowList(searchResultDisplayRows);
272 if (searchResultDisplayRows.size() == 0) {
273 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_GLOBAL_SEARCH_MESSAGE);
274 }
275
276 return navigate(globalEditForm, result, request, response);
277 }
278
279 private List<SearchResultDisplayRow> getSearchResults(SearchParams searchParams, GlobalEditForm globalEditForm) throws Exception {
280 List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>();
281 searchParams.setStartIndex(this.start);
282 for (SearchCondition searchCondition : searchParams.getSearchConditions()) {
283 if (searchCondition.getSearchField() == null) {
284 searchCondition.setSearchField(new SearchField());
285 }
286
287 if (!"holdings".equals(globalEditForm.getDocType())) {
288 searchCondition.getSearchField().setDocType(globalEditForm.getDocType());
289 }
290 }
291 if (!globalEditForm.isMoreFacets()) {
292 searchParams.getFacetFields().clear();
293 Set<String> facetFields = getFacetFields(globalEditForm.getDocType());
294 searchParams.getFacetFields().addAll(facetFields);
295 searchParams.setFacetLimit(documentSearchConfig.getFacetPageSizeShort());
296 }
297 globalEditForm.setFacetLimit(documentSearchConfig.getFacetPageSizeShort() - 1);
298 SearchResponse searchResponse = null;
299 globalEditForm.setSearchResultDisplayFields(getDisplayFields(globalEditForm));
300 searchParams.buildSearchParams(searchParams, globalEditForm.getDocType());
301
302 if ("holdings".equals(globalEditForm.getDocType())) {
303 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ItemBarcode_display"));
304 }
305
306 try {
307 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
308 } catch (Exception e) {
309 LOG.error("Exception : ", e);
310 }
311 globalEditForm.setSearchResultDisplayFields(getDisplayFields(globalEditForm));
312 globalEditForm.setSearchResponse(searchResponse);
313 for (SearchResult searchResult : searchResponse.getSearchResults()) {
314 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
315 if (org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode().equalsIgnoreCase(globalEditForm.getDocType())) {
316 searchResultDisplayRow.buildBibSearchResultField(searchResult.getSearchResultFields(), eResourceId);
317 } else if (org.kuali.ole.docstore.common.document.content.enums.DocType.HOLDINGS.getCode().equals(globalEditForm.getDocType())) {
318 searchResultDisplayRow.buildHoldingSearchResultField(searchResult.getSearchResultFields());
319 } else if (org.kuali.ole.docstore.common.document.content.enums.DocType.EHOLDINGS.getCode().equals(globalEditForm.getDocType())) {
320 searchResultDisplayRow.buildEHoldingSearchResultField(searchResult.getSearchResultFields());
321 } else if (org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode().equals(globalEditForm.getDocType())) {
322 searchResultDisplayRow.buildItemSearchResultField(searchResult.getSearchResultFields());
323 }
324 searchResultDisplayRows.add(searchResultDisplayRow);
325 }
326 globalEditForm.setSearchResultDisplayRowList(searchResultDisplayRows);
327 if (searchResponse != null && searchResponse.getFacetResult() != null) {
328 globalEditForm.setFacetResultFields(searchResponse.getFacetResult().getFacetResultFields());
329 }
330 if (searchResultDisplayRows.size() == 0) {
331 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
332 }
333 setPageNextPreviousAndEntriesInfo(globalEditForm);
334 if (searchResponse != null && searchResponse.getFacetResult() != null) {
335 globalEditForm.setFacetResultFields(searchResponse.getFacetResult().getFacetResultFields());
336 }
337 return globalEditForm.getSearchResultDisplayRowList();
338 }
339
340
341 @RequestMapping(params = "methodToCall=viewGlobalEditRecords")
342 public ModelAndView viewGlobalEditRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
343 HttpServletRequest request, HttpServletResponse response) {
344 GlobalEditForm globalEditForm = (GlobalEditForm) form;
345 GlobalVariables.getMessageMap().getInfoMessages().clear();
346 if (globalEditForm.getGlobalEditRecords().size() == 0) {
347 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, OLEConstants.GLOBAL_EDIT_VIEW_RECORDS_MESSAGE);
348 } else {
349 globalEditForm.setViewGlobalEditFlag(true);
350 for (SearchResultDisplayRow searchResultDisplayRow : globalEditForm.getGlobalEditRecords()) {
351 searchResultDisplayRow.setSelect(false);
352 }
353 }
354
355 return navigate(globalEditForm, result, request, response);
356 }
357
358 @RequestMapping(params = "methodToCall=addGlobalEditRecords")
359 public ModelAndView addGlobalEditRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
360 HttpServletRequest request, HttpServletResponse response) {
361 GlobalEditForm globalEditForm = (GlobalEditForm) form;
362 GlobalVariables.getMessageMap().getInfoMessages().clear();
363 if (globalEditForm.getSearchResultDisplayRowList() == null || globalEditForm.getSearchResultDisplayRowList().size() == 0) {
364 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, OLEConstants.DESCRIBE_GLOBAL_SEARCH_MESSAGE);
365 return navigate(globalEditForm, result, request, response);
366 }
367 boolean selectFlag = false;
368 List<SearchResultDisplayRow> searchResultDisplayRows = globalEditForm.getGlobalEditRecords();
369 Map<String, SearchResultDisplayRow> searchResultDisplayRowMap = globalEditForm.getGlobalEditMap();
370 int pageSize = globalEditForm.getPageSize();
371 if (globalEditForm.isSelectAll()) {
372 globalEditForm.setPageSize(globalEditForm.getTotalRecords());
373 searchDocstoreData(globalEditForm, request);
374 globalEditForm.setPageSize(pageSize);
375 super.setPageNextPreviousAndEntriesInfo(globalEditForm);
376 }
377 for (SearchResultDisplayRow searchResultDisplayRow : globalEditForm.getSearchResultDisplayRowList()) {
378 if (globalEditForm.isSelectAll() || searchResultDisplayRow.isSelect()) {
379 if ((globalEditForm.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode())
380 || globalEditForm.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode())) &&
381 !searchResultDisplayRowMap.containsKey(searchResultDisplayRow.getLocalId())) {
382 selectFlag = true;
383 searchResultDisplayRow.setDocType(globalEditForm.getDocType());
384
385 searchResultDisplayRows.add(searchResultDisplayRow);
386 searchResultDisplayRowMap.put(searchResultDisplayRow.getLocalId(), searchResultDisplayRow);
387 } else if (globalEditForm.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) &&
388 !searchResultDisplayRowMap.containsKey(searchResultDisplayRow.getItemIdentifier())) {
389 selectFlag = true;
390 searchResultDisplayRows.add(searchResultDisplayRow);
391 searchResultDisplayRow.setDocType(globalEditForm.getDocType());
392
393 searchResultDisplayRowMap.put(searchResultDisplayRow.getItemIdentifier(), searchResultDisplayRow);
394 }
395 }
396 }
397 if (!selectFlag) {
398 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, OLEConstants.GLOBAL_EDIT_ADD_RECORDS_MESSAGE);
399 }
400 return navigate(globalEditForm, result, request, response);
401 }
402
403 @RequestMapping(params = "methodToCall=globalEdit")
404 public ModelAndView globalEdit(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
405 HttpServletRequest request, HttpServletResponse response) throws Exception {
406 GlobalEditForm globalEditForm = (GlobalEditForm) form;
407 GlobalVariables.getMessageMap().getInfoMessages().clear();
408 List<SearchResultDisplayRow> searchResultDisplayRowList = globalEditForm.getGlobalEditRecords();
409 Iterator<SearchResultDisplayRow> iterator = searchResultDisplayRowList.iterator();
410 List<String> ids = new ArrayList();
411 while (iterator.hasNext()) {
412 SearchResultDisplayRow searchResultDisplayRow = iterator.next();
413 if (searchResultDisplayRow.getDocType() != null && (searchResultDisplayRow.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode())
414 || searchResultDisplayRow.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()))) {
415 ids.add(searchResultDisplayRow.getHoldingsIdentifier());
416 } else if (searchResultDisplayRow.getDocType() != null && searchResultDisplayRow.getDocType().equalsIgnoreCase(DocType.ITEM.getCode())) {
417 ids.add(searchResultDisplayRow.getItemIdentifier());
418 }
419 }
420 request.getSession().setAttribute("Ids", ids);
421 return navigate(globalEditForm, result, request, response);
422 }
423
424 @RequestMapping(params = "methodToCall=close")
425 public ModelAndView close(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
426 HttpServletRequest request, HttpServletResponse response) {
427 GlobalEditForm globalEditForm = (GlobalEditForm) form;
428 globalEditForm.setViewGlobalEditFlag(false);
429
430
431
432 globalEditForm.setSelectAll(false);
433 globalEditForm.getSearchConditions().clear();
434 globalEditForm.getSearchConditions().addAll(globalEditForm.getSearchParams().getSearchConditions());
435 return navigate(globalEditForm, result, request, response);
436 }
437
438 @RequestMapping(params = "methodToCall=globalClear")
439 public ModelAndView globalClear(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
440 HttpServletRequest request, HttpServletResponse response) throws Exception {
441 GlobalEditForm globalEditForm = (GlobalEditForm) form;
442 if (globalEditForm.getGlobalEditRecords().size() > 0) {
443 globalEditForm.getGlobalEditRecords().clear();
444 }
445 return navigate(globalEditForm, result, request, response);
446 }
447
448 public SearchResultDisplayFields getDisplayFields(GlobalEditForm globalEditForm) {
449 SearchResultDisplayFields searchResultDisplayFields = new SearchResultDisplayFields();
450 searchResultDisplayFields.buildSearchResultDisplayFields(documentSearchConfig.getDocTypeConfigs(), globalEditForm.getDocType());
451 return searchResultDisplayFields;
452 }
453
454 private void setShowPageSizeEntries(GlobalEditForm globalEditForm) {
455 super.setShowPageSizeEntries(globalEditForm);
456 }
457
458 private boolean canGloballyEdit(String principalId) {
459 PermissionService service = KimApiServiceLocator.getPermissionService();
460 return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.GLOBAL_EDIT_PERMISSION);
461 }
462
463
464
465
466
467
468
469
470
471
472
473 @Override
474 @RequestMapping(params = "methodToCall=clear")
475 public ModelAndView clear(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
476 HttpServletRequest request, HttpServletResponse response) {
477 LOG.debug("Inside the clear method");
478 GlobalEditForm globalEditForm = (GlobalEditForm) form;
479
480
481 globalEditForm.setFile(null);
482 globalEditForm.getGlobalEditRecords().clear();
483 globalEditForm.getGlobalEditMap().clear();
484 globalEditForm.setSearchResultDisplayFields(new SearchResultDisplayFields());
485 globalEditForm.setMessage(null);
486 globalEditForm.setHoldingsList(null);
487 globalEditForm.setItemList(null);
488 globalEditForm.setPageSize(10);
489 globalEditForm.setPreviousFlag(false);
490 globalEditForm.setNextFlag(false);
491 globalEditForm.setCallNumberBrowseText("");
492 globalEditForm.setSelectAll(false);
493 globalEditForm.setSearchParams(new SearchParams());
494 if (globalEditForm.getSearchResultDisplayRowList() != null && globalEditForm.getSearchResultDisplayRowList().size() > 0) {
495 globalEditForm.getSearchResultDisplayRowList().clear();
496 }
497 if (globalEditForm.getSearchParams() != null && globalEditForm.getSearchParams().getFacetFields() != null) {
498 globalEditForm.getSearchParams().getFacetFields().clear();
499 }
500 if (globalEditForm.getFacetResultFields() != null) {
501 globalEditForm.getFacetResultFields().clear();
502 }
503 return start(globalEditForm, result, request, response);
504 }
505
506 @RequestMapping(params = "methodToCall=removeFromList")
507 public ModelAndView removeFromList(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
508 HttpServletRequest request, HttpServletResponse response) {
509 GlobalEditForm globalEditForm = (GlobalEditForm) form;
510 List<SearchResultDisplayRow> rowsListToRemove = new ArrayList<>();
511
512 for (SearchResultDisplayRow searchResultDisplayRow : globalEditForm.getGlobalEditRecords()) {
513 if (searchResultDisplayRow.isSelect()) {
514 searchResultDisplayRow.setSelect(false);
515 rowsListToRemove.add(searchResultDisplayRow);
516 globalEditForm.getGlobalEditMap().remove(searchResultDisplayRow.getLocalId());
517 }
518 }
519 globalEditForm.getGlobalEditRecords().removeAll(rowsListToRemove);
520 return navigate(globalEditForm, result, request, response);
521 }
522 }