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
87 SearchCondition searchCondition = new SearchCondition();
88 searchCondition.setOperator("AND");
89 globalEditForm.getSearchConditions().add(searchCondition);
90 GlobalVariables.getMessageMap().getInfoMessages().clear();
91 globalEditForm.setViewGlobalEditFlag(false);
92 globalEditForm.setStart(0);
93
94 if (globalEditForm.getSearchResultDisplayRowList() != null && globalEditForm.getSearchResultDisplayRowList().size() > 0) {
95 globalEditForm.getSearchResultDisplayRowList().clear();
96 }
97 if (globalEditForm.getGlobalEditMap() != null && globalEditForm.getGlobalEditMap().size() > 0) {
98 globalEditForm.getGlobalEditMap().clear();
99 }
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
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
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
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
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
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
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
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
427
428
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
462
463
464
465
466
467
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
477
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
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 }