|
|
@ -6,6 +6,7 @@ import me.bearns.fias.exceptions.DownloadException; |
|
|
|
import me.bearns.fias.exceptions.UnzipException; |
|
|
|
import me.bearns.fias.exceptions.UnzipException; |
|
|
|
import me.bearns.fias.repository.FiasVersionRepository; |
|
|
|
import me.bearns.fias.repository.FiasVersionRepository; |
|
|
|
import me.bearns.fias.util.Catalog; |
|
|
|
import me.bearns.fias.util.Catalog; |
|
|
|
|
|
|
|
import me.bearns.fias.util.RegionFilter; |
|
|
|
import me.bearns.fias.util.UnmarshallerParameters; |
|
|
|
import me.bearns.fias.util.UnmarshallerParameters; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@ -14,6 +15,7 @@ import java.io.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
import java.util.concurrent.Future; |
|
|
|
import java.util.concurrent.Future; |
|
|
|
|
|
|
|
import java.util.function.Predicate; |
|
|
|
import java.util.zip.ZipEntry; |
|
|
|
import java.util.zip.ZipEntry; |
|
|
|
import java.util.zip.ZipException; |
|
|
|
import java.util.zip.ZipException; |
|
|
|
import java.util.zip.ZipFile; |
|
|
|
import java.util.zip.ZipFile; |
|
|
@ -45,6 +47,7 @@ public class FiasUpdater implements Updater { |
|
|
|
if(dbVersionObj != null) { |
|
|
|
if(dbVersionObj != null) { |
|
|
|
|
|
|
|
|
|
|
|
final Long dbVersion = dbVersionObj.getVersionId(); |
|
|
|
final Long dbVersion = dbVersionObj.getVersionId(); |
|
|
|
|
|
|
|
final String regions = dbVersionObj.getRegions(); |
|
|
|
|
|
|
|
|
|
|
|
final long lastOnlineVersion = clientStub.getLastVersionId(); |
|
|
|
final long lastOnlineVersion = clientStub.getLastVersionId(); |
|
|
|
|
|
|
|
|
|
|
@ -53,6 +56,9 @@ public class FiasUpdater implements Updater { |
|
|
|
|
|
|
|
|
|
|
|
final List<FiasVersion> updates = clientStub.getVersionsAfter(dbVersion); |
|
|
|
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()) { |
|
|
|
if(updates != null && !updates.isEmpty()) { |
|
|
|
processUpdates(updates, false); |
|
|
|
processUpdates(updates, false); |
|
|
|
} |
|
|
|
} |
|
|
@ -66,14 +72,19 @@ public class FiasUpdater implements Updater { |
|
|
|
public void reload(Long... regions) throws CommonException { |
|
|
|
public void reload(Long... regions) throws CommonException { |
|
|
|
|
|
|
|
|
|
|
|
final List<FiasVersion> lastVersion = clientStub.getLastVersion(); |
|
|
|
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
|
|
|
|
//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) { |
|
|
|
if(reloadFlag) { |
|
|
|
//todo reload flag impl
|
|
|
|
//todo reload flag impl
|
|
|
@ -90,13 +101,20 @@ public class FiasUpdater implements Updater { |
|
|
|
//strict order
|
|
|
|
//strict order
|
|
|
|
for (FiasVersion item : updates) { |
|
|
|
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; |
|
|
|
final File file; |
|
|
|
try { |
|
|
|
try { |
|
|
|
//wait for downloading
|
|
|
|
//wait for downloading
|
|
|
|
file = map.get(item).get(); |
|
|
|
file = map.get(item).get(); |
|
|
|
|
|
|
|
|
|
|
|
//process update
|
|
|
|
//process update
|
|
|
|
processArchive(file, regions); |
|
|
|
processArchive(file, filter); |
|
|
|
//apply this version
|
|
|
|
//apply this version
|
|
|
|
versions.save(item); |
|
|
|
versions.save(item); |
|
|
|
|
|
|
|
|
|
|
@ -112,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)){ |
|
|
|
try(final ZipFile zipFile = new ZipFile(file)){ |
|
|
|
|
|
|
|
|
|
|
@ -126,7 +144,7 @@ public class FiasUpdater implements Updater { |
|
|
|
|
|
|
|
|
|
|
|
if(config!=null) { //todo
|
|
|
|
if(config!=null) { //todo
|
|
|
|
try (InputStream is = zipFile.getInputStream(entry)) { |
|
|
|
try (InputStream is = zipFile.getInputStream(entry)) { |
|
|
|
unmarshaller.process(is, config, null); |
|
|
|
unmarshaller.process(is, config, filter); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|