32 |
32 |
import java.io.InputStream;
|
33 |
33 |
import java.io.StringWriter;
|
34 |
34 |
import java.io.Writer;
|
|
35 |
import java.net.MalformedURLException;
|
35 |
36 |
import java.util.ArrayList;
|
36 |
37 |
import java.util.Collections;
|
37 |
38 |
import java.util.Date;
|
... | ... | |
70 |
71 |
import org.dataone.cn.indexer.resourcemap.ResourceMap;
|
71 |
72 |
import org.dataone.cn.indexer.solrhttp.SolrDoc;
|
72 |
73 |
import org.dataone.cn.indexer.solrhttp.SolrElementField;
|
|
74 |
import org.dataone.service.exceptions.NotFound;
|
|
75 |
import org.dataone.service.exceptions.NotImplemented;
|
|
76 |
import org.dataone.service.exceptions.UnsupportedType;
|
|
77 |
import org.dataone.service.types.v1.Subject;
|
73 |
78 |
import org.w3c.dom.Document;
|
74 |
79 |
import org.w3c.dom.Element;
|
75 |
80 |
import org.w3c.dom.NodeList;
|
... | ... | |
77 |
82 |
|
78 |
83 |
import edu.ucsb.nceas.metacat.common.query.SolrQueryResponseTransformer;
|
79 |
84 |
import edu.ucsb.nceas.metacat.common.query.SolrQueryResponseWriterFactory;
|
|
85 |
import edu.ucsb.nceas.metacat.common.query.SolrQueryServiceController;
|
80 |
86 |
import edu.ucsb.nceas.metacat.common.SolrServerFactory;
|
81 |
87 |
import edu.ucsb.nceas.metacat.index.SolrIndex;
|
82 |
88 |
|
... | ... | |
107 |
113 |
@Override
|
108 |
114 |
public Map<String, SolrDoc> processDocument(String identifier, Map<String, SolrDoc> docs,
|
109 |
115 |
Document doc) throws IOException, EncoderException, SAXException,
|
110 |
|
XPathExpressionException, ParserConfigurationException, SolrServerException {
|
|
116 |
XPathExpressionException, ParserConfigurationException, SolrServerException, NotImplemented, NotFound, UnsupportedType {
|
111 |
117 |
SolrDoc resourceMapDoc = docs.get(identifier);
|
112 |
118 |
List<SolrDoc> processedDocs = processResourceMap(resourceMapDoc, doc);
|
113 |
119 |
Map<String, SolrDoc> processedDocsMap = new HashMap<String, SolrDoc>();
|
... | ... | |
118 |
124 |
}
|
119 |
125 |
|
120 |
126 |
private List<SolrDoc> processResourceMap(SolrDoc indexDocument, Document resourceMapDocument)
|
121 |
|
throws XPathExpressionException, IOException, SAXException, ParserConfigurationException, EncoderException, SolrServerException{
|
|
127 |
throws XPathExpressionException, IOException, SAXException, ParserConfigurationException, EncoderException, SolrServerException, NotImplemented, NotFound, UnsupportedType{
|
122 |
128 |
ResourceMap resourceMap = new ResourceMap(resourceMapDocument);
|
123 |
129 |
List<String> documentIds = resourceMap.getAllDocumentIDs();
|
124 |
130 |
//List<SolrDoc> updateDocuments = getHttpService().getDocuments(getSolrQueryUri(), documentIds);
|
... | ... | |
140 |
146 |
/*
|
141 |
147 |
* Get the SolrDoc list for the list of the ids.
|
142 |
148 |
*/
|
143 |
|
public static List<SolrDoc> getSolrDocs(List<String> ids) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException {
|
|
149 |
public static List<SolrDoc> getSolrDocs(List<String> ids) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException, NotImplemented, NotFound, UnsupportedType {
|
144 |
150 |
List<SolrDoc> list = new ArrayList<SolrDoc>();
|
145 |
151 |
if(ids != null) {
|
146 |
152 |
for(String id : ids) {
|
... | ... | |
156 |
162 |
/*
|
157 |
163 |
* Get the SolrDoc for the specified id
|
158 |
164 |
*/
|
159 |
|
private static SolrDoc getSolrDoc(String id) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException {
|
|
165 |
private static SolrDoc getSolrDoc(String id) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException, NotImplemented, NotFound, UnsupportedType {
|
160 |
166 |
SolrDoc solrDoc = null;
|
161 |
167 |
if(solrServer != null) {
|
162 |
168 |
String query = QUERY+"\""+id+"\"";
|
163 |
169 |
SolrParams solrParams = SolrRequestParsers.parseQueryString(query);
|
164 |
|
QueryResponse response = solrServer.query(solrParams);
|
|
170 |
Set<Subject>subjects = null;//when subjects are null, there will not be any access rules.
|
|
171 |
InputStream response = SolrQueryServiceController.getInstance().query(solrParams, subjects);
|
165 |
172 |
solrDoc = transformQueryResponseToSolrDoc(solrParams, response);
|
166 |
173 |
|
167 |
174 |
/*if(solrDoc != null) {
|
... | ... | |
183 |
190 |
* @param reponse
|
184 |
191 |
* @return
|
185 |
192 |
*/
|
186 |
|
private static SolrDoc transformQueryResponseToSolrDoc(SolrParams solrParams, QueryResponse response) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException {
|
|
193 |
private static SolrDoc transformQueryResponseToSolrDoc(SolrParams solrParams, InputStream response) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException, UnsupportedType, NotFound {
|
187 |
194 |
SolrDoc solrDoc = null;
|
188 |
195 |
if(response != null) {
|
189 |
|
SolrQueryResponseTransformer transformer = new SolrQueryResponseTransformer(solrCore);
|
190 |
|
InputStream input = transformer.transformResults(solrParams, response, SolrQueryResponseWriterFactory.XML);
|
191 |
196 |
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
192 |
197 |
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
193 |
|
Document doc = dBuilder.parse(input);
|
|
198 |
Document doc = dBuilder.parse(response);
|
194 |
199 |
solrDoc = parseResults(doc);
|
195 |
200 |
}
|
196 |
201 |
return solrDoc;
|
... | ... | |
201 |
206 |
/*
|
202 |
207 |
* Parse the query result document. This method only choose the first one from a list.
|
203 |
208 |
*/
|
204 |
|
private static SolrDoc parseResults(Document document) throws XPathExpressionException {
|
|
209 |
private static SolrDoc parseResults(Document document) throws XPathExpressionException, MalformedURLException, UnsupportedType, NotFound, ParserConfigurationException, IOException, SAXException {
|
205 |
210 |
SolrDoc solrDoc = null;
|
206 |
211 |
NodeList nodeList = (NodeList) XPathFactory.newInstance().newXPath()
|
207 |
212 |
.evaluate("/response/result/doc", document, XPathConstants.NODESET);
|
... | ... | |
216 |
221 |
/*
|
217 |
222 |
* Parse an element
|
218 |
223 |
*/
|
219 |
|
private static SolrDoc parseDoc(Element docElement) {
|
220 |
|
List<String> validSolrFieldNames = getValidSchemaField();
|
|
224 |
private static SolrDoc parseDoc(Element docElement) throws MalformedURLException, UnsupportedType, NotFound, ParserConfigurationException, IOException, SAXException {
|
|
225 |
List<String> validSolrFieldNames = SolrQueryServiceController.getInstance().getValidSchemaFields();
|
221 |
226 |
SolrDoc doc = new SolrDoc();
|
222 |
227 |
doc.LoadFromElement(docElement, validSolrFieldNames);
|
223 |
228 |
return doc;
|
... | ... | |
228 |
233 |
* Get the valid schema fields from the solr server.
|
229 |
234 |
* @return
|
230 |
235 |
*/
|
231 |
|
private static List<String> getValidSchemaField() {
|
|
236 |
/*private static List<String> getValidSchemaField() {
|
232 |
237 |
List<String> validSolrFieldNames = new ArrayList<String>();
|
233 |
238 |
IndexSchema schema = solrCore.getSchema();
|
234 |
239 |
Map<String, SchemaField> fieldMap = schema.getFields();
|
... | ... | |
242 |
247 |
}
|
243 |
248 |
//System.out.println("the valid file name is\n"+validSolrFieldNames);
|
244 |
249 |
return validSolrFieldNames;
|
245 |
|
}
|
|
250 |
}*/
|
246 |
251 |
|
247 |
252 |
}
|
Use SolrQueryServiceController to get the ValidFieldList.