Project

General

Profile

« Previous | Next » 

Revision 50116

implemented missing method collect in RestCollectorPlugin; added test class; removed RestIteratorFactory class

View differences:

modules/dnet-collector-plugins/trunk/src/test/java/eu/dnetlib/data/collector/plugins/rest/RestCollectorPluginTest.java
1
/**
2
 * 
3
 */
4
package eu.dnetlib.data.collector.plugins.rest;
5

  
6
import java.util.HashMap;
7

  
8
import org.junit.Assert;
9
import org.junit.Before;
10
import org.junit.Ignore;
11
import org.junit.Test;
12

  
13
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
14
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor;
15
import eu.dnetlib.data.collector.rmi.ProtocolDescriptor;
16

  
17
/**
18
 * @author js
19
 *
20
 */
21
public class RestCollectorPluginTest {
22

  
23
	private String baseUrl = "https://share.osf.io/api/v2/search/creativeworks/_search";
24
	private String resumptionType = "count";
25
	private String resumptionParam = "from";
26
	private String resumptionXpath = "";
27
	private String resultTotalXpath = "//hits/total";
28
	private String resultFormatParam = "format";
29
	private String resultFormatValue = "json";
30
	private String resultSizeParam = "size";
31
	private String query = "q=%28sources%3ASocArXiv+AND+type%3Apreprint%29";
32

  
33
	private String protocolDescriptor = "rest_json2xml"; 
34
	private InterfaceDescriptor ifDesc = new InterfaceDescriptor();
35
	private RestCollectorPlugin rcp;
36
	
37
	@Before
38
	public void setUp() {
39
		HashMap<String, String> params = new HashMap<>();
40
		params.put("resumptionType", resumptionType);
41
		params.put("resumptionParam", resumptionParam);
42
		params.put("resumptionXpath", resumptionXpath);
43
		params.put("resultTotalXpath", resultTotalXpath);
44
		params.put("resultFormatParam", resultFormatParam);
45
		params.put("resultFormatValue", resultFormatValue);
46
		params.put("resultSizeParam", resultSizeParam);
47
		params.put("queryParams", query);
48
		
49
		ifDesc.setBaseUrl(baseUrl);
50
		ifDesc.setParams(params);
51
		
52
		ProtocolDescriptor pd = new ProtocolDescriptor();
53
		pd.setName(protocolDescriptor);
54
		rcp = new RestCollectorPlugin();
55
		rcp.setProtocolDescriptor(pd);
56
	}
57

  
58
	@Ignore
59
	@Test
60
	public void test() throws CollectorServiceException{
61
		
62
		int i = 0;
63
		for (String s : rcp.collect(ifDesc, "", "")) {
64
			Assert.assertTrue(s.length() > 0);
65
			i++;
66
			System.out.println(s);
67
			break;
68
		}
69
		Assert.assertTrue(i > 0);
70
	}
71
}
72

  
modules/dnet-collector-plugins/trunk/src/main/java/eu/dnetlib/data/collector/plugins/rest/RestIteratorFactory.java
1
/**
2
 * 
3
 */
4
package eu.dnetlib.data.collector.plugins.rest;
5

  
6
import java.util.Iterator;
7

  
8
/**
9
 * @author Jochen Schirrwagen
10
 *
11
 */
12
public class RestIteratorFactory {
13

  
14
	public Iterator<String> newIterator(
15
			final String baseUrl,
16
			final String resumptionType,
17
			final String resumptionParam,
18
			final String resumptionXpath,
19
			final String resultTotalXpath,
20
			final String resultFormatParam,
21
			final String resultFormatValue,
22
			final String resultSizeParam,
23
			final String query
24
			){
25
		return new RestIterator(baseUrl, resumptionType, resumptionParam, resumptionXpath, resultTotalXpath, resultFormatParam, resultFormatValue, resultSizeParam, query);
26
	}
27
}
modules/dnet-collector-plugins/trunk/src/main/java/eu/dnetlib/data/collector/plugins/rest/RestCollectorPlugin.java
3 3
 */
4 4
package eu.dnetlib.data.collector.plugins.rest;
5 5

  
6
import java.util.Iterator;
7

  
8
import org.apache.commons.lang3.StringUtils;
9

  
6 10
import eu.dnetlib.data.collector.plugin.AbstractCollectorPlugin;
7 11
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
8 12
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor;
......
14 18
public class RestCollectorPlugin extends AbstractCollectorPlugin {
15 19

  
16 20
	@Override
17
	public Iterable<String> collect(InterfaceDescriptor arg0, String arg1, String arg2)
21
	public Iterable<String> collect(InterfaceDescriptor ifDescriptor, String arg1, String arg2)
18 22
			throws CollectorServiceException {
19
		// TODO Auto-generated method stub
20
		return null;
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
		};
21 50
	}
22 51

  
23 52
}

Also available in: Unified diff