1
|
package eu.dnetlib.data.collector.plugins.doiresolver;
|
2
|
|
3
|
import eu.dnetlib.data.collector.plugins.HttpConnector;
|
4
|
import eu.dnetlib.data.collector.plugins.utils.JsonUtils;
|
5
|
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
|
6
|
import org.apache.commons.io.IOUtils;
|
7
|
import org.apache.commons.logging.Log;
|
8
|
import org.apache.commons.logging.LogFactory;
|
9
|
import org.springframework.beans.factory.annotation.Autowired;
|
10
|
|
11
|
import java.io.IOException;
|
12
|
import java.io.InputStream;
|
13
|
|
14
|
public class CrossrefResolver implements DOIResolver{
|
15
|
|
16
|
private static final Log log = LogFactory.getLog(CrossrefResolver.class);
|
17
|
private String baseURL = "https://api.crossref.org/works/";
|
18
|
|
19
|
@Autowired
|
20
|
private HttpConnector httpConnector;
|
21
|
|
22
|
@Override
|
23
|
public String resolve(String doi) {
|
24
|
try {
|
25
|
InputStream is = httpConnector.getInputSourceAsStream(getBaseURL()+doi);
|
26
|
return asXml(IOUtils.toString(is));
|
27
|
} catch (IOException | CollectorServiceException e) {
|
28
|
log.error("Cannot resolve doi "+doi+" Exception: "+e);
|
29
|
return null;
|
30
|
}
|
31
|
}
|
32
|
|
33
|
protected String asXml(final String record){
|
34
|
return new JsonUtils().convertToXML(record);
|
35
|
}
|
36
|
|
37
|
public String getBaseURL() {
|
38
|
return baseURL;
|
39
|
}
|
40
|
|
41
|
public void setBaseURL(final String baseURL) {
|
42
|
this.baseURL = baseURL;
|
43
|
}
|
44
|
|
45
|
public HttpConnector getHttpConnector() {
|
46
|
return httpConnector;
|
47
|
}
|
48
|
|
49
|
public void setHttpConnector(HttpConnector httpConnector) {
|
50
|
this.httpConnector = httpConnector;
|
51
|
}
|
52
|
}
|