Revision 49368
Added by Michele Artini over 6 years ago
EnrichOpenairePlugin.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.mdstore.plugins; |
2 | 2 |
|
3 |
import java.io.StringReader; |
|
3 | 4 |
import java.net.URI; |
4 | 5 |
import java.net.URISyntaxException; |
6 |
import java.util.List; |
|
5 | 7 |
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
6 | 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; |
|
7 | 15 |
|
8 | 16 |
public class EnrichOpenairePlugin extends GenericDoiMdstorePlugin { |
9 | 17 |
|
18 |
private static final Log log = LogFactory.getLog(EnrichOpenairePlugin.class); |
|
19 |
|
|
20 |
@Value("${plugin.enrich.publications.openaire.url}") |
|
21 |
private String baseUrl; |
|
22 |
|
|
10 | 23 |
@Override |
11 | 24 |
protected URI prepareURI(final String doi) throws URISyntaxException { |
12 |
return new URI("http://api.openaire.eu/search/publications?doi=" + doi);
|
|
25 |
return new URI(String.format(baseUrl, doi));
|
|
13 | 26 |
} |
14 | 27 |
|
15 | 28 |
@Override |
16 | 29 |
protected boolean updateDocument(final Document doc, final String response) { |
17 | 30 |
|
18 |
System.out.println("**********"); |
|
19 |
System.out.println(response); |
|
20 |
System.out.println("**********"); |
|
31 |
try { |
|
32 |
final Document docRes = (new SAXReader()).read(new StringReader(response)); |
|
21 | 33 |
|
22 |
return true;
|
|
34 |
final List<?> results = docRes.selectNodes("/response/results/result");
|
|
23 | 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 |
|
|
24 | 56 |
} |
25 | 57 |
} |
Also available in: Unified diff
datasets