Project

General

Profile

1 50066 jochen.sch
/**
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 50584 claudio.at
import org.apache.commons.lang3.StringUtils;
10 50066 jochen.sch
11
/**
12 52970 andreas.cz
 * @author js, Andreas Czerniak
13 50066 jochen.sch
 *
14
 */
15
public class RestCollectorPlugin extends AbstractCollectorPlugin {
16
17
	@Override
18 50116 jochen.sch
	public Iterable<String> collect(InterfaceDescriptor ifDescriptor, String arg1, String arg2)
19 50066 jochen.sch
			throws CollectorServiceException {
20 50116 jochen.sch
		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 52970 andreas.cz
		final String resultSizeValue = (StringUtils.isBlank(ifDescriptor.getParams().get("resultSizeValue"))) ? "100" : ifDescriptor.getParams().get("resultSizeValue");
29 58315 andreas.cz
        final String queryParams = ifDescriptor.getParams().get("queryParams");
30 50582 jochen.sch
		final String entityXpath = ifDescriptor.getParams().get("entityXpath");
31 58315 andreas.cz
		final String authMethod = ifDescriptor.getParams().get("authMethod");
32
		final String authToken = ifDescriptor.getParams().get("authToken");
33 50116 jochen.sch
34
		if (StringUtils.isBlank(baseUrl)) {throw new CollectorServiceException("Param 'baseUrl' is null or empty");}
35
		if (StringUtils.isBlank(resumptionType)) {throw new CollectorServiceException("Param 'resumptionType' is null or empty");}
36
		if (StringUtils.isBlank(resumptionParam)) {throw new CollectorServiceException("Param 'resumptionParam' is null or empty");}
37
		// if (StringUtils.isBlank(resumptionXpath)) {throw new CollectorServiceException("Param 'resumptionXpath' is null or empty");}
38
		// if (StringUtils.isBlank(resultTotalXpath)) {throw new CollectorServiceException("Param 'resultTotalXpath' is null or empty");}
39 52970 andreas.cz
		// resultFormatParam can be emtpy because some Rest-APIs doesn't like this argument in the query
40
                //if (StringUtils.isBlank(resultFormatParam)) {throw new CollectorServiceException("Param 'resultFormatParam' is null, empty or whitespace");}
41 50116 jochen.sch
		if (StringUtils.isBlank(resultFormatValue)) {throw new CollectorServiceException("Param 'resultFormatValue' is null or empty");}
42
		if (StringUtils.isBlank(resultSizeParam)) {throw new CollectorServiceException("Param 'resultSizeParam' is null or empty");}
43 52997 andreas.cz
                // prevent resumptionType: discover -- if (Integer.valueOf(resultSizeValue) <= 1) {throw new CollectorServiceException("Param 'resultSizeValue' is less than 2");}
44 52970 andreas.cz
                if (StringUtils.isBlank(queryParams)) {throw new CollectorServiceException("Param 'queryParams' is null or empty");}
45 50582 jochen.sch
		if (StringUtils.isBlank(entityXpath)) {throw new CollectorServiceException("Param 'entityXpath' is null or empty");}
46 50116 jochen.sch
47 50584 claudio.at
		return () -> new RestIterator(
48
				baseUrl,
49
				resumptionType,
50
				resumptionParam,
51
				resumptionXpath,
52
				resultTotalXpath,
53
				resultFormatParam,
54
				resultFormatValue,
55
				resultSizeParam,
56 58315 andreas.cz
                resultSizeValue,
57 50584 claudio.at
				queryParams,
58
				entityXpath);
59 50066 jochen.sch
	}
60
61
}