Files
VisualSapfor/src/Visual_DVM_2021/Passes/All/SynchronizeTestsTasks.java

96 lines
3.4 KiB
Java
Raw Normal View History

2023-09-17 22:13:42 +03:00
package Visual_DVM_2021.Passes.All;
import Common.Current;
import Common.Global;
2023-09-17 22:13:42 +03:00
import Common.UI.UI;
import Common.Utils.Utils;
import Repository.Server.ServerCode;
import Repository.Server.ServerExchangeUnit_2021;
2023-11-17 00:04:21 +03:00
import TestingSystem.Common.TestingServer;
import Visual_DVM_2021.Passes.Pass_2021;
import Visual_DVM_2021.Passes.Server.TestingSystemPass;
2023-09-17 22:13:42 +03:00
import org.apache.commons.io.FileUtils;
import java.io.File;
public class SynchronizeTestsTasks extends Pass_2021 {
byte[] db_file_bytes;
2023-09-17 22:13:42 +03:00
File new_db_file;
@Override
protected boolean canStart(Object... args) throws Exception {
db_file_bytes = null;
new_db_file = null;
if (Current.getAccount().CheckRegistered(Log)) {
TestingSystemPass download = new TestingSystemPass() {
@Override
protected boolean needsAnimation() {
return false;
}
@Override
public String getDescription() {
return "Загрузка базы тестовых задач";
}
@Override
protected void ServerAction() throws Exception {
Command(new ServerExchangeUnit_2021(ServerCode.ReceiveTestsTasksDatabase, Current.getAccount().email));
db_file_bytes = (byte[]) response.object;
}
};
return download.Do();
}
return false;
2023-09-17 22:13:42 +03:00
}
@Override
protected boolean needsAnimation() {
return false;
}
@Override
public String getIconPath() {
return "/icons/ComponentsActual.png";
}
@Override
public String getButtonText() {
return "";
}
@Override
protected void performPreparation() throws Exception {
Global.testingServer.account_db.Disconnect();
2023-09-17 22:13:42 +03:00
}
@Override
protected void showPreparation() throws Exception {
Global.testingServer.account_db.SaveLastSelections();
Global.testingServer.account_db.packages.ClearUI();
Global.testingServer.account_db.sapforTasksPackages.ClearUI();
2023-09-17 22:13:42 +03:00
}
@Override
protected void body() throws Exception {
Utils.unpackFile(db_file_bytes, new_db_file = Utils.getTempFileName("tdb"));
2023-09-17 22:13:42 +03:00
if (new_db_file.exists()) {
Utils.forceDeleteWithCheck(Global.testingServer.account_db.getFile());
FileUtils.moveFile(new_db_file, Global.testingServer.account_db.getFile());
Global.testingServer.account_db.setFile(Current.getAccount().email);
2023-09-17 22:13:42 +03:00
}
//--
Global.testingServer.account_db.Connect();
Global.testingServer.account_db.CreateAllTables();
Global.testingServer.account_db.prepareTablesStatements();
Global.testingServer.account_db.Synchronize();
2023-09-17 22:13:42 +03:00
UI.getMainWindow().getTestingWindow().RemountTestTable();
//--
2023-09-17 22:13:42 +03:00
}
@Override
protected boolean validate() {
return (db_file_bytes != null);
2023-09-17 22:13:42 +03:00
}
@Override
protected void showFinish() throws Exception {
Global.testingServer.account_db.packages.ShowUI();
Global.testingServer.account_db.sapforTasksPackages.ShowUI();
Global.testingServer.account_db.RestoreLastSelections();
if (!Global.testingServer.account_db.hasActivePackages()) {
Global.properties.updateField("AutoCheckTesting", false);
TestingServer.TimerOff();
UI.testingBar.ShowAutoCheckTesting();
}
2023-09-17 22:13:42 +03:00
}
}