Project

General

Profile

« Previous | Next » 

Revision 7577

Added by Jing Tao over 11 years ago

Add the update method.

View differences:

metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SolrIndex.java
62 62
import org.dataone.cn.indexer.solrhttp.SolrElementAdd;
63 63
import org.dataone.cn.indexer.solrhttp.SolrElementField;
64 64
import org.dataone.configuration.Settings;
65
import org.dataone.service.types.v1.Identifier;
65 66
import org.dataone.service.types.v1.SystemMetadata;
66 67
import org.dataone.service.util.TypeMarshaller;
67 68
import org.jibx.runtime.JiBXException;
......
283 284
    }
284 285
    
285 286
    /**
287
     * Check the parameters of the insert or update methods.
288
     * @param pid
289
     * @param systemMetadata
290
     * @param data
291
     * @throws SolrServerException
292
     */
293
    private void checkParams(String pid, SystemMetadata systemMetadata, InputStream data) throws SolrServerException {
294
        if(pid == null || pid.trim().equals("")) {
295
            throw new SolrServerException("The identifier of the indexed document should not be null or blank.");
296
        }
297
        if(systemMetadata == null) {
298
            throw new SolrServerException("The system metadata of the indexed document should not be null.");
299
        }
300
        if(data == null) {
301
            throw new SolrServerException("The indexed document itself should not be null.");
302
        }
303
    }
304
    
305
    /**
286 306
     * Generate indexes for a newly inserted document.
287 307
     * @param pid  the id of this document
288 308
     * @param systemMetadata  the system metadata associated with the data object
......
293 313
    public void insert(String pid, SystemMetadata systemMetadata, InputStream data) 
294 314
                    throws IOException, SAXException, ParserConfigurationException,
295 315
                    XPathExpressionException, SolrServerException, JiBXException {
316
        checkParams(pid, systemMetadata, data);
296 317
        Map<String, SolrDoc> docs = process(pid, systemMetadata, data);
297 318
        
298 319
        //transform the Map to the SolrInputDocument which can be used by the solr server
......
327 348
            }
328 349
        }
329 350
    }
351
    
352
    /**
353
     * Update an existed document. First, remove the index of the old one. Second,
354
     * insert the new document
355
     * @param newPid  the new id of the document
356
     * @param systemMetadata  the system metadata associated with the data object
357
     * @param data  the data object itself
358
     * @throws SolrServerException 
359
     * @throws JiBXException 
360
     */
361
    public void update(String newPid, SystemMetadata systemMetadata, InputStream data) 
362
                    throws IOException, SAXException, ParserConfigurationException,
363
                    XPathExpressionException, SolrServerException, JiBXException {
364
        checkParams(newPid, systemMetadata, data);
365
        Identifier oldIdentifier = systemMetadata.getObsoletes();
366
        if(oldIdentifier == null) {
367
            throw new SolrServerException("The system metadata of the new document doesn't have the obsoletes element in the update operation.");
368
        }
369
        String oldIdStr = oldIdentifier.getValue();
370
        remove(oldIdStr);
371
        insert(newPid, systemMetadata, data);
372
    }
330 373
 
331 374
    /**
332 375
     * Remove the indexed associated with specified pid.

Also available in: Unified diff