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.document.*;
12  import org.kuali.ole.docstore.common.document.content.enums.DocType;
13  import org.kuali.ole.docstore.common.search.*;
14  import org.kuali.ole.docstore.engine.service.index.solr.BibConstants;
15  import org.kuali.ole.docstore.engine.service.index.solr.ItemConstants;
16  import org.kuali.ole.sys.context.SpringContext;
17  import org.kuali.rice.core.api.config.property.ConfigContext;
18  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
19  import org.kuali.rice.krad.service.KRADServiceLocator;
20  import org.kuali.rice.krad.util.GlobalVariables;
21  import org.kuali.rice.krad.util.KRADConstants;
22  import org.kuali.rice.krad.web.controller.UifControllerBase;
23  import org.kuali.rice.krad.web.form.UifFormBase;
24  import org.springframework.stereotype.Controller;
25  import org.springframework.validation.BindingResult;
26  import org.springframework.web.bind.annotation.ModelAttribute;
27  import org.springframework.web.bind.annotation.RequestMapping;
28  import org.springframework.web.servlet.ModelAndView;
29  
30  import javax.servlet.http.HttpServletRequest;
31  import javax.servlet.http.HttpServletResponse;
32  import java.util.*;
33  
34  /**
35   * Created by chenchulakshmig on 1/12/15.
36   */
37  @Controller
38  @RequestMapping(value = "/deliverItemSearchController")
39  public class OLEDeliverItemSearchController extends UifControllerBase {
40  
41      String baseUrl = ConfigContext.getCurrentContextConfig().getProperty(OLEPropertyConstants.OLE_URL_BASE);
42  
43      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OLEDeliverItemSearchController.class);
44      private DocstoreClientLocator docstoreClientLocator;
45      private OLEDeliverItemSearchService oleDeliverItemSearchService;
46  
47      public DocstoreClientLocator getDocstoreClientLocator() {
48          if (docstoreClientLocator == null) {
49              docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
50          }
51          return docstoreClientLocator;
52      }
53  
54      public OLEDeliverItemSearchService getOleDeliverItemSearchService() {
55          if (oleDeliverItemSearchService == null) {
56              oleDeliverItemSearchService = GlobalResourceLoader.getService(OLEConstants.DELIVER_ITEM__SEARCH_SERVICE);
57          }
58          return oleDeliverItemSearchService;
59      }
60  
61      @Override
62      protected UifFormBase createInitialForm(HttpServletRequest request) {
63          return new OLEDeliverItemSearchForm();
64      }
65  
66      @RequestMapping(params = "methodToCall=search")
67      public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
68                                 HttpServletRequest request, HttpServletResponse response) {
69          OLEDeliverItemSearchForm oleDeliverItemSearchForm = (OLEDeliverItemSearchForm) form;
70          oleDeliverItemSearchForm.setSingleItemFlag(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(), ItemConstants.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(), ItemConstants.LOCATION_LEVEL_SEARCH, itemLocation), OLEConstants.OR_SEARCH_SCOPE));
109                     searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.PHRASE, searchParams.buildSearchField(DocType.ITEM.getCode(),ItemConstants.HOLDINGS_LOCATION_SEARCH, itemLocation), OLEConstants.OR_SEARCH_SCOPE));
110                 }
111                 searchParams.setPageSize(100000);
112                 getSearchResultFields(searchParams);
113                 SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
114                 getSearchResults(searchResponse, oleDeliverItemSearchForm);
115                 if(oleDeliverItemSearchForm.getOleBibSearchResultDisplayRowList()!=null && oleDeliverItemSearchForm.getOleBibSearchResultDisplayRowList().size()>0){
116                     oleDeliverItemSearchForm.setMultipleItemFlag(true);
117                 }
118             } else {
119                 oleDeliverItemSearchForm.setSingleItemFlag(false);
120                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ITM_BLANK_SEARCH_ERROR_MSG);
121                 return getUIFModelAndView(oleDeliverItemSearchForm,"OLEDeliverItemSearchPage");
122             }
123         } catch (Exception e) {
124             LOG.error("Exception " + e);
125         }
126         return getUIFModelAndView(oleDeliverItemSearchForm);
127     }
128 
129     private void getSearchResultFields(SearchParams searchParams) {
130         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.BIB_IDENTIFIER));
131         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.TITLE_SORT));
132         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Bib.AUTHOR));
133         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Bib.PUBLISHER));
134         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.HOLDINGS_LOCATION_DISPLAY));
135         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.LOCATION_LEVEL_DISPLAY));
136         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Item.CALL_NUMBER));
137         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Item.ITEM_STATUS));
138         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.ITEM_TYPE_FULL_VALUE));
139         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.HOLDINGS_IDENTIFIER));
140         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.HOLDINGS_CALLNUMBER_DISPLAY));
141         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Item.ID));
142         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Item.ITEM_BARCODE));
143         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.ENUMERATION_DISPLAY));
144         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.CHRONOLOGY_DISPLAY));
145         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.ITEM_STATUS_EFFECTIVE_DATE));
146         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.DUE_DATE_TIME));
147         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.NUMBER_OF_PIECES_DISPLAY));
148         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.PUBLICATIONDATE_DISPLAY));
149         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.CURRENT_BORROWER));
150         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.PROXY_BORROWER));
151         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), "mdf_035a"));
152         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.ISBN_DISPLAY));
153         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.ITEMNOTE_VALUE_DISPLAY));
154         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.ITEMNOTE_TYPE_DISPLAY));
155         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.MISSING_PIECE_FLAG_DISPLAY));
156         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.MISSING_PIECE_COUNT_DISPLAY));
157         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.MISSING_PIECE_FLAG_NOTE_DISPLAY));
158         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.CLMS_RET_FLAG));
159         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.CLMS_RET_NOTE));
160         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.CLMS_RET_FLAG_CRE_DATE));
161         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.ITEM_DAMAGED_FLAG_DISPLAY));
162         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.DAMAGED_ITEM_NOTE_DISPLAY));
163         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.CREATED_BY));
164         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.DATE_ENTERED));
165         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.UPDATED_BY));
166         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.DATE_UPDATED));
167         buildSortCondition(searchParams);
168     }
169 
170     private void buildSortCondition(SearchParams searchParams) {
171         SortCondition sortCondition = new SortCondition();
172         sortCondition.setSortField(BibConstants.TITLE_SORT);
173         sortCondition.setSortOrder("asc");
174         searchParams.getSortConditions().add(sortCondition);
175     }
176 
177     private void getSearchResults(SearchResponse searchResponse, OLEDeliverItemSearchForm oleDeliverItemSearchForm) {
178         Map<String, OLEBibSearchResultDisplayRow> bibSearchResultDisplayRowMap = new TreeMap<>();
179         Map<String, OLEHoldingsSearchResultDisplayRow> holdingsSearchResultDisplayRowMap = new HashMap<>();
180         List<OLEBibSearchResultDisplayRow> bibSearchResultDisplayRowList = new ArrayList<>();
181         OLESingleItemResultDisplayRow singleItemResultDisplayRow = new OLESingleItemResultDisplayRow();
182         if (searchResponse != null && CollectionUtils.isNotEmpty(searchResponse.getSearchResults())) {
183             for (SearchResult searchResult : searchResponse.getSearchResults()) {
184                 if (CollectionUtils.isNotEmpty(searchResult.getSearchResultFields())) {
185                     OLEBibSearchResultDisplayRow bibSearchResultDisplayRow = new OLEBibSearchResultDisplayRow();
186                     OLEHoldingsSearchResultDisplayRow holdingsSearchResultDisplayRow = new OLEHoldingsSearchResultDisplayRow();
187                     singleItemResultDisplayRow = new OLESingleItemResultDisplayRow();
188                     OLEItemSearchResultDisplayRow itemSearchResultDisplayRow = new OLEItemSearchResultDisplayRow();
189                     for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
190                         if (searchResultField.getFieldName().equalsIgnoreCase(Bib.BIBIDENTIFIER)) {
191                             bibSearchResultDisplayRow.setId(searchResultField.getFieldValue());
192                             holdingsSearchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
193                             singleItemResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
194                             itemSearchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
195                         } else if (searchResultField.getFieldName().equalsIgnoreCase( BibConstants.TITLE_SORT)) {
196                             singleItemResultDisplayRow.setTitle(searchResultField.getFieldValue());
197                             bibSearchResultDisplayRow.setTitle(searchResultField.getFieldValue());
198                         } else if (searchResultField.getFieldName().equalsIgnoreCase(Bib.AUTHOR)) {
199                             singleItemResultDisplayRow.setAuthor(searchResultField.getFieldValue());
200                             bibSearchResultDisplayRow.setAuthor(searchResultField.getFieldValue());
201                         } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.HOLDINGS_LOCATION_DISPLAY)) {
202                             holdingsSearchResultDisplayRow.setLocation(searchResultField.getFieldValue());
203                             singleItemResultDisplayRow.setHoldingsLocation(searchResultField.getFieldValue());
204                         } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.LOCATION_LEVEL_DISPLAY)) {
205                             singleItemResultDisplayRow.setLocation(searchResultField.getFieldValue());
206                             itemSearchResultDisplayRow.setLocation(searchResultField.getFieldValue());
207                         } else if (searchResultField.getFieldName().equalsIgnoreCase(Item.CALL_NUMBER)) {
208                             singleItemResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
209                             itemSearchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
210                         } else if (searchResultField.getFieldName().equalsIgnoreCase(Item.ITEM_STATUS)) {
211                             singleItemResultDisplayRow.setItemStatus(searchResultField.getFieldValue());
212                             itemSearchResultDisplayRow.setItemStatus(searchResultField.getFieldValue());
213                         } else if (searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.ITEM_TYPE_FULL_VALUE)) {
214                             singleItemResultDisplayRow.setItemType(searchResultField.getFieldValue());
215                             itemSearchResultDisplayRow.setItemType(searchResultField.getFieldValue());
216                         } else if (searchResultField.getFieldName().equalsIgnoreCase(Holdings.HOLDINGSIDENTIFIER)) {
217                             holdingsSearchResultDisplayRow.setId(searchResultField.getFieldValue());
218                             singleItemResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
219                             itemSearchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
220                         } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.HOLDINGS_CALLNUMBER_DISPLAY)) {
221                             holdingsSearchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
222                             if(StringUtils.isEmpty(itemSearchResultDisplayRow.getCallNumber())){
223                                 singleItemResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
224                                 itemSearchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
225                             }
226                         } else if (searchResultField.getFieldName().equalsIgnoreCase(Item.ID)) {
227                             singleItemResultDisplayRow.setId(searchResultField.getFieldValue());
228                             itemSearchResultDisplayRow.setId(searchResultField.getFieldValue());
229                         } else if (searchResultField.getFieldName().equalsIgnoreCase(Item.ITEM_BARCODE)) {
230                             singleItemResultDisplayRow.setItemBarCode(searchResultField.getFieldValue());
231                             itemSearchResultDisplayRow.setItemBarCode(searchResultField.getFieldValue());
232                         } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.ENUMERATION_DISPLAY)) {
233                             singleItemResultDisplayRow.setEnumeration(searchResultField.getFieldValue());
234                             itemSearchResultDisplayRow.setEnumeration(searchResultField.getFieldValue());
235                         } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.CHRONOLOGY_DISPLAY)) {
236                             singleItemResultDisplayRow.setChronology(searchResultField.getFieldValue());
237                             itemSearchResultDisplayRow.setChronology(searchResultField.getFieldValue());
238                         } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.ITEM_STATUS_EFFECTIVE_DATE)) {
239                             singleItemResultDisplayRow.setItemStatusDate(searchResultField.getFieldValue());
240                         } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.DUE_DATE_TIME)) {
241                             singleItemResultDisplayRow.setDueDate(searchResultField.getFieldValue());
242                         } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.NUMBER_OF_PIECES_DISPLAY)) {
243                             singleItemResultDisplayRow.setNoOfPieces(searchResultField.getFieldValue());
244                         } else if (searchResultField.getFieldName().equalsIgnoreCase(Bib.PUBLISHER)) {
245                             singleItemResultDisplayRow.setPublication(searchResultField.getFieldValue());
246                         } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.PUBLICATIONDATE_DISPLAY)) {
247                             bibSearchResultDisplayRow.setPublicationYear(searchResultField.getFieldValue());
248                         }
249                         else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.CURRENT_BORROWER)) {
250                             singleItemResultDisplayRow.setCurrentBorrowerId(searchResultField.getFieldValue());
251                         } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.PROXY_BORROWER)) {
252                             singleItemResultDisplayRow.setProxyBorrowerId(searchResultField.getFieldValue());
253                         } else if (searchResultField.getFieldName().equalsIgnoreCase("mdf_035a")) {
254                             singleItemResultDisplayRow.setOclcNumber(searchResultField.getFieldValue());
255                         } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.ISBN_DISPLAY)) {
256                             singleItemResultDisplayRow.setIsbn(searchResultField.getFieldValue());
257                         } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.ITEMNOTE_VALUE_DISPLAY)) {
258                             singleItemResultDisplayRow.setItemNoteValue(searchResultField.getFieldValue());
259                         } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.ITEMNOTE_TYPE_DISPLAY)) {
260                             singleItemResultDisplayRow.setItemNoteType(searchResultField.getFieldValue());
261                         } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.MISSING_PIECE_FLAG_DISPLAY)) {
262                             singleItemResultDisplayRow.setMissingPieceFlag(searchResultField.getFieldValue());
263                         } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.MISSING_PIECE_COUNT_DISPLAY)) {
264                             singleItemResultDisplayRow.setMissingPieceCount(searchResultField.getFieldValue());
265                         } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.MISSING_PIECE_FLAG_NOTE_DISPLAY)) {
266                             singleItemResultDisplayRow.setMissingPieceNote(searchResultField.getFieldValue());
267                         } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.CLMS_RET_FLAG)) {
268                             singleItemResultDisplayRow.setClaimsReturnedFlag(searchResultField.getFieldValue());
269                         } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.CLMS_RET_NOTE)) {
270                             singleItemResultDisplayRow.setClaimsReturnedNote(searchResultField.getFieldValue());
271                         } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.CLMS_RET_FLAG_CRE_DATE)) {
272                             singleItemResultDisplayRow.setClaimsReturnedDate(searchResultField.getFieldValue());
273                         } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.ITEM_DAMAGED_FLAG_DISPLAY)) {
274                             singleItemResultDisplayRow.setItemDamagedStatusFlag(searchResultField.getFieldValue());
275                         } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.DAMAGED_ITEM_NOTE_DISPLAY)) {
276                             singleItemResultDisplayRow.setItemDamagedNote(searchResultField.getFieldValue());
277                         } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.CREATED_BY)) {
278                             singleItemResultDisplayRow.setCreatedBy(searchResultField.getFieldValue());
279                         } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.DATE_ENTERED)) {
280                             singleItemResultDisplayRow.setCreatedDate(searchResultField.getFieldValue());
281                         } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.UPDATED_BY)) {
282                             singleItemResultDisplayRow.setUpdatedBy(searchResultField.getFieldValue());
283                         } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.DATE_UPDATED)) {
284                             singleItemResultDisplayRow.setUpdatedDate(searchResultField.getFieldValue());
285                         }
286                     }
287                     if(StringUtils.isNotEmpty(singleItemResultDisplayRow.getPublication()) && StringUtils.isNotEmpty( bibSearchResultDisplayRow.getPublicationYear())){
288                         singleItemResultDisplayRow.setPublication(singleItemResultDisplayRow.getPublication()+" "+bibSearchResultDisplayRow.getPublicationYear());
289                     }else if(StringUtils.isEmpty(singleItemResultDisplayRow.getPublication())&& StringUtils.isNotEmpty( bibSearchResultDisplayRow.getPublicationYear())){
290                         singleItemResultDisplayRow.setPublication(bibSearchResultDisplayRow.getPublicationYear());
291                     }
292 
293                     if (searchResponse.getSearchResults().size() > 1) {
294                         Map itemMap = new HashMap();
295                         itemMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, itemSearchResultDisplayRow.getItemBarCode());
296                         List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) KRADServiceLocator.getBusinessObjectService().findMatching(OleDeliverRequestBo.class, itemMap);
297                         if (CollectionUtils.isNotEmpty(deliverRequestBos)) {
298                             itemSearchResultDisplayRow.setRequestExists(true);
299                         }
300                         if (!holdingsSearchResultDisplayRowMap.containsKey(holdingsSearchResultDisplayRow.getId())) {
301                             List<OLEItemSearchResultDisplayRow> itemSearchResultDisplayRowList = new ArrayList<>();
302                             itemSearchResultDisplayRowList.add(itemSearchResultDisplayRow);
303                             holdingsSearchResultDisplayRow.setOleItemSearchResultDisplayRowList(itemSearchResultDisplayRowList);
304                             holdingsSearchResultDisplayRowMap.put(holdingsSearchResultDisplayRow.getId(), holdingsSearchResultDisplayRow);
305                         } else {
306                             holdingsSearchResultDisplayRowMap.get(holdingsSearchResultDisplayRow.getId()).getOleItemSearchResultDisplayRowList().add(itemSearchResultDisplayRow);
307                         }
308                         if (!bibSearchResultDisplayRowMap.containsKey(bibSearchResultDisplayRow.getId())) {
309                             List<OLEHoldingsSearchResultDisplayRow> holdingsSearchResultDisplayRowList = new ArrayList<>();
310                             holdingsSearchResultDisplayRowList.add(holdingsSearchResultDisplayRow);
311                             bibSearchResultDisplayRow.setOleHoldingsSearchResultDisplayRowList(holdingsSearchResultDisplayRowList);
312                             bibSearchResultDisplayRowMap.put(bibSearchResultDisplayRow.getId(), bibSearchResultDisplayRow);
313                         } else {
314                             boolean flag = false;
315                             for (OLEHoldingsSearchResultDisplayRow oleHoldingsSearchResultDisplayRow : bibSearchResultDisplayRowMap.get(bibSearchResultDisplayRow.getId()).getOleHoldingsSearchResultDisplayRowList()) {
316                                 if (oleHoldingsSearchResultDisplayRow.getId().equals(holdingsSearchResultDisplayRow.getId())) {
317                                     flag = true;
318                                     break;
319                                 }
320                             }
321                             if (!flag) {
322                                 bibSearchResultDisplayRowMap.get(bibSearchResultDisplayRow.getId()).getOleHoldingsSearchResultDisplayRowList().add(holdingsSearchResultDisplayRow);
323                             }
324                         }
325                     }
326                 }
327             }
328             if (searchResponse.getSearchResults().size() > 1) {
329                 for (OLEBibSearchResultDisplayRow bibSearchResultDisplayRow : bibSearchResultDisplayRowMap.values()) {
330                     if (bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().size() == 1) {
331                         bibSearchResultDisplayRow.setHoldingsLocation(bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().get(0).getLocation());
332                         if (bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().get(0).getOleItemSearchResultDisplayRowList().size() > 1) {
333                             bibSearchResultDisplayRow.setItemLocation(OLEConstants.MULTIPLE);
334                             bibSearchResultDisplayRow.setItemType(OLEConstants.MULTIPLE);
335                             bibSearchResultDisplayRow.setItemStatus(OLEConstants.MULTIPLE);
336                             bibSearchResultDisplayRow.setItemCallNumber(OLEConstants.MULTIPLE);
337                         } else if (bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().get(0).getOleItemSearchResultDisplayRowList().size() == 1) {
338                             OLEItemSearchResultDisplayRow oleItemSearchResultDisplayRow = bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().get(0).getOleItemSearchResultDisplayRowList().get(0);
339                             bibSearchResultDisplayRow.setItemLocation(oleItemSearchResultDisplayRow.getLocation());
340                             bibSearchResultDisplayRow.setItemType(oleItemSearchResultDisplayRow.getItemType());
341                             bibSearchResultDisplayRow.setItemStatus(oleItemSearchResultDisplayRow.getItemStatus());
342                             bibSearchResultDisplayRow.setItemCallNumber(oleItemSearchResultDisplayRow.getCallNumber());
343                         }
344                     } else if (bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().size() > 1) {
345                         bibSearchResultDisplayRow.setHoldingsLocation(OLEConstants.MULTIPLE);
346                         bibSearchResultDisplayRow.setItemLocation(OLEConstants.MULTIPLE);
347                         bibSearchResultDisplayRow.setItemType(OLEConstants.MULTIPLE);
348                         bibSearchResultDisplayRow.setItemStatus(OLEConstants.MULTIPLE);
349                         bibSearchResultDisplayRow.setItemCallNumber(OLEConstants.MULTIPLE);
350                     }
351                     for (OLEHoldingsSearchResultDisplayRow holdingsSearchResultDisplayRow : bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList()) {
352                         if (holdingsSearchResultDisplayRow.getOleItemSearchResultDisplayRowList().size() == 1) {
353                             OLEItemSearchResultDisplayRow oleItemSearchResultDisplayRow = holdingsSearchResultDisplayRow.getOleItemSearchResultDisplayRowList().get(0);
354                             holdingsSearchResultDisplayRow.setItemLocation(oleItemSearchResultDisplayRow.getLocation());
355                         } else if (holdingsSearchResultDisplayRow.getOleItemSearchResultDisplayRowList().size() > 1) {
356                             holdingsSearchResultDisplayRow.setItemLocation(OLEConstants.MULTIPLE);
357                         }
358                     }
359                     bibSearchResultDisplayRowList.add(bibSearchResultDisplayRow);
360                 }
361                 oleDeliverItemSearchForm.setOleBibSearchResultDisplayRowList(bibSearchResultDisplayRowList);
362             } else if (searchResponse.getSearchResults().size() == 1) {
363                 Map itemIdMap = new HashMap();
364                 itemIdMap.put(OLEConstants.ITEM_UUID, singleItemResultDisplayRow.getId());
365                 if (singleItemResultDisplayRow.getItemStatusDate() != null) {
366                     String[] itemStatusEffectiveDate = singleItemResultDisplayRow.getItemStatusDate().split(" ");
367                     singleItemResultDisplayRow.setItemStatusDate(itemStatusEffectiveDate[0]);
368                 }
369                 //borrower
370                 getOleDeliverItemSearchService().setBorrowerInfo(singleItemResultDisplayRow);
371                 //request
372                 getOleDeliverItemSearchService().setDeliverRequestInfo(itemIdMap, singleItemResultDisplayRow);
373                 //outstanding fine
374                 getOleDeliverItemSearchService().setOutstandingFineInfo(itemIdMap, singleItemResultDisplayRow);
375                 //notes
376                 getOleDeliverItemSearchService().setNoteInfo(singleItemResultDisplayRow);
377                 //additional copies
378                 getOleDeliverItemSearchService().setAdditionalCopiesInfo(singleItemResultDisplayRow);
379                 //item history
380                 getOleDeliverItemSearchService().setInTransitHistoryInfo(singleItemResultDisplayRow);
381                 getOleDeliverItemSearchService().setMissingPieceItemInfo(singleItemResultDisplayRow);
382                 getOleDeliverItemSearchService().setClaimsReturnedInfo(singleItemResultDisplayRow);
383                 getOleDeliverItemSearchService().setDamagedInfo(singleItemResultDisplayRow);
384                 getOleDeliverItemSearchService().setRequestHistoryInfo(singleItemResultDisplayRow);
385                 oleDeliverItemSearchForm.setOleSingleItemResultDisplayRow(singleItemResultDisplayRow);
386                 oleDeliverItemSearchForm.setSingleItemFlag(true);
387             }
388         } else {
389             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
390         }
391     }
392 
393     @RequestMapping(params = "methodToCall=clearSearch")
394     public ModelAndView clearSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
395                                     HttpServletRequest request, HttpServletResponse response) {
396         OLEDeliverItemSearchForm oleDeliverItemSearchForm = (OLEDeliverItemSearchForm) form;
397         oleDeliverItemSearchForm.setTitle(null);
398         oleDeliverItemSearchForm.setAuthor(null);
399         oleDeliverItemSearchForm.setPublisher(null);
400         oleDeliverItemSearchForm.setItemBarCode(null);
401         oleDeliverItemSearchForm.setItemCallNumber(null);
402         oleDeliverItemSearchForm.setItemUUID(null);
403         oleDeliverItemSearchForm.setItemType(null);
404         oleDeliverItemSearchForm.setItemLocation(null);
405         oleDeliverItemSearchForm.setOleBibSearchResultDisplayRowList(new ArrayList<OLEBibSearchResultDisplayRow>());
406         oleDeliverItemSearchForm.setSingleItemFlag(false);
407         oleDeliverItemSearchForm.setOleSingleItemResultDisplayRow(new OLESingleItemResultDisplayRow());
408         return getUIFModelAndView(oleDeliverItemSearchForm);
409     }
410 
411 
412 }