Revision 7607
Added by Jing Tao over 11 years ago
metacat-index/src/test/java/edu/ucsb/nceas/metacat/index/SolrIndexIT.java | ||
---|---|---|
107 | 107 |
/* |
108 | 108 |
* Do query |
109 | 109 |
*/ |
110 |
private String doQuery(SolrServer server)
|
|
110 |
public static String doQuery(SolrServer server)
|
|
111 | 111 |
throws SolrServerException { |
112 | 112 |
StringBuffer request = new StringBuffer(); |
113 | 113 |
request.append("q=" + "*:*"); |
... | ... | |
125 | 125 |
/* |
126 | 126 |
* Transform the query response to the xml format. |
127 | 127 |
*/ |
128 |
private String toXML(SolrParams request, QueryResponse response) { |
|
128 |
private static String toXML(SolrParams request, QueryResponse response) {
|
|
129 | 129 |
XMLResponseWriter xmlWriter = new XMLResponseWriter(); |
130 | 130 |
Writer w = new StringWriter(); |
131 | 131 |
SolrQueryResponse sResponse = new SolrQueryResponse(); |
metacat-index/src/test/java/edu/ucsb/nceas/metacat/index/IndexGeneratorIT.java | ||
---|---|---|
1 |
package edu.ucsb.nceas.metacat.index; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertTrue; |
|
4 |
|
|
5 |
import java.io.File; |
|
6 |
import java.io.FileInputStream; |
|
7 |
import java.io.IOException; |
|
8 |
import java.io.InputStream; |
|
9 |
import java.io.StringWriter; |
|
10 |
import java.io.Writer; |
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
import org.apache.solr.client.solrj.SolrServer; |
|
15 |
import org.apache.solr.client.solrj.SolrServerException; |
|
16 |
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; |
|
17 |
import org.apache.solr.client.solrj.response.QueryResponse; |
|
18 |
import org.apache.solr.common.params.SolrParams; |
|
19 |
import org.apache.solr.core.CoreContainer; |
|
20 |
import org.apache.solr.core.SolrCore; |
|
21 |
import org.apache.solr.request.LocalSolrQueryRequest; |
|
22 |
import org.apache.solr.response.SolrQueryResponse; |
|
23 |
import org.apache.solr.response.XMLResponseWriter; |
|
24 |
import org.apache.solr.servlet.SolrRequestParsers; |
|
25 |
import org.dataone.service.types.v1.SystemMetadata; |
|
26 |
import org.dataone.service.util.TypeMarshaller; |
|
27 |
import org.junit.Before; |
|
28 |
import org.junit.Test; |
|
29 |
|
|
30 |
public class IndexGeneratorIT { |
|
31 |
/** |
|
32 |
* Test building index for an insert. |
|
33 |
*/ |
|
34 |
@Test |
|
35 |
public void testGenerateAll() throws Exception { |
|
36 |
SolrIndex solrIndex = generateSolrIndex(); |
|
37 |
SystemMetadataEventListener systeMetaListener = new SystemMetadataEventListener(solrIndex); |
|
38 |
IndexGenerator generator = new IndexGenerator(solrIndex, systeMetaListener); |
|
39 |
generator.indexAll(); |
|
40 |
String result = SolrIndexIT.doQuery(solrIndex.getSolrServer()); |
|
41 |
} |
|
42 |
|
|
43 |
private SolrIndex generateSolrIndex() throws Exception { |
|
44 |
ApplicationController controller = new ApplicationController(); |
|
45 |
List<SolrIndex> list = controller.getSolrIndexes(); |
|
46 |
SolrIndex[] solrIndexesarray = list.toArray(new SolrIndex[list.size()]); |
|
47 |
SolrIndex index = solrIndexesarray[0]; |
|
48 |
//SolrServer solrServer = SolrServerFactory.createSolrServer(); |
|
49 |
//index.setSolrServer(solrServer); |
|
50 |
return index; |
|
51 |
} |
|
52 |
} |
metacat-index/src/test/resources/org/dataone/configuration/test.properties | ||
---|---|---|
7 | 7 |
|
8 | 8 |
#HTTP: |
9 | 9 |
#solr.server.classname=org.apache.solr.client.solrj.impl.CommonsHttpSolrServer |
10 |
solr.endpoint=http://localhost:8080/solr/ |
|
10 |
solr.endpoint=http://localhost:8080/solr/ |
|
11 |
|
|
12 |
server.name=localhost |
|
13 |
server.httpPort=8080 |
|
14 |
server.httpSSLPort=443 |
|
15 |
application.context=knb |
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/IndexGenerator.java | ||
---|---|---|
43 | 43 |
import org.dataone.service.exceptions.NotImplemented; |
44 | 44 |
import org.dataone.service.exceptions.ServiceFailure; |
45 | 45 |
import org.dataone.service.types.v1.Identifier; |
46 |
import org.dataone.service.types.v1.ObjectInfo; |
|
46 | 47 |
import org.dataone.service.types.v1.ObjectList; |
47 | 48 |
import org.dataone.service.types.v1.SystemMetadata; |
48 | 49 |
|
... | ... | |
145 | 146 |
if(!force) { |
146 | 147 |
solrIds = getSolrDocIds(); |
147 | 148 |
} |
149 |
log.info("the solr ids -----------------------------"+solrIds); |
|
148 | 150 |
metacatIds = getMetadataIds(since, until); |
151 |
log.info("the metacat ids -----------------------------"+metacatIds); |
|
149 | 152 |
if(metacatIds != null) { |
150 | 153 |
for(String metacatId : metacatIds) { |
151 | 154 |
if(metacatId != null) { |
... | ... | |
181 | 184 |
*/ |
182 | 185 |
private List<String> getMetadataIds(Date since, Date until) throws InvalidRequest, |
183 | 186 |
InvalidToken, NotAuthorized, NotImplemented, ServiceFailure { |
184 |
List<String> ids = null;
|
|
187 |
List<String> ids = new ArrayList();
|
|
185 | 188 |
ObjectList objects = null; |
186 | 189 |
if(since == null && until == null) { |
187 | 190 |
objects = mNode.listObjects(); |
188 | 191 |
} else { |
189 | 192 |
objects = mNode.listObjects(since, until, null, true, 0, Integer.MAX_VALUE); |
190 | 193 |
} |
194 |
if(objects != null) { |
|
195 |
List<ObjectInfo> objectInfoList = objects.getObjectInfoList(); |
|
196 |
if(objectInfoList != null) { |
|
197 |
for(ObjectInfo info : objectInfoList) { |
|
198 |
if(info != null) { |
|
199 |
Identifier identifier = info.getIdentifier(); |
|
200 |
if(identifier != null && identifier.getValue() != null && !identifier.getValue().equals("")) { |
|
201 |
ids.add(identifier.getValue()); |
|
202 |
} |
|
203 |
} |
|
204 |
} |
|
205 |
} |
|
206 |
} |
|
191 | 207 |
return ids; |
192 | 208 |
} |
193 | 209 |
|
... | ... | |
195 | 211 |
* Build up the mn base url |
196 | 212 |
*/ |
197 | 213 |
private String buildMNBaseURL() { |
198 |
String url = Settings.getConfiguration().getString("server.name")+":"+ |
|
214 |
String url = HTTP+Settings.getConfiguration().getString("server.name")+":"+
|
|
199 | 215 |
Settings.getConfiguration().getString("server.httpPort")+"/"+ |
200 |
Settings.getConfiguration().getString("application.contex")+MNAPPENDIX; |
|
216 |
Settings.getConfiguration().getString("application.context")+MNAPPENDIX;
|
|
201 | 217 |
log.info("IndexGenerator.buildMNBaseURL - the base url of MNode is "+url); |
202 | 218 |
return url; |
203 | 219 |
} |
Also available in: Unified diff
Add a junit test for the IndexGenerator class.