|
|
|
@ -15,6 +15,7 @@ import java.io.*; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
|
import java.util.concurrent.Future; |
|
|
|
|
import java.util.function.Predicate; |
|
|
|
|
import java.util.zip.ZipEntry; |
|
|
|
|
import java.util.zip.ZipException; |
|
|
|
|
import java.util.zip.ZipFile; |
|
|
|
@ -46,6 +47,7 @@ public class FiasUpdater implements Updater { |
|
|
|
|
if(dbVersionObj != null) { |
|
|
|
|
|
|
|
|
|
final Long dbVersion = dbVersionObj.getVersionId(); |
|
|
|
|
final String regions = dbVersionObj.getRegions(); |
|
|
|
|
|
|
|
|
|
final long lastOnlineVersion = clientStub.getLastVersionId(); |
|
|
|
|
|
|
|
|
@ -54,6 +56,9 @@ public class FiasUpdater implements Updater { |
|
|
|
|
|
|
|
|
|
final List<FiasVersion> updates = clientStub.getVersionsAfter(dbVersion); |
|
|
|
|
|
|
|
|
|
//set region filters for updates
|
|
|
|
|
if(regions != null) updates.forEach(u -> u.setRegions(regions)); |
|
|
|
|
|
|
|
|
|
if(updates != null && !updates.isEmpty()) { |
|
|
|
|
processUpdates(updates, false); |
|
|
|
|
} |
|
|
|
@ -67,14 +72,19 @@ public class FiasUpdater implements Updater { |
|
|
|
|
public void reload(Long... regions) throws CommonException { |
|
|
|
|
|
|
|
|
|
final List<FiasVersion> lastVersion = clientStub.getLastVersion(); |
|
|
|
|
if(lastVersion != null) { |
|
|
|
|
processUpdates(lastVersion, true, regions); |
|
|
|
|
|
|
|
|
|
//exist and only one
|
|
|
|
|
if(lastVersion != null && lastVersion.size() == 1) { |
|
|
|
|
//set region filter
|
|
|
|
|
lastVersion.get(0).setRegions(regions); |
|
|
|
|
|
|
|
|
|
processUpdates(lastVersion, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//transaction from here
|
|
|
|
|
private void processUpdates(List<FiasVersion> updates, boolean reloadFlag, Long ... regions) throws CommonException { |
|
|
|
|
private void processUpdates(List<FiasVersion> updates, boolean reloadFlag) throws CommonException { |
|
|
|
|
|
|
|
|
|
if(reloadFlag) { |
|
|
|
|
//todo reload flag impl
|
|
|
|
@ -91,13 +101,20 @@ public class FiasUpdater implements Updater { |
|
|
|
|
//strict order
|
|
|
|
|
for (FiasVersion item : updates) { |
|
|
|
|
|
|
|
|
|
//set region filter
|
|
|
|
|
final String regions = item.getRegions(); |
|
|
|
|
RegionFilter filter = null; |
|
|
|
|
if(regions != null) { |
|
|
|
|
filter = new RegionFilter(regions); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final File file; |
|
|
|
|
try { |
|
|
|
|
//wait for downloading
|
|
|
|
|
file = map.get(item).get(); |
|
|
|
|
|
|
|
|
|
//process update
|
|
|
|
|
processArchive(file, regions); |
|
|
|
|
processArchive(file, filter); |
|
|
|
|
//apply this version
|
|
|
|
|
versions.save(item); |
|
|
|
|
|
|
|
|
@ -113,7 +130,7 @@ public class FiasUpdater implements Updater { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void processArchive(File file, Long ... regions) throws CommonException { |
|
|
|
|
private void processArchive(File file, Predicate filter) throws CommonException { |
|
|
|
|
|
|
|
|
|
try(final ZipFile zipFile = new ZipFile(file)){ |
|
|
|
|
|
|
|
|
@ -123,8 +140,6 @@ public class FiasUpdater implements Updater { |
|
|
|
|
|
|
|
|
|
final ZipEntry entry = entries.nextElement(); |
|
|
|
|
|
|
|
|
|
final RegionFilter filter = regions != null ? new RegionFilter(regions) : null; |
|
|
|
|
|
|
|
|
|
final UnmarshallerParameters config = catalog.getByPrefix(entry.getName()); |
|
|
|
|
|
|
|
|
|
if(config!=null) { //todo
|
|
|
|
|