Project

General

Profile

« Previous | Next » 

Revision 7883

Added by Jing Tao over 11 years ago

Add a class to compare ids in the solr and metacat.

View differences:

metacat-index/src/test/java/edu/ucsb/nceas/metacat/index/SolrMetacatIdsComparatorIT.java
1
package edu.ucsb.nceas.metacat.index;
2

  
3
import java.io.File;
4
import java.util.ArrayList;
5
import java.util.List;
6

  
7
import org.apache.commons.io.FileUtils;
8
import org.dataone.cn.indexer.solrhttp.SolrDoc;
9
import org.dataone.cn.indexer.solrhttp.SolrElementField;
10
import org.junit.Before;
11
import org.junit.Test;
12

  
13
import edu.ucsb.nceas.metacat.index.resourcemap.ResourceMapSubprocessor;
14

  
15
public class SolrMetacatIdsComparatorIT {
16
    
17
  
18
    private static final String metacatIDFileName = "ids";
19
    private static final String NOTINSOLR = "not_in_solr_but_in_metacat_ids";
20
    //private static final String NOTINMETACAT = "in_solr_but_not_in_metacat_ids";
21
    private File metacatIdsFile = null;
22
    private File notInSolrFile = null;
23
    private File notInMetacatFile = null;
24
   
25
    
26
    @Before
27
    public void setUp() throws Exception {
28
        metacatIdsFile = new File( metacatIDFileName);
29
        notInSolrFile = new File(NOTINSOLR);
30
        if(notInSolrFile.exists()) {
31
            notInSolrFile.delete();
32
        }
33
        notInSolrFile.createNewFile();
34
        /*notInMetacatFile = new File(NOTINMETACAT);
35
        if(notInMetacatFile.exists()) {
36
            notInMetacatFile.delete();
37
        }
38
        notInMetacatFile.createNewFile();*/
39
    }
40
    
41
    
42
    /**
43
     * Figure out ids which have been indexed.
44
     */
45
    @Test
46
    public void figureIdsNotIndexed() throws Exception {
47
        List<String> metacatIds = FileUtils.readLines(metacatIdsFile, "UTF-8");
48
        boolean appending = true;
49
        if(metacatIds != null) {
50
            for(String id : metacatIds) {
51
            
52
                if(id != null && !id.trim().equals("")) {
53
                    SolrDoc doc = ResourceMapSubprocessor.getSolrDoc(id);
54
                    if(doc == null) {
55
                        List<String> line = new ArrayList<String>();
56
                        FileUtils.writeLines(notInSolrFile, line, appending);
57
                    } /*else {
58
                      List<SolrElementField> list = doc.getFieldList();
59
                      if(list != null) {
60
                          for(SolrElementField element : list) {
61
                              System.out.println("name "+element.getName());
62
                              System.out.println("value "+element.getValue());
63
                          }
64
                      } else {
65
                          System.out.println("list is null");
66
                      }
67
                      //SolrElementField solrId = doc.getField("id");
68
                      //System.out.println("the value is "+solrId.getValue());
69
                    }*/
70
                }
71
            }
72
        }
73
    }
74
}

Also available in: Unified diff