1
|
package eu.dnetlib.data.collector.plugins.datasources;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
|
5
|
import eu.dnetlib.data.collector.plugin.AbstractCollectorPlugin;
|
6
|
import eu.dnetlib.data.collector.plugins.HttpConnector;
|
7
|
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
|
8
|
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor;
|
9
|
import org.apache.commons.io.IOUtils;
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
|
12
|
/**
|
13
|
* Plugin to collect metadata record about data repositories from re3data.
|
14
|
* <p>
|
15
|
* Documentation on re3data API: http://service.re3data.org/api/doc.
|
16
|
* </p>
|
17
|
* <p>
|
18
|
* BaseURL: http://service.re3data.org
|
19
|
* </p>
|
20
|
* <p>
|
21
|
* API to get the list of repos: baseURL + /api/v1/repositories
|
22
|
* </p>
|
23
|
* <p>
|
24
|
* API to get a repository: baseURL + content of link/@href of the above list
|
25
|
* </p>
|
26
|
*
|
27
|
* @author alessia
|
28
|
*
|
29
|
*/
|
30
|
public class Re3DataCollectorPlugin extends AbstractCollectorPlugin {
|
31
|
|
32
|
private String repositoryListPath = "/api/v1/repositories";
|
33
|
|
34
|
@Autowired
|
35
|
private HttpConnector httpConnector;
|
36
|
|
37
|
@Override
|
38
|
public Iterable<String> collect(final InterfaceDescriptor interfaceDescriptor, final String fromDate, final String untilDate)
|
39
|
throws CollectorServiceException {
|
40
|
String repositoryListURL = interfaceDescriptor.getBaseUrl() + repositoryListPath;
|
41
|
String input;
|
42
|
try {
|
43
|
input = httpConnector.getInputSource(repositoryListURL);
|
44
|
return new Re3DataRepositoriesIterator(IOUtils.toInputStream(input, "UTF-8"), interfaceDescriptor.getBaseUrl(), getHttpConnector());
|
45
|
} catch (IOException e) {
|
46
|
throw new CollectorServiceException(e);
|
47
|
}
|
48
|
|
49
|
}
|
50
|
|
51
|
public String getRepositoryListPath() {
|
52
|
return repositoryListPath;
|
53
|
}
|
54
|
|
55
|
public void setRepositoryListPath(final String repositoryListPath) {
|
56
|
this.repositoryListPath = repositoryListPath;
|
57
|
}
|
58
|
|
59
|
public HttpConnector getHttpConnector() {
|
60
|
return httpConnector;
|
61
|
}
|
62
|
|
63
|
public void setHttpConnector(final HttpConnector httpConnector) {
|
64
|
this.httpConnector = httpConnector;
|
65
|
}
|
66
|
}
|