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.DocumentUniqueIDPrefix;
7 import org.kuali.ole.OLEConstants;
8 import org.kuali.ole.describe.bo.SearchResultDisplayFields;
9 import org.kuali.ole.describe.bo.SearchResultDisplayRow;
10 import org.kuali.ole.describe.form.GlobalEditForm;
11 import org.kuali.ole.describe.form.OLESearchForm;
12 import org.kuali.ole.describe.service.BrowseService;
13 import org.kuali.ole.describe.service.impl.BrowseServiceImpl;
14 import org.kuali.ole.docstore.OleException;
15 import org.kuali.ole.docstore.common.client.DocstoreClient;
16 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
17 import org.kuali.ole.docstore.common.document.*;
18 import org.kuali.ole.docstore.common.document.config.*;
19 import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
20 import org.kuali.ole.docstore.common.document.content.enums.DocType;
21 import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
22 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
23 import org.kuali.ole.docstore.common.search.*;
24 import org.kuali.ole.docstore.common.search.SearchResult;
25 import org.kuali.ole.docstore.engine.client.DocstoreLocalClient;
26 import org.kuali.ole.docstore.engine.service.index.solr.BibConstants;
27 import org.kuali.ole.docstore.engine.service.index.solr.ItemConstants;
28 import org.kuali.ole.docstore.utility.ISBNUtil;
29 import org.kuali.ole.select.bo.OLEEditorResponse;
30 import org.kuali.ole.select.businessobject.OleCopy;
31 import org.kuali.ole.select.businessobject.OleDocstoreResponse;
32 import org.kuali.ole.select.document.OLEEResourceRecordDocument;
33 import org.kuali.ole.service.OLEEResourceSearchService;
34 import org.kuali.ole.sys.context.SpringContext;
35 import org.kuali.rice.core.api.exception.RiceRuntimeException;
36 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
37 import org.kuali.rice.kim.api.identity.Person;
38 import org.kuali.rice.kim.api.identity.PersonService;
39 import org.kuali.rice.kim.api.permission.PermissionService;
40 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
41 import org.kuali.rice.krad.service.BusinessObjectService;
42 import org.kuali.rice.krad.service.DocumentService;
43 import org.kuali.rice.krad.service.KRADServiceLocator;
44 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
45 import org.kuali.rice.krad.uif.UifParameters;
46 import org.kuali.rice.krad.uif.view.View;
47 import org.kuali.rice.krad.util.GlobalVariables;
48 import org.kuali.rice.krad.util.KRADConstants;
49 import org.kuali.rice.krad.web.controller.UifControllerBase;
50 import org.kuali.rice.krad.web.form.UifFormBase;
51 import org.springframework.stereotype.Controller;
52 import org.springframework.validation.BindingResult;
53 import org.springframework.web.bind.annotation.ModelAttribute;
54 import org.springframework.web.bind.annotation.RequestMapping;
55 import org.springframework.web.bind.annotation.RequestMethod;
56 import org.springframework.web.servlet.ModelAndView;
57
58 import javax.servlet.http.HttpServletRequest;
59 import javax.servlet.http.HttpServletResponse;
60 import java.util.*;
61
62
63
64
65
66
67
68
69 @Controller
70 @RequestMapping(value = "/olesearchcontroller")
71 public class OLESearchController extends UifControllerBase {
72
73 private static final Logger LOG = Logger.getLogger(OLESearchController.class);
74 private String eResourceId;
75 private String tokenId;
76 private int totalRecCount;
77 private int start;
78 private int pageSize;
79 private DocstoreClient docstoreClient = getDocstoreLocalClient();
80 private OLEEResourceSearchService oleEResourceSearchService;
81 private BrowseService browseService;
82 private DocumentService documentService;
83
84 public DocstoreClient getDocstoreLocalClient() {
85 if (null == docstoreClient) {
86 return new DocstoreLocalClient();
87 }
88 return docstoreClient;
89 }
90
91 public BrowseService getBrowseService() {
92 if(browseService == null) {
93 browseService = new BrowseServiceImpl();
94 }
95 return browseService;
96 }
97 public OLEEResourceSearchService getOleEResourceSearchService() {
98 if (oleEResourceSearchService == null) {
99 oleEResourceSearchService = GlobalResourceLoader.getService(OLEConstants.OLEEResourceRecord.ERESOURSE_SEARCH_SERVICE);
100 }
101 return oleEResourceSearchService;
102 }
103 public DocumentService getDocumentService() {
104 if (this.documentService == null) {
105 this.documentService = KRADServiceLocatorWeb.getDocumentService();
106 }
107 return this.documentService;
108 }
109
110 public void setDocumentService(DocumentService documentService) {
111 this.documentService = documentService;
112 }
113 DocumentSearchConfig documentSearchConfig = DocumentSearchConfig.getDocumentSearchConfig();
114
115 public int getTotalRecCount() {
116 return totalRecCount;
117 }
118
119 public void setTotalRecCount(int totalRecCount) {
120 this.totalRecCount = totalRecCount;
121 }
122
123 public int getStart() {
124 return start;
125 }
126
127 public void setStart(int start) {
128 this.start = start;
129 }
130
131 public int getPageSize() {
132 return pageSize;
133 }
134
135 public void setPageSize(int pageSize) {
136 this.pageSize = pageSize;
137 }
138
139 public boolean getPreviousFlag() {
140 if (this.start == 0)
141 return false;
142 return true;
143 }
144
145 public boolean getNextFlag() {
146 if (this.start + this.pageSize < this.totalRecCount)
147 return true;
148 return false;
149 }
150
151 public String getPageShowEntries() {
152 return "Showing " + ((this.start == 0) ? 1 : this.start + 1) + " to "
153 + (((this.start + this.pageSize) > this.totalRecCount) ? this.totalRecCount : (this.start + this.pageSize))
154 + " of " + this.totalRecCount + " entries";
155 }
156
157 public String getFacetShowEntries(SearchParams searchParams, int totalRecordCount) {
158 return "Showing " + ((searchParams.getFacetOffset() == 0) ? 1 : searchParams.getFacetOffset() + 1) + " to "
159 + (((searchParams.getFacetOffset() + searchParams.getFacetLimit()) > totalRecordCount) ? totalRecordCount : (searchParams.getFacetOffset() + searchParams.getFacetLimit()))
160 + " of " + totalRecordCount + " entries";
161 }
162
163 @Override
164 protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
165 return new OLESearchForm();
166
167 }
168
169 @Override
170 @RequestMapping(params = "methodToCall=start")
171 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
172 HttpServletRequest request, HttpServletResponse response) {
173 this.start = 0;
174 LOG.debug("Inside the olesearchform start method");
175 OLESearchForm oleSearchForm = (OLESearchForm) form;
176 oleSearchForm.setWorkBibDocumentList(null);
177 oleSearchForm.setWorkHoldingsDocumentList(null);
178 oleSearchForm.setWorkItemDocumentList(null);
179 oleSearchForm.setWorkEHoldingsDocumentList(null);
180 oleSearchForm.setSearchTypeField("OLESearch");
181 oleSearchForm.setSelectAllRecords(false);
182 request.getSession().setAttribute("selectedFacetResults", null);
183 if (oleSearchForm.getDocType() == null) {
184 oleSearchForm.setDocType(DocType.BIB.getCode());
185 }
186 if (StringUtils.isEmpty(oleSearchForm.getSearchType())) {
187 oleSearchForm.setSearchType("search");
188 }
189 if (StringUtils.isEmpty(oleSearchForm.getBrowseField())) {
190 oleSearchForm.setBrowseField("title");
191 }
192
193 oleSearchForm.getSearchConditions().clear();
194
195 SearchCondition searchCondition = new SearchCondition();
196 searchCondition.setOperator("AND");
197 oleSearchForm.getSearchConditions().add(searchCondition);
198 String eInstance = request.getParameter(OLEConstants.E_INSTANCE);
199 if (eInstance != null && eInstance.equalsIgnoreCase(OLEConstants.LINK_EXISTING_INSTANCE)) {
200 oleSearchForm.setLinkExistingInstance(eInstance);
201 }
202 if (request.getParameter(OLEConstants.E_RESOURCE_ID) != null) {
203 eResourceId = request.getParameter(OLEConstants.E_RESOURCE_ID);
204 }
205 if (request.getParameter(OLEConstants.TOKEN_ID) != null) {
206 tokenId = request.getParameter(OLEConstants.TOKEN_ID);
207 }
208 oleSearchForm.setStart(0);
209 if(oleSearchForm.getSearchParams() != null) {
210 oleSearchForm.getSearchParams().setStartIndex(0);
211 }
212 clearForm(oleSearchForm);
213 GlobalVariables.getMessageMap().clearErrorMessages();
214 boolean hasSearchPermission = canSearch(GlobalVariables.getUserSession().getPrincipalId());
215 if (!hasSearchPermission && oleSearchForm.getDocType().equalsIgnoreCase(OLEConstants.BIB_DOC_TYPE)) {
216 boolean hasLinkPermission = canLinkBibForRequisition(GlobalVariables.getUserSession().getPrincipalId());
217 if (!hasLinkPermission) {
218 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
219 return super.navigate(oleSearchForm, result, request, response);
220 }
221 } else if (!hasSearchPermission) {
222 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
223 return super.navigate(oleSearchForm, result, request, response);
224 }
225 oleSearchForm.setMessage(null);
226 oleSearchForm.setSearchResultDisplayRowList(null);
227 oleSearchForm.setBibSearchResultDisplayRowList(null);
228 oleSearchForm.setHoldingSearchResultDisplayRowList(null);
229 oleSearchForm.setShowTime(true);
230 return super.navigate(oleSearchForm, result, request, response);
231 }
232
233 private boolean canSearch(String principalId) {
234 PermissionService service = KimApiServiceLocator.getPermissionService();
235 return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.DESC_WORKBENCH_SEARCH);
236 }
237
238 private boolean canLinkBibForRequisition(String principalId) {
239 PermissionService service = KimApiServiceLocator.getPermissionService();
240 return service.hasPermission(principalId, OLEConstants.SELECT_NMSPC, OLEConstants.LINK_EXISTING_BIB);
241 }
242
243 @RequestMapping(params = "methodToCall=submit")
244 public ModelAndView submit(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
245 HttpServletRequest request, HttpServletResponse response) throws Exception {
246 OLESearchForm oleSearchForm = (OLESearchForm) form;
247 boolean isValid = false;
248 BusinessObjectService boService = KRADServiceLocator.getBusinessObjectService();
249 Map<String, String> map = new HashMap<>();
250 List<Integer> resultList = new ArrayList<>();
251 for (SearchResultDisplayRow searchResultDisplayRow : oleSearchForm.getSearchResultDisplayRowList()) {
252 if (searchResultDisplayRow.isSelect()) {
253 map.put(OLEConstants.BIB_ID, DocumentUniqueIDPrefix.getPrefixedId("wbm",searchResultDisplayRow.getLocalId()));
254 List<OleCopy> listOfValues = (List<OleCopy>) boService.findMatching(OleCopy.class, map);
255 if (listOfValues.size() > 0 && (oleSearchForm.getMessage() == null || oleSearchForm.getMessage().equals(""))) {
256 for (OleCopy oleCopy : listOfValues) {
257 resultList.add(oleCopy.getReqDocNum());
258 }
259 Set<Integer> resultSet = new HashSet<>(resultList);
260 resultList = new ArrayList<>(resultSet);
261 StringBuffer reqIds = new StringBuffer("");
262 if (resultList.size() > 0) {
263 int count = 0;
264 for (; count < resultList.size() - 1; count++) {
265 reqIds.append(resultList.get(count) + ",");
266 }
267 reqIds.append(resultList.get(count));
268 }
269 oleSearchForm.setMessage(OLEConstants.POPUP_MESSAGE + reqIds.toString() + OLEConstants.PROCEED_MESSAGE);
270 return getUIFModelAndView(oleSearchForm);
271 }
272 oleSearchForm.setMessage("");
273 processNewRecordResponseForOLE(searchResultDisplayRow.getLocalId(), oleSearchForm.getTokenId(), oleSearchForm.getLinkToOrderOption());
274 oleSearchForm.setSuccessMessage(OLEConstants.LINK_SUCCESS_MESSAGE);
275 isValid = true;
276 break;
277 }
278 }
279 if (isValid == false) {
280 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.BIB_SELECT);
281 return getUIFModelAndView(oleSearchForm);
282 }
283 return getUIFModelAndView(oleSearchForm);
284 }
285
286 @RequestMapping(params = "methodToCall=search")
287 public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
288 HttpServletRequest request, HttpServletResponse response) {
289 float start = System.currentTimeMillis()/1000;
290 OLESearchForm oleSearchForm = (OLESearchForm) form;
291 boolean hasSearchPermission = canSearch(GlobalVariables.getUserSession().getPrincipalId());
292 if (!hasSearchPermission && oleSearchForm.getDocType().equalsIgnoreCase(OLEConstants.BIB_DOC_TYPE)) {
293 boolean hasLinkPermission = canLinkBibForRequisition(GlobalVariables.getUserSession().getPrincipalId());
294 if (!hasLinkPermission) {
295 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
296 return super.navigate(oleSearchForm, result, request, response);
297 }
298 } else if (!hasSearchPermission) {
299 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
300 return super.navigate(oleSearchForm, result, request, response);
301 }
302 oleSearchForm.getSearchParams().setFacetOffset(0);
303 searchDocstoreData(oleSearchForm, request);
304 float end = System.currentTimeMillis()/1000;
305 oleSearchForm.setServerTime(String.valueOf(end-start));
306 return super.navigate(oleSearchForm, result, request, response);
307 }
308 private void processNewRecordResponseForOLE(String bibId, String tokenId, String linkToOrderOption) throws Exception {
309 String instanceUUID = null;
310 BibTree bibTree = getDocstoreLocalClient().retrieveBibTree(bibId);
311 OLEEditorResponse oleEditorResponse = new OLEEditorResponse();
312 if (bibTree.getHoldingsTrees() != null && bibTree.getHoldingsTrees().size() > 0) {
313 instanceUUID = bibTree.getHoldingsTrees().get(0).getId();
314 }
315 oleEditorResponse.setLinkedInstanceId(instanceUUID);
316 oleEditorResponse.setBib(bibTree.getBib());
317 oleEditorResponse.setTokenId(tokenId);
318 oleEditorResponse.setLinkToOrderOption(linkToOrderOption);
319 HashMap<String, OLEEditorResponse> oleEditorResponseMap = new HashMap<String, OLEEditorResponse>();
320 oleEditorResponseMap.put(tokenId, oleEditorResponse);
321 OleDocstoreResponse.getInstance().setEditorResponse(oleEditorResponseMap);
322 }
323
324 protected void setShowPageSizeEntries(OLESearchForm oleSearchForm) {
325 List<Integer> pageSizes = documentSearchConfig.getPageSizes();
326 if (CollectionUtils.isEmpty(pageSizes)) {
327 pageSizes.add(10);
328 pageSizes.add(25);
329 pageSizes.add(50);
330 pageSizes.add(100);
331 }
332 oleSearchForm.setShowPageSize(pageSizes.toString());
333 }
334
335 @RequestMapping(params = "methodToCall=pageNumberSearch")
336 public ModelAndView pageNumberSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
337 HttpServletRequest request, HttpServletResponse response) throws Exception {
338
339 OLESearchForm oleSearchForm = (OLESearchForm) form;
340 SearchParams searchParams = oleSearchForm.getSearchParams();
341 try {
342 int start = Math.max(0,
343 (Integer.parseInt(oleSearchForm.getPageNumber()) - 1)
344 * searchParams.getPageSize());
345 searchParams.setStartIndex(start);
346 } catch (NumberFormatException e) {
347 LOG.warn("Invalid page number " + oleSearchForm.getPageNumber(), e);
348 }
349 return search(oleSearchForm, result, request, response);
350 }
351
352 @RequestMapping(params = "methodToCall=lastPageSearch")
353 public ModelAndView lastPageSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
354 HttpServletRequest request, HttpServletResponse response) throws Exception {
355
356 OLESearchForm oleSearchForm = (OLESearchForm) form;
357 SearchParams searchParams = oleSearchForm.getSearchParams();
358 try {
359 int totalLines = oleSearchForm.getTotalRecordCount();
360 int pageSize = searchParams.getPageSize();
361 int lastPage = totalLines / pageSize
362 + (totalLines % pageSize == 0 ? 0 : 1);
363 int start = Math.max(0, lastPage);
364 searchParams.setStartIndex(start);
365 } catch (NumberFormatException e) {
366 LOG.warn("Invalid page number " + oleSearchForm.getPageNumber(), e);
367 }
368 return search(oleSearchForm, result, request, response);
369 }
370
371 @RequestMapping(params = "methodToCall=nextSearch")
372 public ModelAndView nextSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
373 HttpServletRequest request, HttpServletResponse response) throws Exception {
374
375 OLESearchForm oleSearchForm = (OLESearchForm) form;
376 SearchParams searchParams = oleSearchForm.getSearchParams();
377 int start = Math.max(0, searchParams.getStartIndex() + searchParams.getPageSize());
378 searchParams.setStartIndex(start);
379 return search(oleSearchForm, result, request, response);
380 }
381
382 @RequestMapping(params = "methodToCall=previousSearch")
383 public ModelAndView previousSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
384 HttpServletRequest request, HttpServletResponse response) throws Exception {
385
386 OLESearchForm oleSearchForm = (OLESearchForm) form;
387 SearchParams searchParams = oleSearchForm.getSearchParams();
388 int start = Math.max(0, searchParams.getStartIndex() - oleSearchForm.getPageSize());
389 searchParams.setStartIndex(start);
390 return search(oleSearchForm, result, request, response);
391 }
392
393 @RequestMapping(params = "methodToCall=facetSearch")
394 public ModelAndView facetSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
395 HttpServletRequest request, HttpServletResponse response) {
396 OLESearchForm oleSearchForm = (OLESearchForm) form;
397 String docType = request.getParameter("docType");
398 String selectedFacet = request.getParameter("selectedFacet");
399 String selectedFacetName = request.getParameter("selectedFacetName");
400 oleSearchForm.setDocType(docType);
401 if (oleSearchForm.getSearchParams() == null) {
402 SearchParams searchParams = (SearchParams) request.getSession().getAttribute("searchParams");
403 oleSearchForm.setSearchParams(searchParams);
404 }
405 oleSearchForm.getSearchConditions().clear();
406 SearchCondition searchCondition = new SearchCondition();
407 List<Integer> pageSizes = documentSearchConfig.getPageSizes();
408 if(!pageSizes.isEmpty() || pageSizes.size() > 0) {
409 oleSearchForm.setPageSize(pageSizes.get(0));
410 }
411 searchCondition.setOperator("AND");
412 oleSearchForm.getSearchConditions().addAll(oleSearchForm.getSearchParams().getSearchConditions());
413 String eInstance = request.getParameter(OLEConstants.E_INSTANCE);
414 if (eInstance != null && eInstance.equalsIgnoreCase(OLEConstants.LINK_EXISTING_INSTANCE)) {
415 oleSearchForm.setLinkExistingInstance(eInstance);
416 }
417 if (request.getParameter(OLEConstants.TOKEN_ID) != null) {
418 tokenId = request.getParameter(OLEConstants.TOKEN_ID);
419 }
420 oleSearchForm.getSearchParams().getFacetFields().addAll(getFacetFields(oleSearchForm.getDocType()));
421 oleSearchForm.getSearchParams().setFacetPrefix("");
422 oleSearchForm.getSearchParams().setFacetLimit(documentSearchConfig.getFacetPageSizeShort());
423 FacetCondition facetCondition = new FacetCondition();
424 facetCondition.setFieldName(selectedFacetName);
425 facetCondition.setFieldValue(selectedFacet);
426 oleSearchForm.getSearchParams().getFacetConditions().add(facetCondition);
427 oleSearchForm.setSearchType("search");
428 GlobalVariables.getMessageMap().clearErrorMessages();
429 return search(oleSearchForm, result, request, response);
430 }
431 @RequestMapping(params = "methodToCall=removeFacet")
432 public ModelAndView removeFacet(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
433 HttpServletRequest request, HttpServletResponse response) {
434 OLESearchForm oleSearchForm = (OLESearchForm) form;
435 int index = Integer.parseInt(oleSearchForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
436 if(!CollectionUtils.isEmpty(oleSearchForm.getSearchParams().getFacetConditions()) && oleSearchForm.getSearchParams().getFacetConditions().size() > index) {
437 oleSearchForm.getSearchParams().getFacetConditions().remove(index);
438 }
439 return search(oleSearchForm, result, request, response);
440 }
441
442 @RequestMapping(params = "methodToCall=moreFacets")
443 public ModelAndView moreFacets(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
444 HttpServletRequest request, HttpServletResponse response) {
445 OLESearchForm oleSearchForm = (OLESearchForm) form;
446 if(StringUtils.isEmpty(oleSearchForm.getDocType())) {
447 oleSearchForm.setDocType(request.getParameter("docType"));
448 }
449 SearchParams searchParams = oleSearchForm.getSearchParams();
450 if(searchParams == null) {
451 searchParams = (SearchParams) request.getSession().getAttribute("searchParams");
452 }
453 if(StringUtils.isNotEmpty(request.getParameter("facetField"))) {
454 if(!CollectionUtils.isEmpty(searchParams.getFacetFields())) {
455 searchParams.getFacetFields().clear();
456 }
457 searchParams.getFacetFields().add(request.getParameter("facetField"));
458 }
459 if(StringUtils.isNotEmpty(request.getParameter("facetPrefix"))) {
460 searchParams.setFacetPrefix(request.getParameter("facetPrefix"));
461 }
462 oleSearchForm.setSearchParams(searchParams);
463 oleSearchForm.getSearchConditions().addAll(searchParams.getSearchConditions());
464 searchParams.setFacetOffset(0);
465 searchParams.setFacetLimit(documentSearchConfig.getFacetPageSizeLong());
466 oleSearchForm.setMoreFacets(true);
467 searchDocstoreData(oleSearchForm, request);
468 return super.navigate(oleSearchForm, result, request, response);
469 }
470
471 @RequestMapping(params = "methodToCall=nextFacet")
472 public ModelAndView nextFacet(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
473 HttpServletRequest request, HttpServletResponse response) {
474 OLESearchForm oleSearchForm = (OLESearchForm) form;
475 if(StringUtils.isEmpty(oleSearchForm.getDocType())) {
476 oleSearchForm.setDocType(request.getParameter("docType"));
477 }
478 SearchParams searchParams = oleSearchForm.getSearchParams();
479 if(searchParams == null) {
480 searchParams = (SearchParams) request.getSession().getAttribute("searchParams");
481 }
482 if(StringUtils.isNotEmpty(request.getParameter("facetField"))) {
483 if(!CollectionUtils.isEmpty(searchParams.getFacetFields())) {
484 searchParams.getFacetFields().clear();
485 }
486 searchParams.getFacetFields().add(request.getParameter("facetField"));
487 }
488 int facetCount = oleSearchForm.getSearchResponse().getFacetResult().getFacetResultFields().get(0).getTotalCount();
489 int facetOffset = searchParams.getFacetOffset() + documentSearchConfig.getFacetPageSizeLong();
490 searchParams.setFacetOffset(facetOffset);
491 oleSearchForm.setSearchParams(searchParams);
492 oleSearchForm.getSearchConditions().addAll(searchParams.getSearchConditions());
493 oleSearchForm.setMoreFacets(true);
494 oleSearchForm.setFacetPageEntries(getFacetShowEntries(searchParams, facetCount));
495 searchDocstoreData(oleSearchForm, request);
496 return super.navigate(oleSearchForm, result, request, response);
497 }
498
499 @RequestMapping(params = "methodToCall=previousFacet")
500 public ModelAndView previousFacet(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
501 HttpServletRequest request, HttpServletResponse response) {
502 OLESearchForm oleSearchForm = (OLESearchForm) form;
503 if(StringUtils.isEmpty(oleSearchForm.getDocType())) {
504 oleSearchForm.setDocType(request.getParameter("docType"));
505 }
506 SearchParams searchParams = oleSearchForm.getSearchParams();
507 if(searchParams == null) {
508 searchParams = (SearchParams) request.getSession().getAttribute("searchParams");
509 }
510 if(StringUtils.isNotEmpty(request.getParameter("facetField"))) {
511 if(!CollectionUtils.isEmpty(searchParams.getFacetFields())) {
512 searchParams.getFacetFields().clear();
513 }
514 searchParams.getFacetFields().add(request.getParameter("facetField"));
515 }
516 int facetCount = oleSearchForm.getSearchResponse().getFacetResult().getFacetResultFields().get(0).getTotalCount();
517 int facetLimit = searchParams.getFacetOffset() - documentSearchConfig.getFacetPageSizeLong();
518 searchParams.setFacetOffset(facetLimit > 0 ? facetLimit : 0);
519 oleSearchForm.setSearchParams(searchParams);
520 oleSearchForm.getSearchConditions().addAll(searchParams.getSearchConditions());
521 oleSearchForm.setMoreFacets(true);
522 oleSearchForm.setFacetPageEntries(getFacetShowEntries(searchParams, facetCount));
523 searchDocstoreData(oleSearchForm, request);
524 return super.navigate(oleSearchForm, result, request, response);
525 }
526
527 @RequestMapping(params = "methodToCall=browse")
528 public ModelAndView browse(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
529 HttpServletRequest request, HttpServletResponse response) {
530 OLESearchForm oleSearchForm = (OLESearchForm) form;
531 boolean hasPermission = performBrowse(GlobalVariables.getUserSession().getPrincipalId());
532 if (!hasPermission) {
533 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_INFO, OLEConstants.ERROR_AUTHORIZATION);
534 return getUIFModelAndView(oleSearchForm);
535 }
536
537 if ("title".equals(oleSearchForm.getBrowseField())) {
538 oleSearchForm.setDocType(DocType.BIB.getCode());
539 List<SearchResultDisplayRow> searchResultDisplayRowList = getBrowseService().browse(oleSearchForm);
540 oleSearchForm.setSearchResultDisplayRowList(searchResultDisplayRowList);
541
542 } else {
543 String location = getBrowseService().validateLocation(oleSearchForm.getLocation());
544 oleSearchForm.setLocation(location);
545 if (oleSearchForm.getDocType().equalsIgnoreCase(DocType.ITEM.getCode())) {
546 List<Item> itemList = getBrowseService().browse(oleSearchForm);
547 oleSearchForm.setItemList(itemList);
548 } else {
549 List<Holdings> holdingsList = getBrowseService().browse(oleSearchForm);
550 oleSearchForm.setHoldingsList(holdingsList);
551 }
552 }
553 setBrowsePageNextPrevoiusAndEntriesInfo(oleSearchForm);
554 return getUIFModelAndView(form);
555 }
556
557 @RequestMapping(params = "methodToCall=workBenchBrowseClear")
558 public ModelAndView workBenchClear(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
559 HttpServletRequest request, HttpServletResponse response) throws Exception {
560 OLESearchForm oleSearchForm = (OLESearchForm) form;
561 List<Integer> pageSizes = documentSearchConfig.getPageSizes();
562 if(!pageSizes.isEmpty() || pageSizes.size() > 0) {
563 oleSearchForm.setPageSize(pageSizes.get(0));
564 }
565 oleSearchForm.setBrowseText("");
566 if(oleSearchForm.getSearchResultDisplayRowList() != null) {
567 oleSearchForm.getSearchResultDisplayRowList().clear();
568 }
569 return navigate(oleSearchForm, result, request, response);
570 }
571
572 @RequestMapping(params = "methodToCall=rowsBrowse")
573 public ModelAndView rowsBrowse(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
574 HttpServletRequest request, HttpServletResponse response) throws Exception {
575 LOG.debug("Inside the browse method");
576 OLESearchForm oleSearchForm = (OLESearchForm) form;
577 if ("title".equals(oleSearchForm.getBrowseField())) {
578 oleSearchForm.setDocType(DocType.BIB.getCode());
579 List<SearchResultDisplayRow> searchResultDisplayRowList = getBrowseService().browseOnChange(oleSearchForm);
580 oleSearchForm.setSearchResultDisplayRowList(searchResultDisplayRowList);
581
582 } else {
583
584 if (oleSearchForm.getDocType().equalsIgnoreCase(DocType.ITEM.getCode())) {
585 List<Item> itemList = getBrowseService().browseOnChange(oleSearchForm);
586 oleSearchForm.setItemList(itemList);
587 } else {
588 List<Holdings> holdingsList = getBrowseService().browseOnChange(oleSearchForm);
589 oleSearchForm.setHoldingsList(holdingsList);
590 }
591 }
592 setBrowsePageNextPrevoiusAndEntriesInfo(oleSearchForm);
593 return getUIFModelAndView(form);
594 }
595
596 @RequestMapping(params = "methodToCall=previous")
597 public ModelAndView previous(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
598 HttpServletRequest request, HttpServletResponse response) throws Exception {
599 LOG.debug("Inside the browse method");
600 OLESearchForm oleSearchForm = (OLESearchForm) form;
601 if ("title".equals(oleSearchForm.getBrowseField())) {
602 oleSearchForm.setDocType(DocType.BIB.getCode());
603 List<SearchResultDisplayRow> searchResultDisplayRowList = getBrowseService().browsePrev(oleSearchForm);
604 oleSearchForm.setSearchResultDisplayRowList(searchResultDisplayRowList);
605
606 } else {
607
608 if (oleSearchForm.getDocType().equalsIgnoreCase(DocType.ITEM.getCode())) {
609 List<Item> itemList = getBrowseService().browsePrev(oleSearchForm);
610 oleSearchForm.setItemList(itemList);
611 } else {
612 List<Holdings> holdingsList = getBrowseService().browsePrev(oleSearchForm);
613 oleSearchForm.setHoldingsList(holdingsList);
614 }
615 }
616 setBrowsePageNextPrevoiusAndEntriesInfo(oleSearchForm);
617 return getUIFModelAndView(form);
618 }
619
620 @RequestMapping(params = "methodToCall=next")
621 public ModelAndView next(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
622 HttpServletRequest request, HttpServletResponse response) throws Exception {
623 LOG.debug("Inside the browse method");
624 OLESearchForm oleSearchForm = (OLESearchForm) form;
625 if ("title".equals(oleSearchForm.getBrowseField())) {
626 oleSearchForm.setDocType(DocType.BIB.getCode());
627 List<SearchResultDisplayRow> searchResultDisplayRowList = getBrowseService().browseNext(oleSearchForm);
628 oleSearchForm.setSearchResultDisplayRowList(searchResultDisplayRowList);
629
630 } else {
631
632 if (oleSearchForm.getDocType().equalsIgnoreCase(DocType.ITEM.getCode())) {
633 List<Item> itemList = getBrowseService().browseNext(oleSearchForm);
634 oleSearchForm.setItemList(itemList);
635 } else {
636 List<Holdings> holdingsList = getBrowseService().browseNext(oleSearchForm);
637 oleSearchForm.setHoldingsList(holdingsList);
638 }
639 }
640 setBrowsePageNextPrevoiusAndEntriesInfo(oleSearchForm);
641 return getUIFModelAndView(form);
642 }
643
644
645 @RequestMapping(params = "methodToCall=clear")
646 public ModelAndView clear(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
647 HttpServletRequest request, HttpServletResponse response) {
648 LOG.debug("Inside the clear method");
649 OLESearchForm oleSearchForm = (OLESearchForm) form;
650 clearForm(oleSearchForm);
651 return super.start(oleSearchForm, result, request, response);
652 }
653
654 @RequestMapping(params = "methodToCall=back")
655 public ModelAndView back(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
656 HttpServletRequest request, HttpServletResponse response) {
657 LOG.debug("Inside the clear method");
658 return super.back(form, result, request, response);
659 }
660
661 @RequestMapping(params = "methodToCall=exportToXml")
662 public ModelAndView exportToXml(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
663 HttpServletRequest request, HttpServletResponse response) {
664 OLESearchForm oleSearchForm = (OLESearchForm) form;
665 boolean hasPermission = canExportToRequestXml(GlobalVariables.getUserSession().getPrincipalId());
666 if (!hasPermission) {
667 oleSearchForm.setJumpToId("breadcrumb_label");
668 oleSearchForm.setFocusId("breadcrumb_label");
669 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
670 return navigate(oleSearchForm, result, request, response);
671 }
672 List<String> idsToExport = new ArrayList<>();
673 if(oleSearchForm.isSelectAllRecords()){
674 if(StringUtils.isEmpty(oleSearchForm.getIdsToBeOpened())){
675 searchDocstoreForLocalIds(oleSearchForm, request);
676 }
677 String[] localIds=oleSearchForm.getIdsToBeOpened().split(",");
678 for(String localId:localIds){
679 String[] ids= localId.split("#");
680 idsToExport.add(ids[0]);
681 }
682
683 }else{
684 for (SearchResultDisplayRow searchResultDisplayRow : oleSearchForm.getSearchResultDisplayRowList()) {
685 if(searchResultDisplayRow.isSelect()) {
686 idsToExport.add(searchResultDisplayRow.getLocalId());
687 }
688 }
689 }
690
691
692 String requestXml = "";
693 if(oleSearchForm.getDocType().equalsIgnoreCase(DocType.BIB.getCode())) {
694
695 try {
696 BibTrees bibTrees = new BibTrees();
697 for(String id : idsToExport) {
698 BibTree bibTree =getDocstoreLocalClient().retrieveBibTree(id);
699 bibTrees.getBibTrees().add(bibTree);
700 }
701 requestXml = BibTrees.serialize(bibTrees);
702 } catch (Exception e) {
703 e.printStackTrace();
704 }
705 }
706
707 if(oleSearchForm.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode())) {
708 try {
709 HoldingsTrees holdingsTrees = new HoldingsTrees();
710 for (String id : idsToExport) {
711 HoldingsTree holdingsTree = getDocstoreLocalClient().retrieveHoldingsTree(id);
712 holdingsTrees.getHoldingsTrees().add(holdingsTree);
713 }
714 requestXml = HoldingsTrees.serialize(holdingsTrees);
715 } catch (Exception e) {
716 e.printStackTrace();
717 }
718
719 }
720
721 if(oleSearchForm.getDocType().equalsIgnoreCase(DocType.ITEM.getCode())) {
722 try {
723 List<Item> itemList = getDocstoreLocalClient().retrieveItems(idsToExport);
724 Items items = new Items();
725 items.getItems().addAll(itemList);
726 requestXml = Items.serialize(items);
727
728 } catch (Exception e) {
729 e.printStackTrace();
730 }
731 }
732 oleSearchForm.setShowRequestXml(true);
733 oleSearchForm.setRequestXMLTextArea(requestXml);
734 return super.navigate(oleSearchForm, result, request, response);
735 }
736
737 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addLine")
738 public ModelAndView addLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
739 HttpServletRequest request, HttpServletResponse response) {
740 OLESearchForm oleSearchForm = (OLESearchForm) uifForm;
741 String selectedCollectionPath = oleSearchForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
742 if (StringUtils.isBlank(selectedCollectionPath)) {
743 throw new RuntimeException("Selected collection was not set for add line action, cannot add new line");
744 }
745
746 View view = oleSearchForm.getPostedView();
747 view.getViewHelperService().processCollectionAddLine(view, oleSearchForm, selectedCollectionPath);
748 SearchCondition searchCondition = oleSearchForm.getSearchParams().getSearchConditions().get(oleSearchForm.getSearchParams().getSearchConditions().size() -1);
749 if(StringUtils.isEmpty(searchCondition.getSearchField().getFieldValue())) {
750 oleSearchForm.getSearchParams().getSearchConditions().remove(oleSearchForm.getSearchParams().getSearchConditions().size() -1);
751 GlobalVariables.getMessageMap().putErrorForSectionId("SearchConditionsSection", OLEConstants.DESCRIBE_ENTER_SEARCH_TEXT);
752 return getUIFModelAndView(oleSearchForm);
753 }
754 oleSearchForm.getSearchParams().setStartIndex(0);
755 return getUIFModelAndView(oleSearchForm);
756 }
757
758 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteLine")
759 public ModelAndView deleteLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
760 HttpServletRequest request, HttpServletResponse response) {
761 OLESearchForm oleSearchForm = (OLESearchForm) uifForm;
762 String selectedCollectionPath = oleSearchForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
763 if (StringUtils.isBlank(selectedCollectionPath)) {
764 throw new RuntimeException("Selected collection was not set for delete line action, cannot delete line");
765 }
766
767 int selectedLineIndex = -1;
768 String selectedLine = oleSearchForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
769 if (StringUtils.isNotBlank(selectedLine)) {
770 selectedLineIndex = Integer.parseInt(selectedLine);
771 }
772
773 if (selectedLineIndex == -1) {
774 throw new RuntimeException("Selected line index was not set for delete line action, cannot delete line");
775 }
776
777 View view = oleSearchForm.getPostedView();
778 view.getViewHelperService().processCollectionDeleteLine(view, oleSearchForm, selectedCollectionPath,
779 selectedLineIndex);
780 oleSearchForm.getSearchParams().setStartIndex(0);
781 return getUIFModelAndView(oleSearchForm);
782 }
783
784
785
786 private boolean performBrowse(String principalId) {
787 PermissionService service = KimApiServiceLocator.getPermissionService();
788 return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.CALL_NUMBER_BROWSE);
789 }
790
791 public Set<String> getFacetFields(String docType) {
792 Set<String> facetFields = new TreeSet<String>();
793 for(DocTypeConfig docTypeConfig : documentSearchConfig.getDocTypeConfigs()) {
794 if(docTypeConfig.getName().equalsIgnoreCase(docType)) {
795 for( DocFormatConfig docFormatConfig : docTypeConfig.getDocFormatConfigList()) {
796 if(docFormatConfig.getName().equalsIgnoreCase(DocFormat.MARC.getCode())) {
797 for(DocFieldConfig docFieldConfig : docFormatConfig.getDocFieldConfigList()) {
798 if (docFieldConfig.isFacet() && docFieldConfig.getDocType().getName().equalsIgnoreCase(docType)) {
799 facetFields.add(docFieldConfig.getName());
800 }
801 }
802 }
803 }
804 }
805 }
806 return facetFields;
807 }
808
809 public SearchResultDisplayFields getDisplayFields(OLESearchForm oleSearchForm) {
810 SearchResultDisplayFields searchResultDisplayFields = new SearchResultDisplayFields();
811 searchResultDisplayFields.buildSearchResultDisplayFields(documentSearchConfig.getDocTypeConfigs(),oleSearchForm.getDocType());
812 return searchResultDisplayFields;
813 }
814
815 public void setPageNextPreviousAndEntriesInfo(OLESearchForm oleSearchForm) {
816 this.totalRecCount = oleSearchForm.getSearchResponse().getTotalRecordCount();
817 this.start = oleSearchForm.getSearchResponse().getStartIndex();
818 this.pageSize = oleSearchForm.getPageSize();
819 oleSearchForm.setPreviousFlag(getPreviousFlag());
820 oleSearchForm.setNextFlag(getNextFlag());
821 oleSearchForm.setPageShowEntries(getPageShowEntries());
822 oleSearchForm.setTotalRecordCount(this.totalRecCount);
823 }
824
825
826 public void setBrowsePageNextPrevoiusAndEntriesInfo(OLESearchForm oleSearchForm) {
827 oleSearchForm.setPreviousFlag(getBrowseService().getPreviosFlag());
828 oleSearchForm.setNextFlag(getBrowseService().getNextFlag());
829 oleSearchForm.setPageShowEntries(getBrowseService().getPageShowEntries());
830 }
831
832 private boolean canExportToRequestXml(String principalId) {
833 PermissionService service = KimApiServiceLocator.getPermissionService();
834 return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.DESC_WORKBENCH_EXPORT_XML);
835 }
836
837
838 @RequestMapping(params = "methodToCall=addLineField")
839 public ModelAndView addLineField(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
840 HttpServletRequest request, HttpServletResponse response) {
841
842 String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
843 if (StringUtils.isBlank(selectedCollectionPath)) {
844 throw new RuntimeException("Selected collection was not set for add line action, cannot add new line");
845 }
846 OLESearchForm oleSearchForm = (OLESearchForm) uifForm;
847 int index = Integer.parseInt(oleSearchForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
848 if(oleSearchForm.getSearchConditions().get(index).getSearchField().getFieldName().isEmpty()&&
849 oleSearchForm.getSearchConditions().get(index).getSearchField().getFieldValue().isEmpty()){
850 return getUIFModelAndView(uifForm);
851 }
852 List<SearchCondition> searchConditions = oleSearchForm.getSearchConditions();
853 index++;
854 SearchCondition searchCondition=new SearchCondition();
855 searchCondition.setOperator("AND");
856 searchConditions.add(index,searchCondition);
857
858 return getUIFModelAndView(uifForm);
859 }
860
861 public void searchDocstoreData(OLESearchForm oleSearchForm,HttpServletRequest request) {
862 boolean isRemoveSearchCondition = false;
863 setShowPageSizeEntries(oleSearchForm);
864 SearchParams searchParams = oleSearchForm.getSearchParams();
865 oleSearchForm.getSearchParams().getSearchConditions().clear();
866 searchParams.getSearchConditions().addAll(oleSearchForm.getSearchConditions());
867 searchParams.getSearchResultFields().clear();
868 if ("true".equals(oleSearchForm.getSortFlag())) {
869 searchParams.setPageSize(oleSearchForm.getPageSize());
870
871 searchParams.getSortConditions().clear();
872 if (oleSearchForm.getDocType().equalsIgnoreCase("holdings") && oleSearchForm.getSortField().equalsIgnoreCase("Relations")) {
873 searchParams.getSortConditions().add(searchParams.buildSortCondition("isBoundwith", oleSearchForm.getSortOrder()));
874 searchParams.getSortConditions().add(searchParams.buildSortCondition("isSeries", oleSearchForm.getSortOrder()));
875 searchParams.getSortConditions().add(searchParams.buildSortCondition("isAnalytic", oleSearchForm.getSortOrder()));
876 } else if (oleSearchForm.getDocType().equalsIgnoreCase("item") && oleSearchForm.getSortField().equalsIgnoreCase("Relations")) {
877 searchParams.getSortConditions().add(searchParams.buildSortCondition("isAnalytic", oleSearchForm.getSortOrder()));
878 searchParams.getSortConditions().add(searchParams.buildSortCondition("Title_sort", oleSearchForm.getSortOrder()));
879 } else {
880 searchParams.getSortConditions().add(searchParams.buildSortCondition(oleSearchForm.getSortField(), oleSearchForm.getSortOrder()));
881
882 }
883 } else {
884 searchParams.setPageSize(oleSearchForm.getPageSize());
885
886 }
887 int startIndex = searchParams.getStartIndex();
888 searchParams.setStartIndex(startIndex - startIndex % searchParams.getPageSize());
889 for (SearchCondition searchCondition : oleSearchForm.getSearchConditions()) {
890 searchCondition.getSearchField().setDocType(oleSearchForm.getDocType());
891 if(searchCondition.getSearchField().getFieldName().equalsIgnoreCase(BibConstants.ISBN_SEARCH)){
892 String fieldValue= searchCondition.getSearchField().getFieldValue().replaceAll("-","");
893 ISBNUtil isbnUtil = new ISBNUtil();
894 try {
895 fieldValue = isbnUtil.normalizeISBN(fieldValue);
896 } catch (OleException e) {
897 LOG.error("Exception "+e);
898 }
899 searchCondition.getSearchField().setFieldValue(fieldValue);
900 searchCondition.setSearchScope("phrase");
901 }
902 if(DocType.ITEM.getCode().equals(oleSearchForm.getDocType()) && searchCondition.getSearchField().getFieldName().equalsIgnoreCase(ItemConstants.BIB_IDENTIFIER)){
903 if(!DocumentUniqueIDPrefix.hasPrefix(searchCondition.getSearchField().getFieldValue())){
904 searchCondition.getSearchField().setFieldValue(DocumentUniqueIDPrefix.PREFIX_WORK_BIB_MARC+"-"+searchCondition.getSearchField().getFieldValue());
905 }
906
907 }
908 }
909
910
911 if(CollectionUtils.isEmpty(searchParams.getSearchConditions())) {
912 isRemoveSearchCondition = true;
913 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("", searchParams.buildSearchField(oleSearchForm.getDocType(), "", ""), ""));
914 }
915 request.getSession().setAttribute("searchParams", searchParams);
916 if(!oleSearchForm.isMoreFacets()) {
917 searchParams.getFacetFields().clear();
918 Set<String> facetFields = getFacetFields(oleSearchForm.getDocType());
919 searchParams.getFacetFields().addAll(facetFields);
920 searchParams.setFacetLimit(documentSearchConfig.getFacetPageSizeShort());
921 }
922 oleSearchForm.setFacetLimit(documentSearchConfig.getFacetPageSizeShort()-1);
923 SearchResponse searchResponse = null;
924 oleSearchForm.setSearchResultDisplayFields(getDisplayFields(oleSearchForm));
925 searchParams.buildSearchParams(searchParams,oleSearchForm.getDocType());
926 if (oleSearchForm instanceof GlobalEditForm) {
927 if (((GlobalEditForm) oleSearchForm).isSelectAll()) {
928 searchParams.setStartIndex(0);
929 }
930 }
931 float start = System.currentTimeMillis()/1000;
932 try {
933 if(oleSearchForm.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchParams.getSortConditions() != null && searchParams.getSortConditions().size() == 0) {
934 SortCondition sortCondition = new SortCondition();
935 sortCondition.setSortField("Title_sort");
936 sortCondition.setSortOrder("asc");
937 searchParams.getSortConditions().add(sortCondition);
938 }
939 searchResponse = getDocstoreLocalClient().search(searchParams);
940 oleSearchForm.setSearchResponse(searchResponse);
941 } catch (Exception e) {
942 LOG.error("Exception : ", e);
943 }
944
945
946
947 float end = System.currentTimeMillis()/1000;
948 oleSearchForm.setSolrTime(String.valueOf(end-start));
949 List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>();
950 List<SearchResultDisplayRow> bibSearchResultDisplayRows=new ArrayList<>();
951 List<SearchResultDisplayRow> holdingsSearchResultDisplayRows=new ArrayList<>();
952 for (SearchResult searchResult : searchResponse.getSearchResults()) {
953 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
954 if(DocType.BIB.getCode().equalsIgnoreCase(oleSearchForm.getDocType())){
955 searchResultDisplayRow.buildBibSearchResultField(searchResult.getSearchResultFields(), eResourceId);
956 bibSearchResultDisplayRows.add(searchResultDisplayRow);
957 } else if(DocType.HOLDINGS.getCode().equals(oleSearchForm.getDocType())){
958 searchResultDisplayRow.buildHoldingSearchResultField(searchResult.getSearchResultFields());
959 holdingsSearchResultDisplayRows.add(searchResultDisplayRow);
960 } else if(DocType.EHOLDINGS.getCode().equals(oleSearchForm.getDocType())){
961 searchResultDisplayRow.buildEHoldingSearchResultField(searchResult.getSearchResultFields());
962 holdingsSearchResultDisplayRows.add(searchResultDisplayRow);
963 } else if(DocType.ITEM.getCode().equals(oleSearchForm.getDocType())){
964 searchResultDisplayRow.buildItemSearchResultField(searchResult.getSearchResultFields());
965 }
966 searchResultDisplayRows.add(searchResultDisplayRow);
967 }
968 oleSearchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
969 oleSearchForm.setBibSearchResultDisplayRowList(bibSearchResultDisplayRows);
970 oleSearchForm.setHoldingSearchResultDisplayRowList(holdingsSearchResultDisplayRows);
971 if (searchResponse != null && searchResponse.getFacetResult() != null) {
972 oleSearchForm.setFacetResultFields(searchResponse.getFacetResult().getFacetResultFields());
973 }
974 if (searchResultDisplayRows.size() == 0) {
975 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
976 }
977 request.getSession().setAttribute("searchResultDisplayRowList", searchResultDisplayRows);
978 setPageNextPreviousAndEntriesInfo(oleSearchForm);
979 if(isRemoveSearchCondition) {
980 oleSearchForm.getSearchParams().getSearchConditions().clear();
981 }
982
983 if(oleSearchForm.isMoreFacets()) {
984 showFacetPreviousNext(oleSearchForm);
985 }
986 if (oleSearchForm instanceof GlobalEditForm) {
987 ((GlobalEditForm) oleSearchForm).setTotalRecords(totalRecCount);
988 }
989
990 for (SearchCondition searchCondition : oleSearchForm.getSearchConditions()) {
991 searchCondition.getSearchField().setDocType(oleSearchForm.getDocType());
992 if(DocType.ITEM.getCode().equals(oleSearchForm.getDocType()) && searchCondition.getSearchField().getFieldName().equalsIgnoreCase(ItemConstants.BIB_IDENTIFIER)){
993 if(DocumentUniqueIDPrefix.hasPrefix(searchCondition.getSearchField().getFieldValue())){
994 searchCondition.getSearchField().setFieldValue(DocumentUniqueIDPrefix.getDocumentId(searchCondition.getSearchField().getFieldValue()));
995 }
996 }
997 }
998 }
999
1000 private void showFacetPreviousNext(OLESearchForm oleSearchForm) {
1001 int offset = oleSearchForm.getSearchParams().getFacetOffset();
1002 int size = oleSearchForm.getSearchParams().getFacetLimit();
1003 int totalRecordCount = 0;
1004 if(oleSearchForm.getSearchResponse() != null && oleSearchForm.getSearchResponse().getFacetResult() != null && oleSearchForm.getSearchResponse().getFacetResult().getFacetResultFields() != null && oleSearchForm.getSearchResponse().getFacetResult().getFacetResultFields().get(0) != null) {
1005 totalRecordCount = oleSearchForm.getSearchResponse().getFacetResult().getFacetResultFields().get(0).getValueCounts().size();
1006 }
1007 if(offset - size >= 0) {
1008 oleSearchForm.setShowMoreFacetPrevious(true);
1009 }
1010 else {
1011 oleSearchForm.setShowMoreFacetPrevious(false);
1012 }
1013
1014 if(totalRecordCount >= size) {
1015 oleSearchForm.setShowMoreFacetNext(true);
1016 }
1017 else {
1018 oleSearchForm.setShowMoreFacetNext(false);
1019 }
1020 }
1021
1022 @RequestMapping(params = "methodToCall=deleteLineField")
1023 public ModelAndView deleteLineField(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1024 HttpServletRequest request, HttpServletResponse response) {
1025
1026 String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
1027 if (StringUtils.isBlank(selectedCollectionPath)) {
1028 throw new RuntimeException("Selected collection was not set for add line action, cannot add new line");
1029 }
1030 OLESearchForm oleSearchForm = (OLESearchForm) uifForm;
1031 int index = Integer.parseInt(oleSearchForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1032 List<SearchCondition> searchConditions = oleSearchForm.getSearchConditions();
1033 if (searchConditions.size() > 1) {
1034 searchConditions.remove(index);
1035 }
1036 return getUIFModelAndView(uifForm);
1037 }
1038
1039 @RequestMapping(params = "methodToCall=showBibList")
1040 public ModelAndView showBibList(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1041 HttpServletRequest request, HttpServletResponse response) {
1042 this.start = 0;
1043 LOG.debug("Inside the showBibList method");
1044 OLESearchForm oleSearchForm = (OLESearchForm) uifForm;
1045 oleSearchForm.setSearchTypeField("OLESearch");
1046 String listOfBib = request.getParameter("listOfBib");
1047 String bibList[] = listOfBib.split(",");
1048 SearchParams searchParams = new SearchParams();
1049 for(int bibCount = 0;bibCount<bibList.length;bibCount++){
1050 String uuid = listOfBib.split(",")[bibCount].replaceAll("\\D+","");
1051 SearchCondition searchCondition = searchParams.buildSearchCondition("",searchParams.buildSearchField("bibliographic","LocalId_search",uuid),"OR");
1052 searchParams.getSearchConditions().add(searchCondition);
1053 oleSearchForm.getSearchConditions().add(searchCondition);
1054 }
1055 oleSearchForm.setSearchParams(searchParams);
1056 request.getSession().setAttribute("selectedFacetResults", null);
1057 if (oleSearchForm.getDocType() == null) {
1058 oleSearchForm.setDocType(DocType.BIB.getCode());
1059 }
1060 if(StringUtils.isEmpty(oleSearchForm.getSearchType())) {
1061 oleSearchForm.setSearchType("search");
1062 }
1063 if(StringUtils.isEmpty(oleSearchForm.getBrowseField())) {
1064 oleSearchForm.setBrowseField("title");
1065 }
1066 oleSearchForm.setBrowseText(null);
1067 oleSearchForm.setShowRequestXml(false);
1068 oleSearchForm.setHoldingsList(null);
1069 oleSearchForm.setItemList(null);
1070 oleSearchForm.setSearchResultDisplayRowList(null);
1071 oleSearchForm.setCallNumberBrowseText(null);
1072 oleSearchForm.setLocation(null);
1073 GlobalVariables.getMessageMap().clearErrorMessages();
1074 boolean hasSearchPermission = canSearch(GlobalVariables.getUserSession().getPrincipalId());
1075 if (!hasSearchPermission && oleSearchForm.getDocType().equalsIgnoreCase(OLEConstants.BIB_DOC_TYPE)) {
1076 boolean hasLinkPermission = canLinkBibForRequisition(GlobalVariables.getUserSession().getPrincipalId());
1077 if (!hasLinkPermission) {
1078 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
1079 return search(oleSearchForm, result, request, response);
1080 }
1081 } else if (!hasSearchPermission) {
1082 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
1083 return search(oleSearchForm, result, request, response);
1084 }
1085 return search(oleSearchForm,result,request,response);
1086 }
1087
1088 private void clearForm(OLESearchForm oleSearchForm) {
1089
1090 List<Integer> pageSizes = documentSearchConfig.getPageSizes();
1091 if(!pageSizes.isEmpty() || pageSizes.size() > 0) {
1092 oleSearchForm.setPageSize(pageSizes.get(0));
1093 }
1094 oleSearchForm.setPreviousFlag(false);
1095 oleSearchForm.setNextFlag(false);
1096 oleSearchForm.setBrowseText(null);
1097 oleSearchForm.setShowRequestXml(false);
1098 oleSearchForm.setHoldingsList(null);
1099 oleSearchForm.setItemList(null);
1100 oleSearchForm.setSearchResultDisplayRowList(null);
1101 oleSearchForm.setCallNumberBrowseText(null);
1102 oleSearchForm.setLocation(null);
1103 oleSearchForm.setClassificationScheme("LCC");
1104
1105
1106 if (oleSearchForm.getSearchParams() != null) {
1107 for (SearchCondition searchCondition : oleSearchForm.getSearchConditions()) {
1108 if (searchCondition.getSearchField() != null) {
1109 searchCondition.getSearchField().setFieldName("");
1110 searchCondition.getSearchField().setFieldValue("");
1111 }
1112 }
1113
1114 if (oleSearchForm.getSearchParams().getFacetFields() != null) {
1115 oleSearchForm.getSearchParams().getFacetFields().clear();
1116 }
1117 if (oleSearchForm.getSearchParams().getFacetConditions() != null) {
1118 oleSearchForm.getSearchParams().getFacetConditions().clear();
1119 }
1120 oleSearchForm.getSearchParams().getSearchResultFields().clear();
1121
1122 }
1123 if (oleSearchForm.getSearchResultDisplayRowList() != null && oleSearchForm.getSearchResultDisplayRowList().size() > 0) {
1124 oleSearchForm.getSearchResultDisplayRowList().clear();
1125 }
1126
1127 if (oleSearchForm.getFacetResultFields() != null) {
1128 oleSearchForm.getFacetResultFields().clear();
1129 }
1130
1131 }
1132
1133 @RequestMapping(params = "methodToCall=getHoldingsList")
1134 public ModelAndView getHoldingsList(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1135 HttpServletRequest request, HttpServletResponse response) throws Exception {
1136 OLESearchForm oleSearchForm = (OLESearchForm) form;
1137 oleSearchForm.setErrorMessage(null);
1138 oleSearchForm.setHoldingSearchResultDisplayRowList(null);
1139 oleSearchForm.seteHoldingsFlag("false");
1140 List<SearchResultDisplayRow> searchResultDisplayRowList = new ArrayList<>();
1141
1142 if (oleSearchForm.getSearchResultDisplayRowList() != null && oleSearchForm.getSearchResultDisplayRowList().size() > 0) {
1143 for (SearchResultDisplayRow searchResultDisplay : oleSearchForm.getSearchResultDisplayRowList()) {
1144 if (searchResultDisplay.isSelect()) {
1145 BibTree bibTree = getDocstoreLocalClient().retrieveBibTree(searchResultDisplay.getLocalId());
1146 List<HoldingsTree> holdingsTreeList = bibTree.getHoldingsTrees();
1147 if (holdingsTreeList.size() > 0) {
1148 oleSearchForm.setHoldingsFlag("true");
1149 for (HoldingsTree holdingsTree : holdingsTreeList) {
1150 if (holdingsTree.getHoldings().getHoldingsType().equalsIgnoreCase("print")) {
1151 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
1152 searchResultDisplayRow.setHoldingsIdentifier(holdingsTree.getHoldings().getId());
1153 searchResultDisplayRow.setTitle(holdingsTree.getHoldings().getBib().getTitle());
1154 searchResultDisplayRow.setBibIdentifier(holdingsTree.getHoldings().getBib().getId());
1155 searchResultDisplayRow.setCallNumber(holdingsTree.getHoldings().getCallNumber());
1156 searchResultDisplayRow.setLocalId(DocumentUniqueIDPrefix.getDocumentId(holdingsTree.getHoldings().getId()));
1157 searchResultDisplayRow.setLocationName(holdingsTree.getHoldings().getLocationName());
1158 searchResultDisplayRow.setInstanceIdentifier(holdingsTree.getHoldings().getId());
1159 searchResultDisplayRowList.add(searchResultDisplayRow);
1160 }
1161 }
1162 }
1163 }
1164 }
1165 }
1166 if (searchResultDisplayRowList.size() == 0) {
1167 oleSearchForm.setErrorMessage("selected bib doesnt have Holdings");
1168 }
1169 oleSearchForm.setHoldingSearchResultDisplayRowList(searchResultDisplayRowList);
1170 oleSearchForm.setWorkEHoldingsDocumentList(null);
1171 return super.navigate(oleSearchForm, result, request, response);
1172 }
1173
1174 @RequestMapping(params = "methodToCall=getEHoldingsList")
1175 public ModelAndView getEHoldingsList(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1176 HttpServletRequest request, HttpServletResponse response) throws Exception {
1177 OLESearchForm oleSearchForm = (OLESearchForm) form;
1178 oleSearchForm.setErrorMessage(null);
1179 oleSearchForm.setHoldingsFlag("false");
1180 oleSearchForm.setHoldingSearchResultDisplayRowList(null);
1181 List<SearchResultDisplayRow> searchResultDisplayRowArrayList = new ArrayList<>();
1182 if (oleSearchForm.getSearchResultDisplayRowList() != null && oleSearchForm.getSearchResultDisplayRowList().size() > 0) {
1183 for (SearchResultDisplayRow searchResultDisplay : oleSearchForm.getSearchResultDisplayRowList()) {
1184 if (searchResultDisplay.isSelect()) {
1185 BibTree bibTree = getDocstoreLocalClient().retrieveBibTree(searchResultDisplay.getLocalId());
1186 if (bibTree.getHoldingsTrees().size() > 0) {
1187 oleSearchForm.seteHoldingsFlag("true");
1188 for (HoldingsTree holdingsTree : bibTree.getHoldingsTrees()) {
1189 if (holdingsTree.getHoldings().getHoldingsType().equalsIgnoreCase("electronic")) {
1190 OleHoldings oleHoldings = new OleHoldings();
1191 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
1192 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
1193 oleHoldings = (OleHoldings) holdingOlemlRecordProcessor.fromXML(holdingsTree.getHoldings().getContent());
1194 searchResultDisplayRow.setAccessStatus(oleHoldings.getAccessStatus());
1195 searchResultDisplayRow.setPlatForm(oleHoldings.getPlatform() != null ? oleHoldings.getPlatform().getPlatformName() : null);
1196 searchResultDisplayRow.setImprint(oleHoldings.getImprint());
1197 searchResultDisplayRow.setTitle(holdingsTree.getHoldings().getBib().getTitle());
1198 searchResultDisplayRow.setStatisticalCode(oleHoldings.getStatisticalSearchingCode() != null ? oleHoldings.getStatisticalSearchingCode().getCodeValue() : null);
1199 searchResultDisplayRow.setLocationName(holdingsTree.getHoldings().getLocationName());
1200 searchResultDisplayRow.setBibIdentifier(holdingsTree.getHoldings().getBib().getId());
1201 searchResultDisplayRow.setInstanceIdentifier(holdingsTree.getHoldings().getId());
1202 searchResultDisplayRow.setHoldingsIdentifier(holdingsTree.getHoldings().getId());
1203 searchResultDisplayRow.setLocalId(DocumentUniqueIDPrefix.getDocumentId(holdingsTree.getHoldings().getId()));
1204 searchResultDisplayRowArrayList.add(searchResultDisplayRow);
1205 }
1206 }
1207 }
1208 }
1209 }
1210 }
1211 if (searchResultDisplayRowArrayList.size() == 0) {
1212 oleSearchForm.setErrorMessage("selected bib doesnt have EHoldings");
1213 }
1214 oleSearchForm.setHoldingSearchResultDisplayRowList(searchResultDisplayRowArrayList);
1215 oleSearchForm.setWorkHoldingsDocumentList(null);
1216 return navigate(oleSearchForm, result, request, response);
1217 }
1218
1219 @RequestMapping(params = "methodToCall=linkToBib")
1220 public ModelAndView linkToBib(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1221 HttpServletRequest request, HttpServletResponse response) throws Exception {
1222 OLESearchForm oleSearchForm = (OLESearchForm) form;
1223 List<SearchResultDisplayRow> searchResultDisplayRowList = oleSearchForm.getHoldingSearchResultDisplayRowList();
1224 oleSearchForm.setSuccessMessage(null);
1225 if (searchResultDisplayRowList != null && searchResultDisplayRowList.size() > 0) {
1226 for (SearchResultDisplayRow searchResultDisplayRow : searchResultDisplayRowList) {
1227 if (searchResultDisplayRow.isSelect()) {
1228 processNewHoldingsResponse(searchResultDisplayRow, oleSearchForm.getTokenId());
1229 Holdings holdings =getDocstoreLocalClient().retrieveHoldings(searchResultDisplayRow.getHoldingsIdentifier());
1230 if (holdings.getHoldingsType().equalsIgnoreCase("electronic")) {
1231 saveRecordToDocstore(searchResultDisplayRow, eResourceId);
1232 }
1233 oleSearchForm.setSuccessMessage("");
1234 break;
1235 } else {
1236 oleSearchForm.setSuccessMessage(OLEConstants.HOLDINGS_ERROR_MESSAGE);
1237 }
1238 }
1239 }
1240 if (eResourceId != null && !eResourceId.isEmpty()) {
1241 Map<String, String> tempId = new HashMap<String, String>();
1242 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, eResourceId);
1243 OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
1244 try {
1245 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
1246 tempDocument.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(tempDocument.getDocumentNumber(), principalPerson));
1247 if (tempDocument != null) {
1248 try {
1249 tempDocument.setSelectInstance(OLEConstants.OLEEResourceRecord.LINK_EXIST_INSTANCE);
1250 tempDocument.seteInstanceFlag(true);
1251 getOleEResourceSearchService().getNewInstance(tempDocument, tempDocument.getDocumentNumber());
1252 getDocumentService().updateDocument(tempDocument);
1253 } catch (Exception e) {
1254 throw new RiceRuntimeException(
1255 "Exception trying to save document: " + tempDocument
1256 .getDocumentNumber(), e);
1257 }
1258 }
1259 } catch (Exception e) {
1260 throw new RiceRuntimeException(
1261 "Exception trying to save document: " + tempDocument
1262 .getDocumentNumber(), e);
1263 }
1264 }
1265 return getUIFModelAndView(oleSearchForm);
1266 }
1267
1268 private void processNewHoldingsResponse(SearchResultDisplayRow searchResultDisplayRow, String tokenId) throws Exception {
1269 OLEEditorResponse oleEditorResponse = new OLEEditorResponse();
1270 oleEditorResponse.setLinkedInstanceId(searchResultDisplayRow.getHoldingsIdentifier());
1271 oleEditorResponse.setTokenId(tokenId);
1272 HashMap<String, OLEEditorResponse> oleEditorResponseMap = new HashMap<String, OLEEditorResponse>();
1273 oleEditorResponseMap.put(tokenId, oleEditorResponse);
1274 OleDocstoreResponse.getInstance().setEditorResponse(oleEditorResponseMap);
1275 }
1276
1277 private void saveRecordToDocstore(SearchResultDisplayRow searchResultDisplayRow, String eResourceId) throws Exception {
1278 Holdings eHoldings = new org.kuali.ole.docstore.common.document.EHoldings();
1279 OleHoldings oleHoldings = new OleHoldings();
1280 eHoldings = getDocstoreLocalClient().retrieveHoldings(searchResultDisplayRow.getHoldingsIdentifier());
1281 oleHoldings = new HoldingOlemlRecordProcessor().fromXML(eHoldings.getContent());
1282 oleHoldings.setEResourceId(eResourceId);
1283 eHoldings.setContent(new HoldingOlemlRecordProcessor().toXML(oleHoldings));
1284 getDocstoreLocalClient().updateHoldings(eHoldings);
1285 }
1286
1287 @RequestMapping(params = "methodToCall=filterBibs")
1288 public ModelAndView filterBibs(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1289 HttpServletRequest request, HttpServletResponse response) {
1290 OLESearchForm oleSearchForm = (OLESearchForm) uifForm;
1291 oleSearchForm.setDocType(DocType.BIB.getCode());
1292 oleSearchForm.setShowTime(true);
1293 oleSearchForm.setSearchTypeField("OLESearch");
1294 String author = request.getParameter("author");
1295 String isbn = request.getParameter("isbn");
1296 String oclcNumber = request.getParameter("oclcNumber");
1297 SearchParams searchParams = new SearchParams();
1298 SearchCondition searchCondition = new SearchCondition();
1299 SearchField searchField = new SearchField();
1300 if (StringUtils.isNotBlank(author)) {
1301 searchField.setFieldName("Author_search");
1302 searchField.setFieldValue(author);
1303 request.getSession().setAttribute("author", null);
1304 } else if (StringUtils.isNotBlank(isbn)) {
1305 searchField.setFieldName("ISBN_search");
1306 searchField.setFieldValue(isbn);
1307 request.getSession().setAttribute("isbn", null);
1308 } else if (StringUtils.isNotBlank(oclcNumber)) {
1309 searchField.setFieldName("mdf_035a");
1310 searchField.setFieldValue(oclcNumber);
1311 request.getSession().setAttribute("oclcNumber", null);
1312 }
1313 searchCondition.setOperator("AND");
1314 searchCondition.setSearchScope("AND");
1315 searchCondition.setSearchField(searchField);
1316 searchParams.getSearchConditions().add(searchCondition);
1317 oleSearchForm.getSearchConditions().add(searchCondition);
1318 oleSearchForm.setSearchParams(searchParams);
1319 if (StringUtils.isEmpty(oleSearchForm.getSearchType())) {
1320 oleSearchForm.setSearchType("search");
1321 }
1322 if (StringUtils.isEmpty(oleSearchForm.getBrowseField())) {
1323 oleSearchForm.setBrowseField("title");
1324 }
1325 oleSearchForm.setBrowseText(null);
1326 oleSearchForm.setShowRequestXml(false);
1327 oleSearchForm.setHoldingsList(null);
1328 oleSearchForm.setItemList(null);
1329 oleSearchForm.setSearchResultDisplayRowList(null);
1330 oleSearchForm.setCallNumberBrowseText(null);
1331 oleSearchForm.setLocation(null);
1332 GlobalVariables.getMessageMap().clearErrorMessages();
1333 oleSearchForm.setSearchResultDisplayFields(new SearchResultDisplayFields());
1334 return search(oleSearchForm, result, request, response);
1335 }
1336
1337 @RequestMapping(params = "methodToCall=openAll")
1338 public ModelAndView openAll(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1339 HttpServletRequest request, HttpServletResponse response) {
1340 OLESearchForm oleSearchForm = (OLESearchForm) form;
1341 oleSearchForm.getSearchParams().setFacetOffset(0);
1342 searchDocstoreForLocalIds(oleSearchForm, request);
1343 return super.navigate(oleSearchForm, result, request, response);
1344 }
1345
1346 public void searchDocstoreForLocalIds(OLESearchForm oleSearchForm,HttpServletRequest request) {
1347 setShowPageSizeEntries(oleSearchForm);
1348 SearchParams searchParams = oleSearchForm.getSearchParams();
1349 oleSearchForm.getSearchParams().getSearchConditions().clear();
1350 searchParams.getSearchConditions().addAll(oleSearchForm.getSearchConditions());
1351 searchParams.getSearchResultFields().clear();
1352 searchParams.setPageSize(totalRecCount);
1353 searchParams.setStartIndex(0);
1354 for (SearchCondition searchCondition : oleSearchForm.getSearchConditions()) {
1355 searchCondition.getSearchField().setDocType(oleSearchForm.getDocType());
1356 if(searchCondition.getSearchField().getFieldName().equalsIgnoreCase(BibConstants.ISBN_SEARCH)){
1357 String fieldValue= searchCondition.getSearchField().getFieldValue().replaceAll("-","");
1358 ISBNUtil isbnUtil = new ISBNUtil();
1359 try {
1360 fieldValue = isbnUtil.normalizeISBN(fieldValue);
1361 } catch (OleException e) {
1362 LOG.error("Exception "+e);
1363 }
1364 searchCondition.getSearchField().setFieldValue(fieldValue);
1365 searchCondition.setSearchScope("phrase");
1366 }
1367 if(DocType.ITEM.getCode().equals(oleSearchForm.getDocType()) && searchCondition.getSearchField().getFieldName().equalsIgnoreCase(ItemConstants.BIB_IDENTIFIER)){
1368 if(!DocumentUniqueIDPrefix.hasPrefix(searchCondition.getSearchField().getFieldValue())){
1369 searchCondition.getSearchField().setFieldValue(DocumentUniqueIDPrefix.PREFIX_WORK_BIB_MARC+"-"+searchCondition.getSearchField().getFieldValue());
1370 }
1371 }
1372 }
1373
1374 if(CollectionUtils.isEmpty(searchParams.getSearchConditions())) {
1375 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("", searchParams.buildSearchField(oleSearchForm.getDocType(), "", ""), ""));
1376 }
1377 request.getSession().setAttribute("searchParams", searchParams);
1378
1379 SearchResponse searchResponse = null;
1380 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(oleSearchForm.getDocType(), "LocalId_display"));
1381 if(oleSearchForm.getDocType().equalsIgnoreCase("bibliographic")){
1382 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(oleSearchForm.getDocType(), Bib.ID));
1383 }else{
1384 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(oleSearchForm.getDocType(), Bib.BIBIDENTIFIER));
1385 }
1386
1387 if (oleSearchForm instanceof GlobalEditForm) {
1388 if (((GlobalEditForm) oleSearchForm).isSelectAll()) {
1389 searchParams.setStartIndex(0);
1390 }
1391 }
1392 try {
1393 if(oleSearchForm.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchParams.getSortConditions() != null && searchParams.getSortConditions().size() == 0) {
1394 SortCondition sortCondition = new SortCondition();
1395 sortCondition.setSortField("Title_sort");
1396 sortCondition.setSortOrder("asc");
1397 searchParams.getSortConditions().add(sortCondition);
1398 }
1399 searchResponse = getDocstoreLocalClient().search(searchParams);
1400 StringBuilder ids = new StringBuilder();
1401 for( SearchResult searchResult:searchResponse.getSearchResults()){
1402 ids.append("," + searchResult.getSearchResultFields().get(0).getFieldValue() +"#"+ searchResult.getSearchResultFields().get(1).getFieldValue());
1403 }
1404 oleSearchForm.setIdsToBeOpened(ids.toString().replaceFirst(",",""));
1405
1406 } catch (Exception e) {
1407 LOG.error("Exception : ", e);
1408 }
1409
1410 }
1411
1412
1413
1414 }