1
|
package eu.dnetlib.data.mdstore.plugins;
|
2
|
|
3
|
import java.io.StringReader;
|
4
|
import java.net.URI;
|
5
|
import java.net.URISyntaxException;
|
6
|
import java.util.List;
|
7
|
|
8
|
import org.apache.commons.logging.Log;
|
9
|
import org.apache.commons.logging.LogFactory;
|
10
|
import org.dom4j.Document;
|
11
|
import org.dom4j.DocumentException;
|
12
|
import org.dom4j.Node;
|
13
|
import org.dom4j.io.SAXReader;
|
14
|
import org.springframework.beans.factory.annotation.Value;
|
15
|
|
16
|
public class EnrichOpenairePlugin extends GenericDoiMdstorePlugin {
|
17
|
|
18
|
private static final Log log = LogFactory.getLog(EnrichOpenairePlugin.class);
|
19
|
|
20
|
@Value("${plugin.enrich.publications.openaire.url}")
|
21
|
private String baseUrl;
|
22
|
|
23
|
@Override
|
24
|
protected URI prepareURI(final String doi) throws URISyntaxException {
|
25
|
return new URI(String.format(baseUrl, doi));
|
26
|
}
|
27
|
|
28
|
@Override
|
29
|
protected boolean updateDocument(final Document doc, final String response) {
|
30
|
|
31
|
try {
|
32
|
final Document docRes = (new SAXReader()).read(new StringReader(response));
|
33
|
|
34
|
final List<?> results = docRes.selectNodes("/response/results/result");
|
35
|
|
36
|
if (results.size() == 1) {
|
37
|
final Node n = (Node) results.get(0);
|
38
|
System.out.println("------------");
|
39
|
System.out.println("TITLE 1: " + doc.valueOf("//*[local-name() = 'title']"));
|
40
|
System.out.println("TITLE 2: " + docRes.valueOf("//*[local-name() = 'title' and @classid='main title']"));
|
41
|
|
42
|
for (final Object oid : n.selectNodes(".//originalId")) {
|
43
|
System.out.println(" - " + ((Node) oid).getText());
|
44
|
}
|
45
|
return true;
|
46
|
} else if (results.size() == 1) {
|
47
|
log.warn("Too many responses");
|
48
|
}
|
49
|
|
50
|
} catch (final DocumentException e) {
|
51
|
log.warn("Invalid response", e);
|
52
|
}
|
53
|
|
54
|
return false;
|
55
|
|
56
|
}
|
57
|
}
|