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