1 package org.kuali.ole.serviceimpl;
2
3 import org.kuali.ole.OleSRUConstants;
4 import org.kuali.ole.bo.cql.CQLResponseBO;
5 import org.kuali.ole.bo.diagnostics.OleSRUDiagnostics;
6 import org.kuali.ole.bo.serachRetrieve.OleSRUSearchRetrieveResponse;
7 import org.kuali.ole.handler.OleSRUOpacXMLResponseHandler;
8 import org.kuali.ole.service.*;
9 import org.kuali.rice.core.api.config.property.Config;
10 import org.kuali.rice.core.api.config.property.ConfigContext;
11 import org.xml.sax.SAXException;
12
13 import javax.xml.parsers.ParserConfigurationException;
14 import javax.xml.xpath.XPathExpressionException;
15 import java.io.IOException;
16 import java.util.Map;
17
18
19
20
21
22
23
24
25
26 public class OleSRUWebServiceImpl implements OleSRUWebService {
27
28 public OleDiagnosticsService oleDiagnosticsService;
29 public OleCQLQueryParserService oleCQLQueryParserService;
30 public OleRequestOperationTypeService oleRequestOperationTypeService;
31 public OleValidateInputRequestService oleValidateInputRequestService;
32 private Config currentContextConfig;
33
34 public OleSRUWebServiceImpl() {
35 oleDiagnosticsService = new OleDiagnosticsServiceImpl();
36 oleCQLQueryParserService = new OleCQLQueryParserServiceImpl();
37 oleRequestOperationTypeService = new OleRequestOperationTypeServiceImpl();
38 oleValidateInputRequestService = new OleValidateInputRequestServiceImpl();
39 }
40
41
42
43
44
45
46
47 public String getOleSRUResponse(Map reqParamMap) {
48
49 String respXML = null;
50 String operationType = (String) reqParamMap.get(OleSRUConstants.OperationType);
51
52 String query = (String) reqParamMap.get(OleSRUConstants.QUERY);
53 CQLResponseBO cqlParseBO = null;
54 String reqValidation = oleValidateInputRequestService.inputRequestValidation(reqParamMap);
55 if (reqValidation != null) {
56 OleSRUDiagnostics oleSRUDiagnostics = oleDiagnosticsService.getDiagnosticResponse(getCurrentContextConfig().getProperty(reqValidation));
57 OleSRUSearchRetrieveResponse oleSRUSearchRetrieveResponse = new OleSRUSearchRetrieveResponse();
58 oleSRUSearchRetrieveResponse.setVersion((String) reqParamMap.get(OleSRUConstants.VERSION));
59 oleSRUSearchRetrieveResponse.setNumberOfRecords(new Long(0));
60 oleSRUSearchRetrieveResponse.setOleSRUDiagnostics(oleSRUDiagnostics);
61 OleSRUOpacXMLResponseHandler oleSRUOpacXMLResponseHandler = new OleSRUOpacXMLResponseHandler();
62 return oleSRUOpacXMLResponseHandler.toXML(oleSRUSearchRetrieveResponse,(String)reqParamMap.get("recordSchema"));
63 }
64 if (OleSRUConstants.SEARCH_RETRIEVE.equalsIgnoreCase(operationType)) {
65 String cqlParseXml = oleCQLQueryParserService.parseCQLQuery(query);
66 if (cqlParseXml == null) {
67 OleSRUDiagnostics oleSRUDiagnostics = oleDiagnosticsService.getDiagnosticResponse(getCurrentContextConfig().getProperty(OleSRUConstants.INVALID_QUERY_DIAGNOSTIC_MSG));
68 OleSRUSearchRetrieveResponse oleSRUSearchRetrieveResponse = new OleSRUSearchRetrieveResponse();
69 oleSRUSearchRetrieveResponse.setVersion((String) reqParamMap.get(OleSRUConstants.VERSION));
70 oleSRUSearchRetrieveResponse.setNumberOfRecords(new Long(0));
71 oleSRUSearchRetrieveResponse.setOleSRUDiagnostics(oleSRUDiagnostics);
72 OleSRUOpacXMLResponseHandler oleSRUOpacXMLResponseHandler = new OleSRUOpacXMLResponseHandler();
73 return oleSRUOpacXMLResponseHandler.toXML(oleSRUSearchRetrieveResponse,(String)reqParamMap.get("recordSchema"));
74
75 }
76 cqlParseBO = oleCQLQueryParserService.getCQLResponseObject(cqlParseXml);
77 }
78 respXML = oleRequestOperationTypeService.performOperationTypeService(reqParamMap, cqlParseBO);
79 return respXML;
80 }
81
82 private Config getCurrentContextConfig() {
83 if (null == currentContextConfig) {
84 currentContextConfig = ConfigContext.getCurrentContextConfig();
85 }
86 return currentContextConfig;
87 }
88
89 public void setCurrentContextConfig(Config currentContextConfig) {
90 this.currentContextConfig = currentContextConfig;
91 }
92
93 public void setOleDiagnosticsService(OleDiagnosticsService oleDiagnosticsService) {
94 this.oleDiagnosticsService = oleDiagnosticsService;
95 }
96 }