View Javadoc
1   package org.kuali.ole.deliver.controller;
2   
3   import org.apache.commons.collections.CollectionUtils;
4   import org.apache.commons.lang3.StringUtils;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.OLEPropertyConstants;
7   import org.kuali.ole.deliver.bo.*;
8   import org.kuali.ole.deliver.form.OLEDeliverItemSearchForm;
9   import org.kuali.ole.deliver.service.OLEDeliverItemSearchService;
10  import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
11  import org.kuali.ole.docstore.common.constants.DocstoreConstants;
12  import org.kuali.ole.docstore.common.document.*;
13  import org.kuali.ole.docstore.common.document.content.enums.DocType;
14  import org.kuali.ole.docstore.common.search.*;
15  import org.kuali.ole.sys.context.SpringContext;
16  import org.kuali.rice.core.api.config.property.ConfigContext;
17  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
18  import org.kuali.rice.krad.service.KRADServiceLocator;
19  import org.kuali.rice.krad.util.GlobalVariables;
20  import org.kuali.rice.krad.util.KRADConstants;
21  import org.kuali.rice.krad.web.controller.UifControllerBase;
22  import org.kuali.rice.krad.web.form.UifFormBase;
23  import org.springframework.stereotype.Controller;
24  import org.springframework.validation.BindingResult;
25  import org.springframework.web.bind.annotation.ModelAttribute;
26  import org.springframework.web.bind.annotation.RequestMapping;
27  import org.springframework.web.servlet.ModelAndView;
28  
29  import javax.servlet.http.HttpServletRequest;
30  import javax.servlet.http.HttpServletResponse;
31  import java.util.*;
32  
33  /**
34   * Created by chenchulakshmig on 1/12/15.
35   */
36  @Controller
37  @RequestMapping(value = "/deliverItemSearchController")
38  public class OLEDeliverItemSearchController extends UifControllerBase {
39  
40      String baseUrl = ConfigContext.getCurrentContextConfig().getProperty(OLEPropertyConstants.OLE_URL_BASE);
41  
42      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OLEDeliverItemSearchController.class);
43      private DocstoreClientLocator docstoreClientLocator;
44      private OLEDeliverItemSearchService oleDeliverItemSearchService;
45  
46      public DocstoreClientLocator getDocstoreClientLocator() {
47          if (docstoreClientLocator == null) {
48              docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
49          }
50          return docstoreClientLocator;
51      }
52  
53      public OLEDeliverItemSearchService getOleDeliverItemSearchService() {
54          if (oleDeliverItemSearchService == null) {
55              oleDeliverItemSearchService = GlobalResourceLoader.getService(OLEConstants.DELIVER_ITEM__SEARCH_SERVICE);
56          }
57          return oleDeliverItemSearchService;
58      }
59  
60      @Override
61      protected UifFormBase createInitialForm(HttpServletRequest request) {
62          return new OLEDeliverItemSearchForm();
63      }
64  
65      @RequestMapping(params = "methodToCall=search")
66      public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
67                                 HttpServletRequest request, HttpServletResponse response) {
68          OLEDeliverItemSearchForm oleDeliverItemSearchForm = (OLEDeliverItemSearchForm) form;
69          oleDeliverItemSearchForm.setSingleItemFlag(false);
70          oleDeliverItemSearchForm.setMultipleItemFlag(false);
71          oleDeliverItemSearchForm.setOleBibSearchResultDisplayRowList(new ArrayList<OLEBibSearchResultDisplayRow>());
72          oleDeliverItemSearchForm.setOleSingleItemResultDisplayRow(new OLESingleItemResultDisplayRow());
73          try {
74              String title = oleDeliverItemSearchForm.getTitle();
75              String author = oleDeliverItemSearchForm.getAuthor();
76              String publisher = oleDeliverItemSearchForm.getPublisher();
77              String itemBarcode = oleDeliverItemSearchForm.getItemBarCode();
78              String callNumber = oleDeliverItemSearchForm.getItemCallNumber();
79              String itemUUID = oleDeliverItemSearchForm.getItemUUID();
80              String itemType = oleDeliverItemSearchForm.getItemType();
81              String itemLocation = oleDeliverItemSearchForm.getItemLocation();
82              SearchParams searchParams = new SearchParams();
83              if (StringUtils.isNotBlank(title) || StringUtils.isNotBlank(author) || StringUtils.isNotBlank(publisher) || StringUtils.isNotBlank(itemBarcode)
84                      || StringUtils.isNotBlank(callNumber) || StringUtils.isNotBlank(itemUUID) || StringUtils.isNotBlank(itemType) || StringUtils.isNotBlank(itemLocation)) {
85                  if (StringUtils.isNotBlank(title)) {
86                      searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Bib.TITLE, title), OLEConstants.AND_SEARCH_SCOPE));
87                  }
88                  if (StringUtils.isNotBlank(author)) {
89                      searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Bib.AUTHOR, author), OLEConstants.AND_SEARCH_SCOPE));
90                  }
91                  if (StringUtils.isNotBlank(publisher)) {
92                      searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Bib.PUBLISHER, publisher), OLEConstants.AND_SEARCH_SCOPE));
93                  }
94                  if (StringUtils.isNotBlank(itemBarcode)) {
95                      searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Item.ITEM_BARCODE, itemBarcode), OLEConstants.AND_SEARCH_SCOPE));
96                  }
97                  if (StringUtils.isNotBlank(callNumber)) {
98                      searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Item.CALL_NUMBER, callNumber),OLEConstants.OR_SEARCH_SCOPE));
99                      searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), DocstoreConstants.HOLDINGS_CALLNUMBER_SEARCH, callNumber), OLEConstants.AND_SEARCH_SCOPE));
100                 }
101                 if (StringUtils.isNotBlank(itemUUID)) {
102                     searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Item.ITEMIDENTIFIER, itemUUID), OLEConstants.AND_SEARCH_SCOPE));
103                 }
104                 if (StringUtils.isNotBlank(itemType)) {
105                     searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Item.ITEM_TYPE, itemType), OLEConstants.AND_SEARCH_SCOPE));
106                 }
107                 if (StringUtils.isNotBlank(itemLocation)) {
108                     searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.PHRASE, searchParams.buildSearchField(DocType.ITEM.getCode(), DocstoreConstants.LOCATION_LEVEL_SEARCH, itemLocation), OLEConstants.OR_SEARCH_SCOPE));
109                     searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.PHRASE, searchParams.buildSearchField(DocType.ITEM.getCode(),DocstoreConstants.HOLDINGS_LOCATION_SEARCH, itemLocation), OLEConstants.OR_SEARCH_SCOPE));
110                 }
111                 searchParams.setPageSize(oleDeliverItemSearchForm.getPageSize());
112                 searchParams.setStartIndex(oleDeliverItemSearchForm.getStart());
113                 oleDeliverItemSearchForm.setSearchParams(searchParams);
114                 buildSortCondition(oleDeliverItemSearchForm);
115                 getSearchResultFields(searchParams);
116                 SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
117                 oleDeliverItemSearchForm.setTotalRecordCount(searchResponse.getTotalRecordCount());
118                 getSearchResults(searchResponse, oleDeliverItemSearchForm);
119                 if(oleDeliverItemSearchForm.getOleBibSearchResultDisplayRowList()!=null && oleDeliverItemSearchForm.getOleBibSearchResultDisplayRowList().size()>0){
120                     oleDeliverItemSearchForm.setMultipleItemFlag(true);
121                 }
122             } else {
123                 oleDeliverItemSearchForm.setSingleItemFlag(false);
124                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ITM_BLANK_SEARCH_ERROR_MSG);
125                 return getUIFModelAndView(oleDeliverItemSearchForm,"OLEDeliverItemSearchPage");
126             }
127         } catch (Exception e) {
128             LOG.error("Exception " + e);
129         }
130         return getUIFModelAndView(oleDeliverItemSearchForm);
131     }
132 
133     private void getSearchResultFields(SearchParams searchParams) {
134         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.BIB_IDENTIFIER));
135         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.TITLE_SORT));
136         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Bib.AUTHOR));
137         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Bib.PUBLICATIONPLACE));
138         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Bib.PUBLISHER));
139         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.HOLDINGS_LOCATION_DISPLAY));
140         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.LOCATION_LEVEL_DISPLAY));
141         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Item.CALL_NUMBER));
142         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Item.ITEM_STATUS));
143         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.ITEM_TYPE_FULL_VALUE));
144         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.HOLDINGS_IDENTIFIER));
145         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.HOLDINGS_CALLNUMBER_DISPLAY));
146         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Item.ID));
147         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Item.ITEM_BARCODE));
148         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.ENUMERATION_DISPLAY));
149         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.CHRONOLOGY_DISPLAY));
150         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.ITEM_STATUS_EFFECTIVE_DATE));
151         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.DUE_DATE_TIME));
152         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.ORG_DUE_DATE_TIME));
153         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.NUMBER_OF_PIECES_DISPLAY));
154         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.PUBLICATIONDATE_DISPLAY));
155         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.CURRENT_BORROWER));
156         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.PROXY_BORROWER));
157         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.MDF_035A));
158         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.ISBN_DISPLAY));
159         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.ITEMNOTE_VALUE_DISPLAY));
160         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.ITEMNOTE_TYPE_DISPLAY));
161         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.MISSING_PIECE_FLAG_DISPLAY));
162         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.MISSING_PIECE_COUNT_DISPLAY));
163         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants. MISSING_PIECE_FLAG_NOTE_DISPLAY));
164         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.CLMS_RET_FLAG));
165         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.CLMS_RET_NOTE));
166         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.CLMS_RET_FLAG_CRE_DATE));
167         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.ITEM_DAMAGED_FLAG_DISPLAY));
168         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.DAMAGED_ITEM_NOTE_DISPLAY));
169         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.CREATED_BY));
170         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.DATE_ENTERED));
171         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.UPDATED_BY));
172         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), DocstoreConstants.DATE_UPDATED));
173      }
174 
175     private void buildSortCondition(OLEDeliverItemSearchForm oleDeliverItemSearchForm) {
176         SearchParams searchParams = oleDeliverItemSearchForm.getSearchParams();
177         SortCondition sortCondition = new SortCondition();
178         if(org.apache.commons.lang.StringUtils.isEmpty(oleDeliverItemSearchForm.getSortField())){
179             oleDeliverItemSearchForm.setSortField(DocstoreConstants.TITLE_SORT);
180             oleDeliverItemSearchForm.setSortOrder("asc");
181         }
182         sortCondition.setSortField(oleDeliverItemSearchForm.getSortField());
183         sortCondition.setSortOrder(oleDeliverItemSearchForm.getSortOrder());
184         searchParams.getSortConditions().add(sortCondition);
185     }
186 
187     private void getSearchResults(SearchResponse searchResponse, OLEDeliverItemSearchForm oleDeliverItemSearchForm) {
188         Map<String, OLEBibSearchResultDisplayRow> bibSearchResultDisplayRowMap = new TreeMap<>();
189         Map<String, OLEHoldingsSearchResultDisplayRow> holdingsSearchResultDisplayRowMap = new HashMap<>();
190         List<OLEBibSearchResultDisplayRow> bibSearchResultDisplayRowList = new ArrayList<>();
191         OLESingleItemResultDisplayRow singleItemResultDisplayRow = new OLESingleItemResultDisplayRow();
192         if (searchResponse != null && CollectionUtils.isNotEmpty(searchResponse.getSearchResults())) {
193             for (SearchResult searchResult : searchResponse.getSearchResults()) {
194                 if (CollectionUtils.isNotEmpty(searchResult.getSearchResultFields())) {
195                     OLEBibSearchResultDisplayRow bibSearchResultDisplayRow = new OLEBibSearchResultDisplayRow();
196                     OLEHoldingsSearchResultDisplayRow holdingsSearchResultDisplayRow = new OLEHoldingsSearchResultDisplayRow();
197                     singleItemResultDisplayRow = new OLESingleItemResultDisplayRow();
198                     OLEItemSearchResultDisplayRow itemSearchResultDisplayRow = new OLEItemSearchResultDisplayRow();
199                     for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
200                         if (searchResultField.getFieldName().equalsIgnoreCase(Bib.BIBIDENTIFIER)) {
201                             bibSearchResultDisplayRow.setId(searchResultField.getFieldValue());
202                             holdingsSearchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
203                             singleItemResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
204                             itemSearchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
205                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.TITLE_SORT)) {
206                             singleItemResultDisplayRow.setTitle(searchResultField.getFieldValue());
207                             bibSearchResultDisplayRow.setTitle(searchResultField.getFieldValue());
208                         } else if (searchResultField.getFieldName().equalsIgnoreCase(Bib.AUTHOR)) {
209                             singleItemResultDisplayRow.setAuthor(searchResultField.getFieldValue());
210                             bibSearchResultDisplayRow.setAuthor(searchResultField.getFieldValue());
211                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.HOLDINGS_LOCATION_DISPLAY)) {
212                             holdingsSearchResultDisplayRow.setLocation(searchResultField.getFieldValue());
213                             singleItemResultDisplayRow.setHoldingsLocation(searchResultField.getFieldValue());
214                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.LOCATION_LEVEL_DISPLAY)) {
215                             singleItemResultDisplayRow.setLocation(searchResultField.getFieldValue());
216                             itemSearchResultDisplayRow.setLocation(searchResultField.getFieldValue());
217                         } else if (searchResultField.getFieldName().equalsIgnoreCase(Item.CALL_NUMBER)) {
218                             singleItemResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
219                             itemSearchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
220                         } else if (searchResultField.getFieldName().equalsIgnoreCase(Item.ITEM_STATUS)) {
221                             singleItemResultDisplayRow.setItemStatus(searchResultField.getFieldValue());
222                             itemSearchResultDisplayRow.setItemStatus(searchResultField.getFieldValue());
223                         } else if (searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.ITEM_TYPE_FULL_VALUE)) {
224                             singleItemResultDisplayRow.setItemType(searchResultField.getFieldValue());
225                             itemSearchResultDisplayRow.setItemType(searchResultField.getFieldValue());
226                         } else if (searchResultField.getFieldName().equalsIgnoreCase(Holdings.HOLDINGSIDENTIFIER)) {
227                             holdingsSearchResultDisplayRow.setId(searchResultField.getFieldValue());
228                             singleItemResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
229                             itemSearchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
230                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.HOLDINGS_CALLNUMBER_DISPLAY)) {
231                             holdingsSearchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
232                             if(StringUtils.isEmpty(itemSearchResultDisplayRow.getCallNumber())){
233                                 singleItemResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
234                                 itemSearchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
235                             }
236                         } else if (searchResultField.getFieldName().equalsIgnoreCase(Item.ID)) {
237                             singleItemResultDisplayRow.setId(searchResultField.getFieldValue());
238                             itemSearchResultDisplayRow.setId(searchResultField.getFieldValue());
239                         } else if (searchResultField.getFieldName().equalsIgnoreCase(Item.ITEM_BARCODE)) {
240                             singleItemResultDisplayRow.setItemBarCode(searchResultField.getFieldValue());
241                             itemSearchResultDisplayRow.setItemBarCode(searchResultField.getFieldValue());
242                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.ENUMERATION_DISPLAY)) {
243                             singleItemResultDisplayRow.setEnumeration(searchResultField.getFieldValue());
244                             itemSearchResultDisplayRow.setEnumeration(searchResultField.getFieldValue());
245                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.CHRONOLOGY_DISPLAY)) {
246                             singleItemResultDisplayRow.setChronology(searchResultField.getFieldValue());
247                             itemSearchResultDisplayRow.setChronology(searchResultField.getFieldValue());
248                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.ITEM_STATUS_EFFECTIVE_DATE)) {
249                             singleItemResultDisplayRow.setItemStatusDate(searchResultField.getFieldValue());
250                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.DUE_DATE_TIME)) {
251                             singleItemResultDisplayRow.setDueDate(searchResultField.getFieldValue());
252                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.ORG_DUE_DATE_TIME)) {
253                             singleItemResultDisplayRow.setOriginalDueDate(searchResultField.getFieldValue());
254                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.NUMBER_OF_PIECES_DISPLAY)) {
255                             singleItemResultDisplayRow.setNoOfPieces(searchResultField.getFieldValue());
256                         }else if (searchResultField.getFieldName().equalsIgnoreCase(Bib.PUBLICATIONPLACE)) {
257                             singleItemResultDisplayRow.setPublication(searchResultField.getFieldValue());
258                         }else if (searchResultField.getFieldName().equalsIgnoreCase(Bib.PUBLISHER)) {
259                             if(StringUtils.isNotEmpty(singleItemResultDisplayRow.getPublication())){
260                                 singleItemResultDisplayRow.setPublication(singleItemResultDisplayRow.getPublication()+" "+searchResultField.getFieldValue());
261                             }else{
262                                 singleItemResultDisplayRow.setPublication(searchResultField.getFieldValue());
263                             }
264                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.PUBLICATIONDATE_DISPLAY)) {
265                             bibSearchResultDisplayRow.setPublicationYear(searchResultField.getFieldValue());
266                         }
267                         else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.CURRENT_BORROWER)) {
268                             singleItemResultDisplayRow.setCurrentBorrowerId(searchResultField.getFieldValue());
269                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.PROXY_BORROWER)) {
270                             singleItemResultDisplayRow.setProxyBorrowerId(searchResultField.getFieldValue());
271                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.MDF_035A)) {
272                             singleItemResultDisplayRow.setOclcNumber(searchResultField.getFieldValue());
273                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.ISBN_DISPLAY)) {
274                             singleItemResultDisplayRow.setIsbn(searchResultField.getFieldValue());
275                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.ITEMNOTE_VALUE_DISPLAY)) {
276                             singleItemResultDisplayRow.setItemNoteValue(searchResultField.getFieldValue());
277                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.ITEMNOTE_TYPE_DISPLAY)) {
278                             singleItemResultDisplayRow.setItemNoteType(searchResultField.getFieldValue());
279                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.MISSING_PIECE_FLAG_DISPLAY)) {
280                             singleItemResultDisplayRow.setMissingPieceFlag(searchResultField.getFieldValue());
281                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.MISSING_PIECE_COUNT_DISPLAY)) {
282                             singleItemResultDisplayRow.setMissingPieceCount(searchResultField.getFieldValue());
283                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.MISSING_PIECE_FLAG_NOTE_DISPLAY)) {
284                             singleItemResultDisplayRow.setMissingPieceNote(searchResultField.getFieldValue());
285                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.CLMS_RET_FLAG)) {
286                             singleItemResultDisplayRow.setClaimsReturnedFlag(searchResultField.getFieldValue());
287                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.CLMS_RET_NOTE)) {
288                             singleItemResultDisplayRow.setClaimsReturnedNote(searchResultField.getFieldValue());
289                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.CLMS_RET_FLAG_CRE_DATE)) {
290                             singleItemResultDisplayRow.setClaimsReturnedDate(searchResultField.getFieldValue());
291                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.ITEM_DAMAGED_FLAG_DISPLAY)) {
292                             singleItemResultDisplayRow.setItemDamagedStatusFlag(searchResultField.getFieldValue());
293                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.DAMAGED_ITEM_NOTE_DISPLAY)) {
294                             singleItemResultDisplayRow.setItemDamagedNote(searchResultField.getFieldValue());
295                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.CREATED_BY)) {
296                             singleItemResultDisplayRow.setCreatedBy(searchResultField.getFieldValue());
297                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.DATE_ENTERED)) {
298                             singleItemResultDisplayRow.setCreatedDate(searchResultField.getFieldValue());
299                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.UPDATED_BY)) {
300                             singleItemResultDisplayRow.setUpdatedBy(searchResultField.getFieldValue());
301                         } else if (searchResultField.getFieldName().equalsIgnoreCase(DocstoreConstants.DATE_UPDATED)) {
302                             singleItemResultDisplayRow.setUpdatedDate(searchResultField.getFieldValue());
303                         }
304                     }
305                     if(StringUtils.isNotEmpty(singleItemResultDisplayRow.getPublication()) && StringUtils.isNotEmpty( bibSearchResultDisplayRow.getPublicationYear())){
306                         singleItemResultDisplayRow.setPublication(singleItemResultDisplayRow.getPublication()+" "+bibSearchResultDisplayRow.getPublicationYear());
307                     }else if(StringUtils.isEmpty(singleItemResultDisplayRow.getPublication())&& StringUtils.isNotEmpty( bibSearchResultDisplayRow.getPublicationYear())){
308                         singleItemResultDisplayRow.setPublication(bibSearchResultDisplayRow.getPublicationYear());
309                     }
310                     itemSearchResultDisplayRow.setPlaceRequest(getOleDeliverItemSearchService().validateItemStatusForPlaceRequest(itemSearchResultDisplayRow.getItemStatus()));
311                     singleItemResultDisplayRow.setPlaceRequest(getOleDeliverItemSearchService().validateItemStatusForPlaceRequest(singleItemResultDisplayRow.getItemStatus()));
312 
313                     if (searchResponse.getSearchResults().size() > 1) {
314                         Map itemMap = new HashMap();
315                         itemMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, itemSearchResultDisplayRow.getItemBarCode());
316                         List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) KRADServiceLocator.getBusinessObjectService().findMatching(OleDeliverRequestBo.class, itemMap);
317                         if (CollectionUtils.isNotEmpty(deliverRequestBos)) {
318                             itemSearchResultDisplayRow.setRequestExists(true);
319                         }
320                         if (!holdingsSearchResultDisplayRowMap.containsKey(holdingsSearchResultDisplayRow.getId())) {
321                             List<OLEItemSearchResultDisplayRow> itemSearchResultDisplayRowList = new ArrayList<>();
322                             itemSearchResultDisplayRowList.add(itemSearchResultDisplayRow);
323                             holdingsSearchResultDisplayRow.setOleItemSearchResultDisplayRowList(itemSearchResultDisplayRowList);
324                             holdingsSearchResultDisplayRowMap.put(holdingsSearchResultDisplayRow.getId(), holdingsSearchResultDisplayRow);
325                         } else {
326                             holdingsSearchResultDisplayRowMap.get(holdingsSearchResultDisplayRow.getId()).getOleItemSearchResultDisplayRowList().add(itemSearchResultDisplayRow);
327                         }
328                         if (!bibSearchResultDisplayRowMap.containsKey(bibSearchResultDisplayRow.getId())) {
329                             List<OLEHoldingsSearchResultDisplayRow> holdingsSearchResultDisplayRowList = new ArrayList<>();
330                             holdingsSearchResultDisplayRowList.add(holdingsSearchResultDisplayRow);
331                             bibSearchResultDisplayRow.setOleHoldingsSearchResultDisplayRowList(holdingsSearchResultDisplayRowList);
332                             bibSearchResultDisplayRowMap.put(bibSearchResultDisplayRow.getId(), bibSearchResultDisplayRow);
333                         } else {
334                             boolean flag = false;
335                             for (OLEHoldingsSearchResultDisplayRow oleHoldingsSearchResultDisplayRow : bibSearchResultDisplayRowMap.get(bibSearchResultDisplayRow.getId()).getOleHoldingsSearchResultDisplayRowList()) {
336                                 if (oleHoldingsSearchResultDisplayRow.getId().equals(holdingsSearchResultDisplayRow.getId())) {
337                                     flag = true;
338                                     break;
339                                 }
340                             }
341                             if (!flag) {
342                                 bibSearchResultDisplayRowMap.get(bibSearchResultDisplayRow.getId()).getOleHoldingsSearchResultDisplayRowList().add(holdingsSearchResultDisplayRow);
343                             }
344                         }
345                     }
346                 }
347             }
348             if (searchResponse.getSearchResults().size() > 1) {
349                 for (OLEBibSearchResultDisplayRow bibSearchResultDisplayRow : bibSearchResultDisplayRowMap.values()) {
350                     if (bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().size() == 1) {
351                         bibSearchResultDisplayRow.setHoldingsLocation(bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().get(0).getLocation());
352                         if (bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().get(0).getOleItemSearchResultDisplayRowList().size() > 1) {
353                             bibSearchResultDisplayRow.setItemLocation(OLEConstants.MULTIPLE);
354                             bibSearchResultDisplayRow.setItemType(OLEConstants.MULTIPLE);
355                             bibSearchResultDisplayRow.setItemStatus(OLEConstants.MULTIPLE);
356                             bibSearchResultDisplayRow.setItemCallNumber(OLEConstants.MULTIPLE);
357                         } else if (bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().get(0).getOleItemSearchResultDisplayRowList().size() == 1) {
358                             OLEItemSearchResultDisplayRow oleItemSearchResultDisplayRow = bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().get(0).getOleItemSearchResultDisplayRowList().get(0);
359                             bibSearchResultDisplayRow.setItemLocation(oleItemSearchResultDisplayRow.getLocation());
360                             bibSearchResultDisplayRow.setItemType(oleItemSearchResultDisplayRow.getItemType());
361                             bibSearchResultDisplayRow.setItemStatus(oleItemSearchResultDisplayRow.getItemStatus());
362                             bibSearchResultDisplayRow.setItemCallNumber(oleItemSearchResultDisplayRow.getCallNumber());
363                         }
364                     } else if (bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().size() > 1) {
365                         bibSearchResultDisplayRow.setHoldingsLocation(OLEConstants.MULTIPLE);
366                         bibSearchResultDisplayRow.setItemLocation(OLEConstants.MULTIPLE);
367                         bibSearchResultDisplayRow.setItemType(OLEConstants.MULTIPLE);
368                         bibSearchResultDisplayRow.setItemStatus(OLEConstants.MULTIPLE);
369                         bibSearchResultDisplayRow.setItemCallNumber(OLEConstants.MULTIPLE);
370                     }
371                     for (OLEHoldingsSearchResultDisplayRow holdingsSearchResultDisplayRow : bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList()) {
372                         if (holdingsSearchResultDisplayRow.getOleItemSearchResultDisplayRowList().size() == 1) {
373                             OLEItemSearchResultDisplayRow oleItemSearchResultDisplayRow = holdingsSearchResultDisplayRow.getOleItemSearchResultDisplayRowList().get(0);
374                             holdingsSearchResultDisplayRow.setItemLocation(oleItemSearchResultDisplayRow.getLocation());
375                         } else if (holdingsSearchResultDisplayRow.getOleItemSearchResultDisplayRowList().size() > 1) {
376                             holdingsSearchResultDisplayRow.setItemLocation(OLEConstants.MULTIPLE);
377                         }
378                     }
379                     bibSearchResultDisplayRowList.add(bibSearchResultDisplayRow);
380                 }
381                 oleDeliverItemSearchForm.setOleBibSearchResultDisplayRowList(bibSearchResultDisplayRowList);
382             } else if (searchResponse.getSearchResults().size() == 1) {
383                 Map itemIdMap = new HashMap();
384                 itemIdMap.put(OLEConstants.ITEM_UUID, singleItemResultDisplayRow.getId());
385                 if (singleItemResultDisplayRow.getItemStatusDate() != null) {
386                     String[] itemStatusEffectiveDate = singleItemResultDisplayRow.getItemStatusDate().split(" ");
387                     singleItemResultDisplayRow.setItemStatusDate(itemStatusEffectiveDate[0]);
388                 }
389                 //borrower
390                 getOleDeliverItemSearchService().setBorrowerInfo(singleItemResultDisplayRow);
391                 //request
392                 getOleDeliverItemSearchService().setDeliverRequestInfo(itemIdMap, singleItemResultDisplayRow);
393                 //outstanding fine
394                 getOleDeliverItemSearchService().setOutstandingFineInfo(itemIdMap, singleItemResultDisplayRow);
395                 //notes
396                 getOleDeliverItemSearchService().setNoteInfo(singleItemResultDisplayRow);
397                 //additional copies
398                 getOleDeliverItemSearchService().setAdditionalCopiesInfo(singleItemResultDisplayRow);
399                 //item history
400                 getOleDeliverItemSearchService().setInTransitHistoryInfo(singleItemResultDisplayRow);
401                 getOleDeliverItemSearchService().setMissingPieceItemInfo(singleItemResultDisplayRow);
402                 getOleDeliverItemSearchService().setClaimsReturnedInfo(singleItemResultDisplayRow);
403                 getOleDeliverItemSearchService().setDamagedInfo(singleItemResultDisplayRow);
404                 getOleDeliverItemSearchService().setRequestHistoryInfo(singleItemResultDisplayRow);
405                 oleDeliverItemSearchForm.setOleSingleItemResultDisplayRow(singleItemResultDisplayRow);
406                 oleDeliverItemSearchForm.setSingleItemFlag(true);
407             }
408         } else {
409             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
410         }
411     }
412 
413     @RequestMapping(params = "methodToCall=clearSearch")
414     public ModelAndView clearSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
415                                     HttpServletRequest request, HttpServletResponse response) {
416         OLEDeliverItemSearchForm oleDeliverItemSearchForm = (OLEDeliverItemSearchForm) form;
417         oleDeliverItemSearchForm.setTitle(null);
418         oleDeliverItemSearchForm.setAuthor(null);
419         oleDeliverItemSearchForm.setPublisher(null);
420         oleDeliverItemSearchForm.setItemBarCode(null);
421         oleDeliverItemSearchForm.setItemCallNumber(null);
422         oleDeliverItemSearchForm.setItemUUID(null);
423         oleDeliverItemSearchForm.setItemType(null);
424         oleDeliverItemSearchForm.setItemLocation(null);
425         oleDeliverItemSearchForm.setOleBibSearchResultDisplayRowList(new ArrayList<OLEBibSearchResultDisplayRow>());
426         oleDeliverItemSearchForm.setSingleItemFlag(false);
427         oleDeliverItemSearchForm.setMultipleItemFlag(false);
428         oleDeliverItemSearchForm.setOleSingleItemResultDisplayRow(new OLESingleItemResultDisplayRow());
429         return getUIFModelAndView(oleDeliverItemSearchForm);
430     }
431 
432 
433     @RequestMapping(params = "methodToCall=pageNumberSearch")
434     public ModelAndView pageNumberSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
435                                          HttpServletRequest request, HttpServletResponse response) throws Exception {
436 
437         OLEDeliverItemSearchForm oleDeliverItemSearchForm  = (OLEDeliverItemSearchForm) form;
438         SearchParams searchParams = oleDeliverItemSearchForm.getSearchParams();
439         try {
440             int start = Math.max(0,
441                     (Integer.parseInt(oleDeliverItemSearchForm.getPageNumber()) - 1)
442                             * searchParams.getPageSize());
443             oleDeliverItemSearchForm.setStart(start);
444         } catch (NumberFormatException e) {
445             LOG.warn("Invalid page number " + oleDeliverItemSearchForm.getPageNumber(), e);
446         }
447         return search(oleDeliverItemSearchForm, result, request, response);
448     }
449 
450     @RequestMapping(params = "methodToCall=lastPageSearch")
451     public ModelAndView lastPageSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
452                                        HttpServletRequest request, HttpServletResponse response) throws Exception {
453 
454         OLEDeliverItemSearchForm oleDeliverItemSearchForm = (OLEDeliverItemSearchForm) form;
455         SearchParams searchParams = oleDeliverItemSearchForm.getSearchParams();
456         try {
457             int totalcount = oleDeliverItemSearchForm.getTotalRecordCount();
458             int pageSize = searchParams.getPageSize();
459             int totlaPages = totalcount/pageSize;
460             int lastNumber= pageSize*totlaPages;
461             int lastPage = totalcount - pageSize;
462             oleDeliverItemSearchForm.setPageNumber(Integer.toString(totlaPages));
463             if(lastNumber < totalcount){
464                 lastPage = lastNumber;
465                 oleDeliverItemSearchForm.setPageNumber(Integer.toString(totlaPages+1));
466             }
467             int start = Math.max(0, lastPage);
468             oleDeliverItemSearchForm.setStart(start);
469         } catch (NumberFormatException e) {
470             LOG.warn("Invalid page number " + oleDeliverItemSearchForm.getPageNumber(), e);
471         }
472         return search(oleDeliverItemSearchForm, result, request, response);
473     }
474 
475     @RequestMapping(params = "methodToCall=nextSearch")
476     public ModelAndView nextSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
477                                    HttpServletRequest request, HttpServletResponse response) throws Exception {
478 
479         OLEDeliverItemSearchForm oleDeliverItemSearchForm = (OLEDeliverItemSearchForm) form;
480         SearchParams searchParams = oleDeliverItemSearchForm.getSearchParams();
481         int start = Math.max(0, searchParams.getStartIndex() + searchParams.getPageSize());
482         oleDeliverItemSearchForm.setStart(start);
483         return search(oleDeliverItemSearchForm, result, request, response);
484     }
485 
486     @RequestMapping(params = "methodToCall=previousSearch")
487     public ModelAndView previousSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
488                                        HttpServletRequest request, HttpServletResponse response) throws Exception {
489 
490         OLEDeliverItemSearchForm oleDeliverItemSearchForm = (OLEDeliverItemSearchForm) form;
491         SearchParams searchParams = oleDeliverItemSearchForm.getSearchParams();
492         int start = Math.max(0, searchParams.getStartIndex() - oleDeliverItemSearchForm.getPageSize());
493         oleDeliverItemSearchForm.setStart(start);
494         return search(oleDeliverItemSearchForm, result, request, response);
495     }
496 
497 
498 
499 
500 }