/
MyFolderLocationFactory.java
63 lines (53 loc) · 1.82 KB
/
MyFolderLocationFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package voyager.quickstart.location.folder;
import java.io.File;
import java.io.IOException;
import org.apache.solr.client.solrj.SolrClient;
import voyager.api.discovery.DiscoveryRunner;
import voyager.api.discovery.jobs.JobSubmitter;
import voyager.api.discovery.location.Location;
import voyager.api.discovery.location.LocationFactory;
import voyager.api.infrastructure.util.Registry;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
public class MyFolderLocationFactory implements LocationFactory<MyFolderLocation> {
@Override
public String getName() {
return MyFolderLocation.TYPE;
}
@Override
public MyFolderLocation newInstance() throws IllegalStateException {
return new MyFolderLocation();
}
@Override
public MyFolderLocation newSampleInstance() {
MyFolderLocation loc = new MyFolderLocation();
try {
// Assume we are running in ${app.dir}
File docs = new File( "../dev/java/quickstart/docs" );
loc.setPath(docs.getCanonicalPath());
}
catch(Exception ex) {
Throwables.propagate(ex);
}
loc.setKeywords(new String[] {"aaa", "bbb", "ccc"});
return loc;
}
@Override
public DiscoveryRunner<?> newRunner(MyFolderLocation loc, boolean delta) throws IOException {
SolrClient solr = Registry.get(SolrClient.class);
JobSubmitter jobs = Registry.get(JobSubmitter.class);
return new MyFolderRunner(loc, solr, jobs);
}
@Override
public void validate(MyFolderLocation loc) throws Exception {
if(loc.getPath()==null) {
throw new IllegalArgumentException("Missing Path");
}
if(Strings.isNullOrEmpty(loc.getName())) {
loc.setName( new File(loc.getPath()).getName() );
}
if(Strings.isNullOrEmpty(loc.getId())) {
loc.setId(Location.getLocationHash(loc.getClass()+loc.getPath()));
}
}
}