View Javadoc

1   package org.kuali.ole.serviceimpl;
2   
3   import org.kuali.ole.OleSRUConstants;
4   import org.kuali.ole.bo.explain.*;
5   import org.kuali.ole.handler.OleSRUExplainOperationHandler;
6   import org.kuali.ole.service.OleDiagnosticsService;
7   import org.kuali.ole.service.OleExplainOperationService;
8   import org.kuali.rice.core.api.config.property.Config;
9   import org.kuali.rice.core.api.config.property.ConfigContext;
10  
11  import java.util.Map;
12  
13  /**
14   * Created with IntelliJ IDEA.
15   * User: ?
16   * Date: 7/9/12
17   * Time: 6:53 PM
18   * To change this template use File | Settings | File Templates.
19   */
20  public class OleExplainOperationServiceImpl implements OleExplainOperationService {
21  
22  
23      public OleSRUExplainOperationHandler oleSRUExplainOperationHandler;
24      public OleDiagnosticsService oleDiagnosticsService;
25      private Config currentContextConfig;
26  
27      public OleExplainOperationServiceImpl() {
28          oleSRUExplainOperationHandler = new OleSRUExplainOperationHandler();
29          oleDiagnosticsService = new OleDiagnosticsServiceImpl();
30      }
31  
32      /**
33       * will generate the explain service response xml
34       *
35       * @param reqParamMap
36       * @return explain xml response as a string
37       */
38      public String getExplainResponse(Map reqParamMap) {
39          OleSRUExplainResponse oleSRUExplainResponse = new OleSRUExplainResponse();
40          oleSRUExplainResponse.setVersion((String) reqParamMap.get(OleSRUConstants.VERSION));
41          OleSRUExplainRecord oleSRUExplainRecord = getExplainRecord(reqParamMap);
42          oleSRUExplainResponse.setRecord(oleSRUExplainRecord);
43          if (OleSRUConstants.RECORD_PACK_XML.equalsIgnoreCase((String) reqParamMap.get(OleSRUConstants.RECORD_PACKING))) {
44              String explainXML = oleSRUExplainOperationHandler.toXML(oleSRUExplainResponse);
45              String styleSheet = (String) reqParamMap.get(OleSRUConstants.STYLE_SHEET);
46              if (styleSheet != null) {
47                  explainXML = explainXML.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n <?xml-stylesheet type=\"text/xsl\" href=\"" + styleSheet + "\"?>");
48              }
49              return explainXML;
50          } else if (OleSRUConstants.RECORD_PACK_STRING.equalsIgnoreCase((String) reqParamMap.get(OleSRUConstants.RECORD_PACKING))) {
51              return oleSRUExplainResponse.toString();
52          }
53          return null;
54      }
55  
56      /**
57       * will fetch the values from the property file
58       *
59       * @return OleSRUExplainRecord object
60       */
61      public OleSRUExplainRecord getExplainRecord(Map reqParamMap) {
62          OleSRUExplainRecord oleSRUExplainRecord = new OleSRUExplainRecord();
63          oleSRUExplainRecord.setRecordPacking(OleSRUConstants.RECORD_PACK_XML);
64          oleSRUExplainRecord.setRecordSchema(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_RECORD_SCHEMA));
65          OleSRUExplainRecordData oleSRUExplainRecordData = getExplainRecordData(reqParamMap);
66          oleSRUExplainRecord.setRecordData(oleSRUExplainRecordData);
67          return oleSRUExplainRecord;
68      }
69  
70      private Config getCurrentContextConfig() {
71          if (null == currentContextConfig) {
72              currentContextConfig = ConfigContext.getCurrentContextConfig();
73          }
74          return currentContextConfig;
75      }
76  
77      public void setCurrentContextConfig(Config currentContextConfig) {
78          this.currentContextConfig = currentContextConfig;
79      }
80  
81      /**
82       * will fetch the values from the property file
83       *
84       * @return OleSRUExplainRecordData object
85       */
86      public OleSRUExplainRecordData getExplainRecordData(Map reqParamMap) {
87          OleSRUExplainRecordData oleSRUExplainRecordData = new OleSRUExplainRecordData();
88          OleSRUExplainOperation oleSRUExplainOperation = new OleSRUExplainOperation();
89          OleSRUExplainServerInfo oleSRUExplainServerInfo = getExplainServerInfo();
90          OleSRUExplainDatabaseInfo oleSRUExplainDatabaseInfo = getExplainDatabaseInfo();
91          OleSRUExplainConfigurationInfo oleSRUExplainConfigurationInfo = getExplainConfigInfo();
92          OleSRUExplainIndexInfo oleSRUExplainIndexInfo = getExplainIndexInfo();
93          OleSRUExplainSchemaInfo oleSRUExplainSchemaInfo = getExplainSchemaInfo();
94          oleSRUExplainOperation.setServerInfo(oleSRUExplainServerInfo);
95          oleSRUExplainOperation.setDatabaseInfo(oleSRUExplainDatabaseInfo);
96          oleSRUExplainOperation.setIndexInfo(oleSRUExplainIndexInfo);
97          oleSRUExplainOperation.setSchemaInfo(oleSRUExplainSchemaInfo);
98          oleSRUExplainOperation.setConfigInfo(oleSRUExplainConfigurationInfo);
99          if (reqParamMap.containsKey(OleSRUConstants.EXTRA_REQ_DATA_KEY))
100             oleSRUExplainOperation.setExtraRequestData(getExtraReqDataInfo(reqParamMap));
101         oleSRUExplainRecordData.setExplain(oleSRUExplainOperation);
102         return oleSRUExplainRecordData;
103     }
104 
105     /**
106      * will fetch the values from the property file
107      *
108      * @return oleSRUExplainServerInfo object
109      */
110     public OleSRUExplainServerInfo getExplainServerInfo() {
111         OleSRUExplainServerInfo oleSRUExplainServerInfo = new OleSRUExplainServerInfo();
112         oleSRUExplainServerInfo.setDatabase(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_SERVER_DATABASE_INFO));
113         oleSRUExplainServerInfo.setHost(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_SERVER_HOST));
114         oleSRUExplainServerInfo.setMethod(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_SERVER_METHOD));
115         oleSRUExplainServerInfo.setPort(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_SERVER_PORT));
116         oleSRUExplainServerInfo.setProtocol(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_SERVER_PROTOCOL));
117         oleSRUExplainServerInfo.setTransport(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_SERVER_TRANSPORT));
118         oleSRUExplainServerInfo.setVersion(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_SERVER_VERSION));
119         oleSRUExplainServerInfo.setValue("");
120         return oleSRUExplainServerInfo;
121     }
122 
123     /**
124      * will fetch the values from the property file
125      *
126      * @return oleSRUExplainDatabaseInfo object
127      */
128     public OleSRUExplainDatabaseInfo getExplainDatabaseInfo() {
129         OleSRUExplainDatabaseInfo oleSRUExplainDatabaseInfo = new OleSRUExplainDatabaseInfo();
130         OleSRUExplainDatabaseTitle oleSRUExplainDatabaseTitle = new OleSRUExplainDatabaseTitle();
131         oleSRUExplainDatabaseTitle.setLang(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_DATABASE_LANG));
132         oleSRUExplainDatabaseTitle.setPrimary(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_DATABASE_PRIMARY));
133         oleSRUExplainDatabaseTitle.setValue("");
134         oleSRUExplainDatabaseInfo.setTitle(oleSRUExplainDatabaseTitle);
135         return oleSRUExplainDatabaseInfo;
136     }
137 
138     /**
139      * will fetch the values from the property file
140      *
141      * @return oleSRUExplainIndexInfo object
142      */
143     public OleSRUExplainIndexInfo getExplainIndexInfo() {
144         OleSRUExplainIndexInfo oleSRUExplainIndexInfo = new OleSRUExplainIndexInfo();
145         OleSRUExplainIndex oleSRUExplainIndex = new OleSRUExplainIndex();
146         OleSRUExplainIndexSet oleSRUExplainIndexSet = new OleSRUExplainIndexSet();
147         oleSRUExplainIndexSet.setName(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_INDEX_SET_NAME));
148         oleSRUExplainIndexSet.setIdentifier(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_INDEX_SET_IDENTIFIER));
149         OleSRUExplainIndexMapName oleSRUExplainIndexMapName = new OleSRUExplainIndexMapName();
150         oleSRUExplainIndexMapName.setSet(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_INDEX_MAP_NAME_SET));
151         oleSRUExplainIndexMapName.setValue(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_INDEX_MAP_NAME_VALUE));
152         OleSRUExplainIndexMap oleSRUExplainIndexMap = new OleSRUExplainIndexMap();
153         oleSRUExplainIndexMap.setName(oleSRUExplainIndexMapName);
154         oleSRUExplainIndex.setIndexMap(oleSRUExplainIndexMap);
155         oleSRUExplainIndexInfo.setIndex(oleSRUExplainIndex);
156         oleSRUExplainIndexInfo.setSet(oleSRUExplainIndexSet);
157 /*        oleSRUExplainIndexSet.setName("bath");
158         oleSRUExplainIndexSet.setIdentifier("info:srw/cql-context-set/1/dc-v1.1");    */
159         oleSRUExplainIndexSet.setValue("");
160         return oleSRUExplainIndexInfo;
161     }
162 
163     /**
164      * will fetch the values from the property file
165      *
166      * @return oleSRUExplainSchemaInfo object
167      */
168     public OleSRUExplainSchemaInfo getExplainSchemaInfo() {
169         OleSRUExplainSchemaInfo oleSRUExplainSchemaInfo = new OleSRUExplainSchemaInfo();
170         OleSRUExplainSchema oleSRUExplainSchema = new OleSRUExplainSchema();
171         oleSRUExplainSchema.setTitle(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_SCHEMA_TITLE));
172         oleSRUExplainSchema.setName(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_SCHEMA_NAME));
173         oleSRUExplainSchema.setIdentifier(getCurrentContextConfig().getProperty(OleSRUConstants.EXPLAIN_SCHEMA_IDENTIFIER));
174         oleSRUExplainSchema.setValue("");
175         oleSRUExplainSchemaInfo.setSchema(oleSRUExplainSchema);
176         return oleSRUExplainSchemaInfo;
177     }
178 
179     /**
180      * will fetch the values from the property file
181      *
182      * @return OleSRUExplainConfigurationInfo object
183      */
184     public OleSRUExplainConfigurationInfo getExplainConfigInfo() {
185         OleSRUExplainConfigurationInfo oleSRUExplainConfigurationInfo = new OleSRUExplainConfigurationInfo();
186         OleSRUExplainConfigDefaultTagField oleSRUExplainConfigDefaultTagField = new OleSRUExplainConfigDefaultTagField();
187         OleSRUExplainConfigSettingTagField oleSRUExplainConfigSettingTagField = new OleSRUExplainConfigSettingTagField();
188         OleSRUExplainConfigSupportTagField oleSRUExplainConfigSupportTagField = new OleSRUExplainConfigSupportTagField();
189         oleSRUExplainConfigDefaultTagField.setType("numberOfRecords");
190         oleSRUExplainConfigDefaultTagField.setValue(Integer.parseInt(getCurrentContextConfig().getProperty(OleSRUConstants.STARTRECORD)));
191         oleSRUExplainConfigurationInfo.setDefaultValue(oleSRUExplainConfigDefaultTagField);
192         oleSRUExplainConfigSettingTagField.setType("maximumRecords");
193         oleSRUExplainConfigSettingTagField.setValue(Integer.parseInt(getCurrentContextConfig().getProperty(OleSRUConstants.MAXRECORD)));
194         oleSRUExplainConfigurationInfo.setSetting(oleSRUExplainConfigSettingTagField);
195         oleSRUExplainConfigSupportTagField.setType("proximity");
196         oleSRUExplainConfigSupportTagField.setValue("");
197         oleSRUExplainConfigurationInfo.setSupports(oleSRUExplainConfigSupportTagField);
198         return oleSRUExplainConfigurationInfo;
199     }
200 
201     public String getExtraReqDataInfo(Map reqParamMap) {
202 
203         return "<theo:" + reqParamMap.get(OleSRUConstants.EXTRA_REQ_DATA_KEY) + " xmlns:theo=\"" + getCurrentContextConfig().getProperty(OleSRUConstants.EXTRA_REQ_DATA_XML_NAMESPACE) + "\">\n" +
204                 reqParamMap.get(OleSRUConstants.EXTRA_REQ_DATA_VALUE) + "\n" +
205                 "</theo:" + reqParamMap.get(OleSRUConstants.EXTRA_REQ_DATA_KEY) + ">";
206     }
207 
208 }