Downloaded files processing
This commit is contained in:
@@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@@ -60,11 +61,37 @@ public class FiasUpdater implements Updater {
|
|||||||
//transaction from here
|
//transaction from here
|
||||||
private void processUpdates(List<FiasVersion> updates, boolean reloadFlag, Long ... regions) {
|
private void processUpdates(List<FiasVersion> updates, boolean reloadFlag, Long ... regions) {
|
||||||
|
|
||||||
|
//todo reload flag impl
|
||||||
|
|
||||||
updates.sort((o1, o2) -> Math.toIntExact(o1.getVersionId() - o2.getVersionId()));
|
updates.sort((o1, o2) -> Math.toIntExact(o1.getVersionId() - o2.getVersionId()));
|
||||||
|
|
||||||
//just for test
|
//just for test
|
||||||
final Stream<Future<File>> stream = updates.stream().map(u -> downloader.download(reloadFlag ? u.getFiasCompleteXmlUrl() : u.getFiasDeltaXmlUrl()));
|
final Stream<Future<File>> stream = updates.stream().map(u -> downloader.download(reloadFlag ? u.getFiasCompleteXmlUrl() : u.getFiasDeltaXmlUrl()));
|
||||||
|
|
||||||
|
processDownloads(stream, regions);
|
||||||
|
|
||||||
|
//todo save updates
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processDownloads(Stream<Future<File>> futureStream, Long ... regions) {
|
||||||
|
|
||||||
|
final Stream<File> fileStream = futureStream.map(fileFuture -> {
|
||||||
|
try {
|
||||||
|
return fileFuture.get();
|
||||||
|
} catch (Exception e) {
|
||||||
|
//todo log
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//throw exception
|
||||||
|
assert fileStream.allMatch(Objects::nonNull);
|
||||||
|
|
||||||
|
fileStream.forEachOrdered(f -> {
|
||||||
|
//todo
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user