26 |
26 |
*/
|
27 |
27 |
package edu.ucsb.nceas.metacat.index;
|
28 |
28 |
|
|
29 |
import java.io.ByteArrayInputStream;
|
29 |
30 |
import java.io.IOException;
|
30 |
31 |
import java.io.InputStream;
|
31 |
32 |
import java.util.ArrayList;
|
... | ... | |
60 |
61 |
import org.dataone.cn.indexer.solrhttp.SolrDoc;
|
61 |
62 |
import org.dataone.cn.indexer.solrhttp.SolrElementAdd;
|
62 |
63 |
import org.dataone.cn.indexer.solrhttp.SolrElementField;
|
|
64 |
import org.dataone.service.types.v1.SystemMetadata;
|
|
65 |
import org.dataone.service.util.TypeMarshaller;
|
|
66 |
import org.jibx.runtime.JiBXException;
|
63 |
67 |
import org.w3c.dom.Document;
|
64 |
68 |
import org.xml.sax.SAXException;
|
65 |
69 |
|
... | ... | |
155 |
159 |
/**
|
156 |
160 |
* Generate the index for the given information
|
157 |
161 |
* @param id
|
158 |
|
* @param systemMetaDataStream
|
|
162 |
* @param systemMetadata
|
159 |
163 |
* @param dataStream
|
160 |
164 |
* @return
|
161 |
165 |
* @throws IOException
|
162 |
166 |
* @throws SAXException
|
163 |
167 |
* @throws ParserConfigurationException
|
164 |
168 |
* @throws XPathExpressionException
|
|
169 |
* @throws JiBXException
|
165 |
170 |
* @throws EncoderException
|
166 |
171 |
*/
|
167 |
|
private Map<String, SolrDoc> process(String id, InputStream systemMetaDataStream, InputStream dataStream)
|
|
172 |
private Map<String, SolrDoc> process(String id, SystemMetadata systemMetadata, InputStream dataStream)
|
168 |
173 |
throws IOException, SAXException, ParserConfigurationException,
|
169 |
|
XPathExpressionException{
|
|
174 |
XPathExpressionException, JiBXException{
|
170 |
175 |
|
171 |
176 |
// Load the System Metadata document
|
172 |
|
Document sysMetaDoc = generateXmlDocument(systemMetaDataStream);
|
|
177 |
ByteArrayOutputStream systemMetadataOutputStream = new ByteArrayOutputStream();
|
|
178 |
TypeMarshaller.marshalTypeToOutputStream(systemMetadata, systemMetadataOutputStream);
|
|
179 |
ByteArrayInputStream systemMetadataStream = new ByteArrayInputStream(systemMetadataOutputStream.toByteArray());
|
|
180 |
Document sysMetaDoc = generateXmlDocument(systemMetadataStream);
|
173 |
181 |
if (sysMetaDoc == null) {
|
174 |
182 |
log.error("Could not load System metadata for ID: " + id);
|
175 |
183 |
return null;
|
... | ... | |
263 |
271 |
* @param systemMetadata the system metadata associated with the data object
|
264 |
272 |
* @param data the data object itself
|
265 |
273 |
* @throws SolrServerException
|
|
274 |
* @throws JiBXException
|
266 |
275 |
*/
|
267 |
|
public void insert(String pid, InputStream systemMetadata, InputStream data)
|
|
276 |
public void insert(String pid, SystemMetadata systemMetadata, InputStream data)
|
268 |
277 |
throws IOException, SAXException, ParserConfigurationException,
|
269 |
|
XPathExpressionException, SolrServerException {
|
|
278 |
XPathExpressionException, SolrServerException, JiBXException {
|
270 |
279 |
Map<String, SolrDoc> docs = process(pid, systemMetadata, data);
|
271 |
280 |
|
272 |
281 |
//transform the Map to the SolrInputDocument which can be used by the solr server
|
... | ... | |
286 |
295 |
if(field != null) {
|
287 |
296 |
String value = field.getValue();
|
288 |
297 |
String name = field.getName();
|
289 |
|
System.out.println("add name/value pair - "+name+"/"+value);
|
|
298 |
//System.out.println("add name/value pair - "+name+"/"+value);
|
290 |
299 |
solrDoc.addField(name, value);
|
291 |
300 |
}
|
292 |
301 |
}
|
... | ... | |
296 |
305 |
if(!solrDoc.isEmpty()) {
|
297 |
306 |
UpdateResponse response = solrServer.add(solrDoc);
|
298 |
307 |
solrServer.commit();
|
299 |
|
System.out.println("=================the response is:\n"+response.toString());
|
|
308 |
//System.out.println("=================the response is:\n"+response.toString());
|
300 |
309 |
}
|
301 |
310 |
}
|
302 |
311 |
}
|
Change one parameter type of the insert method from the InputStream to the SystemMetadata.