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