1 |
7883
|
tao
|
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 |
8094
|
tao
|
import org.apache.solr.client.solrj.SolrServer;
|
9 |
|
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
10 |
|
|
import org.apache.solr.common.SolrDocumentList;
|
11 |
|
|
import org.apache.solr.common.params.SolrParams;
|
12 |
|
|
import org.apache.solr.servlet.SolrRequestParsers;
|
13 |
7883
|
tao
|
import org.dataone.cn.indexer.solrhttp.SolrDoc;
|
14 |
|
|
import org.dataone.cn.indexer.solrhttp.SolrElementField;
|
15 |
|
|
import org.junit.Before;
|
16 |
|
|
import org.junit.Test;
|
17 |
|
|
|
18 |
8094
|
tao
|
import edu.ucsb.nceas.metacat.common.SolrServerFactory;
|
19 |
7883
|
tao
|
import edu.ucsb.nceas.metacat.index.resourcemap.ResourceMapSubprocessor;
|
20 |
|
|
|
21 |
|
|
public class SolrMetacatIdsComparatorIT {
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
private static final String metacatIDFileName = "ids";
|
25 |
|
|
private static final String NOTINSOLR = "not_in_solr_but_in_metacat_ids";
|
26 |
8094
|
tao
|
private static final String NUMBEROFIDS = "number_of_ids_in_solr";
|
27 |
7883
|
tao
|
//private static final String NOTINMETACAT = "in_solr_but_not_in_metacat_ids";
|
28 |
|
|
private File metacatIdsFile = null;
|
29 |
|
|
private File notInSolrFile = null;
|
30 |
|
|
private File notInMetacatFile = null;
|
31 |
8094
|
tao
|
private File numberOfIdsFile = null;
|
32 |
7883
|
tao
|
|
33 |
|
|
|
34 |
|
|
@Before
|
35 |
8095
|
tao
|
public void setUp() throws Exception {
|
36 |
7883
|
tao
|
/*notInMetacatFile = new File(NOTINMETACAT);
|
37 |
|
|
if(notInMetacatFile.exists()) {
|
38 |
|
|
notInMetacatFile.delete();
|
39 |
|
|
}
|
40 |
|
|
notInMetacatFile.createNewFile();*/
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
/**
|
45 |
|
|
* Figure out ids which have been indexed.
|
46 |
|
|
*/
|
47 |
|
|
@Test
|
48 |
|
|
public void figureIdsNotIndexed() throws Exception {
|
49 |
8095
|
tao
|
metacatIdsFile = new File( metacatIDFileName);
|
50 |
|
|
notInSolrFile = new File(NOTINSOLR);
|
51 |
|
|
if(notInSolrFile.exists()) {
|
52 |
|
|
notInSolrFile.delete();
|
53 |
|
|
}
|
54 |
|
|
notInSolrFile.createNewFile();
|
55 |
7883
|
tao
|
List<String> metacatIds = FileUtils.readLines(metacatIdsFile, "UTF-8");
|
56 |
|
|
boolean appending = true;
|
57 |
|
|
if(metacatIds != null) {
|
58 |
|
|
for(String id : metacatIds) {
|
59 |
7888
|
tao
|
//String id = metacatIds.get(0);
|
60 |
7883
|
tao
|
if(id != null && !id.trim().equals("")) {
|
61 |
|
|
SolrDoc doc = ResourceMapSubprocessor.getSolrDoc(id);
|
62 |
|
|
if(doc == null) {
|
63 |
|
|
List<String> line = new ArrayList<String>();
|
64 |
7888
|
tao
|
line.add(id);
|
65 |
7883
|
tao
|
FileUtils.writeLines(notInSolrFile, line, appending);
|
66 |
7888
|
tao
|
}
|
67 |
7883
|
tao
|
}
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
8094
|
tao
|
|
72 |
|
|
/**
|
73 |
|
|
* Figure out ids which have been indexed.
|
74 |
|
|
*/
|
75 |
|
|
@Test
|
76 |
|
|
public void getNumberOfIdsInSolr() throws Exception {
|
77 |
8095
|
tao
|
numberOfIdsFile = new File(NUMBEROFIDS);
|
78 |
|
|
if(numberOfIdsFile.exists()) {
|
79 |
|
|
numberOfIdsFile.delete();
|
80 |
|
|
}
|
81 |
|
|
numberOfIdsFile.createNewFile();
|
82 |
8094
|
tao
|
String query = "q=*:*";
|
83 |
|
|
SolrParams solrParams = SolrRequestParsers.parseQueryString(query);
|
84 |
|
|
SolrServer solrServer = SolrServerFactory.createSolrServer();
|
85 |
|
|
QueryResponse response = solrServer.query(solrParams);
|
86 |
|
|
SolrDocumentList list = response.getResults();
|
87 |
|
|
long number = list.getNumFound();
|
88 |
|
|
FileUtils.writeStringToFile(numberOfIdsFile, (new Long(number)).toString());
|
89 |
|
|
}
|
90 |
7883
|
tao
|
}
|