Project

General

Profile

« Previous | Next » 

Revision 9018

update classes and context files that use cn-index-processor classes. allowing document subprocessors to be less tied to XML.

View differences:

SolrIndex.java
58 58
import org.apache.solr.schema.IndexSchema;
59 59
import org.dataone.cn.indexer.XMLNamespaceConfig;
60 60
import org.dataone.cn.indexer.convert.SolrDateConverter;
61
import org.dataone.cn.indexer.parser.AbstractDocumentSubprocessor;
61 62
import org.dataone.cn.indexer.parser.IDocumentSubprocessor;
62 63
import org.dataone.cn.indexer.parser.SolrField;
63
import org.dataone.cn.indexer.resourcemap.ResourceEntry;
64
import org.dataone.cn.indexer.resourcemap.ResourceMap;
65
import org.dataone.cn.indexer.resourcemap.ResourceMapFactory;
66 64
import org.dataone.cn.indexer.solrhttp.SolrDoc;
67 65
import org.dataone.cn.indexer.solrhttp.SolrElementField;
68 66
import org.dataone.service.exceptions.NotFound;
......
156 154
     */
157 155
    public void setSubprocessors(List<IDocumentSubprocessor> subprocessorList) {
158 156
        for (IDocumentSubprocessor subprocessor : subprocessorList) {
159
            subprocessor.initExpression(xpath);
157
        	if (subprocessor instanceof AbstractDocumentSubprocessor) {
158
        		((AbstractDocumentSubprocessor)subprocessor).initExpression(xpath);
159
        	}
160 160
        }
161 161
        this.subprocessors = subprocessorList;
162 162
    }
......
197 197
        SolrDoc indexDocument = new SolrDoc(sysSolrFields);
198 198
        Map<String, SolrDoc> docs = new HashMap<String, SolrDoc>();
199 199
        docs.put(id, indexDocument);
200
        
201
        // get the format id for this object
202
        String formatId = indexDocument.getFirstFieldValue(SolrElementField.FIELD_OBJECTFORMAT);
200 203

  
201 204
        // Determine if subprocessors are available for this ID
202 205
        if (subprocessors != null) {
203
                    // for each subprocessor loaded from the spring config
204
                    for (IDocumentSubprocessor subprocessor : subprocessors) {
205
                        // Does this subprocessor apply?
206
                        if (subprocessor.canProcess(sysMetaDoc)) {
207
                            // if so, then extract the additional information from the
208
                            // document.
209
                            try {
210
                                // docObject = the resource map document or science
211
                                // metadata document.
212
                                // note that resource map processing touches all objects
213
                                // referenced by the resource map.
214
                            	InputStream dataStream = new FileInputStream(objectPath);
215
                                Document docObject = generateXmlDocument(dataStream);
216
                                if (docObject == null) {
217
                                    throw new Exception("Could not load OBJECT for ID " + id );
218
                                } else {
219
                                    docs = subprocessor.processDocument(id, docs, docObject);
220
                                }
221
                            } catch (Exception e) {
222
                                log.error(e.getMessage(), e);
223
                                throw new SolrServerException(e.getMessage());
224
                            }
225
                        }
226
                    }
206
	        // for each subprocessor loaded from the spring config
207
	        for (IDocumentSubprocessor subprocessor : subprocessors) {
208
	            // Does this subprocessor apply?
209
	            if (subprocessor.canProcess(formatId)) {
210
	                // if so, then extract the additional information from the
211
	                // document.
212
	                try {
213
	                    // docObject = the resource map document or science
214
	                    // metadata document.
215
	                    // note that resource map processing touches all objects
216
	                    // referenced by the resource map.
217
	                	FileInputStream dataStream = new FileInputStream(objectPath);
218
	                    if (!dataStream.getFD().valid()) {
219
	                    	log.error("Could not load OBJECT file for ID,Path=" + id + ", "
220
                                    + objectPath);
221
	                        //throw new Exception("Could not load OBJECT for ID " + id );
222
	                    } else {
223
	                        docs = subprocessor.processDocument(id, docs, dataStream);
224
	                    }
225
	                } catch (Exception e) {
226
	                    log.error(e.getMessage(), e);
227
	                    throw new SolrServerException(e.getMessage());
228
	                }
229
	            }
230
	        }
227 231
       }
228 232

  
229 233
       // TODO: in the XPathDocumentParser class in d1_cn_index_process module,

Also available in: Unified diff