1 package org.kuali.ole.serviceimpl;
2
3 import org.apache.solr.client.solrj.SolrServerException;
4 import org.kuali.ole.OLESruItemHandler;
5 import org.kuali.ole.OleSRUConstants;
6 import org.kuali.ole.bo.diagnostics.OleSRUDiagnostics;
7 import org.kuali.ole.bo.serachRetrieve.*;
8 import org.kuali.ole.docstore.common.client.DocstoreClient;
9 import org.kuali.ole.docstore.common.document.Bib;
10 import org.kuali.ole.docstore.common.document.HoldingsTree;
11 import org.kuali.ole.docstore.common.document.content.bib.dc.BibDcRecord;
12 import org.kuali.ole.docstore.common.document.content.bib.dc.DCValue;
13 import org.kuali.ole.docstore.common.document.content.bib.dc.xstream.BibDcRecordProcessor;
14 import org.kuali.ole.docstore.common.document.content.instance.*;
15 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
16 import org.kuali.ole.docstore.common.document.content.instance.xstream.InstanceOlemlRecordProcessor;
17 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
18 import org.kuali.ole.docstore.discovery.service.SRUCQLQueryService;
19 import org.kuali.ole.docstore.discovery.service.SRUCQLQueryServiceImpl;
20 import org.kuali.ole.docstore.engine.client.DocstoreLocalClient;
21 import org.kuali.ole.docstore.model.bo.OleDocument;
22 import org.kuali.ole.docstore.model.bo.WorkBibDocument;
23 import org.kuali.ole.docstore.model.bo.WorkInstanceDocument;
24 import org.kuali.ole.docstore.service.OleWebServiceProvider;
25 import org.kuali.ole.docstore.service.impl.OleWebServiceProviderImpl;
26 import org.kuali.ole.handler.OleSRUDublinRecordResponseHandler;
27 import org.kuali.ole.handler.OleSRUOpacXMLResponseHandler;
28 import org.kuali.ole.pojo.OLESruItem;
29 import org.kuali.ole.service.OleDiagnosticsService;
30 import org.kuali.ole.service.OleLoanDocumentWebService;
31 import org.kuali.ole.service.OleSRUDataService;
32 import org.kuali.rice.core.api.config.property.ConfigContext;
33 import org.kuali.rice.core.api.criteria.QueryByCriteria;
34 import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
35 import org.kuali.rice.krad.service.KRADServiceLocator;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 import java.util.*;
40
41
42
43
44
45
46
47
48
49 public class OleSRUDataServiceImpl implements OleSRUDataService {
50
51 private Logger LOG = LoggerFactory.getLogger(this.getClass());
52 public SRUCQLQueryService srucqlQueryService;
53 public OleDiagnosticsService oleDiagnosticsService;
54 private DocstoreClient docstoreClient;
55
56 private HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
57 private InstanceOlemlRecordProcessor instanceOlemlRecordProcessor = new InstanceOlemlRecordProcessor();
58 private ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
59 private OLESruItemHandler oleSruItemHandler;
60
61 public OleSRUDataServiceImpl() {
62 srucqlQueryService = SRUCQLQueryServiceImpl.getInstance();
63 oleDiagnosticsService = new OleDiagnosticsServiceImpl();
64 }
65
66 public OLESruItemHandler getOleSruItemHandler(){
67 if(oleSruItemHandler == null){
68 oleSruItemHandler = new OLESruItemHandler();
69 }
70 return oleSruItemHandler;
71 }
72
73
74
75
76
77
78
79
80 public List getBibRecordsIdList(Map reqParamMap, String solrQuery) {
81 LOG.info("Inside getBibRecordsIdList method");
82 List oleBibIDList = null;
83 List<OleDocument> oleDocumentsList = null;
84 try {
85 oleBibIDList = new ArrayList();
86 oleDocumentsList = (ArrayList<OleDocument>) srucqlQueryService.queryForBibDocs(reqParamMap, solrQuery);
87 if ((oleDocumentsList != null) && (oleDocumentsList.size() > 0)) {
88 oleBibIDList = generateBibIDList(oleDocumentsList);
89 }
90 } catch (Exception e) {
91 LOG.error(e.getMessage());
92 if(e instanceof SolrServerException){
93 if(solrQuery.contains("LocalId"))
94 oleBibIDList.add("Invalid Local Id");
95 else
96 oleBibIDList.add("Exception Occured");
97
98 return oleBibIDList;
99 } else
100 return null;
101 }
102 return oleBibIDList;
103 }
104
105
106
107
108
109
110
111
112 public String getOPACXMLSearchRetrieveResponse(List oleBibIDList, Map reqParamMap) {
113 LOG.info("Inside getOPACXMLSearchRetrieveResponse method");
114 try {
115 OleSRUOpacXMLResponseHandler oleSRUOpacXMLResponseHandler = new OleSRUOpacXMLResponseHandler();
116 OleSRUSearchRetrieveResponse oleSRUSearchRetrieveResponse = new OleSRUSearchRetrieveResponse();
117 oleSRUSearchRetrieveResponse.setVersion((String) reqParamMap.get(OleSRUConstants.VERSION));
118 OleSRUResponseRecords oleSRUResponseRecords = new OleSRUResponseRecords();
119 List<OleSRUResponseRecord> oleSRUResponseRecordList = new ArrayList<OleSRUResponseRecord>();
120 if (oleBibIDList != null && oleBibIDList.size() > 0) {
121 List<OleSRUResponseDocument> oleSRUResponseDocumentList = new ArrayList<OleSRUResponseDocument>();
122 String bibRecordInfo = null;
123 int startPosition = 0;
124 if ((Integer) reqParamMap.get(OleSRUConstants.START_RECORD) != 0) {
125 startPosition = (Integer) reqParamMap.get(OleSRUConstants.START_RECORD);
126 }
127 for (int i = 0; i < oleBibIDList.size(); i++) {
128 OleSRUResponseRecord oleSRUResponseRecord = new OleSRUResponseRecord();
129 oleSRUResponseRecord.setRecordPacking((String) reqParamMap.get(OleSRUConstants.RECORD_PACKING));
130 if ((Integer) reqParamMap.get(OleSRUConstants.START_RECORD) == 0) {
131 oleSRUResponseRecord.setRecordPosition(i + 1);
132 } else {
133 oleSRUResponseRecord.setRecordPosition(startPosition + 1);
134 startPosition = startPosition + 1;
135 }
136 OleSRUResponseDocument oleSRUResponseDocument = new OleSRUResponseDocument();
137 OleSRUData oleSRUData = (OleSRUData) oleBibIDList.get(i);
138 bibRecordInfo = getBibliographicRecordInfo(oleSRUData.getBibId());
139 OleSRUResponseRecordData oleSRUResponseRecordData = new OleSRUResponseRecordData();
140 String recordSchema= (String)reqParamMap.get(OleSRUConstants.RECORD_SCHEMA);
141 if (recordSchema.equalsIgnoreCase(OleSRUConstants.OPAC_RECORD)) {
142 List<OleSRUInstanceDocument> oleSRUInstanceDocumentList = new ArrayList<OleSRUInstanceDocument>();
143 if (oleSRUData.getInstanceIds() != null && oleSRUData.getInstanceIds().size() > 0) {
144 for (String instance : oleSRUData.getInstanceIds()) {
145 String holdingInfo = getInstanceInfoRecordInfo(instance);
146 OleSRUInstanceDocument oleSRUInstanceDocument = processInstanceCollectionXml(holdingInfo);
147 oleSRUInstanceDocumentList.add(oleSRUInstanceDocument);
148 }
149 }
150 oleSRUResponseRecordData.setHoldings(oleSRUInstanceDocumentList);
151 }
152
153 if (((String) reqParamMap.get(OleSRUConstants.RECORD_SCHEMA)).equalsIgnoreCase(OleSRUConstants.DUBLIN_RECORD_SCHEMA)) {
154 String dublinRecordInfo = null;
155 BibDcRecordProcessor qualifiedDublinRecordHandler = new BibDcRecordProcessor();
156 BibDcRecord workBibDublinRecord = qualifiedDublinRecordHandler.fromXML(bibRecordInfo);
157 OleSRUDublinRecord oleSRUDublinRecord = new OleSRUDublinRecord();
158 for (DCValue dcValue : workBibDublinRecord.getDcValues()) {
159 oleSRUDublinRecord.put(dcValue.getElement(), dcValue.getValue());
160 }
161 OleSRUDublinRecordResponseHandler oleSRUDublinRecordResponseHandler = new OleSRUDublinRecordResponseHandler();
162 String dublinInfo = oleSRUDublinRecordResponseHandler.toXML(oleSRUDublinRecord);
163 oleSRUResponseRecordData.setBibliographicRecord(dublinInfo);
164 oleSRUResponseDocument.setOleSRUResponseRecordData(oleSRUResponseRecordData);
165 } else {
166 oleSRUResponseRecordData.setBibliographicRecord(bibRecordInfo);
167 oleSRUResponseDocument.setOleSRUResponseRecordData(oleSRUResponseRecordData);
168 }
169 oleSRUSearchRetrieveResponse.setNumberOfRecords((Long) (reqParamMap.get(OleSRUConstants.NUMBER_OF_REORDS)));
170 if(recordSchema == null ||(recordSchema!=null && (recordSchema.equalsIgnoreCase(OleSRUConstants.MARC) || recordSchema.equalsIgnoreCase(OleSRUConstants.MARC_SCHEMA)))){
171 oleSRUResponseRecord.setRecordSchema(OleSRUConstants.MARC_RECORD_RESPONSE_SCHEMA);
172 }else if(recordSchema!=null && recordSchema!=null && recordSchema.equalsIgnoreCase(OleSRUConstants.DC_SCHEMA)){
173 oleSRUResponseRecord.setRecordSchema(OleSRUConstants.DC_RECORD_RESPONSE_SCHEMA);
174 }else if(recordSchema!=null && recordSchema.equalsIgnoreCase(OleSRUConstants.OPAC_RECORD)){
175 oleSRUResponseRecord.setRecordSchema(OleSRUConstants.OPAC_RECORD_RESPONSE_SCHEMA);
176 }
177 if (reqParamMap.containsKey(OleSRUConstants.EXTRA_REQ_DATA_KEY))
178 oleSRUResponseRecordData.setExtraRequestData(getExtraReqDataInfo(reqParamMap));
179 oleSRUResponseRecord.setOleSRUResponseDocument(oleSRUResponseDocument);
180 oleSRUResponseRecordList.add(oleSRUResponseRecord);
181 }
182 oleSRUResponseRecords.setOleSRUResponseRecordList(oleSRUResponseRecordList);
183 oleSRUSearchRetrieveResponse.setOleSRUResponseRecords(oleSRUResponseRecords);
184 int maxRecords = (Integer) reqParamMap.get(OleSRUConstants.MAXIMUM_RECORDS);
185 if (maxRecords == 0) {
186 oleSRUSearchRetrieveResponse = new OleSRUSearchRetrieveResponse();
187 oleSRUSearchRetrieveResponse.setVersion((String) reqParamMap.get(OleSRUConstants.VERSION));
188 oleSRUSearchRetrieveResponse.setNumberOfRecords((Long) (reqParamMap.get(OleSRUConstants.NUMBER_OF_REORDS)));
189 String xml = oleSRUOpacXMLResponseHandler.toXML(oleSRUSearchRetrieveResponse,(String)reqParamMap.get(OleSRUConstants.RECORD_SCHEMA));
190 return xml;
191 }
192 if (OleSRUConstants.RECORD_PACK_XML.equalsIgnoreCase((String) reqParamMap.get(OleSRUConstants.RECORD_PACKING))) {
193 String opacXML = oleSRUOpacXMLResponseHandler.toXML(oleSRUSearchRetrieveResponse,(String)reqParamMap.get(OleSRUConstants.RECORD_SCHEMA));
194 if (null != opacXML)
195 opacXML = replaceStringWithSymbols(opacXML);
196 return opacXML;
197 } else if (OleSRUConstants.RECORD_PACK_STRING.equalsIgnoreCase((String) reqParamMap.get(OleSRUConstants.RECORD_PACKING))) {
198 return oleSRUSearchRetrieveResponse.toString();
199 }
200 }
201 Long numberOfRecords = (Long) (reqParamMap.get(OleSRUConstants.NUMBER_OF_REORDS));
202 oleSRUSearchRetrieveResponse.setNumberOfRecords(numberOfRecords);
203 OleSRUDiagnostics oleSRUDiagnostics = null;
204 if (numberOfRecords > 0) {
205 oleSRUDiagnostics = oleDiagnosticsService.getDiagnosticResponse(ConfigContext.getCurrentContextConfig().getProperty(OleSRUConstants.START_RECORD_UNMATCH));
206 } else {
207 oleSRUDiagnostics = oleDiagnosticsService.getDiagnosticResponse(ConfigContext.getCurrentContextConfig().getProperty(OleSRUConstants.NORECORDS_DIAGNOSTIC_MSG));
208 }
209 int start = (Integer) reqParamMap.get(OleSRUConstants.START_RECORD);
210 if(start > numberOfRecords){
211 oleSRUDiagnostics = oleDiagnosticsService.getDiagnosticResponse(ConfigContext.getCurrentContextConfig().getProperty(OleSRUConstants.START_RECORD_UNMATCH));
212 }
213 oleSRUSearchRetrieveResponse.setOleSRUDiagnostics(oleSRUDiagnostics);
214 return oleSRUOpacXMLResponseHandler.toXML(oleSRUSearchRetrieveResponse,(String)reqParamMap.get(OleSRUConstants.RECORD_SCHEMA));
215 } catch (Exception e) {
216 LOG.error(e.getMessage() , e );
217 }
218 return null;
219 }
220
221
222
223
224
225
226
227 public List generateBibIDList(List<OleDocument> oleDocumentsList) {
228 LOG.info("Inside generateBibIDList method");
229 List oleBibIDList = new ArrayList();
230 WorkBibDocument workBibDocument = null;
231 List<OleSRUData> oleSRUDataList = new ArrayList<OleSRUData>();
232 OleSRUData oleSRUData = null;
233 for (int i = 0; i < oleDocumentsList.size(); i++) {
234 workBibDocument = (WorkBibDocument) oleDocumentsList.get(i);
235 oleSRUData = new OleSRUData();
236 oleSRUData.setBibId(workBibDocument.getId());
237 List<String> instanceList = new ArrayList<String>();
238 if (workBibDocument.getWorkInstanceDocumentList() != null) {
239 for (WorkInstanceDocument workInstanceDocument : workBibDocument.getWorkInstanceDocumentList()) {
240 instanceList.add(workInstanceDocument.getInstanceIdentifier());
241 }
242 }
243 oleSRUData.setInstanceIds(instanceList);
244 oleSRUDataList.add(oleSRUData);
245 }
246 return oleSRUDataList;
247 }
248
249
250
251
252
253
254
255 public String getBibliographicRecordInfo(String uuid) {
256 LOG.info("Inside getBibliographicRecordInfo method");
257 String bibRecordInfo = null;
258
259 Bib bib = getDocstoreClient().retrieveBib(uuid);
260 bibRecordInfo = bib.getContent();
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296 return bibRecordInfo;
297 }
298
299
300 public String getInstanceInfoRecordInfo(String uuid) {
301 String instanceXml = "";
302 InstanceCollection instanceCollection = new InstanceCollection();
303 HoldingsTree holdingsTree = getDocstoreClient().retrieveHoldingsTree(uuid);
304 OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdingsTree.getHoldings().getContent());
305 Items items = new Items();
306 for(org.kuali.ole.docstore.common.document.Item itemDoc : holdingsTree.getItems()) {
307 items.getItem().add(itemOlemlRecordProcessor.fromXML(itemDoc.getContent()));
308 }
309 Instance instance = new Instance();
310 instance.setOleHoldings(oleHoldings);
311 instance.setItems(items);
312 instanceCollection.getInstance().add(instance);
313 instanceXml = instanceOlemlRecordProcessor.toXML(instanceCollection);
314 return instanceXml;
315 }
316
317
318
319
320
321
322
323 private String replaceStringWithSymbols(String opacXML) {
324 LOG.info("Inside replaceStringWithSymbols method");
325 opacXML = opacXML.replaceAll("<", "<");
326 opacXML = opacXML.replaceAll(">", ">");
327 opacXML = opacXML.replaceAll(""", "\"");
328 opacXML = opacXML.replaceAll("'", "\'");
329
330
331 return opacXML;
332 }
333
334 public List<OleSRUInstanceDocument> getOleSRUInstanceDocument() {
335 LOG.info("Inside getOleSRUInstanceDocument method");
336 OleSRUInstanceDocument oleSRUInstanceDocument = new OleSRUInstanceDocument();
337 List<OleSRUInstanceDocument> oleSRUInstanceDocumentList = new ArrayList<OleSRUInstanceDocument>();
338 List<OleSRUCirculationDocument> oleSRUCirculationDocumentList = getOleSRUCirculationDocument();
339 List<OleSRUInstanceVolume> oleSRUInstanceVolumeList = getOleSRUInstanceVolumes();
340 oleSRUInstanceDocument.setCallNumber("mockCallNumber");
341 oleSRUInstanceDocument.setCompleteness("mockCompleteness");
342 oleSRUInstanceDocument.setCopyNumber("mockCopyNumber");
343 oleSRUInstanceDocument.setDateOfReport("mockDateOfReport");
344 oleSRUInstanceDocument.setEncodingLevel("mockEncodingLevel");
345 oleSRUInstanceDocument.setEnumAndChron("mockEnumAndChorn");
346 oleSRUInstanceDocument.setFormat("mockFormat");
347 oleSRUInstanceDocument.setGeneralRetention("mockGeneralRentention");
348 oleSRUInstanceDocument.setLocalLocation("mockLocalLocation");
349 oleSRUInstanceDocument.setTypeOfRecord("mockTypeOfRecord");
350 oleSRUInstanceDocument.setShelvingLocation("mockShelvingLocation");
351 oleSRUInstanceDocument.setShelvingData("mockShelvingData");
352 oleSRUInstanceDocument.setReproductionNote("mockReproductionNote");
353 oleSRUInstanceDocument.setReceiptAcqStatus("mockReceiptAcqStatus");
354 oleSRUInstanceDocument.setNucCode("mockNucCode");
355 oleSRUInstanceDocument.setPublicNote("mockPublicNote");
356 oleSRUInstanceDocument.setCirculations(oleSRUCirculationDocumentList);
357 oleSRUInstanceDocument.setVolumes(oleSRUInstanceVolumeList);
358 oleSRUInstanceDocumentList.add(oleSRUInstanceDocument);
359 return oleSRUInstanceDocumentList;
360 }
361
362 public List<OleSRUCirculationDocument> getOleSRUCirculationDocument() {
363 LOG.info("Inside getOleSRUCirculationDocument method");
364 OleSRUCirculationDocument oleSRUCirculationDocument = new OleSRUCirculationDocument();
365 List<OleSRUCirculationDocument> oleSRUCirculationDocumentList = new ArrayList<OleSRUCirculationDocument>();
366 oleSRUCirculationDocument.setAvailabilityDate("mockAvailabilityDate");
367 oleSRUCirculationDocument.setAvailableNow("mockAvailableNow");
368 oleSRUCirculationDocument.setAvailableThru("mockAvailableThru");
369 oleSRUCirculationDocument.setEnumAndChron("mockEnumAndChron");
370 oleSRUCirculationDocument.setItemId("mockItemId");
371 oleSRUCirculationDocument.setMidspine("mockMidspine");
372 oleSRUCirculationDocument.setOnHold("mockOnHold");
373
374 oleSRUCirculationDocument.setRestrictions("mockRestrictions");
375 oleSRUCirculationDocument.setTemporaryLocation("mockTemporaryLocation");
376 oleSRUCirculationDocumentList.add(oleSRUCirculationDocument);
377 return oleSRUCirculationDocumentList;
378 }
379
380 public List<OleSRUInstanceVolume> getOleSRUInstanceVolumes() {
381 LOG.info("Inside getOleSRUInstanceVolumes method");
382 OleSRUInstanceVolume oleSRUInstanceVolume = new OleSRUInstanceVolume();
383 List<OleSRUInstanceVolume> oleSRUInstanceVolumeList = new ArrayList<OleSRUInstanceVolume>();
384 oleSRUInstanceVolume.setChronology("mockChronology");
385 oleSRUInstanceVolume.setEnumAndChron("mockEnumAndChron");
386 oleSRUInstanceVolume.setEnumeration("mockEnumeration");
387 oleSRUInstanceVolumeList.add(oleSRUInstanceVolume);
388 return oleSRUInstanceVolumeList;
389 }
390
391 public String getExtraReqDataInfo(Map reqParamMap) {
392 LOG.info("Inside getExtraReqDataInfo method");
393 return "<theo:" + reqParamMap.get(OleSRUConstants.EXTRA_REQ_DATA_KEY) + " xmlns:theo=\"" + ConfigContext.getCurrentContextConfig().getProperty(OleSRUConstants.EXTRA_REQ_DATA_XML_NAMESPACE) + "\">\n" +
394 reqParamMap.get(OleSRUConstants.EXTRA_REQ_DATA_VALUE) + "\n" +
395 "</theo:" + reqParamMap.get(OleSRUConstants.EXTRA_REQ_DATA_KEY) + ">";
396 }
397
398 public OleSRUInstanceDocument processInstanceCollectionXml(String instanceXml) {
399 LOG.info("Inside processInstanceCollectionXml method");
400 String sruTrueValue = getParameter(OleSRUConstants.BOOLEAN_FIELD_TRUE_FORMAT);
401 String sruFalseValue = getParameter(OleSRUConstants.BOOLEAN_FIELD_FALSE_FORMAT);
402 InstanceOlemlRecordProcessor instanceOlemlRecordProcessor = new InstanceOlemlRecordProcessor();
403 InstanceCollection instanceCollection = instanceOlemlRecordProcessor.fromXML(instanceXml);
404 OleSRUInstanceDocument oleSRUInstanceDocument = null;
405 if (instanceCollection != null) {
406 List<Instance> instances = instanceCollection.getInstance();
407 if (instances != null && instances.size() > 0) {
408 for (Instance instance : instances) {
409 oleSRUInstanceDocument = new OleSRUInstanceDocument();
410 if (instance.getOleHoldings() != null && instance.getOleHoldings().getCallNumber() != null) {
411 oleSRUInstanceDocument.setCallNumber(instance.getOleHoldings().getCallNumber().getNumber());
412 oleSRUInstanceDocument.setShelvingData(instance.getOleHoldings().getCallNumber().getPrefix());
413 }
414 if (instance.getOleHoldings() != null) {
415 oleSRUInstanceDocument.setReceiptAcqStatus(instance.getOleHoldings().getReceiptStatus());
416 }
417 if (instance.getOleHoldings().getLocation() != null) {
418 oleSRUInstanceDocument.setLocalLocation(getLocations(instance.getOleHoldings().getLocation(), OleSRUConstants.LOCAL_LOCATION));
419 oleSRUInstanceDocument.setShelvingLocation(getLocations(instance.getOleHoldings().getLocation(), OleSRUConstants.SHELVING_LOCATION));
420 }
421 Items items = instance.getItems();
422 List<OleSRUInstanceVolume> oleSRUInstanceVolumeList = new ArrayList<OleSRUInstanceVolume>();
423 List<OleSRUCirculationDocument> oleSRUCirculationDocumentList = new ArrayList<OleSRUCirculationDocument>();
424 if (items != null) {
425 List<Item> itemList = items.getItem();
426
427 for(int i=0;i<itemList.size();i++){
428 Item item = itemList.get(i);
429
430 if (item != null) {
431 oleSRUInstanceDocument.setCopyNumber(item.getCopyNumber());
432 }
433 OleSRUInstanceVolume oleSRUInstanceVolume = new OleSRUInstanceVolume();
434 oleSRUInstanceVolume.setChronology(item.getChronology());
435 oleSRUInstanceVolume.setEnumeration(item.getEnumeration());
436 if (item.getEnumeration() != null && item.getChronology() != null) {
437 oleSRUInstanceVolume.setEnumAndChron(item.getEnumeration() + "," + item.getChronology());
438 }
439 oleSRUInstanceVolumeList.add(oleSRUInstanceVolume);
440 OleSRUCirculationDocument oleSRUCirculationDocument = new OleSRUCirculationDocument();
441 oleSRUCirculationDocument.setItemId(item.getBarcodeARSL());
442 StringBuffer locationName = new StringBuffer();
443 if (item.getLocation() != null) {
444 buildLocationNameAndLocationLevel(item.getLocation(), locationName);
445 }
446
447
448
449 if (item.getItemStatus() != null && item.getItemStatus().getCodeValue().equalsIgnoreCase(OleSRUConstants.ITEM_STATUS_AVAILABLE)) {
450 oleSRUCirculationDocument.setAvailableNow(sruTrueValue);
451 } else {
452 oleSRUCirculationDocument.setAvailableNow(sruFalseValue);
453 }
454 if (item.getItemStatus() != null && item.getItemStatus().getCodeValue().equalsIgnoreCase(OleSRUConstants.ITEM_STATUS_ONHOLD)) {
455 oleSRUCirculationDocument.setOnHold(sruTrueValue);
456 } else {
457 oleSRUCirculationDocument.setOnHold(sruFalseValue);
458 }
459 OleWebServiceProvider oleWebServiceProvider = new OleWebServiceProviderImpl();
460 String url = ConfigContext.getCurrentContextConfig().getProperty("oleLoanWebService.url");
461 OleLoanDocumentWebService oleLoanDocumentService = (OleLoanDocumentWebService) oleWebServiceProvider.getService("org.kuali.ole.service.OleLoanDocumentWebService", "oleLoanWebService", url);
462 String shelvingLocation = "";
463 if (item.getLocation() != null) {
464 shelvingLocation = getShelvingLocation(item.getLocation());
465 }
466 String itemTypeCode = "";
467 if (item.getItemType() != null) {
468 itemTypeCode = item.getItemType().getCodeValue();
469 }
470 String sruItemContent;
471 OLESruItem oleSruItem;
472 if (i == 0) {
473 if (instance.getOleHoldings().getLocation() != null) {
474 sruItemContent = oleLoanDocumentService.getItemInformation(item.getItemIdentifier(), itemTypeCode, shelvingLocation, getLocations(instance.getOleHoldings().getLocation(), OleSRUConstants.SHELVING_LOCATION), getLocations(instance.getOleHoldings().getLocation(), OleSRUConstants.LOCAL_LOCATION));
475 oleSruItem = (OLESruItem) getOleSruItemHandler().getObjectFromXml(sruItemContent, (Object) new OLESruItem());
476 if(oleSruItem!=null) {
477 oleSRUInstanceDocument.setLocalLocation(oleSruItem.getLocalLocation());
478 oleSRUInstanceDocument.setShelvingLocation(oleSruItem.getShelvingLocation());
479 String sruIsRenewable = oleSruItem.isRenewable() ? sruTrueValue : sruFalseValue;
480 oleSRUCirculationDocument.setRenewable(sruIsRenewable);
481 oleSRUCirculationDocument.setAvailabilityDate(oleSruItem.getItemDueDate());
482 }
483 } else{
484
485 sruItemContent = oleLoanDocumentService.getItemInformation(item.getItemIdentifier(),itemTypeCode,shelvingLocation,null,null);
486 oleSruItem = (OLESruItem)getOleSruItemHandler().getObjectFromXml(sruItemContent,(Object)new OLESruItem());
487 if(oleSruItem!=null){
488 String sruIsRenewable = oleSruItem.isRenewable() ? sruTrueValue : sruFalseValue;
489 oleSRUCirculationDocument.setRenewable(sruIsRenewable);
490 oleSRUCirculationDocument.setAvailabilityDate(oleSruItem.getItemDueDate());
491 }
492 }
493 }
494 oleSRUCirculationDocumentList.add(oleSRUCirculationDocument);
495 if (item.getEnumeration() != null && item.getChronology() != null) {
496 oleSRUCirculationDocument.setEnumAndChron(item.getEnumeration() + "," + item.getChronology());
497 }
498 if(item.getAccessInformation()!= null && item.getAccessInformation().getBarcode() != null){
499 oleSRUCirculationDocument.setItemId(item.getAccessInformation().getBarcode());
500 }
501 if(item.getItemType() !=null && item.getItemType().getFullValue()!=null){
502 oleSRUCirculationDocument.setRestrictions(item.getItemType().getFullValue());
503 oleSRUCirculationDocument.setAvailableThru(item.getItemType().getFullValue());
504 }
505 }
506 }
507 oleSRUInstanceDocument.setVolumes(oleSRUInstanceVolumeList);
508 oleSRUInstanceDocument.setCirculations(oleSRUCirculationDocumentList);
509 }
510 }
511 }
512 return oleSRUInstanceDocument;
513 }
514
515 private void buildLocationNameAndLocationLevel(Location location, StringBuffer locationName) {
516 if (location.getLocationLevel() != null) {
517 locationName = locationName.append(location.getLocationLevel().getName());
518
519 if (location.getLocationLevel().getLocationLevel() != null) {
520 locationName = locationName.append("/").append(location.getLocationLevel().getLocationLevel().getName());
521
522 if (location.getLocationLevel().getLocationLevel().getLocationLevel() != null) {
523 locationName = locationName.append("/").append(location.getLocationLevel().getLocationLevel().getLocationLevel().getName());
524
525 if (location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel() != null) {
526 locationName = locationName.append("/").append(location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getName());
527
528 if (location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel() != null) {
529 locationName = locationName.append("/").append(location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getName());
530 }
531 }
532 }
533 }
534 }
535 }
536 public String getParameter(String name) {
537 String parameter = "";
538 try {
539 Map<String, String> criteriaMap = new HashMap<String, String>();
540 criteriaMap.put("namespaceCode", "OLE-DESC");
541 criteriaMap.put("componentCode", "Describe");
542 criteriaMap.put("name", name);
543 List<ParameterBo> parametersList = (List<ParameterBo>) KRADServiceLocator.getDataObjectService().findMatching(ParameterBo.class, QueryByCriteria.Builder.andAttributes(criteriaMap).build()).getResults();
544 for (ParameterBo parameterBo : parametersList) {
545 parameter = parameterBo.getValue();
546 }
547 } catch (Exception e) {
548 LOG.error("Exception while getting parameter value", e);
549 }
550 return parameter;
551 }
552 private String getShelvingLocation(Location location) {
553 String locationName = "";
554 if (location.getLocationLevel() != null) {
555 locationName = location.getLocationLevel().getName();
556
557 if (location.getLocationLevel().getLocationLevel() != null) {
558 locationName = location.getLocationLevel().getLocationLevel().getName();
559
560 if (location.getLocationLevel().getLocationLevel().getLocationLevel() != null) {
561 locationName = location.getLocationLevel().getLocationLevel().getLocationLevel().getName();
562
563 if (location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel() != null) {
564 locationName = location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getName();
565
566 if (location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel() != null) {
567 locationName = location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getName();
568 }
569 }
570 }
571 }
572 }
573 return locationName;
574 }
575 private String getLocations(Location location,String paramName) {
576 String locationName = "";
577 String level =getParameter(paramName);
578 int i = 0;
579 LocationLevel locationLevel = location.getLocationLevel();
580 if (locationLevel != null && level!=null) {
581 while (locationLevel!=null) {
582 if (locationLevel.getLevel()!=null && locationLevel.getLevel().equalsIgnoreCase(level)) {
583 locationName = locationLevel.getName();
584 break;
585 } else {
586 locationLevel = locationLevel.getLocationLevel();
587 }
588
589 }
590 }
591 return locationName;
592 }
593
594 private DocstoreClient getDocstoreClient(){
595
596 if (docstoreClient == null) {
597 docstoreClient = new DocstoreLocalClient();
598 }
599 return docstoreClient;
600 }
601
602 }