Project

General

Profile

« Previous | Next » 

Revision 52889

SftpIterator can work incrementally with dates and datetimes

View differences:

SftpIterator.java
8 8
import java.time.LocalDateTime;
9 9
import java.time.ZoneId;
10 10
import java.time.format.DateTimeFormatter;
11
import java.time.format.DateTimeParseException;
11 12
import java.util.LinkedList;
12 13
import java.util.Queue;
13 14
import java.util.Set;
......
57 58

  
58 59
	private LocalDateTime fromDate = null;
59 60
	private DateTimeFormatter simpleDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
61
	private DateTimeFormatter fullDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
60 62

  
61 63
	private void init(final String baseUrl, final boolean isRecursive, final Set<String> extensionsSet, final String fromDate) {
62 64
		this.baseUrl = baseUrl;
......
64 66
		this.extensionsSet = extensionsSet;
65 67
		this.incremental = StringUtils.isNotBlank(fromDate);
66 68
		if (incremental) {
67
			//I expect fromDate in the format 'yyyy-MM-dd'. See class eu.dnetlib.msro.workflows.nodes.collect.FindDateRangeForIncrementalHarvestingJobNode .
68
			//see https://stackoverflow.com/questions/27454025/unable-to-obtain-localdatetime-from-temporalaccessor-when-parsing-localdatetime
69
			this.fromDate = LocalDateTime.from(LocalDate.parse(fromDate, simpleDateTimeFormatter).atStartOfDay());
69
			try {
70
				this.fromDate = LocalDateTime.parse(fromDate, fullDateTimeFormatter);
71
			}catch(DateTimeParseException dtpe){
72
				//try with the simple formatter
73
				this.fromDate = LocalDateTime.from(LocalDate.parse(fromDate, simpleDateTimeFormatter).atStartOfDay());
74
			}
70 75
			log.debug("fromDate string: " + fromDate + " -- parsed: " + this.fromDate.toString());
71 76
		}
72 77
		try {

Also available in: Unified diff