34 |
34 |
import java.util.Map;
|
35 |
35 |
import java.util.Set;
|
36 |
36 |
|
|
37 |
import javax.xml.parsers.DocumentBuilder;
|
|
38 |
import javax.xml.parsers.DocumentBuilderFactory;
|
|
39 |
import javax.xml.parsers.ParserConfigurationException;
|
|
40 |
import javax.xml.xpath.XPathConstants;
|
|
41 |
import javax.xml.xpath.XPathFactory;
|
|
42 |
|
37 |
43 |
import org.apache.commons.codec.net.URLCodec;
|
38 |
44 |
import org.apache.commons.logging.Log;
|
39 |
45 |
import org.apache.commons.logging.LogFactory;
|
... | ... | |
42 |
48 |
|
43 |
49 |
import org.apache.solr.common.params.SolrParams;
|
44 |
50 |
import org.apache.solr.schema.SchemaField;
|
|
51 |
import org.dataone.configuration.Settings;
|
45 |
52 |
import org.dataone.service.exceptions.NotFound;
|
46 |
53 |
import org.dataone.service.exceptions.NotImplemented;
|
47 |
54 |
import org.dataone.service.types.v1.Subject;
|
|
55 |
import org.w3c.dom.Document;
|
|
56 |
import org.w3c.dom.Node;
|
|
57 |
import org.w3c.dom.NodeList;
|
|
58 |
import org.xml.sax.SAXException;
|
48 |
59 |
|
49 |
60 |
|
50 |
61 |
|
... | ... | |
55 |
66 |
*/
|
56 |
67 |
public class HttpSolrQueryService extends SolrQueryService {
|
57 |
68 |
private static final String SELECTIONPHASE = "/select";
|
|
69 |
private static final String SOLR_SYSTEMINFO_URLAPPENDIX = "solr.systeminfo.urlappendix";
|
|
70 |
private static final String SOLR_SCHEMA_URLAPPENDIX = "sorl.schema.urlappendix";
|
|
71 |
private static final String SPEC_PATH = "//str[@name=\"solr-spec-version\"]";
|
58 |
72 |
|
59 |
73 |
private String solrServerBaseURL = null;
|
60 |
74 |
private CommonsHttpSolrServer httpSolrServer = null;
|
... | ... | |
145 |
159 |
return null;
|
146 |
160 |
}
|
147 |
161 |
|
|
162 |
|
|
163 |
|
148 |
164 |
/**
|
|
165 |
* Get the list of the valid field name (moved the fields names of the CopyFieldTarget).
|
|
166 |
* @return
|
|
167 |
*/
|
|
168 |
public List<String> getValidSchemaField() {
|
|
169 |
return null;
|
|
170 |
}
|
|
171 |
|
|
172 |
/**
|
149 |
173 |
* Get the version of the solr server.
|
150 |
174 |
* @return
|
151 |
175 |
*/
|
152 |
176 |
public String getSolrServerVersion() {
|
153 |
|
return null;
|
|
177 |
if(solrSpecVersion == null) {
|
|
178 |
getHttpSolrServerVersion();
|
|
179 |
}
|
|
180 |
return solrSpecVersion;
|
154 |
181 |
}
|
155 |
182 |
|
|
183 |
|
|
184 |
/*
|
|
185 |
* Get the solr server version from the system information url.
|
|
186 |
*/
|
|
187 |
private void getHttpSolrServerVersion() {
|
|
188 |
String systemInfoUrlAppendix = Settings.getConfiguration().getString(SOLR_SYSTEMINFO_URLAPPENDIX);
|
|
189 |
String systemInfoUrl = solrServerBaseURL+systemInfoUrlAppendix;
|
|
190 |
try {
|
|
191 |
Document doc = transformInputStreamToDoc((new URL(systemInfoUrl)).openStream());
|
|
192 |
NodeList nodeList = (NodeList) XPathFactory.newInstance().newXPath()
|
|
193 |
.evaluate(SPEC_PATH, doc, XPathConstants.NODESET);
|
|
194 |
if(nodeList != null && nodeList.getLength() >0) {
|
|
195 |
Node specNode = nodeList.item(0);
|
|
196 |
solrSpecVersion = specNode.getFirstChild().getNodeValue();
|
|
197 |
} else {
|
|
198 |
solrSpecVersion = UNKNOWN;
|
|
199 |
}
|
|
200 |
|
|
201 |
} catch (Exception e) {
|
|
202 |
log.error("HttpSolrQueryService.getHttpSolrServerVersion - can't get the solr specification version since "+e.getMessage());
|
|
203 |
solrSpecVersion = UNKNOWN;
|
|
204 |
}
|
|
205 |
|
|
206 |
|
|
207 |
}
|
|
208 |
|
156 |
209 |
/**
|
157 |
|
* Get the list of the valid field name (moved the fields names of the CopyFieldTarget).
|
|
210 |
* Generate a Document from the InputStream
|
|
211 |
* @param input
|
158 |
212 |
* @return
|
|
213 |
* @throws ParserConfigurationException
|
|
214 |
* @throws SAXException
|
|
215 |
* @throws IOException
|
159 |
216 |
*/
|
160 |
|
public List<String> getValidSchemaField() {
|
161 |
|
return null;
|
|
217 |
private Document transformInputStreamToDoc(InputStream input) throws ParserConfigurationException, SAXException, IOException {
|
|
218 |
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
|
219 |
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
|
220 |
Document doc = dBuilder.parse(input);
|
|
221 |
return doc;
|
162 |
222 |
}
|
|
223 |
|
163 |
224 |
|
164 |
225 |
}
|
Add getSolrSpecVersion method for the HttpServer and the controller.