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
                final String queryParams = ifDescriptor.getParams().get("queryParams");
30 50582 jochen.sch
		final String entityXpath = ifDescriptor.getParams().get("entityXpath");
31 50116 jochen.sch
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 52970 andreas.cz
		// 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 50116 jochen.sch
		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 52997 andreas.cz
                // prevent resumptionType: discover -- if (Integer.valueOf(resultSizeValue) <= 1) {throw new CollectorServiceException("Param 'resultSizeValue' is less than 2");}
42 52970 andreas.cz
                if (StringUtils.isBlank(queryParams)) {throw new CollectorServiceException("Param 'queryParams' is null or empty");}
43 50582 jochen.sch
		if (StringUtils.isBlank(entityXpath)) {throw new CollectorServiceException("Param 'entityXpath' is null or empty");}
44 50116 jochen.sch
45 50584 claudio.at
		return () -> new RestIterator(
46
				baseUrl,
47
				resumptionType,
48
				resumptionParam,
49
				resumptionXpath,
50
				resultTotalXpath,
51
				resultFormatParam,
52
				resultFormatValue,
53
				resultSizeParam,
54 52970 andreas.cz
                                resultSizeValue,
55 50584 claudio.at
				queryParams,
56
				entityXpath);
57 50066 jochen.sch
	}
58
59
}