Project

General

Profile

« Previous | Next » 

Revision 7603

Added by Jing Tao over 11 years ago

Add a remove(List) method in the class and an obsoletes list parameter in the update method.

View differences:

metacat-index/src/test/java/edu/ucsb/nceas/metacat/index/SolrIndexIT.java
8 8
import java.io.InputStream;
9 9
import java.io.StringWriter;
10 10
import java.io.Writer;
11
import java.util.ArrayList;
11 12
import java.util.List;
12 13

  
13 14
import org.apache.solr.client.solrj.SolrServer;
......
76 77
    public void testUpdate() throws Exception {
77 78
       //InputStream systemInputStream = new FileInputStream(new File(SYSTEMMETAFILEPATH));
78 79
       SystemMetadata systemMetadata = TypeMarshaller.unmarshalTypeFromFile(SystemMetadata.class, SYSTEMMETAUPDATEFILEPATH);
79
       InputStream emlInputStream = new FileInputStream(new File(EMLUPDATEFILEPATH));    
80
       solrIndex.update(newId, systemMetadata, emlInputStream);
80
       InputStream emlInputStream = new FileInputStream(new File(EMLUPDATEFILEPATH));  
81
       ArrayList<String> obsoletes = new ArrayList<String>();
82
       obsoletes.add(id);
83
       obsoletes.add("tao");
84
       solrIndex.update(newId, obsoletes, systemMetadata, emlInputStream);
81 85
       String result = doQuery(solrIndex.getSolrServer());
82 86
       assertTrue(result.contains("version2"));
83 87
    }
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SolrIndex.java
317 317
     * Update an existed document. First, remove the index of the old one. Second,
318 318
     * insert the new document
319 319
     * @param newPid  the new id of the document
320
     * @param obsoleteIds  the chain of the obsoletes by this id
320 321
     * @param systemMetadata  the system metadata associated with the data object
321 322
     * @param data  the data object itself
322 323
     * @throws SolrServerException 
323 324
     * @throws JiBXException 
324 325
     */
325
    public void update(String newPid, SystemMetadata systemMetadata, InputStream data) 
326
    public void update(String newPid, List<String> obsoleteIds, SystemMetadata systemMetadata, InputStream data) 
326 327
                    throws IOException, SAXException, ParserConfigurationException,
327 328
                    XPathExpressionException, SolrServerException, JiBXException {
328 329
        checkParams(newPid, systemMetadata, data);
329 330
        Identifier oldIdentifier = systemMetadata.getObsoletes();
330 331
        if(oldIdentifier == null) {
331 332
            throw new SolrServerException("The system metadata of the new document doesn't have the obsoletes element in the update operation.");
333
        } 
334
        
335
        if(obsoleteIds == null || obsoleteIds.isEmpty()) {
336
            throw new SolrServerException("The obsoletes chain can't be null in the update operation."); 
332 337
        }
333
        String oldIdStr = oldIdentifier.getValue();
334
        remove(oldIdStr);
338
        if(!obsoleteIds.contains(oldIdentifier.getValue())) {
339
            throw new SolrServerException("The obsoletes elment in thesystem metadata is not in the obsoleteIds list in the update operation."); 
340
        }
341
        remove(obsoleteIds);
335 342
        insert(newPid, systemMetadata, data);
336 343
    }
344
    
345
    /**
346
     * Remove all the indexes associated with the pids in the list.
347
     * @param pidList
348
     * @throws IOException
349
     * @throws SolrServerException
350
     */
351
    public void remove(List<String> pidList) throws IOException, SolrServerException {
352
        if(pidList != null) {
353
            for(String id : pidList) {
354
                remove(id);
355
            }
356
        }
357
    }
337 358
 
338 359
    /**
339 360
     * Remove the indexed associated with specified pid.

Also available in: Unified diff