Project

General

Profile

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

    
6
import eu.dnetlib.data.collector.plugin.AbstractCollectorPlugin;
7
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
8
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor;
9
import org.apache.commons.lang3.StringUtils;
10

    
11
/**
12
 * @author js, Andreas Czerniak
13
 *
14
 */
15
public class RestCollectorPlugin extends AbstractCollectorPlugin {
16

    
17
	@Override
18
	public Iterable<String> collect(InterfaceDescriptor ifDescriptor, String arg1, String arg2)
19
			throws CollectorServiceException {
20
		final String baseUrl = ifDescriptor.getBaseUrl();
21
		final String resumptionType = ifDescriptor.getParams().get("resumptionType");
22
		final String resumptionParam = ifDescriptor.getParams().get("resumptionParam");
23
		final String resumptionXpath = ifDescriptor.getParams().get("resumptionXpath");
24
		final String resultTotalXpath = ifDescriptor.getParams().get("resultTotalXpath");
25
		final String resultFormatParam = ifDescriptor.getParams().get("resultFormatParam");
26
		final String resultFormatValue = ifDescriptor.getParams().get("resultFormatValue");
27
		final String resultSizeParam = ifDescriptor.getParams().get("resultSizeParam");
28
		final String resultSizeValue = (StringUtils.isBlank(ifDescriptor.getParams().get("resultSizeValue"))) ? "100" : ifDescriptor.getParams().get("resultSizeValue");
29
                final String queryParams = ifDescriptor.getParams().get("queryParams");
30
		final String entityXpath = ifDescriptor.getParams().get("entityXpath");
31
		
32
		if (StringUtils.isBlank(baseUrl)) {throw new CollectorServiceException("Param 'baseUrl' is null or empty");}
33
		if (StringUtils.isBlank(resumptionType)) {throw new CollectorServiceException("Param 'resumptionType' is null or empty");}
34
		if (StringUtils.isBlank(resumptionParam)) {throw new CollectorServiceException("Param 'resumptionParam' is null or empty");}
35
		// if (StringUtils.isBlank(resumptionXpath)) {throw new CollectorServiceException("Param 'resumptionXpath' is null or empty");}
36
		// if (StringUtils.isBlank(resultTotalXpath)) {throw new CollectorServiceException("Param 'resultTotalXpath' is null or empty");}
37
		// resultFormatParam can be emtpy because some Rest-APIs doesn't like this argument in the query
38
                //if (StringUtils.isBlank(resultFormatParam)) {throw new CollectorServiceException("Param 'resultFormatParam' is null, empty or whitespace");}
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
		if (StringUtils.isBlank(entityXpath)) {throw new CollectorServiceException("Param 'entityXpath' is null or empty");}
43
		
44
		return () -> new RestIterator(
45
				baseUrl,
46
				resumptionType,
47
				resumptionParam,
48
				resumptionXpath,
49
				resultTotalXpath,
50
				resultFormatParam,
51
				resultFormatValue,
52
				resultSizeParam,
53
                                resultSizeValue,
54
				queryParams,
55
				entityXpath);
56
	}
57

    
58
}
(1-1/2)