1 package org.kuali.ole.deliver.util;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.OLEParameterConstants;
7 import org.kuali.ole.deliver.bo.OleCirculationDesk;
8 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
9 import org.kuali.ole.deliver.bo.OleLoanDocument;
10 import org.kuali.ole.deliver.bo.OleTemporaryCirculationHistory;
11 import org.kuali.ole.deliver.service.CircDeskLocationResolver;
12 import org.kuali.ole.describe.bo.OleLocation;
13 import org.kuali.ole.describe.keyvalue.LocationValuesBuilder;
14 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
15 import org.kuali.ole.docstore.common.document.Holdings;
16 import org.kuali.ole.docstore.common.document.ItemOleml;
17 import org.kuali.ole.docstore.common.document.content.instance.CallNumber;
18 import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
19 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
20 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
21 import org.kuali.ole.docstore.common.search.*;
22 import org.kuali.ole.sys.context.SpringContext;
23 import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
24 import org.kuali.rice.coreservice.api.parameter.Parameter;
25 import org.kuali.rice.coreservice.api.parameter.ParameterKey;
26 import org.kuali.rice.krad.service.BusinessObjectService;
27 import org.kuali.rice.krad.service.KRADServiceLocator;
28
29 import java.sql.Timestamp;
30 import java.text.DateFormat;
31 import java.text.ParseException;
32 import java.text.SimpleDateFormat;
33 import java.util.*;
34
35
36
37
38 public class OleLoanDocumentsFromSolrBuilder {
39 private static final Logger LOG = Logger.getLogger(OleLoanDocumentsFromSolrBuilder.class);
40
41 private DocstoreClientLocator docstoreClientLocator;
42 private BusinessObjectService businessObjectService;
43 private CircDeskLocationResolver circDeskLocationResolver;
44 private ItemOlemlRecordProcessor itemOlemlRecordProcessor;
45 private static Map<String, String> locationName = new HashMap<>();
46
47 public List<OleLoanDocument> getPatronLoanedItemBySolr(String patronId, String itemBarcode) throws Exception {
48 LOG.debug("Inside the getPatronLoanedItemBySolr method");
49 Long b1 = System.currentTimeMillis();
50 SearchResponse searchResponse = new SearchResponse();
51 HashMap<String, Object> loanMap = new HashMap<>();
52 if (patronId != null) {
53 String itemStatusParam = getParameter(OLEParameterConstants.ITEM_STATUS_FOR_RET_LOAN);
54 String[] itemStatus = new String[0];
55 if (itemStatusParam != null) {
56 itemStatus = itemStatusParam.split("[|]");
57 }
58 SearchParams searchParams = new SearchParams();
59 List<SearchCondition> searchConditions = new ArrayList<>();
60 int count = itemStatus.length;
61 for (int i = 0; i < count; i++) {
62 if (i == (count - 1)) {
63 searchConditions.add(searchParams.buildSearchCondition("", searchParams.buildSearchField("item", "ItemStatus_search", itemStatus[i]), "AND"));
64 } else {
65 searchConditions.add(searchParams.buildSearchCondition("", searchParams.buildSearchField("item", "ItemStatus_search", itemStatus[i]), "OR"));
66 }
67 }
68
69 searchConditions.add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField("item", "currentBorrower", patronId), "AND"));
70 if (null != itemBarcode) {
71 searchConditions.add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org
72 .kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), ItemOleml.ITEM_BARCODE,
73 itemBarcode), "AND"));
74 }
75 searchParams.setPageSize(Integer.parseInt(OLEConstants.MAX_PAGE_SIZE_FOR_LOAN));
76 SearchParmsBuilder.buildSearchParams(searchParams);
77 searchParams.getSearchConditions().addAll(searchConditions);
78 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
79 }
80 List<OleLoanDocument> matchingLoan = getOleLoanDocumentsFromSearchResponse(searchResponse, loanMap);
81
82
83 Long b2 = System.currentTimeMillis();
84 Long total = b2 - b1;
85 LOG.info("The time taken for Docstore call :" + total);
86 return sortLoanDocumentByDueDate(matchingLoan);
87 }
88
89 public OleLoanDocument retrieveByPatronAndItem(String patronId, String itemBarcode) throws Exception {
90 LOG.debug("Inside the retrieveByPatronAndItem method");
91 Long b1 = System.currentTimeMillis();
92 SearchResponse searchResponse = new SearchResponse();
93 HashMap<String, Object> loanMap = new HashMap<>();
94 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
95 if (patronId != null) {
96 String itemStatusParam = getParameter(OLEParameterConstants.ITEM_STATUS_FOR_RET_LOAN);
97 String[] itemStatus = new String[0];
98 if (itemStatusParam != null) {
99 itemStatus = itemStatusParam.split("[|]");
100 }
101 SearchParams searchParams = new SearchParams();
102 List<SearchCondition> searchConditions = new ArrayList<>();
103 int count = itemStatus.length;
104 for (int i = 0; i < count; i++) {
105 if (i == (count - 1)) {
106 searchConditions.add(searchParams.buildSearchCondition("", searchParams.buildSearchField("item", "ItemStatus_search", itemStatus[i]), "AND"));
107 } else {
108 searchConditions.add(searchParams.buildSearchCondition("", searchParams.buildSearchField("item", "ItemStatus_search", itemStatus[i]), "OR"));
109 }
110 }
111
112 searchConditions.add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField("item", "currentBorrower", patronId), "AND"));
113 searchConditions.add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, itemBarcode), "AND"));
114 searchParams.setPageSize(Integer.parseInt(OLEConstants.MAX_PAGE_SIZE_FOR_LOAN));
115 SearchParmsBuilder.buildSearchParams(searchParams);
116 searchParams.getSearchConditions().addAll(searchConditions);
117 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
118 }
119 List<OleLoanDocument> matchingLoan = getOleLoanDocumentsFromSearchResponse(searchResponse, loanMap);
120 Long b2 = System.currentTimeMillis();
121 Long b3 = b2 - b1;
122 LOG.info("The Time taken retrieveByPatronAndItem--" + b3);
123 return matchingLoan != null && matchingLoan.size() > 0 ? matchingLoan.get(0) : null;
124 }
125
126
127 public String getParameter(String name) {
128 ParameterKey parameterKey = ParameterKey.create(OLEConstants.APPL_ID, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, name);
129 Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
130 if (parameter == null) {
131 parameterKey = ParameterKey.create(OLEConstants.APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, name);
132 parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
133 }
134 return parameter != null ? parameter.getValue() : null;
135 }
136
137 public List<OleLoanDocument> getOleLoanDocumentsFromSearchResponse(SearchResponse searchResponse, HashMap<String, Object> loanMap) throws Exception {
138 int count = 0;
139 DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
140 List<OleLoanDocument> oleLoanDocuments = new ArrayList<>();
141 if (searchResponse != null) {
142 for (SearchResult searchResult : searchResponse.getSearchResults()) {
143 OleLoanDocument oleLoanDocument = null;
144 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
145
146 if (searchResultField.getFieldValue() != null) {
147
148 if (searchResultField.getFieldName().equalsIgnoreCase("ItemBarcode_display")) {
149 oleLoanDocument = new OleLoanDocument();
150 oleLoanDocument.setItemId(searchResultField.getFieldValue());
151 Map itemMap = new HashMap();
152 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, oleLoanDocument.getItemId());
153 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, itemMap);
154 if (oleDeliverRequestBoList != null && oleDeliverRequestBoList.size() > 0) {
155 oleLoanDocument.setRequestFlag(OLEConstants.VIEW_ALL_REQUESTS);
156 } else {
157 oleLoanDocument.setRequestFlag(" ");
158 }
159 }
160 if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
161
162 if (null == oleLoanDocument) {
163 oleLoanDocument = new OleLoanDocument();
164 }
165 oleLoanDocument.setItemUuid(searchResultField.getFieldValue());
166 } else if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
167 oleLoanDocument.setBibUuid(searchResultField.getFieldValue());
168 } else if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
169 oleLoanDocument.setTitle(searchResultField.getFieldValue());
170 } else if (searchResultField.getFieldName().equalsIgnoreCase("Author_display")) {
171 oleLoanDocument.setAuthor(searchResultField.getFieldValue());
172 } else if (searchResultField.getFieldName().equalsIgnoreCase("holdingsIdentifier")) {
173 oleLoanDocument.setInstanceUuid(searchResultField.getFieldValue());
174 } else if (searchResultField.getFieldName().equalsIgnoreCase("claimsReturnedNote")) {
175 oleLoanDocument.setClaimsReturnNote(searchResultField.getFieldValue());
176
177 } else if (searchResultField.getFieldName().equalsIgnoreCase("ClaimsReturnedFlag_display") && searchResultField.getFieldValue().equalsIgnoreCase("true")) {
178 oleLoanDocument.setClaimsReturnedIndicator(true);
179 count++;
180 } else if (searchResultField.getFieldName().equalsIgnoreCase("Location_display")) {
181 getLocationBySolr(searchResultField, oleLoanDocument);
182 oleLoanDocument.setItemFullLocation(searchResultField.getFieldValue());
183 } else if (searchResultField.getFieldName().equalsIgnoreCase("HoldingsLocation_search") &&
184 (oleLoanDocument.getItemLocation() == null || oleLoanDocument.getItemLocation().isEmpty())) {
185 getLocationBySolr(searchResultField, oleLoanDocument);
186 oleLoanDocument.setItemFullLocation(searchResultField.getFieldValue());
187 } else if (searchResultField.getFieldName().equalsIgnoreCase("claimsReturnedFlagCreateDate")) {
188 String[] formatStrings = new String[]{"MM/dd/yyyy hh:mm:ss", "MM/dd/yyyy", "yyyy-MM-dd hh:mm:ss"};
189 Date date = tryParse(formatStrings, searchResultField.getFieldValue());
190 oleLoanDocument.setClaimsReturnedDate(new Timestamp(date.getTime()));
191
192 } else if (searchResultField.getFieldName().equalsIgnoreCase("dueDateTime")) {
193 String[] formatStrings = new String[]{"MM/dd/yyyy hh:mm:ssa", "MM/dd/yyyy hh:mm:ss", "MM/dd/yyyy", "yyyy-MM-dd hh:mm:ss"};
194 Date date = tryParse(formatStrings, searchResultField.getFieldValue());
195 oleLoanDocument.setLoanDueDate(new Timestamp(date.getTime()));
196
197 } else if (searchResultField.getFieldName().equalsIgnoreCase("CallNumber_display")) {
198 oleLoanDocument.setItemCallNumber(searchResultField.getFieldValue());
199 } else if (searchResultField.getFieldName().equalsIgnoreCase("CallNumberPrefix_display")) {
200 oleLoanDocument.setItemCallNumberPrefix(searchResultField.getFieldValue());
201 } else if (searchResultField.getFieldName().equalsIgnoreCase("HoldingsCallNumberPrefix_display") &&
202 (oleLoanDocument.getItemCallNumberPrefix() == null || oleLoanDocument.getItemCallNumberPrefix().isEmpty())) {
203 oleLoanDocument.setItemCallNumberPrefix(searchResultField.getFieldValue());
204 } else if (searchResultField.getFieldName().equalsIgnoreCase("TemporaryItemTypeFullValue_search")) {
205 oleLoanDocument.setItemType(searchResultField.getFieldValue());
206 } else if (searchResultField.getFieldName().equalsIgnoreCase("ItemTypeFullValue_display") &&
207 (oleLoanDocument.getItemType() == null || oleLoanDocument.getItemType().isEmpty())) {
208 oleLoanDocument.setItemType(searchResultField.getFieldValue());
209 } else if (searchResultField.getFieldName().equalsIgnoreCase("TemporaryItemTypeCodeValue_search")) {
210 oleLoanDocument.setItemTypeName(searchResultField.getFieldValue());
211 } else if (searchResultField.getFieldName().equalsIgnoreCase("ItemTypeCodeValue_display") &&
212 (oleLoanDocument.getItemTypeName() == null || oleLoanDocument.getItemTypeName().isEmpty())) {
213 oleLoanDocument.setItemTypeName(searchResultField.getFieldValue());
214 } else if (searchResultField.getFieldName().equalsIgnoreCase("Enumeration_display")) {
215 oleLoanDocument.setEnumeration(searchResultField.getFieldValue());
216 } else if (searchResultField.getFieldName().equalsIgnoreCase("Chronology_display")) {
217 oleLoanDocument.setChronology(searchResultField.getFieldValue());
218 } else if (searchResultField.getFieldName().equalsIgnoreCase("ItemStatus_display")) {
219 oleLoanDocument.setItemStatus(searchResultField.getFieldValue());
220 } else if (searchResultField.getFieldName().equalsIgnoreCase("ItemDamagedStatus_display")) {
221 oleLoanDocument.setItemDamagedStatus(searchResultField.getFieldValue().equalsIgnoreCase("true"));
222 } else if (searchResultField.getFieldName().equalsIgnoreCase("DamagedItemNote_search")) {
223 oleLoanDocument.setItemDamagedNote(searchResultField.getFieldValue());
224 } else if (searchResultField.getFieldName().equalsIgnoreCase("MissingPieceFlagNote_search")) {
225 oleLoanDocument.setMissingPieceNote(searchResultField.getFieldValue());
226 } else if (searchResultField.getFieldName().equalsIgnoreCase("MissingPieceFlag_display")) {
227 oleLoanDocument.setMissingPieceFlag(searchResultField.getFieldValue().equalsIgnoreCase("true"));
228 } else if (searchResultField.getFieldName().equalsIgnoreCase("CopyNumber_search")) {
229 oleLoanDocument.setItemCopyNumber(searchResultField.getFieldValue());
230 } else if (searchResultField.getFieldName().equalsIgnoreCase("HoldingsCopyNumber_search") &&
231 (oleLoanDocument.getItemCopyNumber() == null || oleLoanDocument.getItemCopyNumber().isEmpty())) {
232 oleLoanDocument.setItemCopyNumber(searchResultField.getFieldValue());
233 } else if (searchResultField.getFieldName().equalsIgnoreCase("HoldingsCallNumber_search") &&
234 (oleLoanDocument.getItemCallNumber() == null || oleLoanDocument.getItemCallNumber().isEmpty())) {
235 oleLoanDocument.setItemCallNumber(searchResultField.getFieldValue());
236 } else if (searchResultField.getFieldName().equalsIgnoreCase("MissingPieceCount_search")) {
237 oleLoanDocument.setMissingPiecesCount(searchResultField.getFieldValue());
238 } else if (searchResultField.getFieldName().equalsIgnoreCase("NumberOfPieces_search")) {
239 oleLoanDocument.setItemNumberOfPieces(Integer.parseInt(searchResultField.getFieldValue()));
240 oleLoanDocument.setBackUpNoOfPieces(searchResultField.getFieldValue());
241 } else if (searchResultField.getFieldName().equalsIgnoreCase("proxyBorrower")) {
242 oleLoanDocument.setRealPatronName(searchResultField.getFieldValue());
243 } else if (searchResultField.getFieldName().equalsIgnoreCase("MissingPieceFlag_display")) {
244 oleLoanDocument.setMissingPieceFlag(Boolean.parseBoolean(searchResultField.getFieldValue()));
245 } else if (searchResultField.getFieldName().equalsIgnoreCase("NumberOfRenew_display")) {
246 oleLoanDocument.setNumberOfRenewals(searchResultField.getFieldValue());
247 } else if (searchResultField.getFieldName().equalsIgnoreCase("checkOutDateTime")) {
248 SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
249 Date date = formatter.parse(searchResultField.getFieldValue());
250 oleLoanDocument.setCreateDate(date);
251 }
252 }
253 }
254 if (oleLoanDocument.getOlePatron() != null) {
255 oleLoanDocument.getOlePatron().setNumberOfClaimsReturned(count);
256 }
257 if (oleLoanDocument.getItemCallNumber() != null && oleLoanDocument.getItemCallNumberPrefix() != null) {
258 oleLoanDocument.setItemCallNumber(oleLoanDocument.getItemCallNumberPrefix() + "-" + oleLoanDocument.getItemCallNumber());
259 }
260 oleLoanDocuments.add(oleLoanDocument);
261 }
262
263 }
264 return oleLoanDocuments;
265 }
266
267 public void getLocationBySolr(SearchResultField searchResultField, OleLoanDocument oleLoanDocument) throws Exception {
268 String locationCode = searchResultField.getFieldValue().split("/")[searchResultField.getFieldValue().split("/").length - 1];
269 String levelFullName = "";
270 if (locationName.containsKey(locationCode)) {
271 levelFullName = locationName.get(locationCode);
272 } else {
273 OleLocation oleLocation = getCircDeskLocationResolver().getLocationByLocationCode(locationCode);
274 levelFullName = getCircDeskLocationResolver().getFullPathLocationByName(oleLocation);
275 locationName.put(locationCode, levelFullName);
276 }
277
278 oleLoanDocument.setItemLocation(levelFullName);
279 oleLoanDocument.setLocation(levelFullName);
280 }
281
282 public Date tryParse(String[] formatStrings, String dateString) throws ParseException {
283 StringBuffer exceptionMessage = new StringBuffer("Parse Exception'");
284 for (String formatString : formatStrings) {
285 try {
286 return new SimpleDateFormat(formatString).parse(dateString);
287 } catch (ParseException e) {
288 exceptionMessage.append(e.getMessage());
289 }
290 }
291 throw new ParseException(exceptionMessage.toString(), 0);
292 }
293
294 public List<OleLoanDocument> sortLoanDocumentByDueDate(List<OleLoanDocument> loanDocuments) {
295 List<OleLoanDocument> LoanDocumentList = new ArrayList<>();
296 List<OleLoanDocument> indefiniteLoanDocumentList = new ArrayList<>();
297 for (OleLoanDocument loanDoc : loanDocuments) {
298 if (loanDoc.getLoanDueDate() != null && !(loanDoc.getLoanDueDate().toString().isEmpty())) {
299 LoanDocumentList.add(loanDoc);
300 } else {
301
302 indefiniteLoanDocumentList.add(loanDoc);
303 }
304 }
305 Collections.sort(LoanDocumentList, new Comparator<OleLoanDocument>() {
306 public int compare(OleLoanDocument o1, OleLoanDocument o2) {
307 return o1.getLoanDueDate().compareTo(o2.getLoanDueDate());
308 }
309 });
310 LoanDocumentList.addAll(indefiniteLoanDocumentList);
311 return LoanDocumentList;
312 }
313
314
315 public DocstoreClientLocator getDocstoreClientLocator() {
316 if (docstoreClientLocator == null) {
317 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
318
319 }
320 return docstoreClientLocator;
321 }
322
323 public BusinessObjectService getBusinessObjectService() {
324 if (null == businessObjectService) {
325 businessObjectService = KRADServiceLocator.getBusinessObjectService();
326 }
327 return businessObjectService;
328 }
329
330 private CircDeskLocationResolver getCircDeskLocationResolver() {
331 if (circDeskLocationResolver == null) {
332 circDeskLocationResolver = new CircDeskLocationResolver();
333 }
334 return circDeskLocationResolver;
335 }
336
337 public ItemOlemlRecordProcessor getItemOlemlRecordProcessor() {
338 if (itemOlemlRecordProcessor == null) {
339 itemOlemlRecordProcessor = SpringContext.getBean(ItemOlemlRecordProcessor.class);
340 }
341 return itemOlemlRecordProcessor;
342 }
343
344
345
346
347
348
349
350
351
352 public List<OleTemporaryCirculationHistory> getPatronTemporaryCirculationHistoryRecords(String patronId) {
353 LOG.debug("Inside the getPatronTemporaryCirculationHistoryRecords method");
354 Map barMap = new HashMap();
355 barMap.put("olePatronId", patronId);
356 List<OleTemporaryCirculationHistory> matchingLoan = (List<OleTemporaryCirculationHistory>) getBusinessObjectService().findMatching(OleTemporaryCirculationHistory.class, barMap);
357 for (int itemid = 0; itemid < matchingLoan.size(); itemid++) {
358 String itemUuid = matchingLoan.get(itemid).getItemUuid();
359 org.kuali.ole.docstore.common.document.Item item = null;
360 try {
361 item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(itemUuid);
362
363 org.kuali.ole.docstore.common.document.content.instance.Item itemContent = getItemOlemlRecordProcessor().fromXML(item.getContent());
364 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
365 OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(item.getHolding().getContent());
366 OleTemporaryCirculationHistory oleTemporaryCirculationHistory = matchingLoan.get(itemid);
367 if (oleTemporaryCirculationHistory.getItemUuid().equals(item.getId())) {
368 oleTemporaryCirculationHistory.setTitle(item.getHolding().getBib().getTitle());
369 oleTemporaryCirculationHistory.setAuthor(item.getHolding().getBib().getAuthor());
370 oleTemporaryCirculationHistory.setItemUuid(item.getId());
371 oleTemporaryCirculationHistory.setCallNumber(getItemCallNumber(itemContent.getCallNumber(), oleHoldings.getCallNumber()));
372 oleTemporaryCirculationHistory.setCopyNumber(itemContent.getCopyNumber());
373 oleTemporaryCirculationHistory.setVolumeNumber(itemContent.getVolumeNumber());
374 oleTemporaryCirculationHistory.setItemStatus(itemContent.getItemStatus().getFullValue());
375 oleTemporaryCirculationHistory.setItemType(itemContent.getItemType().getCodeValue());
376
377 OleCirculationDesk val = getCircDeskLocationResolver().getOleCirculationDesk(oleTemporaryCirculationHistory.getCirculationLocationId());
378 if (val != null) {
379 oleTemporaryCirculationHistory.setCirculationLocationCode(val.getCirculationDeskCode());
380 }
381 if (oleTemporaryCirculationHistory.getCirculationLocationId() != null && !oleTemporaryCirculationHistory.getCirculationLocationId().equals("")) {
382 LocationValuesBuilder locationValuesBuilder = new LocationValuesBuilder();
383 locationValuesBuilder.getLocation(itemContent, oleTemporaryCirculationHistory, item.getHolding().getId());
384 }
385 }
386 } catch (Exception e) {
387 LOG.error("Error while looking up temp circ history records.");
388 LOG.error(e.getStackTrace());
389
390 }
391
392 }
393 return matchingLoan;
394 }
395
396 public String getItemCallNumber(org.kuali.ole.docstore.common.document.content.instance.Item oleItem, String instanceUUID) throws Exception {
397 OleHoldings oleHoldings = getOleHoldings(instanceUUID);
398 return getItemCallNumber(oleItem.getCallNumber(), oleHoldings.getCallNumber());
399 }
400
401
402
403
404
405
406
407
408 public String getItemCallNumber(CallNumber itemCallNumber, CallNumber holdingCallNumber) throws Exception {
409 LOG.debug("Inside the getItemCallNumber method");
410 String callNumber = "";
411
412 if (itemCallNumber != null && StringUtils.isNotBlank(itemCallNumber.getType())) {
413 callNumber += itemCallNumber.getType() + OLEConstants.DELIMITER_DASH;
414 } else if (holdingCallNumber != null && StringUtils.isNotBlank(holdingCallNumber.getType())) {
415 callNumber += holdingCallNumber.getType() + OLEConstants.DELIMITER_DASH;
416 }
417 if (itemCallNumber != null && StringUtils.isNotBlank(itemCallNumber.getPrefix())) {
418 callNumber += itemCallNumber.getPrefix() + OLEConstants.DELIMITER_DASH;
419 } else if (holdingCallNumber != null && StringUtils.isNotBlank(holdingCallNumber.getPrefix())) {
420 callNumber += holdingCallNumber.getPrefix() + OLEConstants.DELIMITER_DASH;
421 }
422 if (itemCallNumber != null && StringUtils.isNotBlank(itemCallNumber.getNumber())) {
423 callNumber += itemCallNumber.getNumber();
424 } else if (holdingCallNumber != null && StringUtils.isNotBlank(holdingCallNumber.getNumber())) {
425 callNumber += holdingCallNumber.getNumber();
426 }
427
428 return callNumber;
429 }
430
431
432
433
434
435
436
437
438 public OleHoldings getOleHoldings(String instanceUUID) throws Exception {
439 LOG.debug("--Inside getOleHoldings---");
440 Holdings holdings = new Holdings();
441 holdings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(instanceUUID);
442 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
443 OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
444 return oleHoldings;
445 }
446
447
448 }