1
|
package eu.dnetlib.data.collector.plugins.datacite;
|
2
|
|
3
|
import java.time.LocalDateTime;
|
4
|
import java.time.ZoneId;
|
5
|
import java.time.format.DateTimeFormatter;
|
6
|
|
7
|
import eu.dnetlib.data.collector.plugin.AbstractCollectorPlugin;
|
8
|
import eu.dnetlib.data.collector.plugin.CollectorPlugin;
|
9
|
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
|
10
|
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor;
|
11
|
import org.apache.commons.lang3.StringUtils;
|
12
|
import org.apache.commons.logging.Log;
|
13
|
import org.apache.commons.logging.LogFactory;
|
14
|
|
15
|
public class DataciteCollectorPlugin extends AbstractCollectorPlugin implements CollectorPlugin {
|
16
|
|
17
|
private static final Log log = LogFactory.getLog(DataciteCollectorPlugin.class);
|
18
|
|
19
|
private DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
20
|
|
21
|
@Override
|
22
|
public Iterable<String> collect(InterfaceDescriptor interfaceDescriptor, String fromDate, String untilDate) throws CollectorServiceException {
|
23
|
|
24
|
String baseurl = interfaceDescriptor.getBaseUrl();
|
25
|
if(StringUtils.isBlank(baseurl)) throw new CollectorServiceException("baseUrl cannot be empty");
|
26
|
long timestamp= 0;
|
27
|
if (StringUtils.isNotBlank(fromDate)) {
|
28
|
LocalDateTime d = LocalDateTime.parse(fromDate, dtf);
|
29
|
timestamp = d.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
30
|
log.info("Querying for Datacite records from timestamp "+timestamp+" (date was "+fromDate+")");
|
31
|
}
|
32
|
|
33
|
final long finalTimestamp = timestamp;
|
34
|
return () -> {
|
35
|
try {
|
36
|
return new DataciteESIterator(finalTimestamp, baseurl);
|
37
|
} catch (Exception e) {
|
38
|
throw new RuntimeException(e );
|
39
|
}
|
40
|
};
|
41
|
}
|
42
|
|
43
|
}
|