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
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.setMultipleItemFlag(false);
72 oleDeliverItemSearchForm.setOleBibSearchResultDisplayRowList(new ArrayList<OLEBibSearchResultDisplayRow>());
73 oleDeliverItemSearchForm.setOleSingleItemResultDisplayRow(new OLESingleItemResultDisplayRow());
74 try {
75 String title = oleDeliverItemSearchForm.getTitle();
76 String author = oleDeliverItemSearchForm.getAuthor();
77 String publisher = oleDeliverItemSearchForm.getPublisher();
78 String itemBarcode = oleDeliverItemSearchForm.getItemBarCode();
79 String callNumber = oleDeliverItemSearchForm.getItemCallNumber();
80 String itemUUID = oleDeliverItemSearchForm.getItemUUID();
81 String itemType = oleDeliverItemSearchForm.getItemType();
82 String itemLocation = oleDeliverItemSearchForm.getItemLocation();
83 SearchParams searchParams = new SearchParams();
84 if (StringUtils.isNotBlank(title) || StringUtils.isNotBlank(author) || StringUtils.isNotBlank(publisher) || StringUtils.isNotBlank(itemBarcode)
85 || StringUtils.isNotBlank(callNumber) || StringUtils.isNotBlank(itemUUID) || StringUtils.isNotBlank(itemType) || StringUtils.isNotBlank(itemLocation)) {
86 if (StringUtils.isNotBlank(title)) {
87 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Bib.TITLE, title), OLEConstants.AND_SEARCH_SCOPE));
88 }
89 if (StringUtils.isNotBlank(author)) {
90 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Bib.AUTHOR, author), OLEConstants.AND_SEARCH_SCOPE));
91 }
92 if (StringUtils.isNotBlank(publisher)) {
93 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Bib.PUBLISHER, publisher), OLEConstants.AND_SEARCH_SCOPE));
94 }
95 if (StringUtils.isNotBlank(itemBarcode)) {
96 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Item.ITEM_BARCODE, itemBarcode), OLEConstants.AND_SEARCH_SCOPE));
97 }
98 if (StringUtils.isNotBlank(callNumber)) {
99 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Item.CALL_NUMBER, callNumber),OLEConstants.OR_SEARCH_SCOPE));
100 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), ItemConstants.HOLDINGS_CALLNUMBER_SEARCH, callNumber), OLEConstants.AND_SEARCH_SCOPE));
101 }
102 if (StringUtils.isNotBlank(itemUUID)) {
103 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Item.ITEMIDENTIFIER, itemUUID), OLEConstants.AND_SEARCH_SCOPE));
104 }
105 if (StringUtils.isNotBlank(itemType)) {
106 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.AND_SEARCH_SCOPE, searchParams.buildSearchField(DocType.ITEM.getCode(), Item.ITEM_TYPE, itemType), OLEConstants.AND_SEARCH_SCOPE));
107 }
108 if (StringUtils.isNotBlank(itemLocation)) {
109 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.PHRASE, searchParams.buildSearchField(DocType.ITEM.getCode(), ItemConstants.LOCATION_LEVEL_SEARCH, itemLocation), OLEConstants.OR_SEARCH_SCOPE));
110 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.PHRASE, searchParams.buildSearchField(DocType.ITEM.getCode(),ItemConstants.HOLDINGS_LOCATION_SEARCH, itemLocation), OLEConstants.OR_SEARCH_SCOPE));
111 }
112 searchParams.setPageSize(oleDeliverItemSearchForm.getPageSize());
113 searchParams.setStartIndex(oleDeliverItemSearchForm.getStart());
114 oleDeliverItemSearchForm.setSearchParams(searchParams);
115 buildSortCondition(oleDeliverItemSearchForm);
116 getSearchResultFields(searchParams);
117 SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
118 oleDeliverItemSearchForm.setTotalRecordCount(searchResponse.getTotalRecordCount());
119 getSearchResults(searchResponse, oleDeliverItemSearchForm);
120 if(oleDeliverItemSearchForm.getOleBibSearchResultDisplayRowList()!=null && oleDeliverItemSearchForm.getOleBibSearchResultDisplayRowList().size()>0){
121 oleDeliverItemSearchForm.setMultipleItemFlag(true);
122 }
123 } else {
124 oleDeliverItemSearchForm.setSingleItemFlag(false);
125 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ITM_BLANK_SEARCH_ERROR_MSG);
126 return getUIFModelAndView(oleDeliverItemSearchForm,"OLEDeliverItemSearchPage");
127 }
128 } catch (Exception e) {
129 LOG.error("Exception " + e);
130 }
131 return getUIFModelAndView(oleDeliverItemSearchForm);
132 }
133
134 private void getSearchResultFields(SearchParams searchParams) {
135 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.BIB_IDENTIFIER));
136 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.TITLE_SORT));
137 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Bib.AUTHOR));
138 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), Bib.PUBLISHER));
139 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.HOLDINGS_LOCATION_DISPLAY));
140 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.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(), ItemConstants.HOLDINGS_IDENTIFIER));
145 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.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(), ItemConstants.ENUMERATION_DISPLAY));
149 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.CHRONOLOGY_DISPLAY));
150 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.ITEM_STATUS_EFFECTIVE_DATE));
151 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.DUE_DATE_TIME));
152 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.NUMBER_OF_PIECES_DISPLAY));
153 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.PUBLICATIONDATE_DISPLAY));
154 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.CURRENT_BORROWER));
155 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.PROXY_BORROWER));
156 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.MDF_035A));
157 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.ISBN_DISPLAY));
158 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.ITEMNOTE_VALUE_DISPLAY));
159 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.ITEMNOTE_TYPE_DISPLAY));
160 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.MISSING_PIECE_FLAG_DISPLAY));
161 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.MISSING_PIECE_COUNT_DISPLAY));
162 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.MISSING_PIECE_FLAG_NOTE_DISPLAY));
163 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.CLMS_RET_FLAG));
164 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.CLMS_RET_NOTE));
165 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.CLMS_RET_FLAG_CRE_DATE));
166 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.ITEM_DAMAGED_FLAG_DISPLAY));
167 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), ItemConstants.DAMAGED_ITEM_NOTE_DISPLAY));
168 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.CREATED_BY));
169 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.DATE_ENTERED));
170 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.UPDATED_BY));
171 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), BibConstants.DATE_UPDATED));
172 }
173
174 private void buildSortCondition(OLEDeliverItemSearchForm oleDeliverItemSearchForm) {
175 SearchParams searchParams = oleDeliverItemSearchForm.getSearchParams();
176 SortCondition sortCondition = new SortCondition();
177 if(org.apache.commons.lang.StringUtils.isEmpty(oleDeliverItemSearchForm.getSortField())){
178 oleDeliverItemSearchForm.setSortField(BibConstants.TITLE_SORT);
179 oleDeliverItemSearchForm.setSortOrder("asc");
180 }
181 sortCondition.setSortField(oleDeliverItemSearchForm.getSortField());
182 sortCondition.setSortOrder(oleDeliverItemSearchForm.getSortOrder());
183 searchParams.getSortConditions().add(sortCondition);
184 }
185
186 private void getSearchResults(SearchResponse searchResponse, OLEDeliverItemSearchForm oleDeliverItemSearchForm) {
187 Map<String, OLEBibSearchResultDisplayRow> bibSearchResultDisplayRowMap = new TreeMap<>();
188 Map<String, OLEHoldingsSearchResultDisplayRow> holdingsSearchResultDisplayRowMap = new HashMap<>();
189 List<OLEBibSearchResultDisplayRow> bibSearchResultDisplayRowList = new ArrayList<>();
190 OLESingleItemResultDisplayRow singleItemResultDisplayRow = new OLESingleItemResultDisplayRow();
191 if (searchResponse != null && CollectionUtils.isNotEmpty(searchResponse.getSearchResults())) {
192 for (SearchResult searchResult : searchResponse.getSearchResults()) {
193 if (CollectionUtils.isNotEmpty(searchResult.getSearchResultFields())) {
194 OLEBibSearchResultDisplayRow bibSearchResultDisplayRow = new OLEBibSearchResultDisplayRow();
195 OLEHoldingsSearchResultDisplayRow holdingsSearchResultDisplayRow = new OLEHoldingsSearchResultDisplayRow();
196 singleItemResultDisplayRow = new OLESingleItemResultDisplayRow();
197 OLEItemSearchResultDisplayRow itemSearchResultDisplayRow = new OLEItemSearchResultDisplayRow();
198 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
199 if (searchResultField.getFieldName().equalsIgnoreCase(Bib.BIBIDENTIFIER)) {
200 bibSearchResultDisplayRow.setId(searchResultField.getFieldValue());
201 holdingsSearchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
202 singleItemResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
203 itemSearchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
204 } else if (searchResultField.getFieldName().equalsIgnoreCase( BibConstants.TITLE_SORT)) {
205 singleItemResultDisplayRow.setTitle(searchResultField.getFieldValue());
206 bibSearchResultDisplayRow.setTitle(searchResultField.getFieldValue());
207 } else if (searchResultField.getFieldName().equalsIgnoreCase(Bib.AUTHOR)) {
208 singleItemResultDisplayRow.setAuthor(searchResultField.getFieldValue());
209 bibSearchResultDisplayRow.setAuthor(searchResultField.getFieldValue());
210 } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.HOLDINGS_LOCATION_DISPLAY)) {
211 holdingsSearchResultDisplayRow.setLocation(searchResultField.getFieldValue());
212 singleItemResultDisplayRow.setHoldingsLocation(searchResultField.getFieldValue());
213 } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.LOCATION_LEVEL_DISPLAY)) {
214 singleItemResultDisplayRow.setLocation(searchResultField.getFieldValue());
215 itemSearchResultDisplayRow.setLocation(searchResultField.getFieldValue());
216 } else if (searchResultField.getFieldName().equalsIgnoreCase(Item.CALL_NUMBER)) {
217 singleItemResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
218 itemSearchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
219 } else if (searchResultField.getFieldName().equalsIgnoreCase(Item.ITEM_STATUS)) {
220 singleItemResultDisplayRow.setItemStatus(searchResultField.getFieldValue());
221 itemSearchResultDisplayRow.setItemStatus(searchResultField.getFieldValue());
222 } else if (searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.ITEM_TYPE_FULL_VALUE)) {
223 singleItemResultDisplayRow.setItemType(searchResultField.getFieldValue());
224 itemSearchResultDisplayRow.setItemType(searchResultField.getFieldValue());
225 } else if (searchResultField.getFieldName().equalsIgnoreCase(Holdings.HOLDINGSIDENTIFIER)) {
226 holdingsSearchResultDisplayRow.setId(searchResultField.getFieldValue());
227 singleItemResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
228 itemSearchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
229 } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.HOLDINGS_CALLNUMBER_DISPLAY)) {
230 holdingsSearchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
231 if(StringUtils.isEmpty(itemSearchResultDisplayRow.getCallNumber())){
232 singleItemResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
233 itemSearchResultDisplayRow.setCallNumber(searchResultField.getFieldValue());
234 }
235 } else if (searchResultField.getFieldName().equalsIgnoreCase(Item.ID)) {
236 singleItemResultDisplayRow.setId(searchResultField.getFieldValue());
237 itemSearchResultDisplayRow.setId(searchResultField.getFieldValue());
238 } else if (searchResultField.getFieldName().equalsIgnoreCase(Item.ITEM_BARCODE)) {
239 singleItemResultDisplayRow.setItemBarCode(searchResultField.getFieldValue());
240 itemSearchResultDisplayRow.setItemBarCode(searchResultField.getFieldValue());
241 } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.ENUMERATION_DISPLAY)) {
242 singleItemResultDisplayRow.setEnumeration(searchResultField.getFieldValue());
243 itemSearchResultDisplayRow.setEnumeration(searchResultField.getFieldValue());
244 } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.CHRONOLOGY_DISPLAY)) {
245 singleItemResultDisplayRow.setChronology(searchResultField.getFieldValue());
246 itemSearchResultDisplayRow.setChronology(searchResultField.getFieldValue());
247 } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.ITEM_STATUS_EFFECTIVE_DATE)) {
248 singleItemResultDisplayRow.setItemStatusDate(searchResultField.getFieldValue());
249 } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.DUE_DATE_TIME)) {
250 singleItemResultDisplayRow.setDueDate(searchResultField.getFieldValue());
251 } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.NUMBER_OF_PIECES_DISPLAY)) {
252 singleItemResultDisplayRow.setNoOfPieces(searchResultField.getFieldValue());
253 } else if (searchResultField.getFieldName().equalsIgnoreCase(Bib.PUBLISHER)) {
254 singleItemResultDisplayRow.setPublication(searchResultField.getFieldValue());
255 } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.PUBLICATIONDATE_DISPLAY)) {
256 bibSearchResultDisplayRow.setPublicationYear(searchResultField.getFieldValue());
257 }
258 else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.CURRENT_BORROWER)) {
259 singleItemResultDisplayRow.setCurrentBorrowerId(searchResultField.getFieldValue());
260 } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.PROXY_BORROWER)) {
261 singleItemResultDisplayRow.setProxyBorrowerId(searchResultField.getFieldValue());
262 } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.MDF_035A)) {
263 singleItemResultDisplayRow.setOclcNumber(searchResultField.getFieldValue());
264 } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.ISBN_DISPLAY)) {
265 singleItemResultDisplayRow.setIsbn(searchResultField.getFieldValue());
266 } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.ITEMNOTE_VALUE_DISPLAY)) {
267 singleItemResultDisplayRow.setItemNoteValue(searchResultField.getFieldValue());
268 } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.ITEMNOTE_TYPE_DISPLAY)) {
269 singleItemResultDisplayRow.setItemNoteType(searchResultField.getFieldValue());
270 } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.MISSING_PIECE_FLAG_DISPLAY)) {
271 singleItemResultDisplayRow.setMissingPieceFlag(searchResultField.getFieldValue());
272 } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.MISSING_PIECE_COUNT_DISPLAY)) {
273 singleItemResultDisplayRow.setMissingPieceCount(searchResultField.getFieldValue());
274 } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.MISSING_PIECE_FLAG_NOTE_DISPLAY)) {
275 singleItemResultDisplayRow.setMissingPieceNote(searchResultField.getFieldValue());
276 } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.CLMS_RET_FLAG)) {
277 singleItemResultDisplayRow.setClaimsReturnedFlag(searchResultField.getFieldValue());
278 } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.CLMS_RET_NOTE)) {
279 singleItemResultDisplayRow.setClaimsReturnedNote(searchResultField.getFieldValue());
280 } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.CLMS_RET_FLAG_CRE_DATE)) {
281 singleItemResultDisplayRow.setClaimsReturnedDate(searchResultField.getFieldValue());
282 } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.ITEM_DAMAGED_FLAG_DISPLAY)) {
283 singleItemResultDisplayRow.setItemDamagedStatusFlag(searchResultField.getFieldValue());
284 } else if (searchResultField.getFieldName().equalsIgnoreCase(ItemConstants.DAMAGED_ITEM_NOTE_DISPLAY)) {
285 singleItemResultDisplayRow.setItemDamagedNote(searchResultField.getFieldValue());
286 } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.CREATED_BY)) {
287 singleItemResultDisplayRow.setCreatedBy(searchResultField.getFieldValue());
288 } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.DATE_ENTERED)) {
289 singleItemResultDisplayRow.setCreatedDate(searchResultField.getFieldValue());
290 } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.UPDATED_BY)) {
291 singleItemResultDisplayRow.setUpdatedBy(searchResultField.getFieldValue());
292 } else if (searchResultField.getFieldName().equalsIgnoreCase(BibConstants.DATE_UPDATED)) {
293 singleItemResultDisplayRow.setUpdatedDate(searchResultField.getFieldValue());
294 }
295 }
296 if(StringUtils.isNotEmpty(singleItemResultDisplayRow.getPublication()) && StringUtils.isNotEmpty( bibSearchResultDisplayRow.getPublicationYear())){
297 singleItemResultDisplayRow.setPublication(singleItemResultDisplayRow.getPublication()+" "+bibSearchResultDisplayRow.getPublicationYear());
298 }else if(StringUtils.isEmpty(singleItemResultDisplayRow.getPublication())&& StringUtils.isNotEmpty( bibSearchResultDisplayRow.getPublicationYear())){
299 singleItemResultDisplayRow.setPublication(bibSearchResultDisplayRow.getPublicationYear());
300 }
301
302 if (searchResponse.getSearchResults().size() > 1) {
303 Map itemMap = new HashMap();
304 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, itemSearchResultDisplayRow.getItemBarCode());
305 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) KRADServiceLocator.getBusinessObjectService().findMatching(OleDeliverRequestBo.class, itemMap);
306 if (CollectionUtils.isNotEmpty(deliverRequestBos)) {
307 itemSearchResultDisplayRow.setRequestExists(true);
308 }
309 if (!holdingsSearchResultDisplayRowMap.containsKey(holdingsSearchResultDisplayRow.getId())) {
310 List<OLEItemSearchResultDisplayRow> itemSearchResultDisplayRowList = new ArrayList<>();
311 itemSearchResultDisplayRowList.add(itemSearchResultDisplayRow);
312 holdingsSearchResultDisplayRow.setOleItemSearchResultDisplayRowList(itemSearchResultDisplayRowList);
313 holdingsSearchResultDisplayRowMap.put(holdingsSearchResultDisplayRow.getId(), holdingsSearchResultDisplayRow);
314 } else {
315 holdingsSearchResultDisplayRowMap.get(holdingsSearchResultDisplayRow.getId()).getOleItemSearchResultDisplayRowList().add(itemSearchResultDisplayRow);
316 }
317 if (!bibSearchResultDisplayRowMap.containsKey(bibSearchResultDisplayRow.getId())) {
318 List<OLEHoldingsSearchResultDisplayRow> holdingsSearchResultDisplayRowList = new ArrayList<>();
319 holdingsSearchResultDisplayRowList.add(holdingsSearchResultDisplayRow);
320 bibSearchResultDisplayRow.setOleHoldingsSearchResultDisplayRowList(holdingsSearchResultDisplayRowList);
321 bibSearchResultDisplayRowMap.put(bibSearchResultDisplayRow.getId(), bibSearchResultDisplayRow);
322 } else {
323 boolean flag = false;
324 for (OLEHoldingsSearchResultDisplayRow oleHoldingsSearchResultDisplayRow : bibSearchResultDisplayRowMap.get(bibSearchResultDisplayRow.getId()).getOleHoldingsSearchResultDisplayRowList()) {
325 if (oleHoldingsSearchResultDisplayRow.getId().equals(holdingsSearchResultDisplayRow.getId())) {
326 flag = true;
327 break;
328 }
329 }
330 if (!flag) {
331 bibSearchResultDisplayRowMap.get(bibSearchResultDisplayRow.getId()).getOleHoldingsSearchResultDisplayRowList().add(holdingsSearchResultDisplayRow);
332 }
333 }
334 }
335 }
336 }
337 if (searchResponse.getSearchResults().size() > 1) {
338 for (OLEBibSearchResultDisplayRow bibSearchResultDisplayRow : bibSearchResultDisplayRowMap.values()) {
339 if (bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().size() == 1) {
340 bibSearchResultDisplayRow.setHoldingsLocation(bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().get(0).getLocation());
341 if (bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().get(0).getOleItemSearchResultDisplayRowList().size() > 1) {
342 bibSearchResultDisplayRow.setItemLocation(OLEConstants.MULTIPLE);
343 bibSearchResultDisplayRow.setItemType(OLEConstants.MULTIPLE);
344 bibSearchResultDisplayRow.setItemStatus(OLEConstants.MULTIPLE);
345 bibSearchResultDisplayRow.setItemCallNumber(OLEConstants.MULTIPLE);
346 } else if (bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().get(0).getOleItemSearchResultDisplayRowList().size() == 1) {
347 OLEItemSearchResultDisplayRow oleItemSearchResultDisplayRow = bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().get(0).getOleItemSearchResultDisplayRowList().get(0);
348 bibSearchResultDisplayRow.setItemLocation(oleItemSearchResultDisplayRow.getLocation());
349 bibSearchResultDisplayRow.setItemType(oleItemSearchResultDisplayRow.getItemType());
350 bibSearchResultDisplayRow.setItemStatus(oleItemSearchResultDisplayRow.getItemStatus());
351 bibSearchResultDisplayRow.setItemCallNumber(oleItemSearchResultDisplayRow.getCallNumber());
352 }
353 } else if (bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList().size() > 1) {
354 bibSearchResultDisplayRow.setHoldingsLocation(OLEConstants.MULTIPLE);
355 bibSearchResultDisplayRow.setItemLocation(OLEConstants.MULTIPLE);
356 bibSearchResultDisplayRow.setItemType(OLEConstants.MULTIPLE);
357 bibSearchResultDisplayRow.setItemStatus(OLEConstants.MULTIPLE);
358 bibSearchResultDisplayRow.setItemCallNumber(OLEConstants.MULTIPLE);
359 }
360 for (OLEHoldingsSearchResultDisplayRow holdingsSearchResultDisplayRow : bibSearchResultDisplayRow.getOleHoldingsSearchResultDisplayRowList()) {
361 if (holdingsSearchResultDisplayRow.getOleItemSearchResultDisplayRowList().size() == 1) {
362 OLEItemSearchResultDisplayRow oleItemSearchResultDisplayRow = holdingsSearchResultDisplayRow.getOleItemSearchResultDisplayRowList().get(0);
363 holdingsSearchResultDisplayRow.setItemLocation(oleItemSearchResultDisplayRow.getLocation());
364 } else if (holdingsSearchResultDisplayRow.getOleItemSearchResultDisplayRowList().size() > 1) {
365 holdingsSearchResultDisplayRow.setItemLocation(OLEConstants.MULTIPLE);
366 }
367 }
368 bibSearchResultDisplayRowList.add(bibSearchResultDisplayRow);
369 }
370 oleDeliverItemSearchForm.setOleBibSearchResultDisplayRowList(bibSearchResultDisplayRowList);
371 } else if (searchResponse.getSearchResults().size() == 1) {
372 Map itemIdMap = new HashMap();
373 itemIdMap.put(OLEConstants.ITEM_UUID, singleItemResultDisplayRow.getId());
374 if (singleItemResultDisplayRow.getItemStatusDate() != null) {
375 String[] itemStatusEffectiveDate = singleItemResultDisplayRow.getItemStatusDate().split(" ");
376 singleItemResultDisplayRow.setItemStatusDate(itemStatusEffectiveDate[0]);
377 }
378
379 getOleDeliverItemSearchService().setBorrowerInfo(singleItemResultDisplayRow);
380
381 getOleDeliverItemSearchService().setDeliverRequestInfo(itemIdMap, singleItemResultDisplayRow);
382
383 getOleDeliverItemSearchService().setOutstandingFineInfo(itemIdMap, singleItemResultDisplayRow);
384
385 getOleDeliverItemSearchService().setNoteInfo(singleItemResultDisplayRow);
386
387 getOleDeliverItemSearchService().setAdditionalCopiesInfo(singleItemResultDisplayRow);
388
389 getOleDeliverItemSearchService().setInTransitHistoryInfo(singleItemResultDisplayRow);
390 getOleDeliverItemSearchService().setMissingPieceItemInfo(singleItemResultDisplayRow);
391 getOleDeliverItemSearchService().setClaimsReturnedInfo(singleItemResultDisplayRow);
392 getOleDeliverItemSearchService().setDamagedInfo(singleItemResultDisplayRow);
393 getOleDeliverItemSearchService().setRequestHistoryInfo(singleItemResultDisplayRow);
394 oleDeliverItemSearchForm.setOleSingleItemResultDisplayRow(singleItemResultDisplayRow);
395 oleDeliverItemSearchForm.setSingleItemFlag(true);
396 }
397 } else {
398 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
399 }
400 }
401
402 @RequestMapping(params = "methodToCall=clearSearch")
403 public ModelAndView clearSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
404 HttpServletRequest request, HttpServletResponse response) {
405 OLEDeliverItemSearchForm oleDeliverItemSearchForm = (OLEDeliverItemSearchForm) form;
406 oleDeliverItemSearchForm.setTitle(null);
407 oleDeliverItemSearchForm.setAuthor(null);
408 oleDeliverItemSearchForm.setPublisher(null);
409 oleDeliverItemSearchForm.setItemBarCode(null);
410 oleDeliverItemSearchForm.setItemCallNumber(null);
411 oleDeliverItemSearchForm.setItemUUID(null);
412 oleDeliverItemSearchForm.setItemType(null);
413 oleDeliverItemSearchForm.setItemLocation(null);
414 oleDeliverItemSearchForm.setOleBibSearchResultDisplayRowList(new ArrayList<OLEBibSearchResultDisplayRow>());
415 oleDeliverItemSearchForm.setSingleItemFlag(false);
416 oleDeliverItemSearchForm.setOleSingleItemResultDisplayRow(new OLESingleItemResultDisplayRow());
417 return getUIFModelAndView(oleDeliverItemSearchForm);
418 }
419 @RequestMapping(params = "methodToCall=pageNumberSearch")
420 public ModelAndView pageNumberSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
421 HttpServletRequest request, HttpServletResponse response) throws Exception {
422
423 OLEDeliverItemSearchForm oleDeliverItemSearchForm = (OLEDeliverItemSearchForm) form;
424 SearchParams searchParams = oleDeliverItemSearchForm.getSearchParams();
425 try {
426 int start = Math.max(0,
427 (Integer.parseInt(oleDeliverItemSearchForm.getPageNumber()) - 1)
428 * searchParams.getPageSize());
429 oleDeliverItemSearchForm.setStart(start);
430 } catch (NumberFormatException e) {
431 LOG.warn("Invalid page number " + oleDeliverItemSearchForm.getPageNumber(), e);
432 }
433 return search(oleDeliverItemSearchForm, result, request, response);
434 }
435
436 @RequestMapping(params = "methodToCall=lastPageSearch")
437 public ModelAndView lastPageSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
438 HttpServletRequest request, HttpServletResponse response) throws Exception {
439
440 OLEDeliverItemSearchForm oleDeliverItemSearchForm = (OLEDeliverItemSearchForm) form;
441 SearchParams searchParams = oleDeliverItemSearchForm.getSearchParams();
442 try {
443 int totalcount = oleDeliverItemSearchForm.getTotalRecordCount();
444 int pageSize = searchParams.getPageSize();
445 int totlaPages = totalcount/pageSize;
446 int lastNumber= pageSize*totlaPages;
447 int lastPage = totalcount - pageSize;
448 oleDeliverItemSearchForm.setPageNumber(Integer.toString(totlaPages));
449 if(lastNumber < totalcount){
450 lastPage = lastNumber;
451 oleDeliverItemSearchForm.setPageNumber(Integer.toString(totlaPages+1));
452 }
453 int start = Math.max(0, lastPage);
454 oleDeliverItemSearchForm.setStart(start);
455 } catch (NumberFormatException e) {
456 LOG.warn("Invalid page number " + oleDeliverItemSearchForm.getPageNumber(), e);
457 }
458 return search(oleDeliverItemSearchForm, result, request, response);
459 }
460
461 @RequestMapping(params = "methodToCall=nextSearch")
462 public ModelAndView nextSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
463 HttpServletRequest request, HttpServletResponse response) throws Exception {
464
465 OLEDeliverItemSearchForm oleDeliverItemSearchForm = (OLEDeliverItemSearchForm) form;
466 SearchParams searchParams = oleDeliverItemSearchForm.getSearchParams();
467 int start = Math.max(0, searchParams.getStartIndex() + searchParams.getPageSize());
468 oleDeliverItemSearchForm.setStart(start);
469 return search(oleDeliverItemSearchForm, result, request, response);
470 }
471
472 @RequestMapping(params = "methodToCall=previousSearch")
473 public ModelAndView previousSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
474 HttpServletRequest request, HttpServletResponse response) throws Exception {
475
476 OLEDeliverItemSearchForm oleDeliverItemSearchForm = (OLEDeliverItemSearchForm) form;
477 SearchParams searchParams = oleDeliverItemSearchForm.getSearchParams();
478 int start = Math.max(0, searchParams.getStartIndex() - oleDeliverItemSearchForm.getPageSize());
479 oleDeliverItemSearchForm.setStart(start);
480 return search(oleDeliverItemSearchForm, result, request, response);
481 }
482
483 }