1
|
package eu.dnetlib.msro.workflows.nodes.objectstore;
|
2
|
|
3
|
import java.io.File;
|
4
|
import java.util.List;
|
5
|
|
6
|
import eu.dnetlib.enabling.resultset.client.ResultSetClient;
|
7
|
import eu.dnetlib.enabling.resultset.factory.ResultSetFactory;
|
8
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
9
|
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
|
10
|
import eu.dnetlib.msro.workflows.procs.Env;
|
11
|
import eu.dnetlib.msro.workflows.procs.Token;
|
12
|
import eu.dnetlib.msro.workflows.util.ResultsetProgressProvider;
|
13
|
import eu.dnetlib.rmi.common.ResultSet;
|
14
|
import eu.dnetlib.rmi.data.ObjectStoreService;
|
15
|
import eu.dnetlib.rmi.data.Protocols;
|
16
|
import org.apache.commons.io.FileUtils;
|
17
|
import org.apache.commons.io.filefilter.TrueFileFilter;
|
18
|
import org.springframework.beans.factory.annotation.Autowired;
|
19
|
|
20
|
public class ImportFilesJobNode extends BlackboardJobNode {
|
21
|
|
22
|
private String basePath;
|
23
|
private String repositoryPrefix;
|
24
|
private String oaiPrefix;
|
25
|
private String objectStoreId;
|
26
|
private String contentDescription;
|
27
|
|
28
|
@Autowired
|
29
|
private ResultSetFactory resultSetFactory;
|
30
|
|
31
|
@Autowired
|
32
|
private ResultSetClient resultSetClient;
|
33
|
|
34
|
public String getRepositoryPrefix() {
|
35
|
return this.repositoryPrefix;
|
36
|
}
|
37
|
|
38
|
public void setRepositoryPrefix(final String repositoryPrefix) {
|
39
|
this.repositoryPrefix = repositoryPrefix;
|
40
|
}
|
41
|
|
42
|
public String getBasePath() {
|
43
|
return this.basePath;
|
44
|
}
|
45
|
|
46
|
public void setBasePath(final String basePath) {
|
47
|
this.basePath = basePath;
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
protected String obtainServiceId(final Env env) {
|
52
|
return getServiceLocator().getServiceId(ObjectStoreService.class);
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
protected void prepareJob(final BlackboardJob job, final Token token) throws Exception {
|
57
|
final File dir = new File(this.basePath);
|
58
|
|
59
|
System.out.println("Getting all files in " + dir.getCanonicalPath() + " including those in subdirectories");
|
60
|
final List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
|
61
|
IteratorRepository irepo;
|
62
|
if (this.repositoryPrefix.equals("od________18")) {
|
63
|
irepo = new ArxivIteratorRepository(files, this.repositoryPrefix, this.oaiPrefix);
|
64
|
} else if (this.repositoryPrefix.equals("od______2367")) {
|
65
|
irepo = new PUMAIteratorRepository(files, this.repositoryPrefix, this.oaiPrefix);
|
66
|
} else {
|
67
|
irepo = new RepositoryNoURLIterator(files, this.repositoryPrefix, this.oaiPrefix);
|
68
|
}
|
69
|
final ResultSet<String> epr = this.resultSetFactory.createResultSet(irepo);
|
70
|
|
71
|
token.setProgressProvider(new ResultsetProgressProvider(epr, this.resultSetClient));
|
72
|
|
73
|
job.setAction("FEED");
|
74
|
job.getParameters().put("obsID", getObjectStoreId());
|
75
|
job.getParameters().put("mime", getContentDescription());
|
76
|
job.getParameters().put("protocol", Protocols.File_System.toString());
|
77
|
job.getParameters().put("epr", epr.toJson());
|
78
|
}
|
79
|
|
80
|
public String getObjectStoreId() {
|
81
|
return this.objectStoreId;
|
82
|
}
|
83
|
|
84
|
public void setObjectStoreId(final String objectStoreId) {
|
85
|
this.objectStoreId = objectStoreId;
|
86
|
}
|
87
|
|
88
|
public String getContentDescription() {
|
89
|
return this.contentDescription;
|
90
|
}
|
91
|
|
92
|
public void setContentDescription(final String contentDescription) {
|
93
|
this.contentDescription = contentDescription;
|
94
|
}
|
95
|
|
96
|
public String getOaiPrefix() {
|
97
|
return this.oaiPrefix;
|
98
|
}
|
99
|
|
100
|
public void setOaiPrefix(final String oaiPrefix) {
|
101
|
this.oaiPrefix = oaiPrefix;
|
102
|
}
|
103
|
}
|