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