1 package org.kuali.ole.serviceimpl;
2
3
4 import org.apache.commons.lang.StringEscapeUtils;
5 import org.kuali.ole.OleSRUConstants;
6 import org.kuali.ole.PropertyUtil;
7 import org.kuali.ole.bo.serachRetrieve.*;
8 import org.kuali.ole.docstore.discovery.service.SRUCQLQueryService;
9 import org.kuali.ole.docstore.discovery.service.SRUCQLQueryServiceImpl;
10 import org.kuali.ole.docstore.model.bo.OleDocument;
11 import org.kuali.ole.docstore.model.bo.WorkBibDocument;
12 import org.kuali.ole.handler.OleSRUOpacXMLResponseHandler;
13 import org.kuali.ole.repository.CheckoutManager;
14 import org.kuali.ole.service.OleDiagnosticsService;
15 import org.kuali.ole.service.OleSRUDataService;
16
17 import java.util.ArrayList;
18 import java.util.List;
19 import java.util.Map;
20
21
22
23
24
25
26
27
28
29 public class OleSRUDataServiceImpl implements OleSRUDataService {
30
31 public SRUCQLQueryService srucqlQueryService;
32 public OleDiagnosticsService oleDiagnosticsService;
33
34 public OleSRUDataServiceImpl()
35 {
36 srucqlQueryService = SRUCQLQueryServiceImpl.getInstance();
37 oleDiagnosticsService=new OleDiagnosticsServiceImpl();
38 }
39
40
41
42
43
44
45
46 public List getBibRecordsIdList(Map reqParamMap,String solrQuery){
47
48 List oleBibIDList=null;
49 List<OleDocument> oleDocumentsList=null;
50 try{
51 oleDocumentsList = (ArrayList<OleDocument>)srucqlQueryService.queryForBibDocs(reqParamMap,solrQuery);
52 oleBibIDList=new ArrayList();
53 if(oleDocumentsList.size()>0) {
54 oleBibIDList= generateBibIDList(oleDocumentsList);
55 }
56 }
57 catch (Exception e){
58 System.out.println(e);
59 }
60 return oleBibIDList;
61 }
62
63
64
65
66
67
68
69 public String getOPACXMLSearchRetrieveResponse(List oleBibIDList,Map reqParamMap){
70
71 if(oleBibIDList!=null && oleBibIDList.size()>0){
72 OleSRUOpacXMLResponseHandler oleSRUOpacXMLResponseHandler =new OleSRUOpacXMLResponseHandler();
73 OleSRUResponseDocuments oleSRUResponseDocuments=new OleSRUResponseDocuments();
74 List<OleSRUResponseDocument> oleSRUResponseDocumentList=new ArrayList<OleSRUResponseDocument>();
75 String bibRecordInfo=null;
76 for(int i=0;i<oleBibIDList.size();i++)
77 {
78 List<OleSRUInstanceDocument> oleSRUInstanceDocumentList = getOleSRUInstanceDocument();
79 OleSRUResponseDocument oleSRUResponseDocument=new OleSRUResponseDocument();
80 bibRecordInfo=getBibliographicRecordInfo((String) oleBibIDList.get(i));
81 oleSRUResponseDocument.setBibliographicRecord(bibRecordInfo);
82 oleSRUResponseDocument.setHoldings(oleSRUInstanceDocumentList);
83 if(reqParamMap.containsKey(OleSRUConstants.EXTRA_REQ_DATA_KEY))
84 oleSRUResponseDocument.setExtraRequestData(getExtraReqDataInfo(reqParamMap));
85 oleSRUResponseDocumentList.add(oleSRUResponseDocument);
86 }
87 oleSRUResponseDocuments.setOpacRecords(oleSRUResponseDocumentList);
88 if(OleSRUConstants.RECORD_PACK_XML.equalsIgnoreCase((String)reqParamMap.get(OleSRUConstants.RECORD_PACKING))) {
89 String opacXML= oleSRUOpacXMLResponseHandler.toXML(oleSRUResponseDocuments);
90 if (null != opacXML)
91 opacXML = replaceStringWithSymbols(opacXML);
92
93 return opacXML;
94 }
95 else if(OleSRUConstants.RECORD_PACK_STRING.equalsIgnoreCase((String)reqParamMap.get(OleSRUConstants.RECORD_PACKING))){
96 return oleSRUResponseDocuments.toString();
97 }
98 }
99 return oleDiagnosticsService.getDiagnosticResponse(PropertyUtil.getPropertyUtil().getProperty(OleSRUConstants.NORECORDS_DIAGNOSTIC_MSG));
100 }
101
102
103
104
105
106
107 public List generateBibIDList( List<OleDocument> oleDocumentsList){
108
109 List oleBibIDList=new ArrayList();
110 WorkBibDocument workBibDocument=null;
111 for(int i=0;i<oleDocumentsList.size();i++){
112 workBibDocument=(WorkBibDocument)oleDocumentsList.get(i);
113 oleBibIDList.add(workBibDocument.getId());
114 }
115 return oleBibIDList;
116 }
117
118
119
120
121
122
123 public String getBibliographicRecordInfo(String uuid){
124
125 String bibRecordInfo=null;
126 CheckoutManager checkoutManager=new CheckoutManager();
127 try{
128 bibRecordInfo=checkoutManager.checkOut(uuid,"defaultUser","checkOut");
129 if(bibRecordInfo!=null)
130 bibRecordInfo=bibRecordInfo.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>","");
131 }
132 catch(Exception e){}
133 return bibRecordInfo;
134 }
135
136
137
138
139
140
141 private String replaceStringWithSymbols(String opacXML){
142 opacXML = opacXML.replaceAll("<","<");
143 opacXML = opacXML.replaceAll(">",">");
144 opacXML = opacXML.replaceAll(""","\"");
145 opacXML = opacXML.replaceAll("'", "\'");
146
147
148
149 return opacXML;
150 }
151
152 public List<OleSRUInstanceDocument> getOleSRUInstanceDocument(){
153 OleSRUInstanceDocument oleSRUInstanceDocument = new OleSRUInstanceDocument();
154 List<OleSRUInstanceDocument> oleSRUInstanceDocumentList = new ArrayList<OleSRUInstanceDocument>();
155 List<OleSRUCirculationDocument> oleSRUCirculationDocumentList = getOleSRUCirculationDocument();
156 List<OleSRUInstanceVolume> oleSRUInstanceVolumeList = getOleSRUInstanceVolumes();
157 oleSRUInstanceDocument.setCallNumber("mockCallNumber");
158 oleSRUInstanceDocument.setCompleteness("mockCompleteness");
159 oleSRUInstanceDocument.setCopyNumber("mockCopyNumber");
160 oleSRUInstanceDocument.setDateOfReport("mockDateOfReport");
161 oleSRUInstanceDocument.setEncodingLevel("mockEncodingLevel");
162 oleSRUInstanceDocument.setEnumAndChron("mockEnumAndChorn");
163 oleSRUInstanceDocument.setFormat("mockFormat");
164 oleSRUInstanceDocument.setGeneralRetention("mockGeneralRentention");
165 oleSRUInstanceDocument.setLocalLocation("mockLocalLocation");
166 oleSRUInstanceDocument.setTypeOfRecord("mockTypeOfRecord");
167 oleSRUInstanceDocument.setShelvingLocation("mockShelvingLocation");
168 oleSRUInstanceDocument.setShelvingData("mockShelvingData");
169 oleSRUInstanceDocument.setReproductionNote("mockReproductionNote");
170 oleSRUInstanceDocument.setReceiptAcqStatus("mockReceiptAcqStatus");
171 oleSRUInstanceDocument.setNucCode("mockNucCode");
172 oleSRUInstanceDocument.setPublicNote("mockPublicNote");
173 oleSRUInstanceDocument.setCirculations(oleSRUCirculationDocumentList);
174 oleSRUInstanceDocument.setVolumes(oleSRUInstanceVolumeList);
175 oleSRUInstanceDocumentList.add(oleSRUInstanceDocument);
176 return oleSRUInstanceDocumentList;
177 }
178
179 public List<OleSRUCirculationDocument> getOleSRUCirculationDocument(){
180
181 OleSRUCirculationDocument oleSRUCirculationDocument = new OleSRUCirculationDocument();
182 List<OleSRUCirculationDocument> oleSRUCirculationDocumentList = new ArrayList<OleSRUCirculationDocument>();
183 oleSRUCirculationDocument.setAvailabilityDate("mockAvailabilityDate");
184 oleSRUCirculationDocument.setAvailableNow("mockAvailableNow");
185 oleSRUCirculationDocument.setAvailableThru("mockAvailableThru");
186 oleSRUCirculationDocument.setEnumAndChron("mockEnumAndChron");
187 oleSRUCirculationDocument.setItemId("mockItemId");
188 oleSRUCirculationDocument.setMidspine("mockMidspine");
189 oleSRUCirculationDocument.setOnHold("mockOnHold");
190 oleSRUCirculationDocument.setRenewable("mockRenewable");
191 oleSRUCirculationDocument.setRestrictions("mockRestrictions");
192 oleSRUCirculationDocument.setTemporaryLocation("mockTemporaryLocation");
193 oleSRUCirculationDocumentList.add(oleSRUCirculationDocument);
194 return oleSRUCirculationDocumentList;
195 }
196
197 public List<OleSRUInstanceVolume> getOleSRUInstanceVolumes(){
198 OleSRUInstanceVolume oleSRUInstanceVolume = new OleSRUInstanceVolume();
199 List<OleSRUInstanceVolume> oleSRUInstanceVolumeList = new ArrayList<OleSRUInstanceVolume>();
200 oleSRUInstanceVolume.setChronology("mockChronology");
201 oleSRUInstanceVolume.setEnumAndChron("mockEnumAndChron");
202 oleSRUInstanceVolume.setEnumeration("mockEnumeration");
203 oleSRUInstanceVolumeList.add(oleSRUInstanceVolume);
204 return oleSRUInstanceVolumeList;
205 }
206 public String getExtraReqDataInfo(Map reqParamMap){
207
208 return "<theo:"+reqParamMap.get(OleSRUConstants.EXTRA_REQ_DATA_KEY) +" xmlns:theo=\""+PropertyUtil.getPropertyUtil().getProperty(OleSRUConstants.EXTRA_REQ_DATA_XML_NAMESPACE)+"\">\n" +
209 reqParamMap.get(OleSRUConstants.EXTRA_REQ_DATA_VALUE)+"\n" +
210 "</theo:"+reqParamMap.get(OleSRUConstants.EXTRA_REQ_DATA_KEY)+">";
211 }
212 }