Files
VisualSapfor/src/TestingSystem/Common/Test/Test.java

134 lines
4.9 KiB
Java
Raw Normal View History

package TestingSystem.Common.Test;
import Common.Constants;
2023-09-17 22:13:42 +03:00
import Common.Current;
import Common.Database.DBObject;
import Common.Database.riDBObject;
2023-11-17 00:04:21 +03:00
import Common.Global;
2023-09-17 22:13:42 +03:00
import Common.UI.UI;
import Common.Utils.Utils;
import ProjectData.Project.db_project_info;
import Repository.RepositoryRefuseException;
import Visual_DVM_2021.Passes.All.UnzipFolderPass;
import Visual_DVM_2021.Passes.All.ZipFolderPass;
import Visual_DVM_2021.Passes.PassException;
2023-09-17 22:13:42 +03:00
import com.sun.org.glassfish.gmbal.Description;
import org.apache.commons.io.FileUtils;
2023-11-17 00:04:21 +03:00
import java.io.File;
public class Test extends riDBObject {
2023-09-17 22:13:42 +03:00
@Description("DEFAULT 1")
2023-11-23 01:50:04 +03:00
public int min_dim = 1; //мин размерность теста.
@Description("DEFAULT 1")
public int max_dim = 1; //макс размерность теста.
2023-09-17 22:13:42 +03:00
@Description("DEFAULT ''")
public String args = ""; //аргументы командной строки. на всякий случай поле зарезервирую. пусть будут.
@Description("DEFAULT -1")
public int group_id = Constants.Nan;
2023-09-17 22:13:42 +03:00
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
Test t = (Test) src;
2023-11-23 01:50:04 +03:00
min_dim = t.min_dim;
max_dim = t.max_dim;
2023-09-17 22:13:42 +03:00
args = t.args;
group_id = t.group_id;
}
@Description("DEFAULT ''")
public String files = ""; //файлы теста
//--------------------------------------------->>>
@Description("IGNORE")
public String temp_project_name = "";
@Description("IGNORE")
public byte[] project_archive_bytes = null;
//--------------------------------------------->>>
2023-09-17 22:13:42 +03:00
public Test(Test test) {
this.SynchronizeFields(test);
}
public Test() {
}
@Override
public void select(boolean flag) {
super.select(flag);
if (Current.hasUI())
UI.getMainWindow().ShowCheckedTestsCount();
2023-09-17 22:13:42 +03:00
}
2023-11-17 00:04:21 +03:00
//---
@Override
public boolean isVisible() {
return Current.HasGroup() && (Current.getGroup().id == group_id);
}
//-
public File getArchive() {
return new File(Global.TestsDirectory, id + ".zip");
}
//-
public File getServerPath() {
return new File(Global.TestsDirectory, String.valueOf(id));
}
public File getHomePath() {
return new File(Global.visualiser.getWorkspace(), String.valueOf(id));
}
//--
public File getTempArchive() {
return new File(Global.TempDirectory, temp_project_name + ".zip");
}
public File getTempProject() {
return new File(Global.TempDirectory, temp_project_name);
}
//--
public db_project_info packCode(File dir) throws Exception {
2023-11-23 22:38:21 +03:00
temp_project_name = Utils.getDateName("test");
//-
File tempProject = getTempProject();
File tempArchive = getTempArchive();
//- создать бд.
2023-11-24 12:28:12 +03:00
FileUtils.forceMkdir(tempProject);
FileUtils.copyDirectory(dir, tempProject);
//---
db_project_info project = new db_project_info(tempProject);
2023-11-23 22:38:21 +03:00
project.Open();
project.Close();
project.clearData();
//--
ZipFolderPass zip = new ZipFolderPass();
if (zip.Do(tempProject.getAbsolutePath(), tempArchive.getAbsolutePath())) {
project_archive_bytes = Utils.packFile(tempArchive);
} else throw new PassException("Не удалось создать архив папки с кодом.");
return project;
}
public boolean unpackProjectOnServer() throws Exception {
File tmpArchive = new File(Global.TempDirectory, temp_project_name + ".zip");
File tmpProject = new File(Global.TempDirectory, temp_project_name);
File testProject = new File(Global.TestsDirectory, String.valueOf(id));
File testArchive = new File(Global.TestsDirectory, id + ".zip");
//--
if (tmpArchive.exists())
FileUtils.forceDelete(tmpArchive);
if (tmpProject.exists())
FileUtils.forceDelete(tmpProject);
if (testProject.exists())
FileUtils.forceDelete(testProject);
if (testArchive.exists())
FileUtils.forceDelete(testArchive);
//--
Utils.unpackFile(project_archive_bytes, tmpArchive); // распаковка байтов.
//--
UnzipFolderPass unzipFolderPass = new UnzipFolderPass();
if (!unzipFolderPass.Do(
tmpArchive.getAbsolutePath(),
Global.TempDirectory.getAbsolutePath())) {
return false;
}
//--
FileUtils.moveDirectory(tmpProject, testProject);
//--
ZipFolderPass zip = new ZipFolderPass();
if (!zip.Do(testProject.getAbsolutePath(), testArchive.getAbsolutePath()))
throw new RepositoryRefuseException("Не удалось переписать архив проекта");
return true;
}
public String getFilesForTable() {
2023-11-23 22:38:21 +03:00
return files.replace("\n", ";");
}
2023-09-17 22:13:42 +03:00
}