View Javadoc

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   * Created with IntelliJ IDEA.
24   * User: ?
25   * Date: 7/9/12
26   * Time: 7:41 PM
27   * To change this template use File | Settings | File Templates.
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       * this method will fetch the bib id list from the docstore
42       * @param reqParamMap
43       * @param solrQuery
44       * @return list of bib id
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       * this method will fetch the bib details , holding details from the docstore data base , creates an object for bib and holdings , and generates OPAC xml
65       * @param oleBibIDList
66       * @param    reqParamMap
67       * @return  opac xml or diagnostics or oleSRUResponseDocuments as a string depends upon the record packing
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      * this will generate the list of document from docstore
104      * @param oleDocumentsList (list of OleDocument)
105      * @return bib id list
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      * this method will do checkout operation of docstore which gives the bib info details
120      * @param uuid
121      * @return bib info xml as a string
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      *  to replace the encoded value from the string to original special character to display as an xml
138      * @param opacXML
139      * @return opac xml response
140      */
141     private String replaceStringWithSymbols(String opacXML){
142         opacXML = opacXML.replaceAll("&lt;","<");
143         opacXML = opacXML.replaceAll("&gt;",">");
144         opacXML = opacXML.replaceAll("&quot;","\"");
145         opacXML = opacXML.replaceAll("&apos;", "\'");
146         //opacXML = opacXML.replaceAll("&","&amp;");
147         //opacXML = StringEscapeUtils.unescapeHtml(opacXML).replaceAll("[^\\x20-\\x7e]", "");
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 }