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.BIB_ITEM_ID, poLineItemId);
214 OlePurchaseOrderItem olePurchaseOrderItem = boService.findByPrimaryKey(OlePurchaseOrderItem.class, map);
215 if (olePurchaseOrderItem != null && olePurchaseOrderItem.getDocumentNumber() != null) {
216 map.clear();
217 map.put(OLEConstants.DOC_NUM, olePurchaseOrderItem.getDocumentNumber());
218 OlePurchaseOrderDocument olePurchaseOrderDocument = boService.findByPrimaryKey(OlePurchaseOrderDocument.class, map);
219 Date purchaseOrderDate = olePurchaseOrderDocument.getPurchaseOrderCreateTimestamp();
220 try {
221 String begin = null;
222 if (fromDate != null) {
223 begin = dateFormat.format(fromDate);
224 }
225 String end = null;
226 if (toDate != null) {
227 end = dateFormat.format(toDate);
228 }
229 boolean isValid = false;
230 OleLicenseRequestServiceImpl oleLicenseRequestService = GlobalResourceLoader.getService(OLEConstants.OleLicenseRequest.LICENSE_REQUEST_SERVICE);
231 isValid = oleLicenseRequestService.validateDate(purchaseOrderDate, begin, end);
232 if (isValid) {
233 return true;
234 }
235 } catch (Exception e) {
236 LOG.error("Exception while calling the licenseRequest service" + e.getMessage());
237 throw new RuntimeException(e);
238 }
239 }
240 return false;
241 }
242
243 private List<SearchResultDisplayRow> getSearchResultDisplayRowListFromItems(String code, String value) throws Exception {
244 SearchParams searchParams = new SearchParams();
245 SearchField searchField = searchParams.buildSearchField(DocType.ITEM.getCode(), code, value);
246 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.OLEEResourceRecord.AND, searchField, OLEConstants.OLEEResourceRecord.AND));
247 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.COPY_NUM_DISPLAY));
248 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.ENUMERATION_DISPLAY));
249 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.CHRONOLOGY_DISPLAY));
250 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.DONOR_CODE_SEARCH));
251 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.ITEM_STATUS_DISPLAY));
252 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.PURCHASE_ORDER_LINE_ID_SEARCH));
253 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.ITEM_IDENTIFIER_SEARCH));
254 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.CALL_NUM_PREFIX_DISPLAY));
255 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.CALL_NUM_DISPLAY));
256 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), OLEConstants.LOACTION_LEVEL_DISPLAY));
257 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.HOLDINGS.getCode(), OLEConstants.LOACTION_LEVEL_DISPLAY));
258 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.HOLDINGS.getCode(), OLEConstants.CALL_NUM_PREFIX_DISPLAY));
259 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.HOLDINGS.getCode(), OLEConstants.CALL_NUM_DISPLAY));
260 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), Bib.TITLE));
261 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), Bib.AUTHOR));
262 searchParams.setPageSize(10000);
263 if (LOG.isDebugEnabled()){
264 LOG.debug("searchparams ==========>>>>>>>>> " + searchParams.serialize(searchParams));
265 }
266 SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
267 if (LOG.isDebugEnabled()){
268 LOG.debug("SearchResponse ==========>>>>>>>>> " + searchResponse.serialize(searchResponse));
269 }
270 List<SearchResultDisplayRow> searchResultDisplayRowList = new ArrayList<>();
271 for (SearchResult searchResult : searchResponse.getSearchResults()) {
272 String itemCallNumberPrefix = null;
273 String itemCallNumber = null;
274 String itemLocation = null;
275 String holdingsLocation = null;
276 String holdingsCallNumberPrefix = null;
277 String holdingsCallNumber = null;
278 String callNumber = null;
279 String callNumberPrefix = null;
280 for (SearchResultField resultField : searchResult.getSearchResultFields()) {
281 if (resultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && resultField.getFieldName().equalsIgnoreCase(OLEConstants.DONOR_CODE_SEARCH) && resultField.getFieldValue() != null) {
282 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
283 if ((StringUtils.isNotBlank(value) && resultField.getFieldValue().equals(value)) || StringUtils.isBlank(value)) {
284 searchResultDisplayRow.setDonorCode(resultField.getFieldValue());
285 }
286 if (StringUtils.isNotEmpty(searchResultDisplayRow.getDonorCode())) {
287 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
288 if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.COPY_NUM_DISPLAY)) {
289 searchResultDisplayRow.setCopyNumber(searchResultField.getFieldValue());
290 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.ENUMERATION_DISPLAY)) {
291 searchResultDisplayRow.setEnumeration(searchResultField.getFieldValue());
292 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CHRONOLOGY_DISPLAY)) {
293 searchResultDisplayRow.setChronology(searchResultField.getFieldValue());
294 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.ITEM_STATUS_DISPLAY)) {
295 searchResultDisplayRow.setItemStatus(searchResultField.getFieldValue());
296 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.PURCHASE_ORDER_LINE_ID_SEARCH)) {
297 searchResultDisplayRow.setPoLineItemId(searchResultField.getFieldValue());
298 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.ITEM_IDENTIFIER_SEARCH)) {
299 searchResultDisplayRow.setItemIdentifier(searchResultField.getFieldValue());
300 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CALL_NUM_PREFIX_DISPLAY)) {
301 itemCallNumberPrefix = searchResultField.getFieldValue();
302 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CALL_NUM_DISPLAY)) {
303 itemCallNumber = searchResultField.getFieldValue();
304 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.LOACTION_LEVEL_DISPLAY)) {
305 itemLocation = searchResultField.getFieldValue();
306 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.LOACTION_LEVEL_DISPLAY)) {
307 holdingsLocation = searchResultField.getFieldValue();
308 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CALL_NUM_PREFIX_DISPLAY)) {
309 holdingsCallNumberPrefix = searchResultField.getFieldValue();
310 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CALL_NUM_DISPLAY)) {
311 holdingsCallNumber = searchResultField.getFieldValue();
312 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(Bib.TITLE)) {
313 searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
314 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(Bib.AUTHOR)) {
315 searchResultDisplayRow.setAuthor(searchResultField.getFieldValue());
316 }
317 }
318 if (StringUtils.isEmpty(itemLocation)) {
319 searchResultDisplayRow.setLocationName(holdingsLocation);
320 } else {
321 searchResultDisplayRow.setLocationName(itemLocation);
322 }
323 if (StringUtils.isEmpty(itemCallNumber)) {
324 callNumber = holdingsCallNumber;
325 } else {
326 callNumber = itemCallNumber;
327 }
328 if (StringUtils.isEmpty(itemCallNumberPrefix)) {
329 callNumberPrefix = holdingsCallNumberPrefix;
330 } else {
331 callNumberPrefix = itemCallNumberPrefix;
332 }
333 if (StringUtils.isNotEmpty(callNumberPrefix) && StringUtils.isNotEmpty(callNumber)) {
334 searchResultDisplayRow.setPrefixAndCallnumber(callNumberPrefix.concat("+").concat(callNumber));
335 } else if (StringUtils.isNotEmpty(callNumberPrefix)) {
336 searchResultDisplayRow.setPrefixAndCallnumber(callNumberPrefix);
337 } else if (StringUtils.isNotEmpty(callNumber)) {
338 searchResultDisplayRow.setPrefixAndCallnumber(callNumber);
339 }
340 if (LOG.isDebugEnabled()){
341 LOG.debug("searchResultDisplayRow ==========>>>>>>>>> " + searchResultDisplayRow.getDonorCode());
342 }
343 searchResultDisplayRowList.add(searchResultDisplayRow);
344 }
345 }
346 }
347 }
348 return searchResultDisplayRowList;
349 }
350
351 private List<SearchResultDisplayRow> getSearchResultDisplayRowListFromEHoldings(String code, String value) throws Exception {
352 SearchParams searchParams = new SearchParams();
353 SearchField searchField = searchParams.buildSearchField(DocType.EHOLDINGS.getCode(), code, value);
354 searchParams.getSearchConditions().add(searchParams.buildSearchCondition(OLEConstants.OLEEResourceRecord.AND, searchField, OLEConstants.OLEEResourceRecord.AND));
355 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.EHOLDINGS.getCode(), OLEConstants.DONOR_CODE_SEARCH));
356 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.EHOLDINGS.getCode(), OLEConstants.CALL_NUM_PREFIX_DISPLAY));
357 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.EHOLDINGS.getCode(), OLEConstants.CALL_NUM_DISPLAY));
358 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.EHOLDINGS.getCode(), OLEConstants.LOACTION_LEVEL_DISPLAY));
359 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.EHOLDINGS.getCode(), OLEConstants.IMPRINT_DISPLAY));
360 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.EHOLDINGS.getCode(), OLEConstants.OVERLAY_HOLDINGS_IDENTIFIER));
361 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), Bib.TITLE));
362 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), Bib.AUTHOR));
363 searchParams.setPageSize(10000);
364 if (LOG.isDebugEnabled()){
365 LOG.debug("searchparams ==========>>>>>>>>> " + searchParams.serialize(searchParams));
366 }
367 SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
368 if (LOG.isDebugEnabled()){
369 LOG.debug("SearchResponse ==========>>>>>>>>> " + searchResponse.serialize(searchResponse));
370 }
371 List<SearchResultDisplayRow> searchResultDisplayRowList = new ArrayList<>();
372 for (SearchResult searchResult : searchResponse.getSearchResults()) {
373 String callNumber = null;
374 String callNumberPrefix = null;
375 for (SearchResultField resultField : searchResult.getSearchResultFields()) {
376 if (resultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()) && resultField.getFieldName().equalsIgnoreCase(OLEConstants.DONOR_CODE_SEARCH) && resultField.getFieldValue() != null) {
377 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
378 if ((StringUtils.isNotBlank(value) && resultField.getFieldValue().equals(value)) || StringUtils.isBlank(value)) {
379 searchResultDisplayRow.setDonorCode(resultField.getFieldValue());
380 }
381 if (StringUtils.isNotEmpty(searchResultDisplayRow.getDonorCode())) {
382 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
383 if (searchResultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.LOACTION_LEVEL_DISPLAY)) {
384 searchResultDisplayRow.setLocationName(searchResultField.getFieldValue());
385 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CALL_NUM_PREFIX_DISPLAY)) {
386 callNumberPrefix = searchResultField.getFieldValue();
387 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.CALL_NUM_DISPLAY)) {
388 callNumber = searchResultField.getFieldValue();
389 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.IMPRINT_DISPLAY)) {
390 searchResultDisplayRow.setImprint(searchResultField.getFieldValue());
391 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(OLEConstants.OVERLAY_HOLDINGS_IDENTIFIER)) {
392 searchResultDisplayRow.setInstanceIdentifier(searchResultField.getFieldValue());
393 List<Integer> poLineItemIds=new ArrayList<>();
394 Map map=new HashMap();
395 map.put(OLEConstants.INSTANCE_ID,searchResultField.getFieldValue());
396 List<OleCopy> oleCopyList = (List<OleCopy>)boService.findMatching(OleCopy.class, map);
397 if (oleCopyList!=null && oleCopyList.size()>0){
398 map.clear();
399 map.put(OLEConstants.DONOR_CODE,searchResultDisplayRow.getDonorCode());
400 List<OLELinkPurapDonor> oleLinkPurapDonorList = (List<OLELinkPurapDonor>)boService.findMatching(OLELinkPurapDonor.class, map);
401 if (oleLinkPurapDonorList!=null && oleLinkPurapDonorList.size()>0){
402 for (OLELinkPurapDonor oleLinkPurapDonor:oleLinkPurapDonorList){
403 for (OleCopy oleCopy:oleCopyList){
404 if (oleLinkPurapDonor.getPoItemId().equals(oleCopy.getPoItemId())){
405 poLineItemIds.add(oleLinkPurapDonor.getPoItemId());
406 }
407 }
408 }
409 }
410 }
411 searchResultDisplayRow.setPoLineItemIds(poLineItemIds);
412 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(Bib.TITLE)) {
413 searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
414 } else if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode()) && searchResultField.getFieldName().equalsIgnoreCase(Bib.AUTHOR)) {
415 searchResultDisplayRow.setAuthor(searchResultField.getFieldValue());
416 }
417 }
418 if (StringUtils.isNotEmpty(callNumberPrefix) && StringUtils.isNotEmpty(callNumber)) {
419 searchResultDisplayRow.setPrefixAndCallnumber(callNumberPrefix.concat("+").concat(callNumber));
420 } else if (StringUtils.isNotEmpty(callNumberPrefix)) {
421 searchResultDisplayRow.setPrefixAndCallnumber(callNumberPrefix);
422 } else if (StringUtils.isNotEmpty(callNumber)) {
423 searchResultDisplayRow.setPrefixAndCallnumber(callNumber);
424 }
425 if (LOG.isDebugEnabled()){
426 LOG.debug("searchResultDisplayRow ==========>>>>>>>>> " + searchResultDisplayRow.getDonorCode());
427 }
428 searchResultDisplayRowList.add(searchResultDisplayRow);
429 }
430 }
431 }
432 }
433 return searchResultDisplayRowList;
434 }
435
436 }