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
|
final String authMethod = ifDescriptor.getParams().get("authMethod");
|
32
|
final String authToken = ifDescriptor.getParams().get("authToken");
|
33
|
|
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
|
// 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
|
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
|
// prevent resumptionType: discover -- if (Integer.valueOf(resultSizeValue) <= 1) {throw new CollectorServiceException("Param 'resultSizeValue' is less than 2");}
|
44
|
if (StringUtils.isBlank(queryParams)) {throw new CollectorServiceException("Param 'queryParams' is null or empty");}
|
45
|
if (StringUtils.isBlank(entityXpath)) {throw new CollectorServiceException("Param 'entityXpath' is null or empty");}
|
46
|
|
47
|
return () -> new RestIterator(
|
48
|
baseUrl,
|
49
|
resumptionType,
|
50
|
resumptionParam,
|
51
|
resumptionXpath,
|
52
|
resultTotalXpath,
|
53
|
resultFormatParam,
|
54
|
resultFormatValue,
|
55
|
resultSizeParam,
|
56
|
resultSizeValue,
|
57
|
queryParams,
|
58
|
entityXpath);
|
59
|
}
|
60
|
|
61
|
}
|