Revision 55320
Added by Alessia Bardi over 5 years ago
modules/dnet-collector-plugins/trunk/src/main/java/eu/dnetlib/data/collector/plugins/datacite/DataciteCollectorPlugin.java | ||
---|---|---|
14 | 14 |
|
15 | 15 |
public class DataciteCollectorPlugin extends AbstractCollectorPlugin implements CollectorPlugin { |
16 | 16 |
|
17 |
private static final Log log = LogFactory.getLog(DataciteCollectorPlugin.class);
|
|
17 |
private static final Log log = LogFactory.getLog(DataciteCollectorPlugin.class);
|
|
18 | 18 |
|
19 |
private DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
19 |
private DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
20 | 20 |
|
21 |
@Override
|
|
22 |
public Iterable<String> collect(InterfaceDescriptor interfaceDescriptor, String fromDate, String untilDate) throws CollectorServiceException {
|
|
21 |
@Override
|
|
22 |
public Iterable<String> collect(InterfaceDescriptor interfaceDescriptor, String fromDate, String untilDate) throws CollectorServiceException {
|
|
23 | 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 |
try { |
|
29 |
Date date = org.apache.commons.lang.time.DateUtils.parseDate( |
|
30 |
fromDate, |
|
31 |
new String[] { "yyyy-MM-dd", "yyyy-MM-dd'T'HH:mm:ssXXX", "yyyy-MM-dd'T'HH:mm:ss.SSSX", "yyyy-MM-dd'T'HH:mm:ssZ", |
|
32 |
"yyyy-MM-dd'T'HH:mm:ss.SX" }); |
|
33 |
timestamp = date.toInstant().toEpochMilli(); |
|
34 |
log.info("Querying for Datacite records from timestamp "+timestamp+" (date was "+fromDate+")"); |
|
35 |
} catch (ParseException e) { |
|
36 |
throw new CollectorServiceException(e); |
|
37 |
} |
|
38 |
} |
|
39 |
final long finalTimestamp = timestamp; |
|
40 |
return () -> { |
|
41 |
try { |
|
42 |
return new DataciteESIterator(finalTimestamp, baseurl); |
|
43 |
} catch (Exception e) { |
|
44 |
throw new RuntimeException(e ); |
|
45 |
} |
|
46 |
}; |
|
47 |
} |
|
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 |
try { |
|
29 |
Date date = org.apache.commons.lang.time.DateUtils.parseDate( |
|
30 |
fromDate, |
|
31 |
new String[] { "yyyy-MM-dd", "yyyy-MM-dd'T'HH:mm:ssXXX", "yyyy-MM-dd'T'HH:mm:ss.SSSX", "yyyy-MM-dd'T'HH:mm:ssZ", |
|
32 |
"yyyy-MM-dd'T'HH:mm:ss.SX" }); |
|
33 |
//timestamp =parsed.getTime() /1000; |
|
34 |
timestamp = date.toInstant().toEpochMilli() / 1000; |
|
35 |
log.info("Querying for Datacite records from timestamp " + timestamp + " (date was " + fromDate + ")"); |
|
48 | 36 |
|
37 |
} catch (ParseException e) { |
|
38 |
throw new CollectorServiceException(e); |
|
39 |
} |
|
40 |
} |
|
41 |
final long finalTimestamp = timestamp; |
|
42 |
return () -> { |
|
43 |
try { |
|
44 |
return new DataciteESIterator(finalTimestamp, baseurl); |
|
45 |
} catch (Exception e) { |
|
46 |
throw new RuntimeException(e); |
|
47 |
} |
|
48 |
}; |
|
49 |
} |
|
50 |
|
|
49 | 51 |
} |
Also available in: Unified diff
Fixed timestamp calculation