Project

General

Profile

1
package eu.dnetlib.data.collector.plugins.datasources;
2

    
3
import java.io.IOException;
4
import java.net.URL;
5

    
6
import javax.xml.stream.XMLStreamException;
7

    
8
import org.apache.commons.io.IOUtils;
9

    
10
import eu.dnetlib.data.collector.plugin.AbstractCollectorPlugin;
11
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
12
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor;
13

    
14
/**
15
 * Plugin to collect metadata record about data repositories from re3data.
16
 * <p>
17
 * Documentation on re3data API: http://service.re3data.org/api/doc.
18
 * </p>
19
 * <p>
20
 * BaseURL: http://service.re3data.org
21
 * </p>
22
 * <p>
23
 * API to get the list of repos: baseURL + /api/beta/repositories
24
 * </p>
25
 * <p>
26
 * API to get a repository: baseURL + content of link/@href of the above list
27
 * </p>
28
 * 
29
 * @author alessia
30
 * 
31
 */
32
public class Re3DataCollectorPlugin extends AbstractCollectorPlugin {
33

    
34
	private String repositoryListPath = "/api/beta/repositories";
35

    
36
	@Override
37
	public Iterable<String> collect(final InterfaceDescriptor interfaceDescriptor, final String fromDate, final String untilDate)
38
			throws CollectorServiceException {
39
		String repositoryListURL = interfaceDescriptor.getBaseUrl() + repositoryListPath;
40
		try {
41
			String input = IOUtils.toString(new URL(repositoryListURL));
42
			return new Re3DataRepositoriesIterator(IOUtils.toInputStream(input, "UTF-8"), interfaceDescriptor.getBaseUrl());
43
		} catch (XMLStreamException | IOException e) {
44
			throw new CollectorServiceException(e);
45
		}
46
	}
47

    
48
	public String getRepositoryListPath() {
49
		return repositoryListPath;
50
	}
51

    
52
	public void setRepositoryListPath(final String repositoryListPath) {
53
		this.repositoryListPath = repositoryListPath;
54
	}
55

    
56
}
(1-1/2)