View Javadoc
1   package org.kuali.ole.describe.controller;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.ole.DocumentUniqueIDPrefix;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.describe.bo.OleWorkBibDocument;
7   import org.kuali.ole.describe.bo.OleWorkHoldingsDocument;
8   import org.kuali.ole.describe.bo.SearchResultDisplayRow;
9   import org.kuali.ole.describe.form.WorkbenchForm;
10  import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
11  import org.kuali.ole.docstore.common.document.*;
12  import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
13  import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
14  import org.kuali.ole.docstore.common.search.*;
15  import org.kuali.ole.docstore.model.enums.DocType;
16  import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
17  import org.kuali.ole.select.bo.OLEEditorResponse;
18  import org.kuali.ole.select.businessobject.OleCopy;
19  import org.kuali.ole.select.businessobject.OleDocstoreResponse;
20  import org.kuali.ole.select.document.OLEEResourceRecordDocument;
21  import org.kuali.ole.service.OLEEResourceSearchService;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.rice.core.api.config.property.ConfigContext;
24  import org.kuali.rice.core.api.exception.RiceRuntimeException;
25  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
26  import org.kuali.rice.kim.api.identity.Person;
27  import org.kuali.rice.kim.api.identity.PersonService;
28  import org.kuali.rice.kim.api.permission.PermissionService;
29  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
30  import org.kuali.rice.krad.service.BusinessObjectService;
31  import org.kuali.rice.krad.service.DocumentService;
32  import org.kuali.rice.krad.service.KRADServiceLocator;
33  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
34  import org.kuali.rice.krad.uif.UifParameters;
35  import org.kuali.rice.krad.util.GlobalVariables;
36  import org.kuali.rice.krad.util.KRADConstants;
37  import org.kuali.rice.krad.web.controller.UifControllerBase;
38  import org.kuali.rice.krad.web.form.UifFormBase;
39  import org.springframework.stereotype.Controller;
40  import org.springframework.validation.BindingResult;
41  import org.springframework.web.bind.annotation.ModelAttribute;
42  import org.springframework.web.bind.annotation.RequestMapping;
43  import org.springframework.web.servlet.ModelAndView;
44  
45  import javax.servlet.ServletException;
46  import javax.servlet.http.HttpServletRequest;
47  import javax.servlet.http.HttpServletResponse;
48  import java.io.IOException;
49  import java.util.*;
50  
51  
52  /**
53   * Created with IntelliJ IDEA.
54   * User: PP7788
55   * Date: 11/21/12
56   * Time: 2:45 PM
57   * To change this template use File | Settings | File Templates.
58   */
59  
60  
61  @Controller
62  @RequestMapping(value = "/describeworkbenchcontroller")
63  public class WorkbenchController extends UifControllerBase {
64  
65      private static final Logger LOG = Logger.getLogger(WorkbenchController.class);
66      private OLEEResourceSearchService oleEResourceSearchService;
67      private DocumentService documentService;
68      private int totalRecCount;
69      private int start;
70      private int pageSize;
71      private List<OleWorkBibDocument> finalDocumentList = new ArrayList<>();
72      private DocstoreClientLocator docstoreClientLocator;
73  
74      public DocstoreClientLocator getDocstoreClientLocator() {
75          if (null == docstoreClientLocator) {
76              return SpringContext.getBean(DocstoreClientLocator.class);
77          }
78          return docstoreClientLocator;
79      }
80  
81  
82      public int getTotalRecCount() {
83          return totalRecCount;
84      }
85  
86      public void setTotalRecCount(int totalRecCount) {
87          this.totalRecCount = totalRecCount;
88      }
89  
90      public int getStart() {
91          return start;
92      }
93  
94      public void setStart(int start) {
95          this.start = start;
96      }
97  
98      public int getPageSize() {
99          return pageSize;
100     }
101 
102     public void setPageSize(int pageSize) {
103         this.pageSize = pageSize;
104     }
105 
106     public boolean getWorkbenchPreviousFlag() {
107         if (this.start == 0)
108             return false;
109         return true;
110     }
111 
112     public boolean getWorkbenchNextFlag() {
113         if (this.start + this.pageSize < this.totalRecCount)
114             return true;
115         return false;
116     }
117 
118     public String getWorkbenchPageShowEntries() {
119         return "Showing " + ((this.start == 0) ? 1 : this.start + 1) + " to "
120                 + (((this.start + this.pageSize) > this.totalRecCount) ? this.totalRecCount : (this.start + this.pageSize))
121                 + " of " + this.totalRecCount + " entries";
122     }
123 
124     public OLEEResourceSearchService getOleEResourceSearchService() {
125         if (oleEResourceSearchService == null) {
126             oleEResourceSearchService = GlobalResourceLoader.getService(OLEConstants.OLEEResourceRecord.ERESOURSE_SEARCH_SERVICE);
127         }
128         return oleEResourceSearchService;
129     }
130 
131     public DocumentService getDocumentService() {
132         if (this.documentService == null) {
133             this.documentService = KRADServiceLocatorWeb.getDocumentService();
134         }
135         return this.documentService;
136     }
137 
138     public void setDocumentService(DocumentService documentService) {
139         this.documentService = documentService;
140     }
141 
142     boolean hasSearchPermission = false;
143     private String eResourceId;
144     private String tokenId;
145 
146     @Override
147     protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
148         return new WorkbenchForm();
149     }
150 
151     /**
152      * This method converts UifFormBase to WorkbenchForm
153      *
154      * @param form
155      * @param result
156      * @param request
157      * @param response
158      * @return ModelAndView
159      */
160     @Override
161     @RequestMapping(params = "methodToCall=start")
162     public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
163                               HttpServletRequest request, HttpServletResponse response) {
164         LOG.debug("Inside the workbenchForm start method");
165         WorkbenchForm workbenchForm = (WorkbenchForm) form;
166         workbenchForm.setWorkBibDocumentList(null);
167         workbenchForm.setWorkHoldingsDocumentList(null);
168         workbenchForm.setWorkItemDocumentList(null);
169         workbenchForm.setWorkEHoldingsDocumentList(null);
170         workbenchForm.setShowRequestXML(false);
171         if (request.getParameter(OLEConstants.E_RESOURCE_ID) != null) {
172             eResourceId = request.getParameter(OLEConstants.E_RESOURCE_ID);
173         }
174         if (request.getParameter(OLEConstants.TOKEN_ID) != null) {
175             tokenId = request.getParameter(OLEConstants.TOKEN_ID);
176         }
177         /*if (workbenchForm.getSearchParams().getSearchConditions().get(0).getSearchField().getDocType() == null) {
178             workbenchForm.getSearchParams().getSearchConditions().get(0).getSearchField().setDocType(DocType.BIB.getDescription());
179         }*/
180         if (workbenchForm.getDocType() == null || workbenchForm.getSearchParams() == null || workbenchForm.getSearchParams().getSearchConditions().size() == 0) {
181             //workbenchForm.getSearchParams().getSearchConditions().add(workbenchForm.getSearchParams().buildSearchCondition("", workbenchForm.getSearchParams().buildSearchField(DocType.BIB.getDescription(), "", ""), ""));
182             // workbenchForm.getSearchParams().getSearchConditions().add(workbenchForm.getSearchParams().buildSearchCondition("", workbenchForm.getSearchParams().buildSearchField(DocType.BIB.getDescription(), "", ""), ""));
183             workbenchForm.setDocType("bibliographic");
184 
185 
186         }
187 
188         String eInstance = request.getParameter(OLEConstants.E_INSTANCE);
189         if (eInstance != null && eInstance.equalsIgnoreCase(OLEConstants.LINK_EXISTING_INSTANCE)) {
190             //workbenchForm.getSearchParams().setDocType(DocType.HOLDINGS.getDescription());
191             workbenchForm.setLinkExistingInstance(eInstance);
192         }
193         //String docType1 = workbenchForm.getDocType();
194         String docType = "";
195         if(null != workbenchForm.getSearchParams().getSearchConditions() && null != workbenchForm.getSearchParams().getSearchConditions().get(0).getSearchField()){
196             docType = workbenchForm.getSearchParams().getSearchConditions().get(0).getSearchField().getDocType();
197         }
198     /*    if ("".equals(docType)) {
199             docType = workbenchForm.getDocType();
200         } else if (!"".equals(docType) && docType!=null && docType1!=null && docType1.equalsIgnoreCase(docType)) {
201 
202         } else {
203             workbenchForm.getSearchParams().getSearchConditions().get(0).getSearchField().setFieldName(null);
204             workbenchForm.getSearchParams().getSearchConditions().get(0).getSearchField().setFieldValue(null);
205         }*/
206         //String docType = workbenchForm.getSearchParams().getSearchConditions().add(workbenchForm.getSearchParams().buildSearchCondition(workbenchForm.getSearchParams().buildSearchField(DocType.BIB.getDescription());
207         //String docType = workbenchForm.getSearchParams().getSearchConditions().add(workbenchForm.getSearchParams().buildSearchCondition("",workbenchForm.getSearchParams().buildSearchField(DocType.BIB.getDescription(),"",""),""));
208         boolean hasSearchPermission = canSearch(GlobalVariables.getUserSession().getPrincipalId());
209         if (!hasSearchPermission && docType.equalsIgnoreCase(OLEConstants.BIB_DOC_TYPE)) {
210             boolean hasLinkPermission = canLinkBibForRequisition(GlobalVariables.getUserSession().getPrincipalId());
211             /*boolean hasPermission = canSearchBib(GlobalVariables.getUserSession().getPrincipalId());*/
212             if (!hasLinkPermission) {
213                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
214                 return super.navigate(workbenchForm, result, request, response);
215             }
216         /*} else if (!hasSearchPermission && docType.equalsIgnoreCase(OLEConstants.ITEM_DOC_TYPE)) {
217             boolean hasPermission = canSearchItem(GlobalVariables.getUserSession().getPrincipalId());
218             if (!hasPermission) {
219                 workbenchForm.setMessage("<font size='4' color='red'>" + OLEConstants.SEARCH_AUTHORIZATION_ERROR + "</font>");
220                 return super.navigate(workbenchForm, result, request, response);
221             }*/
222         } else if (!hasSearchPermission) {
223             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
224             return super.navigate(workbenchForm, result, request, response);
225         }
226         workbenchForm.setWorkBibDocumentList(null);
227         workbenchForm.setWorkHoldingsDocumentList(null);
228         workbenchForm.setWorkItemDocumentList(null);
229         workbenchForm.setWorkEHoldingsDocumentList(null);
230         workbenchForm.setShowRequestXML(false);
231         workbenchForm.setMessage(null);
232         workbenchForm.setSearchResultDisplayRowList(null);
233         workbenchForm.setBibSearchResultDisplayRowList(null);
234         workbenchForm.setHoldingSearchResultDisplayRowList(null);
235         GlobalVariables.getMessageMap().clearErrorMessages();
236         return super.navigate(workbenchForm, result, request, response);
237     }
238 
239     /**
240      * Used for Test-case
241      *
242      * @param result
243      * @param request
244      * @param response
245      * @param workbenchForm
246      * @return ModelAndView
247      */
248     protected ModelAndView callSuper(BindingResult result, HttpServletRequest request, HttpServletResponse response, WorkbenchForm workbenchForm) {
249         return super.navigate(workbenchForm, result, request, response);
250     }
251 
252     /*private boolean canSearchBib(String principalId) {
253         PermissionService service = KimApiServiceLocator.getPermissionService();
254         return service.hasPermission(principalId, OLEConstants.OlePatron.PATRON_NAMESPACE, OLEConstants.SEARCH_BIB);
255     }
256 
257     private boolean canSearchItem(String principalId) {
258         PermissionService service = KimApiServiceLocator.getPermissionService();
259         return service.hasPermission(principalId, OLEConstants.OlePatron.PATRON_NAMESPACE, OLEConstants.SEARCH_ITEM);
260     }*/
261 
262     private boolean canSearch(String principalId) {
263         PermissionService service = KimApiServiceLocator.getPermissionService();
264         return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.DESC_WORKBENCH_SEARCH);
265     }
266 
267     private boolean canLinkBibForRequisition(String principalId) {
268         PermissionService service = KimApiServiceLocator.getPermissionService();
269         return service.hasPermission(principalId, OLEConstants.SELECT_NMSPC, OLEConstants.LINK_EXISTING_BIB);
270     }
271 
272     /**
273      * @param form
274      * @param result
275      * @param request
276      * @param response
277      * @return
278      */
279     @RequestMapping(params = "methodToCall=search")
280     public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
281                                HttpServletRequest request, HttpServletResponse response) throws Exception {
282         LOG.info("*** WorkbenchController - Inside Search Method ***");
283         WorkbenchForm workbenchForm = (WorkbenchForm) form;
284         workbenchForm.setMessage(null);
285         SearchResponse searchResponse = null;
286         //String docType = workbenchForm.getSearchParams().getSearchConditions().get(0).getSearchField().getDocType();
287         String docType = workbenchForm.getDocType();
288         boolean hasSearchPermission = canSearch(GlobalVariables.getUserSession().getPrincipalId());
289         if (!hasSearchPermission && docType.equalsIgnoreCase(OLEConstants.BIB_DOC_TYPE)) {
290             boolean hasLinkPermission = canLinkBibForRequisition(GlobalVariables.getUserSession().getPrincipalId());
291             if (!hasLinkPermission) {
292                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
293                 return super.navigate(workbenchForm, result, request, response);
294             }
295         } else if (!hasSearchPermission) {
296             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
297             return super.navigate(workbenchForm, result, request, response);
298         }
299         workbenchForm.setShowRequestXML(false);
300         try {
301             SearchParams searchParams = workbenchForm.getSearchParams();
302             searchParams.getSearchResultFields().clear();
303             // List<SearchCondition> searchConditionList = new ArrayList<SearchCondition>();
304             if ("true".equals(workbenchForm.getSortFlag())) {
305                 searchParams.setPageSize(workbenchForm.getPageSize());
306                 searchParams.setStartIndex(this.start);
307                 searchParams.getSortConditions().clear();
308                 searchParams.getSortConditions().add(searchParams.buildSortCondition(workbenchForm.getSortField(), workbenchForm.getSortOrder()));
309                 //searchParams.setSortField(workbenchForm.getSortField());
310                 //searchParams.setSortOrder(workbenchForm.getSortOrder());
311             } else {
312                 searchParams.setPageSize(workbenchForm.getPageSize());
313                 searchParams.setStartIndex(workbenchForm.getStart());
314             }
315             if (DocType.BIB.getDescription().equalsIgnoreCase(docType)) {
316                 List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>();
317                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "LocalId_display"));
318                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title_sort"));
319                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Author_display"));
320                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "PublicationDate_display"));
321                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "DocFormat"));
322                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "bibIdentifier"));
323                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "id"));
324                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "staffOnlyFlag"));
325                 searchParams.getSearchConditions().get(0).getSearchField().setDocType(docType);
326                 searchParams.getSearchConditions().get(1).getSearchField().setDocType(docType);
327                 LOG.info("*** WorkbenchController - Inside Search Method - search Bibs ***");
328                 workbenchForm.setShowExport(true);
329                 workbenchForm.setLinkToERSFlag(true);
330                 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
331                 workbenchForm.setSearchResponse(searchResponse);
332                 LOG.info("*** WorkbenchController - Inside Search Method - search Bibs - bibList size *** - " + searchResponse.getPageSize());
333                 if (searchResponse.getSearchResults() == null) {
334                     GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
335                     workbenchForm.setWorkBibDocumentList(null);
336                     workbenchForm.setWorkHoldingsDocumentList(null);
337                     workbenchForm.setWorkItemDocumentList(null);
338                     workbenchForm.setWorkEHoldingsDocumentList(null);
339                     return super.navigate(workbenchForm, result, request, response);
340                 }
341 
342                 for (SearchResult searchResult : searchResponse.getSearchResults()) {
343                     SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
344                     for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
345                         // if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode())) {
346                         if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
347                             searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
348                         }
349                         if (searchResultField.getFieldName().equalsIgnoreCase("Title_sort")) {
350                             searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
351                         }
352                         if (searchResultField.getFieldName().equalsIgnoreCase("Author_display")) {
353                             searchResultDisplayRow.setAuthor(searchResultField.getFieldValue());
354                         }
355                         if (searchResultField.getFieldName().equalsIgnoreCase("PublicationDate_display")) {
356                             searchResultDisplayRow.setPublicationDate(searchResultField.getFieldValue());
357                         }
358                         if (searchResultField.getFieldName().equalsIgnoreCase("DocFormat")) {
359                             searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
360                         }
361                         if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
362                             searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
363                         }
364                         if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
365                             searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
366                         }
367                         if (searchResultField.getFieldName().equalsIgnoreCase("staffOnlyFlag")) {
368                             searchResultDisplayRow.setStaffOnly(searchResultField.getFieldValue());
369                         }
370                         if (eResourceId != null) {
371                             searchResultDisplayRow.setOleERSIdentifier(eResourceId);
372                         }
373                         if (tokenId != null) {
374                             searchResultDisplayRow.setTokenId(tokenId);
375                         }
376                         // }
377                     }
378                     searchResultDisplayRows.add(searchResultDisplayRow);
379                 }
380                 workbenchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
381                 workbenchForm.setBibSearchResultDisplayRowList(searchResultDisplayRows);
382                 if (searchResultDisplayRows.size() == 0) {
383                     GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
384                 }
385                 workbenchForm.setWorkHoldingsDocumentList(null);
386                 workbenchForm.setWorkItemDocumentList(null);
387                 workbenchForm.setWorkEHoldingsDocumentList(null);
388                 request.getSession().setAttribute("searchResultDisplayRowList", searchResultDisplayRows);
389                 setPageNextPreviousAndEntriesInfo(workbenchForm);
390                 //   request.getSession().setAttribute("oleWorkBibDocumentList", searchResultDisplayRowList);
391             }
392             if (DocType.HOLDINGS.getCode().equalsIgnoreCase(docType)) {
393                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "LocalId_display"));
394                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title_sort"));
395                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "Location_display"));
396                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "CallNumber_display"));
397                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "DocFormat"));
398                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "bibIdentifier"));
399                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "itemIdentifier"));
400                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "holdingsIdentifier"));
401                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "Location_display"));
402                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "staffOnlyFlag"));
403                 List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>();
404                 LOG.info("*** WorkbenchController - Inside Search Method - search Holdings ***");
405                 workbenchForm.setShowExport(true);
406                 searchParams.getSearchConditions().get(0).getSearchField().setDocType(docType);
407                 searchParams.getSearchConditions().get(1).getSearchField().setDocType(docType);
408                 List<OleWorkHoldingsDocument> oleWorkHoldingsDocuments = new ArrayList<>();
409                 LOG.info("*** WorkbenchController - Inside Search Method - search Holdings - searchParams *** - " + searchParams.toString());
410 
411                 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
412                 workbenchForm.setSearchResponse(searchResponse);
413                 LOG.info("*** WorkbenchController - Inside Search Method - search Holdings - holdingList size *** - " + searchResponse.getPageSize());
414                 if (searchResponse == null) {
415                     GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
416                     workbenchForm.setWorkBibDocumentList(null);
417                     workbenchForm.setWorkHoldingsDocumentList(null);
418                     workbenchForm.setWorkItemDocumentList(null);
419                     workbenchForm.setWorkEHoldingsDocumentList(null);
420                     return super.navigate(workbenchForm, result, request, response);
421                 }
422                 for (SearchResult searchResult : searchResponse.getSearchResults()) {
423                     SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
424                     for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
425 
426                         if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
427                             searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
428                         }
429                         if (searchResultField.getFieldName().equalsIgnoreCase("Title_sort")) {
430                             searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
431                         }
432                         if (searchResultField.getFieldName().equalsIgnoreCase("Location_display")) {
433                             searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
434                         }
435                         if (searchResultField.getFieldName().equalsIgnoreCase("CallNumber_display")) {
436                             searchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
437                         }
438                         if (searchResultField.getFieldName().equalsIgnoreCase("DocFormat")) {
439                             searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
440                         }
441                         if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
442                             searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
443                         }
444                         if (searchResultField.getFieldName().equalsIgnoreCase("holdingsIdentifier")) {
445                             searchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
446                         }
447                         if (searchResultField.getFieldName().equalsIgnoreCase("itemIdentifier")) {
448                             searchResultDisplayRow.setItemIdentifier(searchResultField.getFieldValue());
449                         }
450                         if (searchResultField.getFieldName().equalsIgnoreCase("Location_display")) {
451                             searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
452                         }
453                         if (searchResultField.getFieldName().equalsIgnoreCase("staffOnlyFlag")) {
454                             searchResultDisplayRow.setStaffOnly(searchResultField.getFieldValue());
455                         }
456 
457                     }
458                     searchResultDisplayRows.add(searchResultDisplayRow);
459                 }
460                 workbenchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
461                 workbenchForm.setHoldingSearchResultDisplayRowList(searchResultDisplayRows);
462                 if (searchResultDisplayRows.size() == 0) {
463                     GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
464                 }
465                 workbenchForm.setWorkBibDocumentList(null);
466                 workbenchForm.setWorkItemDocumentList(null);
467                 workbenchForm.setWorkEHoldingsDocumentList(null);
468                 setPageNextPreviousAndEntriesInfo(workbenchForm);
469             }
470             if (DocType.ITEM.getCode().equalsIgnoreCase(docType)) {
471                 List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>();
472                 LOG.info("*** WorkbenchController - Inside Search Method - search Items ***");
473                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "LocalId_display"));
474                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title_sort"));
475                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "Location_display"));
476                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "CallNumber_display"));
477                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "DocFormat"));
478                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "bibIdentifier"));
479                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "holdingsIdentifier"));
480                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "id"));
481                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ItemBarcode_display"));
482                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "Location_display"));
483                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "staffOnlyFlag"));
484                 searchParams.getSearchConditions().get(0).getSearchField().setDocType(docType);
485                 searchParams.getSearchConditions().get(1).getSearchField().setDocType(docType);
486                 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
487                 workbenchForm.setSearchResponse(searchResponse);
488                 LOG.info("*** WorkbenchController - Inside Search Method - search Items - itemList size *** - " + searchResponse.getPageSize());
489                 if (searchResponse == null) {
490                     GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
491                     workbenchForm.setWorkBibDocumentList(null);
492                     workbenchForm.setWorkHoldingsDocumentList(null);
493                     workbenchForm.setWorkItemDocumentList(null);
494                     workbenchForm.setWorkEHoldingsDocumentList(null);
495                     return super.navigate(workbenchForm, result, request, response);
496                 }
497 
498                 for (SearchResult searchResult : searchResponse.getSearchResults()) {
499                     SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
500 
501                     for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
502 
503                         if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
504                             searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
505                         }
506                         if (searchResultField.getFieldName().equalsIgnoreCase("Title_sort")) {
507                             searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
508                         }
509                         if (searchResultField.getFieldName().equalsIgnoreCase("locationName")) {
510                             searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
511                         }
512                         if (searchResultField.getFieldName().equalsIgnoreCase("CallNumber_display")) {
513                             searchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
514                         }
515                         if (searchResultField.getFieldName().equalsIgnoreCase("BarcodeARSL_display")) {
516                             searchResultDisplayRow.setBarcode(searchResultField.getFieldValue());
517                         }
518                         if (searchResultField.getFieldName().equalsIgnoreCase("docFormat")) {
519                             searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
520                         }
521                         if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
522                             searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
523                         }
524                         if (searchResultField.getFieldName().equalsIgnoreCase("holdingsIdentifier")) {
525                             searchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
526                         }
527                         if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
528                             searchResultDisplayRow.setItemIdentifier(searchResultField.getFieldValue());
529                         }
530                         if (searchResultField.getFieldName().equalsIgnoreCase("ItemBarcode_display")) {
531                             searchResultDisplayRow.setBarcode(searchResultField.getFieldValue());
532                         }
533                         if (searchResultField.getFieldName().equalsIgnoreCase("Location_display")) {
534                             searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
535                         }
536 
537                         if (searchResultField.getFieldName().equalsIgnoreCase("staffOnlyFlag")) {
538                             searchResultDisplayRow.setStaffOnly(searchResultField.getFieldValue());
539                         }
540                     }
541                     searchResultDisplayRows.add(searchResultDisplayRow);
542                 }
543 
544                 workbenchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
545                 if (searchResultDisplayRows.size() == 0) {
546                     GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
547                 }
548                 workbenchForm.setWorkBibDocumentList(null);
549                 workbenchForm.setWorkHoldingsDocumentList(null);
550                 workbenchForm.setWorkEHoldingsDocumentList(null);
551                 setPageNextPreviousAndEntriesInfo(workbenchForm);
552             }
553             if (DocType.EHOLDINGS.getCode().equalsIgnoreCase(docType)) {
554                 List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>();
555                 LOG.info("***** Inside Search Method - search EHoldings *****");
556                 workbenchForm.setShowExport(true);
557                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "LocalId_display"));
558                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "AccessStatus_display"));
559                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "Platform_display"));
560                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "Imprint_display"));
561                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "StatisticalSearchingFullValue_display"));
562                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "StatisticalSearchingCodeValue_display"));
563                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "DocFormat"));
564                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "bibIdentifier"));
565                 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "holdingsIdentifier"));
566                 searchParams.getSearchConditions().get(0).getSearchField().setDocType(docType);
567                 searchParams.getSearchConditions().get(1).getSearchField().setDocType(docType);
568                 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
569                 workbenchForm.setSearchResponse(searchResponse);
570                 if (searchParams == null) {
571                     GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
572                     workbenchForm.setWorkBibDocumentList(null);
573                     workbenchForm.setWorkHoldingsDocumentList(null);
574                     workbenchForm.setWorkItemDocumentList(null);
575                     workbenchForm.setWorkEHoldingsDocumentList(null);
576                     return super.navigate(workbenchForm, result, request, response);
577                 }
578 
579                 for (SearchResult searchResult : searchResponse.getSearchResults()) {
580                     SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
581 
582 
583                     for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
584                         //if (searchResultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode())) {
585                         if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
586                             searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
587                         }
588                         if (searchResultField.getFieldName().equalsIgnoreCase("AccessStatus_display")) {
589                             searchResultDisplayRow.setAccessStatus(searchResultField.getFieldValue());
590                         }
591                         if (searchResultField.getFieldName().equalsIgnoreCase("Platform_display")) {
592                             searchResultDisplayRow.setPlatForm(searchResultField.getFieldValue());
593                         }
594                         if (searchResultField.getFieldName().equalsIgnoreCase("Imprint_display")) {
595                             searchResultDisplayRow.setImprint(searchResultField.getFieldValue());
596                         }
597                         if (searchResultField.getFieldName().equalsIgnoreCase("StatisticalSearchingFullValue_display")) {
598                             searchResultDisplayRow.setStatisticalCode(searchResultField.getFieldValue());
599                         }
600                         if (searchResultField.getFieldName().equalsIgnoreCase("StatisticalSearchingCodeValue_display")) {
601                             searchResultDisplayRow.setStatisticalCode(searchResultField.getFieldValue());
602                         }
603                         if (searchResultField.getFieldName().equalsIgnoreCase("DocFormat")) {
604                             searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
605                         }
606                         if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
607                             searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
608                         }
609                         if (searchResultField.getFieldName().equalsIgnoreCase("holdingsIdentifier")) {
610                             searchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
611                         }
612 
613                         //  }
614 
615                     }
616                     searchResultDisplayRows.add(searchResultDisplayRow);
617                 }
618 
619 
620                 workbenchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
621                 workbenchForm.setHoldingSearchResultDisplayRowList(searchResultDisplayRows);
622                 workbenchForm.setSearchResponse(searchResponse);
623                 if (searchResultDisplayRows.size() == 0) {
624                     GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
625                 }
626                 workbenchForm.setWorkBibDocumentList(null);
627                 workbenchForm.setWorkHoldingsDocumentList(null);
628                 workbenchForm.setWorkItemDocumentList(null);
629                 setPageNextPreviousAndEntriesInfo(workbenchForm);
630 
631             }
632 
633 
634         } catch (Exception e) {
635             LOG.error("Exception :", e);
636             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
637             LOG.error("Workbenchcontroller Search Exception:" + e);
638         }
639         return navigate(workbenchForm, result, request, response);
640     }
641 
642     /**
643      * Enable, disable the next and previous and also show the message for number of entries
644      *
645      * @param workbenchForm
646      * @return
647      */
648     public void setPageNextPreviousAndEntriesInfo(WorkbenchForm workbenchForm) {
649         this.totalRecCount = workbenchForm.getSearchResponse().getTotalRecordCount();
650         this.start = workbenchForm.getSearchResponse().getStartIndex();
651         this.pageSize = workbenchForm.getSearchResponse().getPageSize();
652         workbenchForm.setPreviousFlag(getWorkbenchPreviousFlag());
653         workbenchForm.setNextFlag(getWorkbenchNextFlag());
654         workbenchForm.setPageShowEntries(getWorkbenchPageShowEntries());
655     }
656 
657     /**
658      * search to Get the next documents
659      *
660      * @param form
661      * @param result
662      * @param request
663      * @param response
664      * @return
665      */
666     @RequestMapping(params = "methodToCall=nextSearch")
667     public ModelAndView nextSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
668                                    HttpServletRequest request, HttpServletResponse response) throws Exception {
669 
670         LOG.debug("Inside the nextSearch method");
671         WorkbenchForm workbenchForm = (WorkbenchForm) form;
672         SearchParams searchParams = workbenchForm.getSearchParams();
673         SearchResponse searchResponse = null;
674         List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>();
675         searchParams.getSearchResultFields().clear();
676 
677         this.start = Math.max(0, this.start + this.pageSize);
678         searchParams.setStartIndex(this.start);
679         if (searchParams.getSearchConditions().get(0).getSearchField().getDocType().equalsIgnoreCase("item")) {
680 
681 
682             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "LocalId_display"));
683             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title_display"));
684             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "Location_display"));
685             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "CallNumber_display"));
686             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "DocFormat"));
687             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "bibIdentifier"));
688             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "holdingsIdentifier"));
689             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "id"));
690             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ItemBarcode_display"));
691             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "Location_display"));
692 
693 
694             searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
695             for (SearchResult searchResult : searchResponse.getSearchResults()) {
696                 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
697 
698                 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
699 
700                     if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
701                         searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
702                     }
703                     if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
704                         searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
705                     }
706                     if (searchResultField.getFieldName().equalsIgnoreCase("locationName")) {
707                         searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
708                     }
709                     if (searchResultField.getFieldName().equalsIgnoreCase("CallNumber_display")) {
710                         searchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
711                     }
712                     if (searchResultField.getFieldName().equalsIgnoreCase("BarcodeARSL_display")) {
713                         searchResultDisplayRow.setBarcode(searchResultField.getFieldValue());
714                     }
715                     if (searchResultField.getFieldName().equalsIgnoreCase("docFormat")) {
716                         searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
717                     }
718                     if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
719                         searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
720                     }
721                     if (searchResultField.getFieldName().equalsIgnoreCase("holdingsIdentifier")) {
722                         searchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
723                     }
724                     if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
725                         searchResultDisplayRow.setItemIdentifier(searchResultField.getFieldValue());
726                     }
727                     if (searchResultField.getFieldName().equalsIgnoreCase("ItemBarcode_display")) {
728                         searchResultDisplayRow.setBarcode(searchResultField.getFieldValue());
729                     }
730                     if (searchResultField.getFieldName().equalsIgnoreCase("Location_display")) {
731                         searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
732                     }
733 
734                 }
735                 searchResultDisplayRows.add(searchResultDisplayRow);
736             }
737 
738             workbenchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
739             workbenchForm.setSearchResponse(searchResponse);
740             if (searchResultDisplayRows.size() == 0) {
741                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
742             }
743             setPageNextPreviousAndEntriesInfo(workbenchForm);
744             return navigate(workbenchForm, result, request, response);
745         } else if (searchParams.getSearchConditions().get(0).getSearchField().getDocType().equalsIgnoreCase("holdings")) {
746 
747             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "LocalId_display"));
748             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title_display"));
749             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "Location_display"));
750             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "CallNumber_display"));
751             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "DocFormat"));
752             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "bibIdentifier"));
753             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "itemIdentifier"));
754             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "holdingsIdentifier"));
755             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "Location_display"));
756 
757             searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
758             for (SearchResult searchResult : searchResponse.getSearchResults()) {
759                 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
760                 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
761                     if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
762                         searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
763                     }
764                     if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
765                         searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
766                     }
767                     if (searchResultField.getFieldName().equalsIgnoreCase("Location_display")) {
768                         searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
769                     }
770                     if (searchResultField.getFieldName().equalsIgnoreCase("CallNumber_display")) {
771                         searchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
772                     }
773                     if (searchResultField.getFieldName().equalsIgnoreCase("DocFormat")) {
774                         searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
775                     }
776                     if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
777                         searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
778                     }
779                     if (searchResultField.getFieldName().equalsIgnoreCase("holdingsIdentifier")) {
780                         searchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
781                     }
782                     if (searchResultField.getFieldName().equalsIgnoreCase("itemIdentifier")) {
783                         searchResultDisplayRow.setItemIdentifier(searchResultField.getFieldValue());
784                     }
785                     if (searchResultField.getFieldName().equalsIgnoreCase("Location_display")) {
786                         searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
787                     }
788 
789                 }
790                 searchResultDisplayRows.add(searchResultDisplayRow);
791             }
792             workbenchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
793             workbenchForm.setSearchResponse(searchResponse);
794             if (searchResultDisplayRows.size() == 0) {
795                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
796             }
797             setPageNextPreviousAndEntriesInfo(workbenchForm);
798             return navigate(workbenchForm, result, request, response);
799         } else if (searchParams.getSearchConditions().get(0).getSearchField().getDocType().equalsIgnoreCase("bibliographic")) {
800 
801             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "LocalId_display"));
802             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title_display"));
803             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Author_display"));
804             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "PublicationDate_display"));
805             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "DocFormat"));
806             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "bibIdentifier"));
807             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "id"));
808 
809             searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
810             for (SearchResult searchResult : searchResponse.getSearchResults()) {
811                 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
812                 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
813                     // if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode())) {
814                     if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
815                         searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
816                     }
817                     if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
818                         searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
819                     }
820                     if (searchResultField.getFieldName().equalsIgnoreCase("Author_display")) {
821                         searchResultDisplayRow.setAuthor(searchResultField.getFieldValue());
822                     }
823                     if (searchResultField.getFieldName().equalsIgnoreCase("PublicationDate_display")) {
824                         searchResultDisplayRow.setPublicationDate(searchResultField.getFieldValue());
825                     }
826                     if (searchResultField.getFieldName().equalsIgnoreCase("DocFormat")) {
827                         searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
828                     }
829                     if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
830                         searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
831                     }
832                     if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
833                         searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
834                     }
835                     if (eResourceId != null) {
836                         searchResultDisplayRow.setOleERSIdentifier(eResourceId);
837                     }
838                     if (tokenId != null) {
839                         searchResultDisplayRow.setTokenId(tokenId);
840                     }
841                     // }
842                 }
843                 searchResultDisplayRows.add(searchResultDisplayRow);
844             }
845             workbenchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
846             workbenchForm.setSearchResponse(searchResponse);
847             //List<Bib> bibList = getBibList(searchParams);
848             setPageNextPreviousAndEntriesInfo(workbenchForm);
849             return navigate(workbenchForm, result, request, response);
850         } else if (searchParams.getSearchConditions().get(0).getSearchField().getDocType().equalsIgnoreCase("eholdings")) {
851             /*List<OleWorkEHoldingsDocument> oleWorkEHoldingsDocuments = queryService.getDocuments(searchParams);
852             workbenchForm.setWorkEHoldingsDocumentList(oleWorkEHoldingsDocuments);*/
853             /*List<Holdings> holdingsList = null;
854             holdingsList = getHoldingsList(searchParams);
855             workbenchForm.setHoldingsList(holdingsList);*/
856 
857             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "LocalId_display"));
858             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "AccessStatus_display"));
859             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "Platform_display"));
860             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "Imprint_display"));
861             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "StatisticalSearchingFullValue_display"));
862             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "StatisticalSearchingCodeValue_display"));
863             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "DocFormat"));
864             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "bibIdentifier"));
865             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("eHoldings", "holdingsIdentifier"));
866 
867             searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
868             for (SearchResult searchResult : searchResponse.getSearchResults()) {
869                 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
870 
871 
872                 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
873                     if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
874                         searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
875                     }
876                     if (searchResultField.getFieldName().equalsIgnoreCase("AccessStatus_display")) {
877                         searchResultDisplayRow.setAccessStatus(searchResultField.getFieldValue());
878                     }
879                     if (searchResultField.getFieldName().equalsIgnoreCase("Platform_display")) {
880                         searchResultDisplayRow.setPlatForm(searchResultField.getFieldValue());
881                     }
882                     if (searchResultField.getFieldName().equalsIgnoreCase("Imprint_display")) {
883                         searchResultDisplayRow.setImprint(searchResultField.getFieldValue());
884                     }
885                     if (searchResultField.getFieldName().equalsIgnoreCase("StatisticalSearchingFullValue_display")) {
886                         searchResultDisplayRow.setStatisticalCode(searchResultField.getFieldValue());
887                     }
888                     if (searchResultField.getFieldName().equalsIgnoreCase("StatisticalSearchingCodeValue_display")) {
889                         searchResultDisplayRow.setStatisticalCode(searchResultField.getFieldValue());
890                     }
891                     if (searchResultField.getFieldName().equalsIgnoreCase("DocFormat")) {
892                         searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
893                     }
894                     if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
895                         searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
896                     }
897                     if (searchResultField.getFieldName().equalsIgnoreCase("holdingsIdentifier")) {
898                         searchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
899                     }
900 
901                 }
902                 searchResultDisplayRows.add(searchResultDisplayRow);
903             }
904 
905 
906             workbenchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
907             workbenchForm.setSearchResponse(searchResponse);
908             setPageNextPreviousAndEntriesInfo(workbenchForm);
909             return navigate(workbenchForm, result, request, response);
910         }
911         return navigate(workbenchForm, result, request, response);
912     }
913 
914     /**
915      * search to Get the previous documents
916      *
917      * @param form
918      * @param result
919      * @param request
920      * @param response
921      * @return
922      */
923     @RequestMapping(params = "methodToCall=previousSearch")
924     public ModelAndView previousSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
925                                        HttpServletRequest request, HttpServletResponse response) throws Exception {
926 
927         LOG.debug("Inside the previousSearch method");
928         WorkbenchForm workbenchForm = (WorkbenchForm) form;
929         SearchParams searchParams = workbenchForm.getSearchParams();
930         searchParams.getSearchResultFields().clear();
931         SearchResponse searchResponse = null;
932         List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>();
933         this.start = Math.max(0, this.start - this.pageSize);
934         searchParams.setStartIndex((this.start == 0) ? 0 : this.start);
935         if (searchParams.getSearchConditions().get(0).getSearchField().getDocType().equalsIgnoreCase("item")) {
936 
937             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "LocalId_display"));
938             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title_display"));
939             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "Location_display"));
940             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "CallNumber_display"));
941             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "DocFormat"));
942             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "bibIdentifier"));
943             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "holdingsIdentifier"));
944             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "id"));
945             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ItemBarcode_display"));
946             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "Location_display"));
947 
948 
949             searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
950             for (SearchResult searchResult : searchResponse.getSearchResults()) {
951                 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
952 
953                 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
954 
955                     if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
956                         searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
957                     }
958                     if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
959                         searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
960                     }
961                     if (searchResultField.getFieldName().equalsIgnoreCase("locationName")) {
962                         searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
963                     }
964                     if (searchResultField.getFieldName().equalsIgnoreCase("CallNumber_display")) {
965                         searchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
966                     }
967                     if (searchResultField.getFieldName().equalsIgnoreCase("BarcodeARSL_display")) {
968                         searchResultDisplayRow.setBarcode(searchResultField.getFieldValue());
969                     }
970                     if (searchResultField.getFieldName().equalsIgnoreCase("docFormat")) {
971                         searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
972                     }
973                     if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
974                         searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
975                     }
976                     if (searchResultField.getFieldName().equalsIgnoreCase("holdingsIdentifier")) {
977                         searchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
978                     }
979                     if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
980                         searchResultDisplayRow.setItemIdentifier(searchResultField.getFieldValue());
981                     }
982                     if (searchResultField.getFieldName().equalsIgnoreCase("ItemBarcode_display")) {
983                         searchResultDisplayRow.setBarcode(searchResultField.getFieldValue());
984                     }
985                     if (searchResultField.getFieldName().equalsIgnoreCase("Location_display")) {
986                         searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
987                     }
988 
989 
990 
991                 }
992                 searchResultDisplayRows.add(searchResultDisplayRow);
993             }
994 
995             workbenchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
996             workbenchForm.setSearchResponse(searchResponse);
997             if (searchResultDisplayRows.size() == 0) {
998                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
999             }
1000             setPageNextPreviousAndEntriesInfo(workbenchForm);
1001             return navigate(workbenchForm, result, request, response);
1002         } else if (searchParams.getSearchConditions().get(0).getSearchField().getDocType().equalsIgnoreCase("holdings")) {
1003             /*List<OleWorkHoldingsDocument> oleWorkHoldingsDocuments = queryService.getDocuments(searchParams);
1004             workbenchForm.setWorkHoldingsDocumentList(oleWorkHoldingsDocuments);*/
1005             /*List<Holdings> holdingsList = null;
1006             holdingsList = getHoldingsList(searchParams);*/
1007 
1008             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "LocalId_display"));
1009             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title_display"));
1010             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "Location_display"));
1011             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "CallNumber_display"));
1012             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "DocFormat"));
1013             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "bibIdentifier"));
1014             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "itemIdentifier"));
1015             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "holdingsIdentifier"));
1016             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "Location_display"));
1017 
1018             searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
1019             for (SearchResult searchResult : searchResponse.getSearchResults()) {
1020                 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
1021                 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
1022 
1023                     if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
1024                         searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
1025                     }
1026                     if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
1027                         searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
1028                     }
1029                     if (searchResultField.getFieldName().equalsIgnoreCase("Location_display")) {
1030                         searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
1031                     }
1032                     if (searchResultField.getFieldName().equalsIgnoreCase("CallNumber_display")) {
1033                         searchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
1034                     }
1035                     if (searchResultField.getFieldName().equalsIgnoreCase("DocFormat")) {
1036                         searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
1037                     }
1038                     if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
1039                         searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
1040                     }
1041                     if (searchResultField.getFieldName().equalsIgnoreCase("holdingsIdentifier")) {
1042                         searchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
1043                     }
1044                     if (searchResultField.getFieldName().equalsIgnoreCase("itemIdentifier")) {
1045                         searchResultDisplayRow.setItemIdentifier(searchResultField.getFieldValue());
1046                     }
1047                     if (searchResultField.getFieldName().equalsIgnoreCase("Location_display")) {
1048                         searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
1049                     }
1050 
1051 
1052 
1053 
1054                 }
1055                 searchResultDisplayRows.add(searchResultDisplayRow);
1056             }
1057             workbenchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
1058             workbenchForm.setSearchResponse(searchResponse);
1059             if (searchResultDisplayRows.size() == 0) {
1060                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
1061             }
1062             setPageNextPreviousAndEntriesInfo(workbenchForm);
1063             return navigate(workbenchForm, result, request, response);
1064         } else if (searchParams.getSearchConditions().get(0).getSearchField().getDocType().equalsIgnoreCase("bibliographic")) {
1065 
1066             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "LocalId_display"));
1067             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title_display"));
1068             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Author_display"));
1069             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "PublicationDate_display"));
1070             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "DocFormat"));
1071             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "bibIdentifier"));
1072             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "id"));
1073 
1074             searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
1075             for (SearchResult searchResult : searchResponse.getSearchResults()) {
1076                 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
1077                 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
1078                     if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
1079                         searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
1080                     }
1081                     if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
1082                         searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
1083                     }
1084                     if (searchResultField.getFieldName().equalsIgnoreCase("Author_display")) {
1085                         searchResultDisplayRow.setAuthor(searchResultField.getFieldValue());
1086                     }
1087                     if (searchResultField.getFieldName().equalsIgnoreCase("PublicationDate_display")) {
1088                         searchResultDisplayRow.setPublicationDate(searchResultField.getFieldValue());
1089                     }
1090                     if (searchResultField.getFieldName().equalsIgnoreCase("DocFormat")) {
1091                         searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
1092                     }
1093                     if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
1094                         searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
1095                     }
1096                     if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
1097                         searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
1098                     }
1099                     if (eResourceId != null) {
1100                         searchResultDisplayRow.setOleERSIdentifier(eResourceId);
1101                     }
1102                     if (tokenId != null) {
1103                         searchResultDisplayRow.setTokenId(tokenId);
1104                     }
1105                 }
1106                 searchResultDisplayRows.add(searchResultDisplayRow);
1107             }
1108             workbenchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
1109             workbenchForm.setSearchResponse(searchResponse);
1110             setPageNextPreviousAndEntriesInfo(workbenchForm);
1111             return navigate(workbenchForm, result, request, response);
1112         } else if (searchParams.getSearchConditions().get(0).getSearchField().getDocType().equalsIgnoreCase("eholdings")) {
1113             searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
1114             for (SearchResult searchResult : searchResponse.getSearchResults()) {
1115                 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
1116 
1117 
1118                 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
1119                     if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
1120                         searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
1121                     }
1122                     if (searchResultField.getFieldName().equalsIgnoreCase("AccessStatus_display")) {
1123                         searchResultDisplayRow.setAccessStatus(searchResultField.getFieldValue());
1124                     }
1125                     if (searchResultField.getFieldName().equalsIgnoreCase("Platform_display")) {
1126                         searchResultDisplayRow.setPlatForm(searchResultField.getFieldValue());
1127                     }
1128                     if (searchResultField.getFieldName().equalsIgnoreCase("Imprint_display")) {
1129                         searchResultDisplayRow.setImprint(searchResultField.getFieldValue());
1130                     }
1131                     if (searchResultField.getFieldName().equalsIgnoreCase("StatisticalSearchingFullValue_display")) {
1132                         searchResultDisplayRow.setStatisticalCode(searchResultField.getFieldValue());
1133                     }
1134                     if (searchResultField.getFieldName().equalsIgnoreCase("StatisticalSearchingCodeValue_display")) {
1135                         searchResultDisplayRow.setStatisticalCode(searchResultField.getFieldValue());
1136                     }
1137                     if (searchResultField.getFieldName().equalsIgnoreCase("DocFormat")) {
1138                         searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
1139                     }
1140                     if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
1141                         searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
1142                     }
1143                     if (searchResultField.getFieldName().equalsIgnoreCase("holdingsIdentifier")) {
1144                         searchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
1145                     }
1146 
1147 
1148 
1149                 }
1150                 searchResultDisplayRows.add(searchResultDisplayRow);
1151             }
1152 
1153 
1154             workbenchForm.setSearchResultDisplayRowList(searchResultDisplayRows);
1155             workbenchForm.setSearchResponse(searchResponse);
1156             setPageNextPreviousAndEntriesInfo(workbenchForm);
1157             return navigate(workbenchForm, result, request, response);
1158         }
1159 
1160         return navigate(workbenchForm, result, request, response);
1161 
1162     }
1163 
1164     /**
1165      * @param form
1166      * @param result
1167      * @param request
1168      * @param response
1169      * @return
1170      */
1171     @RequestMapping(params = "methodToCall=clearSearch")
1172     public ModelAndView clearSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1173                                     HttpServletRequest request, HttpServletResponse response) {
1174         LOG.info("Inside clearSearch Method");
1175         WorkbenchForm workbenchForm = (WorkbenchForm) form;
1176         workbenchForm.setSearchParams(new SearchParams());
1177         List<SearchCondition> searchConditions = workbenchForm.getSearchParams().getSearchConditions();
1178         searchConditions.add(new SearchCondition());
1179         searchConditions.add(new SearchCondition());
1180         workbenchForm.setWorkBibDocumentList(null);
1181         workbenchForm.setWorkHoldingsDocumentList(null);
1182         workbenchForm.setWorkItemDocumentList(null);
1183         workbenchForm.setWorkEHoldingsDocumentList(null);
1184         workbenchForm.setMessage(null);
1185         return getUIFModelAndView(workbenchForm);
1186 //        return navigate(workbenchForm, result, request, response);
1187     }
1188 
1189     @RequestMapping(params = "methodToCall=select")
1190     public ModelAndView select(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1191                                HttpServletRequest request, HttpServletResponse response) {
1192         WorkbenchForm workbenchForm = (WorkbenchForm) form;
1193         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1194         String selectedRecord = workbenchForm.getWorkBibDocumentList().get(index).getId();
1195         LOG.info("selectedRecord--->" + selectedRecord);
1196         return super.navigate(workbenchForm, result, request, response);
1197     }
1198 
1199     @RequestMapping(params = "methodToCall=selectRecords")
1200     public ModelAndView selectRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1201                                       HttpServletRequest request, HttpServletResponse response) {
1202         WorkbenchForm workbenchForm = (WorkbenchForm) form;
1203         List<String> selectedRecordIds = new ArrayList<String>();
1204         List<OleWorkBibDocument> oleWorkBibDocuments = workbenchForm.getWorkBibDocumentList();
1205         for (OleWorkBibDocument oleWorkBibDocument : oleWorkBibDocuments) {
1206             if (oleWorkBibDocument.isSelect()) {
1207                 selectedRecordIds.add(oleWorkBibDocument.getId());
1208             }
1209         }
1210         LOG.info("selectedRecords--->" + selectedRecordIds);
1211         return getUIFModelAndView(workbenchForm);
1212     }
1213 
1214     /**
1215      * Exports the selected bib records as request XML.
1216      *
1217      * @param form
1218      * @param result
1219      * @param request
1220      * @param response
1221      * @return
1222      * @throws IOException
1223      * @throws ServletException
1224      */
1225     @RequestMapping(params = "methodToCall=export")
1226     public ModelAndView export(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1227                                HttpServletRequest request, HttpServletResponse response) throws Exception {
1228         WorkbenchForm workbenchForm = (WorkbenchForm) form;
1229         boolean hasPermission = canExportToRequestXml(GlobalVariables.getUserSession().getPrincipalId());
1230         if (!hasPermission) {
1231             workbenchForm.setJumpToId("breadcrumb_label");
1232             workbenchForm.setFocusId("breadcrumb_label");
1233             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ERROR_AUTHORIZATION);
1234             return navigate(workbenchForm, result, request, response);
1235         }
1236         workbenchForm.setShowRequestXML(true);
1237         Request docStoreRequest = new Request();
1238         docStoreRequest.setOperation(Request.Operation.ingest.toString());
1239         docStoreRequest.setUser("ole-khuntley");
1240         List<String> selectedRecordIds = new ArrayList<String>();
1241         List<SearchResultDisplayRow> searchResultDisplayRows = workbenchForm.getSearchResultDisplayRowList();
1242         for (SearchResultDisplayRow searchResultDisplayRow : searchResultDisplayRows) {
1243             if (searchResultDisplayRow.isSelect()) {
1244                 selectedRecordIds.add(searchResultDisplayRow.getBibIdentifier());
1245             }
1246         }
1247         LOG.info("selectedRecords--->" + selectedRecordIds);
1248         String bibTreesContent = "";
1249         BibTrees bibTrees = new BibTrees();
1250         for (int i = 0; i < selectedRecordIds.size(); i++) {
1251             String id = selectedRecordIds.get(i);
1252             BibTree bibTree = new BibTree();
1253             Map findBibTreeMap = new HashMap();
1254             findBibTreeMap.put("DocType", "bibliographic");
1255             findBibTreeMap.put("ID", id);
1256             bibTree = getDocstoreClientLocator().getDocstoreClient().findBibTree(findBibTreeMap);
1257             bibTrees.getBibTrees().add(bibTree);
1258         }
1259         bibTreesContent = BibTrees.serialize(bibTrees);
1260         workbenchForm.setRequestXMLTextArea(bibTreesContent);
1261         return getUIFModelAndView(workbenchForm);
1262     }
1263 
1264     @RequestMapping(params = "methodToCall=submit")
1265     public ModelAndView submit(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1266                                HttpServletRequest request, HttpServletResponse response) throws Exception {
1267         WorkbenchForm workbenchForm = (WorkbenchForm) form;
1268         boolean isValid = false;
1269         BusinessObjectService boService = KRADServiceLocator.getBusinessObjectService();
1270         Map<String, String> map = new HashMap<>();
1271         List<Integer> resultList = new ArrayList<>();
1272         for (SearchResultDisplayRow searchResultDisplayRow : workbenchForm.getSearchResultDisplayRowList()) {
1273             if (searchResultDisplayRow.isSelect()) {
1274                 map.put(OLEConstants.BIB_ID, searchResultDisplayRow.getBibIdentifier());
1275                 List<OleCopy> listOfValues = (List<OleCopy>) boService.findMatching(OleCopy.class, map);
1276                 if (listOfValues.size() > 0 && (workbenchForm.getMessage() == null || workbenchForm.getMessage().equals(""))) {
1277                     for (OleCopy oleCopy : listOfValues) {
1278                         resultList.add(oleCopy.getReqDocNum());
1279                     }
1280                     Set<Integer> resultSet = new HashSet<>(resultList);
1281                     resultList = new ArrayList<>(resultSet);
1282                     StringBuffer reqIds = new StringBuffer("");
1283                     if (resultList.size() > 0) {
1284                         int count = 0;
1285                         for (; count < resultList.size() - 1; count++) {
1286                             reqIds.append(resultList.get(count) + ",");
1287                         }
1288                         reqIds.append(resultList.get(count));
1289                     }
1290                     workbenchForm.setMessage(OLEConstants.POPUP_MESSAGE + reqIds.toString() + OLEConstants.PROCEED_MESSAGE);
1291                     return getUIFModelAndView(workbenchForm);
1292                 }
1293                 workbenchForm.setMessage("");
1294                 processNewRecordResponseForOLE(searchResultDisplayRow.getLocalId(), workbenchForm.getTokenId());
1295                 workbenchForm.setSuccessMessage(OLEConstants.LINK_SUCCESS_MESSAGE);
1296                 isValid = true;
1297                 break;
1298             }
1299         }
1300         if (isValid == false) {
1301             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.BIB_SELECT);
1302             return getUIFModelAndView(workbenchForm);
1303         }
1304         return getUIFModelAndView(workbenchForm);
1305     }
1306 
1307     private void processNewRecordResponseForOLE(String bibId, String tokenId) throws Exception {
1308         String instanceUUID = null;
1309         BibTree bibTree = getDocstoreClientLocator().getDocstoreClient().retrieveBibTree(bibId);
1310         OLEEditorResponse oleEditorResponse = new OLEEditorResponse();
1311         if (bibTree.getHoldingsTrees() != null && bibTree.getHoldingsTrees().size() > 0) {
1312             instanceUUID = bibTree.getHoldingsTrees().get(0).getId();
1313         }
1314         oleEditorResponse.setLinkedInstanceId(instanceUUID);
1315         oleEditorResponse.setBib(bibTree.getBib());
1316         oleEditorResponse.setTokenId(tokenId);
1317         HashMap<String, OLEEditorResponse> oleEditorResponseMap = new HashMap<String, OLEEditorResponse>();
1318         oleEditorResponseMap.put(tokenId, oleEditorResponse);
1319         OleDocstoreResponse.getInstance().setEditorResponse(oleEditorResponseMap);
1320     }
1321 
1322     public String getURL() {
1323         String url = ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.OLE_EXPOSED_WEB_SERVICE_url);
1324         return url;
1325     }
1326 
1327     @RequestMapping(params = "methodToCall=linkToBib")
1328     public ModelAndView linkToBib(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1329                                   HttpServletRequest request, HttpServletResponse response) throws Exception {
1330         WorkbenchForm workbenchForm = (WorkbenchForm) form;
1331         List<SearchResultDisplayRow> searchResultDisplayRowList = workbenchForm.getHoldingSearchResultDisplayRowList();
1332         workbenchForm.setSuccessMessage(null);
1333         if (searchResultDisplayRowList != null && searchResultDisplayRowList.size() > 0) {
1334             for (SearchResultDisplayRow searchResultDisplayRow : searchResultDisplayRowList) {
1335                 if (searchResultDisplayRow.isSelect()) {
1336                     processNewHoldingsResponse(searchResultDisplayRow, workbenchForm.getTokenId());
1337                     Holdings holdings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(searchResultDisplayRow.getHoldingsIdentifier());
1338                     if (holdings.getHoldingsType().equalsIgnoreCase("electronic")) {
1339                         saveRecordToDocstore(searchResultDisplayRow, eResourceId);
1340                     }
1341                     workbenchForm.setSuccessMessage("");
1342                     break;
1343                 } else {
1344                     workbenchForm.setSuccessMessage(OLEConstants.HOLDINGS_ERROR_MESSAGE);
1345                 }
1346             }
1347         }
1348         if (eResourceId != null && !eResourceId.isEmpty()) {
1349             Map<String, String> tempId = new HashMap<String, String>();
1350             tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, eResourceId);
1351             OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
1352             try {
1353                 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
1354                 tempDocument.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(tempDocument.getDocumentNumber(), principalPerson));
1355                 if (tempDocument != null) {
1356                     try {
1357                         tempDocument.setSelectInstance(OLEConstants.OLEEResourceRecord.LINK_EXIST_INSTANCE);
1358                         tempDocument.seteInstanceFlag(true);
1359                         getOleEResourceSearchService().getNewInstance(tempDocument, tempDocument.getDocumentNumber());
1360                         getDocumentService().updateDocument(tempDocument);
1361                     } catch (Exception e) {
1362                         throw new RiceRuntimeException(
1363                                 "Exception trying to save document: " + tempDocument
1364                                         .getDocumentNumber(), e);
1365                     }
1366                 }
1367             } catch (Exception e) {
1368                 throw new RiceRuntimeException(
1369                         "Exception trying to save document: " + tempDocument
1370                                 .getDocumentNumber(), e);
1371             }
1372         }
1373         return getUIFModelAndView(workbenchForm);
1374     }
1375 
1376     @RequestMapping(params = "methodToCall=getHoldingsList")
1377     public ModelAndView getHoldingsList(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1378                                         HttpServletRequest request, HttpServletResponse response) throws Exception {
1379         WorkbenchForm workbenchForm = (WorkbenchForm) form;
1380         workbenchForm.setErrorMessage(null);
1381         workbenchForm.setHoldingSearchResultDisplayRowList(null);
1382         workbenchForm.seteHoldingsFlag("false");
1383         List<SearchResultDisplayRow> searchResultDisplayRowList = new ArrayList<>();
1384 
1385         if (workbenchForm.getSearchResultDisplayRowList() != null && workbenchForm.getSearchResultDisplayRowList().size() > 0) {
1386             for (SearchResultDisplayRow searchResultDisplay : workbenchForm.getSearchResultDisplayRowList()) {
1387                 if (searchResultDisplay.isSelect()) {
1388                     BibTree bibTree = getDocstoreClientLocator().getDocstoreClient().retrieveBibTree(searchResultDisplay.getLocalId());
1389                     List<HoldingsTree> holdingsTreeList = bibTree.getHoldingsTrees();
1390                     if (holdingsTreeList.size() > 0) {
1391                         workbenchForm.setHoldingsFlag("true");
1392                         for (HoldingsTree holdingsTree : holdingsTreeList) {
1393                             if (holdingsTree.getHoldings().getHoldingsType().equalsIgnoreCase("print")) {
1394                                 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
1395                                 searchResultDisplayRow.setHoldingsIdentifier(holdingsTree.getHoldings().getId());
1396                                 searchResultDisplayRow.setTitle(holdingsTree.getHoldings().getBib().getTitle());
1397                                 searchResultDisplayRow.setBibIdentifier(holdingsTree.getHoldings().getBib().getId());
1398                                 searchResultDisplayRow.setCallNumber(holdingsTree.getHoldings().getCallNumber());
1399                                 // searchResultDisplayRow.setCallNumberPrefix(holdingsTree.getHoldings().getCallNumberPrefix());
1400                                 // searchResultDisplayRow.setCallNumberType(holdingsTree.getHoldings().getCallNumberType());
1401                                 // searchResultDisplayRow.setCopyNumber(holdingsTree.getHoldings().getCopyNumber());
1402                                 //  searchResultDisplayRow.setStaffOnlyFlag(holdingsTree.getStaffOnlyFlag());
1403                                 // searchResultDisplayRow.setLinkedBibCount(holdingsTree.getLinkedBibCount());
1404                                 searchResultDisplayRow.setLocalId(DocumentUniqueIDPrefix.getDocumentId(holdingsTree.getHoldings().getId()));
1405                                 searchResultDisplayRow.setLocationName(holdingsTree.getHoldings().getLocationName());
1406                                 searchResultDisplayRow.setInstanceIdentifier(holdingsTree.getHoldings().getId());
1407                                 searchResultDisplayRowList.add(searchResultDisplayRow);
1408                             }
1409                         }
1410                     }
1411                 }
1412             }
1413         }
1414         if (searchResultDisplayRowList.size() == 0) {
1415             workbenchForm.setErrorMessage("selected bib doesnt have Holdings");
1416         }
1417         workbenchForm.setHoldingSearchResultDisplayRowList(searchResultDisplayRowList);
1418         workbenchForm.setWorkEHoldingsDocumentList(null);
1419         return navigate(workbenchForm, result, request, response);
1420     }
1421 
1422     @RequestMapping(params = "methodToCall=getEHoldingsList")
1423     public ModelAndView getEHoldingsList(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1424                                          HttpServletRequest request, HttpServletResponse response) throws Exception {
1425         WorkbenchForm workbenchForm = (WorkbenchForm) form;
1426         workbenchForm.setErrorMessage(null);
1427         workbenchForm.setHoldingsFlag("false");
1428         workbenchForm.setHoldingSearchResultDisplayRowList(null);
1429         List<SearchResultDisplayRow> searchResultDisplayRowArrayList = new ArrayList<>();
1430         if (workbenchForm.getSearchResultDisplayRowList() != null && workbenchForm.getSearchResultDisplayRowList().size() > 0) {
1431             for (SearchResultDisplayRow searchResultDisplay : workbenchForm.getSearchResultDisplayRowList()) {
1432                 if (searchResultDisplay.isSelect()) {
1433                     BibTree bibTree = getDocstoreClientLocator().getDocstoreClient().retrieveBibTree(searchResultDisplay.getLocalId());
1434                     if (bibTree.getHoldingsTrees().size() > 0) {
1435                         workbenchForm.seteHoldingsFlag("true");
1436                         for (HoldingsTree holdingsTree : bibTree.getHoldingsTrees()) {
1437                             if (holdingsTree.getHoldings().getHoldingsType().equalsIgnoreCase("electronic")) {
1438                                 OleHoldings oleHoldings = new OleHoldings();
1439                                 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
1440                                 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
1441                                 oleHoldings = (OleHoldings) holdingOlemlRecordProcessor.fromXML(holdingsTree.getHoldings().getContent());
1442                                 searchResultDisplayRow.setAccessStatus(oleHoldings.getAccessStatus());
1443                                 searchResultDisplayRow.setPlatForm(oleHoldings.getPlatform() != null ? oleHoldings.getPlatform().getPlatformName() : null);
1444                                 searchResultDisplayRow.setImprint(oleHoldings.getImprint());
1445                                 searchResultDisplayRow.setStatisticalCode(oleHoldings.getStatisticalSearchingCode() != null ? oleHoldings.getStatisticalSearchingCode().getCodeValue() : null);
1446                                 searchResultDisplayRow.setLocationName(holdingsTree.getHoldings().getLocationName());
1447                                 searchResultDisplayRow.setBibIdentifier(holdingsTree.getHoldings().getBib().getId());
1448                                 searchResultDisplayRow.setInstanceIdentifier(holdingsTree.getHoldings().getId());
1449                                 searchResultDisplayRow.setHoldingsIdentifier(holdingsTree.getHoldings().getId());
1450                                 searchResultDisplayRow.setLocalId(DocumentUniqueIDPrefix.getDocumentId(holdingsTree.getHoldings().getId()));
1451                                 //searchResultDisplayRow.setUrl(oleHoldings.getLink().getUrl());
1452                                 //oleWorkEHoldingsDocument.seteResourceName(holdingsTree.geteResourceName());
1453                                 searchResultDisplayRowArrayList.add(searchResultDisplayRow);
1454                             }
1455                         }
1456                     }
1457                 }
1458             }
1459         }
1460         if (searchResultDisplayRowArrayList.size() == 0) {
1461             workbenchForm.setErrorMessage("selected bib doesnt have EHoldings");
1462         }
1463         workbenchForm.setHoldingSearchResultDisplayRowList(searchResultDisplayRowArrayList);
1464         workbenchForm.setWorkHoldingsDocumentList(null);
1465         return navigate(workbenchForm, result, request, response);
1466     }
1467 
1468     private void saveRecordToDocstore(SearchResultDisplayRow searchResultDisplayRow, String eResourceId) throws Exception {
1469         Holdings eHoldings = new org.kuali.ole.docstore.common.document.EHoldings();
1470         OleHoldings oleHoldings = new OleHoldings();
1471         eHoldings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(searchResultDisplayRow.getHoldingsIdentifier());
1472         oleHoldings = new HoldingOlemlRecordProcessor().fromXML(eHoldings.getContent());
1473         oleHoldings.setEResourceId(eResourceId);
1474         eHoldings.setContent(new HoldingOlemlRecordProcessor().toXML(oleHoldings));
1475         getDocstoreClientLocator().getDocstoreClient().updateHoldings(eHoldings);
1476     }
1477 
1478     private void processNewHoldingsResponse(SearchResultDisplayRow searchResultDisplayRow, String tokenId) throws Exception {
1479         OLEEditorResponse oleEditorResponse = new OLEEditorResponse();
1480         oleEditorResponse.setLinkedInstanceId(searchResultDisplayRow.getHoldingsIdentifier());
1481         oleEditorResponse.setTokenId(tokenId);
1482         HashMap<String, OLEEditorResponse> oleEditorResponseMap = new HashMap<String, OLEEditorResponse>();
1483         oleEditorResponseMap.put(tokenId, oleEditorResponse);
1484         OleDocstoreResponse.getInstance().setEditorResponse(oleEditorResponseMap);
1485     }
1486 
1487     private boolean canExportToRequestXml(String principalId) {
1488         PermissionService service = KimApiServiceLocator.getPermissionService();
1489         return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.DESC_WORKBENCH_EXPORT_XML);
1490     }
1491 
1492 }