Project

General

Profile

1
/**
2
 * 
3
 */
4
package eu.dnetlib.data.collector.plugins.rest;
5

    
6
import java.util.Iterator;
7

    
8
import org.apache.commons.lang3.StringUtils;
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
 * @author js
16
 *
17
 */
18
public class RestCollectorPlugin extends AbstractCollectorPlugin {
19

    
20
	@Override
21
	public Iterable<String> collect(InterfaceDescriptor ifDescriptor, String arg1, String arg2)
22
			throws CollectorServiceException {
23
		final String baseUrl = ifDescriptor.getBaseUrl();
24
		final String resumptionType = ifDescriptor.getParams().get("resumptionType");
25
		final String resumptionParam = ifDescriptor.getParams().get("resumptionParam");
26
		final String resumptionXpath = ifDescriptor.getParams().get("resumptionXpath");
27
		final String resultTotalXpath = ifDescriptor.getParams().get("resultTotalXpath");
28
		final String resultFormatParam = ifDescriptor.getParams().get("resultFormatParam");
29
		final String resultFormatValue = ifDescriptor.getParams().get("resultFormatValue");
30
		final String resultSizeParam = ifDescriptor.getParams().get("resultSizeParam");
31
		final String queryParams = ifDescriptor.getParams().get("queryParams");
32
		
33
		if (StringUtils.isBlank(baseUrl)) {throw new CollectorServiceException("Param 'baseUrl' is null or empty");}
34
		if (StringUtils.isBlank(resumptionType)) {throw new CollectorServiceException("Param 'resumptionType' is null or empty");}
35
		if (StringUtils.isBlank(resumptionParam)) {throw new CollectorServiceException("Param 'resumptionParam' is null or empty");}
36
		// if (StringUtils.isBlank(resumptionXpath)) {throw new CollectorServiceException("Param 'resumptionXpath' is null or empty");}
37
		// if (StringUtils.isBlank(resultTotalXpath)) {throw new CollectorServiceException("Param 'resultTotalXpath' is null or empty");}
38
		if (StringUtils.isBlank(resultFormatParam)) {throw new CollectorServiceException("Param 'resultFormatParam' is null or empty");}
39
		if (StringUtils.isBlank(resultFormatValue)) {throw new CollectorServiceException("Param 'resultFormatValue' is null or empty");}
40
		if (StringUtils.isBlank(resultSizeParam)) {throw new CollectorServiceException("Param 'resultSizeParam' is null or empty");}
41
		if (StringUtils.isBlank(queryParams)) {throw new CollectorServiceException("Param 'queryParams' is null or empty");}
42
		
43
		return new Iterable<String>() {
44
			
45
			@Override
46
			public Iterator<String> iterator() {
47
				return new RestIterator(baseUrl, resumptionType, resumptionParam, resumptionXpath, resultTotalXpath, resultFormatParam, resultFormatValue, resultSizeParam, queryParams);
48
			}
49
		};
50
	}
51

    
52
}
(1-1/2)