parent
7b26ce92fe
commit
fd2e8cd199
@ -0,0 +1,43 @@ |
|||||||
|
package me.bearns.fias.util; |
||||||
|
|
||||||
|
import me.bearns.fias.domain.FiasVersion; |
||||||
|
import me.bearns.fias.service.Downloader; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.util.concurrent.ExecutionException; |
||||||
|
import java.util.concurrent.Future; |
||||||
|
|
||||||
|
public class DownlodableUpdate { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private static Downloader service; |
||||||
|
|
||||||
|
private final FiasVersion update; |
||||||
|
private final Future<File> file; |
||||||
|
|
||||||
|
private static DownlodableUpdate process(FiasVersion ver, boolean reload) { |
||||||
|
return new DownlodableUpdate(ver, service.download(reload ? ver.getFiasCompleteXmlUrl() : ver.getFiasDeltaXmlUrl())); |
||||||
|
} |
||||||
|
|
||||||
|
public static DownlodableUpdate processReload(FiasVersion ver){ |
||||||
|
return process(ver, true); |
||||||
|
} |
||||||
|
|
||||||
|
public static DownlodableUpdate processUpdate(FiasVersion ver){ |
||||||
|
return process(ver, false); |
||||||
|
} |
||||||
|
|
||||||
|
private DownlodableUpdate(FiasVersion update, Future<File> file) { |
||||||
|
this.update = update; |
||||||
|
this.file = file; |
||||||
|
} |
||||||
|
|
||||||
|
public File getFile() throws ExecutionException, InterruptedException { |
||||||
|
return file.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public FiasVersion getVersion() { |
||||||
|
return update; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue