1
|
package eu.dnetlib.data.mdstore.plugins;
|
2
|
|
3
|
import java.net.URI;
|
4
|
import java.net.URISyntaxException;
|
5
|
|
6
|
import org.apache.commons.logging.Log;
|
7
|
import org.apache.commons.logging.LogFactory;
|
8
|
|
9
|
import eu.dnetlib.data.mdstore.plugins.objects.MdRecord;
|
10
|
import eu.dnetlib.data.utils.HttpFetcher;
|
11
|
|
12
|
public abstract class GenericDoiMdstorePlugin extends MdRecordPlugin {
|
13
|
|
14
|
private static final Log log = LogFactory.getLog(GenericDoiMdstorePlugin.class);
|
15
|
|
16
|
@Override
|
17
|
protected final boolean updateRecord(final String recordId, final MdRecord record) {
|
18
|
for (final String doi : record.getDois()) {
|
19
|
log.debug(" Record " + record.getId() + " has doi " + doi);
|
20
|
final String response = download(doi);
|
21
|
if ((response != null) && updateDocument(record, response)) { return true; }
|
22
|
}
|
23
|
return false;
|
24
|
}
|
25
|
|
26
|
abstract protected boolean updateDocument(MdRecord doc, String response);
|
27
|
|
28
|
abstract protected URI prepareURI(String doi) throws URISyntaxException;
|
29
|
|
30
|
private String download(final String doi) {
|
31
|
try {
|
32
|
return HttpFetcher.fetch(prepareURI(doi));
|
33
|
} catch (final URISyntaxException e) {
|
34
|
log.error("Error resolving doi: " + doi, e);
|
35
|
return null;
|
36
|
}
|
37
|
}
|
38
|
|
39
|
}
|