1 |
45395
|
michele.ar
|
package eu.dnetlib.msro.workers.aggregation.collect.functions;
|
2 |
|
|
|
3 |
|
|
import java.io.StringReader;
|
4 |
|
|
import java.util.Iterator;
|
5 |
|
|
import java.util.List;
|
6 |
|
|
import java.util.Map;
|
7 |
|
|
|
8 |
|
|
import org.dom4j.Document;
|
9 |
|
|
import org.dom4j.DocumentException;
|
10 |
|
|
import org.dom4j.io.SAXReader;
|
11 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
12 |
|
|
import org.springframework.stereotype.Component;
|
13 |
|
|
|
14 |
|
|
import com.google.common.collect.Iterators;
|
15 |
|
|
import com.google.common.collect.Lists;
|
16 |
|
|
|
17 |
|
|
import eu.dnetlib.msro.workers.aggregation.collect.plugins.oai.engine.HttpConnector;
|
18 |
|
|
import eu.dnetlib.msro.workers.aggregation.collect.plugins.oaisets.OaiSetsIterator;
|
19 |
|
|
import eu.dnetlib.rmi.data.ProtocolParameterValue;
|
20 |
|
|
import eu.dnetlib.rmi.data.functions.ParamValuesFunction;
|
21 |
|
|
|
22 |
|
|
@Component
|
23 |
|
|
public class ListOaiSetsFunction implements ParamValuesFunction {
|
24 |
|
|
|
25 |
|
|
@Autowired
|
26 |
|
|
private HttpConnector httpConnector;
|
27 |
|
|
|
28 |
|
|
@Override
|
29 |
|
|
public List<ProtocolParameterValue> findValues(final String baseUrl, final Map<String, String> params) {
|
30 |
|
|
final SAXReader reader = new SAXReader();
|
31 |
|
|
|
32 |
|
|
final Iterator<ProtocolParameterValue> iter = Iterators.transform(new OaiSetsIterator(baseUrl, httpConnector),
|
33 |
|
|
s -> {
|
34 |
|
|
try {
|
35 |
|
|
final Document doc = reader.read(new StringReader(s));
|
36 |
|
|
final String id = doc.valueOf("//*[local-name()='setSpec']");
|
37 |
|
|
final String name = doc.valueOf("//*[local-name()='setName']");
|
38 |
|
|
return new ProtocolParameterValue(id, name);
|
39 |
|
|
} catch (final DocumentException e) {
|
40 |
|
|
throw new RuntimeException("Error in ListSets", e);
|
41 |
|
|
}
|
42 |
|
|
});
|
43 |
|
|
return Lists.newArrayList(iter);
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
}
|