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