69 lines
2.4 KiB
Java
69 lines
2.4 KiB
Java
|
|
package Visual_DVM_2021.Passes.All;
|
||
|
|
import Common.Constants;
|
||
|
|
import Common.Current;
|
||
|
|
import Common.Utils.Utils;
|
||
|
|
import Repository.Server.ServerCode;
|
||
|
|
import Repository.Server.ServerExchangeUnit_2021;
|
||
|
|
import TestingSystem.DVM.DVMPackage.DVMPackage;
|
||
|
|
import TestingSystem.DVM.TasksPackage.TasksPackageState;
|
||
|
|
import Visual_DVM_2021.Passes.PassCode_2021;
|
||
|
|
import Visual_DVM_2021.Passes.Server.TestingSystemPass;
|
||
|
|
import javafx.util.Pair;
|
||
|
|
import org.apache.commons.io.FileUtils;
|
||
|
|
|
||
|
|
import java.io.File;
|
||
|
|
import java.util.Date;
|
||
|
|
public class DownloadDVMPackage extends TestingSystemPass<DVMPackage> {
|
||
|
|
@Override
|
||
|
|
public String getIconPath() {
|
||
|
|
return "/icons/Apply.png";
|
||
|
|
}
|
||
|
|
@Override
|
||
|
|
public String getButtonText() {
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
File workspace;
|
||
|
|
File results_zip;
|
||
|
|
File results;
|
||
|
|
File loaded;
|
||
|
|
@Override
|
||
|
|
protected boolean canStart(Object... args) throws Exception {
|
||
|
|
if (Current.Check(Log, Current.DVMPackage)){
|
||
|
|
//--
|
||
|
|
target = Current.getDVMPackage();
|
||
|
|
workspace = target.getLocalWorkspace();
|
||
|
|
results_zip = new File(workspace, "results.zip");
|
||
|
|
results = new File(workspace, "results");
|
||
|
|
loaded = new File(workspace, Constants.LOADED);
|
||
|
|
//--
|
||
|
|
if (!target.state.equals(TasksPackageState.Done)){
|
||
|
|
Log.Writeln_("Возможно скачать только завершённый пакет!");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (loaded.exists()){
|
||
|
|
Log.Writeln_("Пакет уже загружен");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
@Override
|
||
|
|
protected void performPreparation() throws Exception {
|
||
|
|
Utils.CheckAndCleanDirectory(target.getLocalWorkspace());
|
||
|
|
}
|
||
|
|
@Override
|
||
|
|
protected void ServerAction() throws Exception {
|
||
|
|
Command(new ServerExchangeUnit_2021(ServerCode.DownloadDVMPackage,"", target.id));
|
||
|
|
}
|
||
|
|
@Override
|
||
|
|
protected void performDone() throws Exception {
|
||
|
|
super.performDone();
|
||
|
|
Pair<byte[], byte[]> packed = (Pair<byte[], byte[]>) response.object;
|
||
|
|
Utils.unpackFile(packed.getKey(), results_zip);
|
||
|
|
Utils.unpackFile(packed.getValue(), target.getJsonFile());
|
||
|
|
passes.get(PassCode_2021.UnzipFolderPass).Do(results_zip.getAbsolutePath(), workspace.getAbsolutePath());
|
||
|
|
FileUtils.writeStringToFile(loaded, new Date().toString());
|
||
|
|
}
|
||
|
|
}
|