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