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 if (searchResponse != null) {
953 for (SearchResult searchResult : searchResponse.getSearchResults()) {
954 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
955 if (DocType.BIB.getCode().equalsIgnoreCase(oleSearchForm.getDocType())) {
956 searchResultDisplayRow.buildBibSearchResultField(searchResult.getSearchResultFields(), eResourceId);
957 bibSearchResultDisplayRows.add(searchResultDisplayRow);
958 } else if (DocType.HOLDINGS.getCode().equals(oleSearchForm.getDocType())) {
959 searchResultDisplayRow.buildHoldingSearchResultField(searchResult.getSearchResultFields());
960 holdingsSearchResultDisplayRows.add(searchResultDisplayRow);
961 } else if (DocType.EHOLDINGS.getCode().equals(oleSearchForm.getDocType())) {
962 searchResultDisplayRow.buildEHoldingSearchResultField(searchResult.getSearchResultFields());
963 holdingsSearchResultDisplayRows.add(searchResultDisplayRow);
964 } else if (DocType.ITEM.getCode().equals(oleSearchForm.getDocType())) {
965 searchResultDisplayRow.buildItemSearchResultField(searchResult.getSearchResultFields());
966 }
967 searchResultDisplayRows.add(searchResultDisplayRow);
968 }
969 } else {
970 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_INFIELD);
971 return;
972 }
973 oleSearchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
974 oleSearchForm.setBibSearchResultDisplayRowList(bibSearchResultDisplayRows);
975 oleSearchForm.setHoldingSearchResultDisplayRowList(holdingsSearchResultDisplayRows);
976 if (searchResponse != null && searchResponse.getFacetResult() != null) {
977 oleSearchForm.setFacetResultFields(searchResponse.getFacetResult().getFacetResultFields());
978 }
979 if (searchResultDisplayRows.size() == 0) {
980 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
981 }
982 request.getSession().setAttribute("searchResultDisplayRowList", searchResultDisplayRows);
983 setPageNextPreviousAndEntriesInfo(oleSearchForm);
984 if(isRemoveSearchCondition) {
985 oleSearchForm.getSearchParams().getSearchConditions().clear();
986 }
987
988 if(oleSearchForm.isMoreFacets()) {
989 showFacetPreviousNext(oleSearchForm);
990 }
991 if (oleSearchForm instanceof GlobalEditForm) {
992 ((GlobalEditForm) oleSearchForm).setTotalRecords(totalRecCount);
993 }
994
995 for (SearchCondition searchCondition : oleSearchForm.getSearchConditions()) {
996 searchCondition.getSearchField().setDocType(oleSearchForm.getDocType());
997 if(DocType.ITEM.getCode().equals(oleSearchForm.getDocType()) && searchCondition.getSearchField().getFieldName().equalsIgnoreCase(ItemConstants.BIB_IDENTIFIER)){
998 if(DocumentUniqueIDPrefix.hasPrefix(searchCondition.getSearchField().getFieldValue())){
999 searchCondition.getSearchField().setFieldValue(DocumentUniqueIDPrefix.getDocumentId(searchCondition.getSearchField().getFieldValue()));
1000 }
1001 }
1002 }
1003 }
1004
1005 private void showFacetPreviousNext(OLESearchForm oleSearchForm) {
1006 int offset = oleSearchForm.getSearchParams().getFacetOffset();
1007 int size = oleSearchForm.getSearchParams().getFacetLimit();
1008 int totalRecordCount = 0;
1009 if(oleSearchForm.getSearchResponse() != null && oleSearchForm.getSearchResponse().getFacetResult() != null && oleSearchForm.getSearchResponse().getFacetResult().getFacetResultFields() != null && oleSearchForm.getSearchResponse().getFacetResult().getFacetResultFields().get(0) != null) {
1010 totalRecordCount = oleSearchForm.getSearchResponse().getFacetResult().getFacetResultFields().get(0).getValueCounts().size();
1011 }
1012 if(offset - size >= 0) {
1013 oleSearchForm.setShowMoreFacetPrevious(true);
1014 }
1015 else {
1016 oleSearchForm.setShowMoreFacetPrevious(false);
1017 }
1018
1019 if(totalRecordCount >= size) {
1020 oleSearchForm.setShowMoreFacetNext(true);
1021 }
1022 else {
1023 oleSearchForm.setShowMoreFacetNext(false);
1024 }
1025 }
1026
1027 @RequestMapping(params = "methodToCall=deleteLineField")
1028 public ModelAndView deleteLineField(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1029 HttpServletRequest request, HttpServletResponse response) {
1030
1031 String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
1032 if (StringUtils.isBlank(selectedCollectionPath)) {
1033 throw new RuntimeException("Selected collection was not set for add line action, cannot add new line");
1034 }
1035 OLESearchForm oleSearchForm = (OLESearchForm) uifForm;
1036 int index = Integer.parseInt(oleSearchForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1037 List<SearchCondition> searchConditions = oleSearchForm.getSearchConditions();
1038 if (searchConditions.size() > 1) {
1039 searchConditions.remove(index);
1040 }
1041 return getUIFModelAndView(uifForm);
1042 }
1043
1044 @RequestMapping(params = "methodToCall=showBibList")
1045 public ModelAndView showBibList(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1046 HttpServletRequest request, HttpServletResponse response) {
1047 this.start = 0;
1048 LOG.debug("Inside the showBibList method");
1049 OLESearchForm oleSearchForm = (OLESearchForm) uifForm;
1050 oleSearchForm.setSearchTypeField("OLESearch");
1051 String listOfBib = request.getParameter("listOfBib");
1052 String bibList[] = listOfBib.split(",");
1053 SearchParams searchParams = new SearchParams();
1054 for(int bibCount = 0;bibCount<bibList.length;bibCount++){
1055 String uuid = listOfBib.split(",")[bibCount].replaceAll("\\D+","");
1056 SearchCondition searchCondition = searchParams.buildSearchCondition("",searchParams.buildSearchField("bibliographic","LocalId_search",uuid),"OR");
1057 searchParams.getSearchConditions().add(searchCondition);
1058 oleSearchForm.getSearchConditions().add(searchCondition);
1059 }
1060 oleSearchForm.setSearchParams(searchParams);
1061 request.getSession().setAttribute("selectedFacetResults", null);
1062 if (oleSearchForm.getDocType() == null) {
1063 oleSearchForm.setDocType(DocType.BIB.getCode());
1064 }
1065 if(StringUtils.isEmpty(oleSearchForm.getSearchType())) {
1066 oleSearchForm.setSearchType("search");
1067 }
1068 if(StringUtils.isEmpty(oleSearchForm.getBrowseField())) {
1069 oleSearchForm.setBrowseField("title");
1070 }
1071 oleSearchForm.setBrowseText(null);
1072 oleSearchForm.setShowRequestXml(false);
1073 oleSearchForm.setHoldingsList(null);
1074 oleSearchForm.setItemList(null);
1075 oleSearchForm.setSearchResultDisplayRowList(null);
1076 oleSearchForm.setCallNumberBrowseText(null);
1077 oleSearchForm.setLocation(null);
1078 GlobalVariables.getMessageMap().clearErrorMessages();
1079 boolean hasSearchPermission = canSearch(GlobalVariables.getUserSession().getPrincipalId());
1080 if (!hasSearchPermission && oleSearchForm.getDocType().equalsIgnoreCase(OLEConstants.BIB_DOC_TYPE)) {
1081 boolean hasLinkPermission = canLinkBibForRequisition(GlobalVariables.getUserSession().getPrincipalId());
1082 if (!hasLinkPermission) {
1083 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
1084 return search(oleSearchForm, result, request, response);
1085 }
1086 } else if (!hasSearchPermission) {
1087 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
1088 return search(oleSearchForm, result, request, response);
1089 }
1090 return search(oleSearchForm,result,request,response);
1091 }
1092
1093 private void clearForm(OLESearchForm oleSearchForm) {
1094
1095 List<Integer> pageSizes = documentSearchConfig.getPageSizes();
1096 if(!pageSizes.isEmpty() || pageSizes.size() > 0) {
1097 oleSearchForm.setPageSize(pageSizes.get(0));
1098 }
1099 oleSearchForm.setPreviousFlag(false);
1100 oleSearchForm.setNextFlag(false);
1101 oleSearchForm.setBrowseText(null);
1102 oleSearchForm.setShowRequestXml(false);
1103 oleSearchForm.setHoldingsList(null);
1104 oleSearchForm.setItemList(null);
1105 oleSearchForm.setSearchResultDisplayRowList(null);
1106 oleSearchForm.setCallNumberBrowseText(null);
1107 oleSearchForm.setLocation(null);
1108 oleSearchForm.setClassificationScheme("LCC");
1109
1110
1111 if (oleSearchForm.getSearchParams() != null) {
1112 for (SearchCondition searchCondition : oleSearchForm.getSearchConditions()) {
1113 if (searchCondition.getSearchField() != null) {
1114 searchCondition.getSearchField().setFieldName("");
1115 searchCondition.getSearchField().setFieldValue("");
1116 }
1117 }
1118
1119 if (oleSearchForm.getSearchParams().getFacetFields() != null) {
1120 oleSearchForm.getSearchParams().getFacetFields().clear();
1121 }
1122 if (oleSearchForm.getSearchParams().getFacetConditions() != null) {
1123 oleSearchForm.getSearchParams().getFacetConditions().clear();
1124 }
1125 oleSearchForm.getSearchParams().getSearchResultFields().clear();
1126
1127 }
1128 if (oleSearchForm.getSearchResultDisplayRowList() != null && oleSearchForm.getSearchResultDisplayRowList().size() > 0) {
1129 oleSearchForm.getSearchResultDisplayRowList().clear();
1130 }
1131
1132 if (oleSearchForm.getFacetResultFields() != null) {
1133 oleSearchForm.getFacetResultFields().clear();
1134 }
1135
1136 }
1137
1138 @RequestMapping(params = "methodToCall=getHoldingsList")
1139 public ModelAndView getHoldingsList(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1140 HttpServletRequest request, HttpServletResponse response) throws Exception {
1141 OLESearchForm oleSearchForm = (OLESearchForm) form;
1142 oleSearchForm.setErrorMessage(null);
1143 oleSearchForm.setHoldingSearchResultDisplayRowList(null);
1144 oleSearchForm.seteHoldingsFlag("false");
1145 List<SearchResultDisplayRow> searchResultDisplayRowList = new ArrayList<>();
1146
1147 if (oleSearchForm.getSearchResultDisplayRowList() != null && oleSearchForm.getSearchResultDisplayRowList().size() > 0) {
1148 for (SearchResultDisplayRow searchResultDisplay : oleSearchForm.getSearchResultDisplayRowList()) {
1149 if (searchResultDisplay.isSelect()) {
1150 BibTree bibTree = getDocstoreLocalClient().retrieveBibTree(searchResultDisplay.getLocalId());
1151 List<HoldingsTree> holdingsTreeList = bibTree.getHoldingsTrees();
1152 if (holdingsTreeList.size() > 0) {
1153 oleSearchForm.setHoldingsFlag("true");
1154 for (HoldingsTree holdingsTree : holdingsTreeList) {
1155 if (holdingsTree.getHoldings().getHoldingsType().equalsIgnoreCase("print")) {
1156 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
1157 searchResultDisplayRow.setHoldingsIdentifier(holdingsTree.getHoldings().getId());
1158 searchResultDisplayRow.setTitle(holdingsTree.getHoldings().getBib().getTitle());
1159 searchResultDisplayRow.setBibIdentifier(holdingsTree.getHoldings().getBib().getId());
1160 searchResultDisplayRow.setCallNumber(holdingsTree.getHoldings().getCallNumber());
1161 searchResultDisplayRow.setLocalId(DocumentUniqueIDPrefix.getDocumentId(holdingsTree.getHoldings().getId()));
1162 searchResultDisplayRow.setLocationName(holdingsTree.getHoldings().getLocationName());
1163 searchResultDisplayRow.setInstanceIdentifier(holdingsTree.getHoldings().getId());
1164 searchResultDisplayRowList.add(searchResultDisplayRow);
1165 }
1166 }
1167 }
1168 }
1169 }
1170 }
1171 if (searchResultDisplayRowList.size() == 0) {
1172 oleSearchForm.setErrorMessage("selected bib doesnt have Holdings");
1173 }
1174 oleSearchForm.setHoldingSearchResultDisplayRowList(searchResultDisplayRowList);
1175 oleSearchForm.setWorkEHoldingsDocumentList(null);
1176 return super.navigate(oleSearchForm, result, request, response);
1177 }
1178
1179 @RequestMapping(params = "methodToCall=getEHoldingsList")
1180 public ModelAndView getEHoldingsList(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1181 HttpServletRequest request, HttpServletResponse response) throws Exception {
1182 OLESearchForm oleSearchForm = (OLESearchForm) form;
1183 oleSearchForm.setErrorMessage(null);
1184 oleSearchForm.setHoldingsFlag("false");
1185 oleSearchForm.setHoldingSearchResultDisplayRowList(null);
1186 List<SearchResultDisplayRow> searchResultDisplayRowArrayList = new ArrayList<>();
1187 if (oleSearchForm.getSearchResultDisplayRowList() != null && oleSearchForm.getSearchResultDisplayRowList().size() > 0) {
1188 for (SearchResultDisplayRow searchResultDisplay : oleSearchForm.getSearchResultDisplayRowList()) {
1189 if (searchResultDisplay.isSelect()) {
1190 BibTree bibTree = getDocstoreLocalClient().retrieveBibTree(searchResultDisplay.getLocalId());
1191 if (bibTree.getHoldingsTrees().size() > 0) {
1192 oleSearchForm.seteHoldingsFlag("true");
1193 for (HoldingsTree holdingsTree : bibTree.getHoldingsTrees()) {
1194 if (holdingsTree.getHoldings().getHoldingsType().equalsIgnoreCase("electronic")) {
1195 OleHoldings oleHoldings = new OleHoldings();
1196 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
1197 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
1198 oleHoldings = (OleHoldings) holdingOlemlRecordProcessor.fromXML(holdingsTree.getHoldings().getContent());
1199 searchResultDisplayRow.setAccessStatus(oleHoldings.getAccessStatus());
1200 searchResultDisplayRow.setPlatForm(oleHoldings.getPlatform() != null ? oleHoldings.getPlatform().getPlatformName() : null);
1201 searchResultDisplayRow.setImprint(oleHoldings.getImprint());
1202 searchResultDisplayRow.setTitle(holdingsTree.getHoldings().getBib().getTitle());
1203 searchResultDisplayRow.setStatisticalCode(oleHoldings.getStatisticalSearchingCode() != null ? oleHoldings.getStatisticalSearchingCode().getCodeValue() : null);
1204 searchResultDisplayRow.setLocationName(holdingsTree.getHoldings().getLocationName());
1205 searchResultDisplayRow.setBibIdentifier(holdingsTree.getHoldings().getBib().getId());
1206 searchResultDisplayRow.setInstanceIdentifier(holdingsTree.getHoldings().getId());
1207 searchResultDisplayRow.setHoldingsIdentifier(holdingsTree.getHoldings().getId());
1208 searchResultDisplayRow.setLocalId(DocumentUniqueIDPrefix.getDocumentId(holdingsTree.getHoldings().getId()));
1209 searchResultDisplayRowArrayList.add(searchResultDisplayRow);
1210 }
1211 }
1212 }
1213 }
1214 }
1215 }
1216 if (searchResultDisplayRowArrayList.size() == 0) {
1217 oleSearchForm.setErrorMessage("selected bib doesnt have EHoldings");
1218 }
1219 oleSearchForm.setHoldingSearchResultDisplayRowList(searchResultDisplayRowArrayList);
1220 oleSearchForm.setWorkHoldingsDocumentList(null);
1221 return navigate(oleSearchForm, result, request, response);
1222 }
1223
1224 @RequestMapping(params = "methodToCall=linkToBib")
1225 public ModelAndView linkToBib(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1226 HttpServletRequest request, HttpServletResponse response) throws Exception {
1227 OLESearchForm oleSearchForm = (OLESearchForm) form;
1228 List<SearchResultDisplayRow> searchResultDisplayRowList = oleSearchForm.getHoldingSearchResultDisplayRowList();
1229 oleSearchForm.setSuccessMessage(null);
1230 if (searchResultDisplayRowList != null && searchResultDisplayRowList.size() > 0) {
1231 for (SearchResultDisplayRow searchResultDisplayRow : searchResultDisplayRowList) {
1232 if (searchResultDisplayRow.isSelect()) {
1233 processNewHoldingsResponse(searchResultDisplayRow, oleSearchForm.getTokenId());
1234 Holdings holdings =getDocstoreLocalClient().retrieveHoldings(searchResultDisplayRow.getHoldingsIdentifier());
1235 if (holdings.getHoldingsType().equalsIgnoreCase("electronic")) {
1236 saveRecordToDocstore(searchResultDisplayRow, eResourceId);
1237 }
1238 oleSearchForm.setSuccessMessage("");
1239 break;
1240 } else {
1241 oleSearchForm.setSuccessMessage(OLEConstants.HOLDINGS_ERROR_MESSAGE);
1242 }
1243 }
1244 }
1245 if (eResourceId != null && !eResourceId.isEmpty()) {
1246 Map<String, String> tempId = new HashMap<String, String>();
1247 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, eResourceId);
1248 OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
1249 try {
1250 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
1251 tempDocument.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(tempDocument.getDocumentNumber(), principalPerson));
1252 if (tempDocument != null) {
1253 try {
1254 tempDocument.setSelectInstance(OLEConstants.OLEEResourceRecord.LINK_EXIST_INSTANCE);
1255 tempDocument.seteInstanceFlag(true);
1256 getOleEResourceSearchService().getNewInstance(tempDocument, tempDocument.getDocumentNumber());
1257 getDocumentService().updateDocument(tempDocument);
1258 } catch (Exception e) {
1259 throw new RiceRuntimeException(
1260 "Exception trying to save document: " + tempDocument
1261 .getDocumentNumber(), e);
1262 }
1263 }
1264 } catch (Exception e) {
1265 throw new RiceRuntimeException(
1266 "Exception trying to save document: " + tempDocument
1267 .getDocumentNumber(), e);
1268 }
1269 }
1270 return getUIFModelAndView(oleSearchForm);
1271 }
1272
1273 private void processNewHoldingsResponse(SearchResultDisplayRow searchResultDisplayRow, String tokenId) throws Exception {
1274 OLEEditorResponse oleEditorResponse = new OLEEditorResponse();
1275 oleEditorResponse.setLinkedInstanceId(searchResultDisplayRow.getHoldingsIdentifier());
1276 oleEditorResponse.setTokenId(tokenId);
1277 HashMap<String, OLEEditorResponse> oleEditorResponseMap = new HashMap<String, OLEEditorResponse>();
1278 oleEditorResponseMap.put(tokenId, oleEditorResponse);
1279 OleDocstoreResponse.getInstance().setEditorResponse(oleEditorResponseMap);
1280 }
1281
1282 private void saveRecordToDocstore(SearchResultDisplayRow searchResultDisplayRow, String eResourceId) throws Exception {
1283 Holdings eHoldings = new org.kuali.ole.docstore.common.document.EHoldings();
1284 OleHoldings oleHoldings = new OleHoldings();
1285 eHoldings = getDocstoreLocalClient().retrieveHoldings(searchResultDisplayRow.getHoldingsIdentifier());
1286 oleHoldings = new HoldingOlemlRecordProcessor().fromXML(eHoldings.getContent());
1287 oleHoldings.setEResourceId(eResourceId);
1288 eHoldings.setContent(new HoldingOlemlRecordProcessor().toXML(oleHoldings));
1289 getDocstoreLocalClient().updateHoldings(eHoldings);
1290 }
1291
1292 @RequestMapping(params = "methodToCall=filterBibs")
1293 public ModelAndView filterBibs(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1294 HttpServletRequest request, HttpServletResponse response) {
1295 OLESearchForm oleSearchForm = (OLESearchForm) uifForm;
1296 oleSearchForm.setDocType(DocType.BIB.getCode());
1297 oleSearchForm.setShowTime(true);
1298 oleSearchForm.setSearchTypeField("OLESearch");
1299 String author = request.getParameter("author");
1300 String isbn = request.getParameter("isbn");
1301 String oclcNumber = request.getParameter("oclcNumber");
1302 SearchParams searchParams = new SearchParams();
1303 SearchCondition searchCondition = new SearchCondition();
1304 SearchField searchField = new SearchField();
1305 if (StringUtils.isNotBlank(author)) {
1306 searchField.setFieldName("Author_search");
1307 searchField.setFieldValue(author);
1308 request.getSession().setAttribute("author", null);
1309 } else if (StringUtils.isNotBlank(isbn)) {
1310 searchField.setFieldName("ISBN_search");
1311 searchField.setFieldValue(isbn);
1312 request.getSession().setAttribute("isbn", null);
1313 } else if (StringUtils.isNotBlank(oclcNumber)) {
1314 searchField.setFieldName("mdf_035a");
1315 searchField.setFieldValue(oclcNumber);
1316 request.getSession().setAttribute("oclcNumber", null);
1317 }
1318 searchCondition.setOperator("AND");
1319 searchCondition.setSearchScope("AND");
1320 searchCondition.setSearchField(searchField);
1321 searchParams.getSearchConditions().add(searchCondition);
1322 oleSearchForm.getSearchConditions().add(searchCondition);
1323 oleSearchForm.setSearchParams(searchParams);
1324 if (StringUtils.isEmpty(oleSearchForm.getSearchType())) {
1325 oleSearchForm.setSearchType("search");
1326 }
1327 if (StringUtils.isEmpty(oleSearchForm.getBrowseField())) {
1328 oleSearchForm.setBrowseField("title");
1329 }
1330 oleSearchForm.setBrowseText(null);
1331 oleSearchForm.setShowRequestXml(false);
1332 oleSearchForm.setHoldingsList(null);
1333 oleSearchForm.setItemList(null);
1334 oleSearchForm.setSearchResultDisplayRowList(null);
1335 oleSearchForm.setCallNumberBrowseText(null);
1336 oleSearchForm.setLocation(null);
1337 GlobalVariables.getMessageMap().clearErrorMessages();
1338 oleSearchForm.setSearchResultDisplayFields(new SearchResultDisplayFields());
1339 return search(oleSearchForm, result, request, response);
1340 }
1341
1342 @RequestMapping(params = "methodToCall=openAll")
1343 public ModelAndView openAll(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1344 HttpServletRequest request, HttpServletResponse response) {
1345 OLESearchForm oleSearchForm = (OLESearchForm) form;
1346 oleSearchForm.getSearchParams().setFacetOffset(0);
1347 searchDocstoreForLocalIds(oleSearchForm, request);
1348 return super.navigate(oleSearchForm, result, request, response);
1349 }
1350
1351 public void searchDocstoreForLocalIds(OLESearchForm oleSearchForm,HttpServletRequest request) {
1352 setShowPageSizeEntries(oleSearchForm);
1353 SearchParams searchParams = oleSearchForm.getSearchParams();
1354 oleSearchForm.getSearchParams().getSearchConditions().clear();
1355 searchParams.getSearchConditions().addAll(oleSearchForm.getSearchConditions());
1356 searchParams.getSearchResultFields().clear();
1357 searchParams.setPageSize(totalRecCount);
1358 searchParams.setStartIndex(0);
1359 for (SearchCondition searchCondition : oleSearchForm.getSearchConditions()) {
1360 searchCondition.getSearchField().setDocType(oleSearchForm.getDocType());
1361 if(searchCondition.getSearchField().getFieldName().equalsIgnoreCase(BibConstants.ISBN_SEARCH)){
1362 String fieldValue= searchCondition.getSearchField().getFieldValue().replaceAll("-","");
1363 ISBNUtil isbnUtil = new ISBNUtil();
1364 try {
1365 fieldValue = isbnUtil.normalizeISBN(fieldValue);
1366 } catch (OleException e) {
1367 LOG.error("Exception "+e);
1368 }
1369 searchCondition.getSearchField().setFieldValue(fieldValue);
1370 searchCondition.setSearchScope("phrase");
1371 }
1372 if(DocType.ITEM.getCode().equals(oleSearchForm.getDocType()) && searchCondition.getSearchField().getFieldName().equalsIgnoreCase(ItemConstants.BIB_IDENTIFIER)){
1373 if(!DocumentUniqueIDPrefix.hasPrefix(searchCondition.getSearchField().getFieldValue())){
1374 searchCondition.getSearchField().setFieldValue(DocumentUniqueIDPrefix.PREFIX_WORK_BIB_MARC+"-"+searchCondition.getSearchField().getFieldValue());
1375 }
1376 }
1377 }
1378
1379 if(CollectionUtils.isEmpty(searchParams.getSearchConditions())) {
1380 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("", searchParams.buildSearchField(oleSearchForm.getDocType(), "", ""), ""));
1381 }
1382 request.getSession().setAttribute("searchParams", searchParams);
1383
1384 SearchResponse searchResponse = null;
1385 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(oleSearchForm.getDocType(), "LocalId_display"));
1386 if(oleSearchForm.getDocType().equalsIgnoreCase("bibliographic")){
1387 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(oleSearchForm.getDocType(), Bib.ID));
1388 }else{
1389 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(oleSearchForm.getDocType(), Bib.BIBIDENTIFIER));
1390 }
1391
1392 if (oleSearchForm instanceof GlobalEditForm) {
1393 if (((GlobalEditForm) oleSearchForm).isSelectAll()) {
1394 searchParams.setStartIndex(0);
1395 }
1396 }
1397 try {
1398 if(oleSearchForm.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchParams.getSortConditions() != null && searchParams.getSortConditions().size() == 0) {
1399 SortCondition sortCondition = new SortCondition();
1400 sortCondition.setSortField("Title_sort");
1401 sortCondition.setSortOrder("asc");
1402 searchParams.getSortConditions().add(sortCondition);
1403 }
1404 searchResponse = getDocstoreLocalClient().search(searchParams);
1405 StringBuilder ids = new StringBuilder();
1406 for( SearchResult searchResult:searchResponse.getSearchResults()){
1407 ids.append("," + searchResult.getSearchResultFields().get(0).getFieldValue() +"#"+ searchResult.getSearchResultFields().get(1).getFieldValue());
1408 }
1409 oleSearchForm.setIdsToBeOpened(ids.toString().replaceFirst(",",""));
1410
1411 } catch (Exception e) {
1412 LOG.error("Exception : ", e);
1413 }
1414
1415 }
1416
1417
1418
1419 }