1 package org.kuali.ole.select.controller;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.OLEPropertyConstants;
7 import org.kuali.ole.describe.bo.SearchResultDisplayRow;
8 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
9 import org.kuali.ole.docstore.common.document.Bib;
10 import org.kuali.ole.docstore.common.document.content.enums.DocType;
11 import org.kuali.ole.docstore.common.search.*;
12 import org.kuali.ole.docstore.discovery.service.QueryService;
13 import org.kuali.ole.select.bo.OLEDonor;
14 import org.kuali.ole.select.bo.OLELinkPurapDonor;
15 import org.kuali.ole.select.businessobject.OleCopy;
16 import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
17 import org.kuali.ole.select.document.OlePaymentRequestDocument;
18 import org.kuali.ole.select.document.OlePurchaseOrderDocument;
19 import org.kuali.ole.select.form.OLEAnnualStewardshipReportForm;
20 import org.kuali.ole.service.impl.OleLicenseRequestServiceImpl;
21 import org.kuali.ole.sys.context.SpringContext;
22 import org.kuali.rice.core.api.config.property.ConfigContext;
23 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
24 import org.kuali.rice.krad.service.BusinessObjectService;
25 import org.kuali.rice.krad.service.KRADServiceLocator;
26 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
27 import org.kuali.rice.krad.service.LookupService;
28 import org.kuali.rice.krad.uif.UifConstants;
29 import org.kuali.rice.krad.uif.UifParameters;
30 import org.kuali.rice.krad.util.GlobalVariables;
31 import org.kuali.rice.krad.util.KRADConstants;
32 import org.kuali.rice.krad.web.controller.UifControllerBase;
33 import org.kuali.rice.krad.web.form.UifFormBase;
34 import org.springframework.stereotype.Controller;
35 import org.springframework.validation.BindingResult;
36 import org.springframework.web.bind.annotation.ModelAttribute;
37 import org.springframework.web.bind.annotation.RequestMapping;
38 import org.springframework.web.servlet.ModelAndView;
39
40 import javax.servlet.http.HttpServletRequest;
41 import javax.servlet.http.HttpServletResponse;
42 import java.text.SimpleDateFormat;
43 import java.util.*;
44
45
46
47
48
49
50
51
52 @Controller
53 @RequestMapping(value = "/searchAnnualStewardshipReportController")
54 public class OLEAnnualStewardshipReportController extends UifControllerBase {
55
56 private QueryService queryService;
57 private static final Logger LOG = Logger.getLogger(OLEEResourceSearchController.class);
58 private static final SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.OLEEResourceRecord.CREATED_DATE_FORMAT);
59 private BusinessObjectService boService = KRADServiceLocator.getBusinessObjectService();
60 private DocstoreClientLocator docstoreClientLocator;
61
62 private LookupService getLookupService() {
63 return KRADServiceLocatorWeb.getLookupService();
64 }
65
66 public DocstoreClientLocator getDocstoreClientLocator() {
67 if (null == docstoreClientLocator) {
68 return SpringContext.getBean(DocstoreClientLocator.class);
69 }
70 return docstoreClientLocator;
71 }
72
73 @Override
74 protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
75 return new OLEAnnualStewardshipReportForm();
76 }
77
78 @RequestMapping(params = "methodToCall=search")
79 public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
80 HttpServletRequest request, HttpServletResponse response) throws Exception {
81 LOG.debug("Entering annual stewardship search");
82 OLEAnnualStewardshipReportForm oleAnnualStewardshipReportForm = (OLEAnnualStewardshipReportForm) form;
83 List<SearchResultDisplayRow> searchResultDisplayRowList = new ArrayList<>();
84 if (StringUtils.isNotEmpty(oleAnnualStewardshipReportForm.getDonorCode())) {
85 Map donorMap = new HashMap();
86 donorMap.put(OLEConstants.DONOR_CODE, oleAnnualStewardshipReportForm.getDonorCode());
87 List<OLEDonor> oleDonorList = (List<OLEDonor>) getLookupService().findCollectionBySearch(OLEDonor.class, donorMap);
88 if (oleDonorList != null && oleDonorList.size() > 0l) {
89 searchResultDisplayRowList = getSearchResultDisplayRowListFromItems(OLEConstants.DONOR_CODE_SEARCH, oleDonorList.get(0).getDonorCode());
90 searchResultDisplayRowList.addAll(getSearchResultDisplayRowListFromEHoldings(OLEConstants.DONOR_CODE_SEARCH, oleDonorList.get(0).getDonorCode()));
91 } else {
92 oleAnnualStewardshipReportForm.setSaerSearchResultDisplayRowList(null);
93 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DONOR_NOT_FOUND);
94 return getUIFModelAndView(oleAnnualStewardshipReportForm);
95 }
96 } else {
97 searchResultDisplayRowList = getSearchResultDisplayRowListFromItems(OLEConstants.DONOR_CODE_SEARCH, oleAnnualStewardshipReportForm.getDonorCode());
98 searchResultDisplayRowList.addAll(getSearchResultDisplayRowListFromEHoldings(OLEConstants.DONOR_CODE_SEARCH, oleAnnualStewardshipReportForm.getDonorCode()));
99 }
100 if (StringUtils.isNotEmpty(oleAnnualStewardshipReportForm.getStatus())) {
101 searchResultDisplayRowList = getSearchResultDisplayRowListBasedOnStatus(searchResultDisplayRowList, oleAnnualStewardshipReportForm.getStatus());
102 }
103 if (oleAnnualStewardshipReportForm.getFromDate() != null || oleAnnualStewardshipReportForm.getToDate() != null) {
104 searchResultDisplayRowList = getSearchResultDisplayRowListBasedOnDate(searchResultDisplayRowList, oleAnnualStewardshipReportForm.getFromDate(), oleAnnualStewardshipReportForm.getToDate());
105 }
106 if (searchResultDisplayRowList.size() == 0) {
107 oleAnnualStewardshipReportForm.setSaerSearchResultDisplayRowList(null);
108 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
109 } else {
110 oleAnnualStewardshipReportForm.setSaerSearchResultDisplayRowList(searchResultDisplayRowList);
111 }
112 LOG.debug("Leaving annual stewardship search");
113 return getUIFModelAndView(oleAnnualStewardshipReportForm);
114 }
115
116 @RequestMapping(params = "methodToCall=clearSearch")
117 public ModelAndView clearSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
118 HttpServletRequest request, HttpServletResponse response) {
119 OLEAnnualStewardshipReportForm oleAnnualStewardshipReportForm = (OLEAnnualStewardshipReportForm) form;
120 oleAnnualStewardshipReportForm.setDonorCode(null);
121 oleAnnualStewardshipReportForm.setStatus(null);
122 oleAnnualStewardshipReportForm.setFromDate(null);
123 oleAnnualStewardshipReportForm.setToDate(null);
124 oleAnnualStewardshipReportForm.setSaerSearchResultDisplayRowList(null);
125 return getUIFModelAndView(oleAnnualStewardshipReportForm);
126 }
127
128 @RequestMapping(params = "methodToCall=cancel")
129 public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
130 HttpServletRequest request, HttpServletResponse response) {
131 String baseUrl = ConfigContext.getCurrentContextConfig().getProperty(OLEPropertyConstants.OLE_URL_BASE);
132 String url = baseUrl + "/portal.do";
133 Properties props = new Properties();
134 props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH);
135 if (org.apache.commons.lang.StringUtils.isNotBlank(form.getReturnFormKey())) {
136 props.put(UifParameters.FORM_KEY, form.getReturnFormKey());
137 }
138 return performRedirect(form, url, props);
139 }
140
141 private List<SearchResultDisplayRow> getSearchResultDisplayRowListBasedOnStatus(List<SearchResultDisplayRow> searchResultDisplayRowList, String status) {
142 List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>();
143 for (SearchResultDisplayRow searchResultDisplayRow : searchResultDisplayRowList) {
144 if (searchResultDisplayRow.getPoLineItemIds().size() > 0) {
145 for (Integer poLineItemId : searchResultDisplayRow.getPoLineItemIds()) {
146 if (getSearchResultDisplayRowBasedOnStatus(status,searchResultDisplayRow,OLEConstants.INSTANCE_ID,searchResultDisplayRow.getInstanceIdentifier(),poLineItemId.toString())){
147 searchResultDisplayRows.add(searchResultDisplayRow);
148 }
149 }
150 } else {
151 if (getSearchResultDisplayRowBasedOnStatus(status,searchResultDisplayRow,OLEConstants.OVERLAY_ITEMUUID,searchResultDisplayRow.getItemIdentifier(),searchResultDisplayRow.getPoLineItemId())){
152 searchResultDisplayRows.add(searchResultDisplayRow);
153 }
154 }
155 }
156 return searchResultDisplayRows;
157 }
158
159 private boolean getSearchResultDisplayRowBasedOnStatus(String status, SearchResultDisplayRow searchResultDisplayRow,String key,String value, String poLineItemId){
160 boolean paidFlag = false;
161 boolean recievedFlag = false;
162 if (status.equals(OLEConstants.RECIEVED) || status.equals(OLEConstants.RECEIVED_PAID)) {
163 Map map = new HashMap();
164 map.put(OLEConstants.OLEEResourceRecord.ERESOURCE_PO_ID, poLineItemId);
165 map.put(key, value);
166 OleCopy oleCopy = boService.findByPrimaryKey(OleCopy.class, map);
167 if (oleCopy != null && oleCopy.getReceiptStatus().equals(OLEConstants.RECIEVED)) {
168 recievedFlag = true;
169 }
170 }
171 if (status.equals(OLEConstants.PAID) || status.equals(OLEConstants.RECEIVED_PAID)) {
172 Map map = new HashMap();
173 map.put(OLEConstants.BIB_ITEM_ID, poLineItemId);
174 OlePurchaseOrderItem olePurchaseOrderItem = boService.findByPrimaryKey(OlePurchaseOrderItem.class, map);
175 if (olePurchaseOrderItem != null && olePurchaseOrderItem.getDocumentNumber() != null) {
176 map.clear();
177 map.put(OLEConstants.DOC_NUM, olePurchaseOrderItem.getDocumentNumber());
178 OlePurchaseOrderDocument olePurchaseOrderDocument = boService.findByPrimaryKey(OlePurchaseOrderDocument.class, map);
179 map.clear();
180 map.put(OLEConstants.PUR_ORDER_IDENTIFIER, olePurchaseOrderDocument.getPurapDocumentIdentifier());
181 OlePaymentRequestDocument olePaymentRequestDocument = boService.findByPrimaryKey(OlePaymentRequestDocument.class, map);
182 if (olePaymentRequestDocument != null) {
183 paidFlag = true;
184 }
185 }
186 }
187 if ((status.equals(OLEConstants.RECIEVED) && recievedFlag == true) || (status.equals(OLEConstants.PAID) && paidFlag == true) || (status.equals(OLEConstants.RECEIVED_PAID) && recievedFlag == true && paidFlag == true)) {
188 return true;
189 }
190 return false;
191 }
192
193 private List<SearchResultDisplayRow> getSearchResultDisplayRowListBasedOnDate(List<SearchResultDisplayRow> searchResultDisplayRowList, Date fromDate, Date toDate) {
194 List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>();
195 for (SearchResultDisplayRow searchResultDisplayRow : searchResultDisplayRowList) {
196 if (searchResultDisplayRow.getPoLineItemIds().size() > 0) {
197 for (Integer poLineItemId : searchResultDisplayRow.getPoLineItemIds()) {
198 if (poLineItemId != null && getSearchResultDisplayRowBasedOnDate(poLineItemId.toString(), fromDate, toDate)) {
199 searchResultDisplayRows.add(searchResultDisplayRow);
200 }
201 }
202 } else {
203 if (getSearchResultDisplayRowBasedOnDate(searchResultDisplayRow.getPoLineItemId(), fromDate, toDate)) {
204 searchResultDisplayRows.add(searchResultDisplayRow);
205 }
206 }
207 }
208 return searchResultDisplayRows;
209 }
210
211 private boolean getSearchResultDisplayRowBasedOnDate(String poLineItemId, Date fromDate, Date toDate) {
212 Map map = new HashMap();
213 map.put(OLEConstants.PURAP_DOC_IDENTIFIER, poLineItemId);
214
215
216
217
218 OlePurchaseOrderDocument olePurchaseOrderDocument = boService.findByPrimaryKey(OlePurchaseOrderDocument.class, map);
219 if(olePurchaseOrderDocument != null){
220 Date purchaseOrderDate = olePurchaseOrderDocument.getPurchaseOrderCreateTimestamp();
221 try {
222 String begin = null;
223 if (fromDate != null) {
224 begin = dateFormat.format(fromDate);
225 }
226 String end = null;
227 if (toDate != null) {
228 end = dateFormat.format(toDate);
229 }
230 boolean isValid = false;
231 OleLicenseRequestServiceImpl oleLicenseRequestService = GlobalResourceLoader.getService(OLEConstants.OleLicenseRequest.LICENSE_REQUEST_SERVICE);
232 isValid = oleLicenseRequestService.validateDate(purchaseOrderDate, begin, end);
233 if (isValid) {
234 return true;
235 }
236 } catch (Exception e) {
237 LOG.error("Exception while calling the licenseRequest service" + e.getMessage());
238 throw new RuntimeException(e);
239 }
240 }
241 return false;
242 }
243
244 private List<SearchResultDisplayRow> getSearchResultDisplayRowListFromItems(String code, String value) throws Exception {
245 SearchParams searchParams = new SearchParams();
246 SearchField searchField = searchParams.buildSearchField(DocType.ITEM.getCode(), code, value);
247 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.OLEEResourceRecord.AND, searchField, OLEConstants.OLEEResourceRecord.AND));
248 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.COPY_NUM_DISPLAY));
249 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.ENUMERATION_DISPLAY));
250 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.CHRONOLOGY_DISPLAY));
251 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.DONOR_CODE_SEARCH));
252 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.ITEM_STATUS_DISPLAY));
253 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.PURCHASE_ORDER_LINE_ID_SEARCH));
254 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.ITEM_IDENTIFIER_SEARCH));
255 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.CALL_NUM_PREFIX_DISPLAY));
256 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.CALL_NUM_DISPLAY));
257 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.LOACTION_LEVEL_DISPLAY));
258 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.HOLDINGS.getCode(), OLEConstants.LOACTION_LEVEL_DISPLAY));
259 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.HOLDINGS.getCode(), OLEConstants.CALL_NUM_PREFIX_DISPLAY));
260 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.HOLDINGS.getCode(), OLEConstants.CALL_NUM_DISPLAY));
261 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.HOLDINGS.getCode(), OLEConstants.OVERLAY_HOLDINGS_IDENTIFIER));
262 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), Bib.TITLE));
263 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), Bib.BIBIDENTIFIER));
264 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), Bib.AUTHOR));
265 searchParams.setPageSize(10000);
266 if (LOG.isDebugEnabled()){
267 LOG.debug("searchparams ==========>>>>>>>>> " + searchParams.serialize(searchParams));
268 }
269 SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
270 if (LOG.isDebugEnabled()){
271 LOG.debug("SearchResponse ==========>>>>>>>>> " + searchResponse.serialize(searchResponse));
272 }
273 List<SearchResultDisplayRow> searchResultDisplayRowList = new ArrayList<>();
274 for (SearchResult searchResult : searchResponse.getSearchResults()) {
275 String itemCallNumberPrefix = null;
276 String itemCallNumber = null;
277 String itemLocation = null;
278 String holdingsLocation = null;
279 String holdingsCallNumberPrefix = null;
280 String holdingsCallNumber = null;
281 String callNumber = null;
282 String callNumberPrefix = null;
283 for (SearchResultField resultField : searchResult.getSearchResultFields()) {
284 if (resultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && resultField.getFieldName().equalsIgnoreCase(OLEConstants.DONOR_CODE_SEARCH) && resultField.getFieldValue() != null) {
285 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
286 if ((StringUtils.isNotBlank(value) && resultField.getFieldValue().equals(value)) || StringUtils.isBlank(value)) {
287 searchResultDisplayRow.setDonorCode(resultField.getFieldValue());
288 }
289 if (StringUtils.isNotEmpty(searchResultDisplayRow.getDonorCode())) {
290 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
291 if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.COPY_NUM_DISPLAY)) {
292 searchResultDisplayRow.setCopyNumber(searchResultField.getFieldValue());
293 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.ENUMERATION_DISPLAY)) {
294 searchResultDisplayRow.setEnumeration(searchResultField.getFieldValue());
295 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CHRONOLOGY_DISPLAY)) {
296 searchResultDisplayRow.setChronology(searchResultField.getFieldValue());
297 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.ITEM_STATUS_DISPLAY)) {
298 searchResultDisplayRow.setItemStatus(searchResultField.getFieldValue());
299 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.PURCHASE_ORDER_LINE_ID_SEARCH)) {
300 searchResultDisplayRow.setPoLineItemId(searchResultField.getFieldValue());
301 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.ITEM_IDENTIFIER_SEARCH)) {
302 searchResultDisplayRow.setItemIdentifier(searchResultField.getFieldValue());
303 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CALL_NUM_PREFIX_DISPLAY)) {
304 itemCallNumberPrefix = searchResultField.getFieldValue();
305 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CALL_NUM_DISPLAY)) {
306 itemCallNumber = searchResultField.getFieldValue();
307 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.LOACTION_LEVEL_DISPLAY)) {
308 itemLocation = searchResultField.getFieldValue();
309 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.LOACTION_LEVEL_DISPLAY)) {
310 holdingsLocation = searchResultField.getFieldValue();
311 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CALL_NUM_PREFIX_DISPLAY)) {
312 holdingsCallNumberPrefix = searchResultField.getFieldValue();
313 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CALL_NUM_DISPLAY)) {
314 holdingsCallNumber = searchResultField.getFieldValue();
315 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(Bib.TITLE)) {
316 searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
317 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(Bib.AUTHOR)) {
318 searchResultDisplayRow.setAuthor(searchResultField.getFieldValue());
319 }
320 else if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(Bib.BIBIDENTIFIER)) {
321 searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
322 }else if (searchResultField.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.OVERLAY_HOLDINGS_IDENTIFIER)) {
323 searchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
324 }
325 }
326 if (StringUtils.isEmpty(itemLocation)) {
327 searchResultDisplayRow.setLocationName(holdingsLocation);
328 } else {
329 searchResultDisplayRow.setLocationName(itemLocation);
330 }
331 if (StringUtils.isEmpty(itemCallNumber)) {
332 callNumber = holdingsCallNumber;
333 } else {
334 callNumber = itemCallNumber;
335 }
336 if (StringUtils.isEmpty(itemCallNumberPrefix)) {
337 callNumberPrefix = holdingsCallNumberPrefix;
338 } else {
339 callNumberPrefix = itemCallNumberPrefix;
340 }
341 if (StringUtils.isNotEmpty(callNumberPrefix) && StringUtils.isNotEmpty(callNumber)) {
342 searchResultDisplayRow.setPrefixAndCallnumber(callNumberPrefix.concat("+").concat(callNumber));
343 } else if (StringUtils.isNotEmpty(callNumberPrefix)) {
344 searchResultDisplayRow.setPrefixAndCallnumber(callNumberPrefix);
345 } else if (StringUtils.isNotEmpty(callNumber)) {
346 searchResultDisplayRow.setPrefixAndCallnumber(callNumber);
347 }
348 if (LOG.isDebugEnabled()){
349 LOG.debug("searchResultDisplayRow ==========>>>>>>>>> " + searchResultDisplayRow.getDonorCode());
350 }
351 searchResultDisplayRowList.add(searchResultDisplayRow);
352 }
353 }
354 }
355 }
356 return searchResultDisplayRowList;
357 }
358
359 private List<SearchResultDisplayRow> getSearchResultDisplayRowListFromEHoldings(String code, String value) throws Exception {
360 SearchParams searchParams = new SearchParams();
361 SearchField searchField = searchParams.buildSearchField(DocType.EHOLDINGS.getCode(), code, value);
362 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.OLEEResourceRecord.AND, searchField, OLEConstants.OLEEResourceRecord.AND));
363 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.EHOLDINGS.getCode(), OLEConstants.DONOR_CODE_SEARCH));
364 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.EHOLDINGS.getCode(), OLEConstants.CALL_NUM_PREFIX_DISPLAY));
365 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.EHOLDINGS.getCode(), OLEConstants.CALL_NUM_DISPLAY));
366 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.EHOLDINGS.getCode(), OLEConstants.LOACTION_LEVEL_DISPLAY));
367 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.EHOLDINGS.getCode(), OLEConstants.IMPRINT_DISPLAY));
368 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.EHOLDINGS.getCode(), OLEConstants.OVERLAY_HOLDINGS_IDENTIFIER));
369 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), Bib.TITLE));
370 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), Bib.AUTHOR));
371 searchParams.setPageSize(10000);
372 if (LOG.isDebugEnabled()){
373 LOG.debug("searchparams ==========>>>>>>>>> " + searchParams.serialize(searchParams));
374 }
375 SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
376 if (LOG.isDebugEnabled()){
377 LOG.debug("SearchResponse ==========>>>>>>>>> " + searchResponse.serialize(searchResponse));
378 }
379 List<SearchResultDisplayRow> searchResultDisplayRowList = new ArrayList<>();
380 for (SearchResult searchResult : searchResponse.getSearchResults()) {
381 String callNumber = null;
382 String callNumberPrefix = null;
383 for (SearchResultField resultField : searchResult.getSearchResultFields()) {
384 if (resultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()) && resultField.getFieldName().equalsIgnoreCase(OLEConstants.DONOR_CODE_SEARCH) && resultField.getFieldValue() != null) {
385 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
386 if ((StringUtils.isNotBlank(value) && resultField.getFieldValue().equals(value)) || StringUtils.isBlank(value)) {
387 searchResultDisplayRow.setDonorCode(resultField.getFieldValue());
388 }
389 if (StringUtils.isNotEmpty(searchResultDisplayRow.getDonorCode())) {
390 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
391 if (searchResultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.LOACTION_LEVEL_DISPLAY)) {
392 searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
393 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CALL_NUM_PREFIX_DISPLAY)) {
394 callNumberPrefix = searchResultField.getFieldValue();
395 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CALL_NUM_DISPLAY)) {
396 callNumber = searchResultField.getFieldValue();
397 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.IMPRINT_DISPLAY)) {
398 searchResultDisplayRow.setImprint(searchResultField.getFieldValue());
399 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.OVERLAY_HOLDINGS_IDENTIFIER)) {
400 searchResultDisplayRow.setInstanceIdentifier(searchResultField.getFieldValue());
401 List<Integer> poLineItemIds=new ArrayList<>();
402 Map map=new HashMap();
403 map.put(OLEConstants.INSTANCE_ID,searchResultField.getFieldValue());
404 List<OleCopy> oleCopyList = (List<OleCopy>)boService.findMatching(OleCopy.class, map);
405 if (oleCopyList!=null && oleCopyList.size()>0){
406 map.clear();
407 map.put(OLEConstants.DONOR_CODE,searchResultDisplayRow.getDonorCode());
408 List<OLELinkPurapDonor> oleLinkPurapDonorList = (List<OLELinkPurapDonor>)boService.findMatching(OLELinkPurapDonor.class, map);
409 if (oleLinkPurapDonorList!=null && oleLinkPurapDonorList.size()>0){
410 for (OLELinkPurapDonor oleLinkPurapDonor:oleLinkPurapDonorList){
411 for (OleCopy oleCopy:oleCopyList){
412 if (oleLinkPurapDonor.getPoItemId().equals(oleCopy.getPoItemId())){
413 poLineItemIds.add(oleLinkPurapDonor.getPoItemId());
414 }
415 }
416 }
417 }
418 }
419 searchResultDisplayRow.setPoLineItemIds(poLineItemIds);
420 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(Bib.TITLE)) {
421 searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
422 }else if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(Bib.BIBIDENTIFIER)) {
423 searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
424 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(Bib.AUTHOR)) {
425 searchResultDisplayRow.setAuthor(searchResultField.getFieldValue());
426 }else if (searchResultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.OVERLAY_HOLDINGS_IDENTIFIER)) {
427 searchResultDisplayRow.setHoldingsIdentifier(searchResultField.getFieldValue());
428 }
429 }
430 if (StringUtils.isNotEmpty(callNumberPrefix) && StringUtils.isNotEmpty(callNumber)) {
431 searchResultDisplayRow.setPrefixAndCallnumber(callNumberPrefix.concat("+").concat(callNumber));
432 } else if (StringUtils.isNotEmpty(callNumberPrefix)) {
433 searchResultDisplayRow.setPrefixAndCallnumber(callNumberPrefix);
434 } else if (StringUtils.isNotEmpty(callNumber)) {
435 searchResultDisplayRow.setPrefixAndCallnumber(callNumber);
436 }
437 if (LOG.isDebugEnabled()){
438 LOG.debug("searchResultDisplayRow ==========>>>>>>>>> " + searchResultDisplayRow.getDonorCode());
439 }
440 searchResultDisplayRowList.add(searchResultDisplayRow);
441 }
442 }
443 }
444 }
445 return searchResultDisplayRowList;
446 }
447
448 }