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