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