2024-10-09 22:21:57 +03:00
|
|
|
|
package _VisualDVM.TestingSystem.Common.Test;
|
2024-10-07 14:22:52 +03:00
|
|
|
|
import Common.CommonConstants;
|
2024-10-14 15:19:13 +03:00
|
|
|
|
import Common.Database.Objects.DBObject;
|
|
|
|
|
|
import Common.Database.Objects.riDBObject;
|
2024-10-17 17:22:33 +03:00
|
|
|
|
import Common.Database.RepositoryRefuseException;
|
2024-10-11 00:00:30 +03:00
|
|
|
|
import Common.Utils.Utils_;
|
2024-10-15 15:13:57 +03:00
|
|
|
|
import Common.Visual.UI;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
import _VisualDVM.Global;
|
2024-10-14 15:19:13 +03:00
|
|
|
|
import _VisualDVM.Passes.All.UnzipFolderPass;
|
|
|
|
|
|
import _VisualDVM.Passes.All.ZipFolderPass;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.ProjectData.Files.FileState;
|
|
|
|
|
|
import _VisualDVM.ProjectData.Files.FileType;
|
|
|
|
|
|
import _VisualDVM.ProjectData.Files.ProjectFile;
|
|
|
|
|
|
import _VisualDVM.ProjectData.LanguageName;
|
2025-03-07 03:10:05 +03:00
|
|
|
|
import _VisualDVM.TestingSystem.Common.Test.Json.TestFileJson;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Test.Json.TestFilesJson;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import com.sun.org.glassfish.gmbal.Description;
|
2023-11-23 01:00:08 +03:00
|
|
|
|
import org.apache.commons.io.FileUtils;
|
2023-11-17 00:04:21 +03:00
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
2023-11-26 00:30:43 +03:00
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
|
import java.util.Vector;
|
2023-11-16 16:20:20 +03:00
|
|
|
|
public class Test extends riDBObject {
|
2023-12-01 21:18:29 +03:00
|
|
|
|
@Description("DEFAULT 0")
|
|
|
|
|
|
public int min_dim = 0; //мин размерность теста.
|
|
|
|
|
|
@Description("DEFAULT 0")
|
|
|
|
|
|
public int max_dim = 0; //макс размерность теста.
|
2023-09-17 22:13:42 +03:00
|
|
|
|
@Description("DEFAULT ''")
|
|
|
|
|
|
public String args = ""; //аргументы командной строки. на всякий случай поле зарезервирую. пусть будут.
|
2023-11-16 16:20:20 +03:00
|
|
|
|
@Description("DEFAULT -1")
|
2024-10-07 14:22:52 +03:00
|
|
|
|
public int group_id = CommonConstants.Nan;
|
2025-03-07 03:10:05 +03:00
|
|
|
|
//@Description("DEFAULT ''")
|
|
|
|
|
|
//public String files = ""; //файлы теста
|
2025-02-13 18:40:53 +03:00
|
|
|
|
@Description("DEFAULT ''")
|
|
|
|
|
|
public String extended_description="";
|
2025-03-07 00:21:43 +03:00
|
|
|
|
@Description("DEFAULT ''")
|
|
|
|
|
|
public String packedFilesJson = "";
|
2023-11-23 01:00:08 +03:00
|
|
|
|
//--------------------------------------------->>>
|
|
|
|
|
|
@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
|
2024-10-14 15:19:13 +03:00
|
|
|
|
public void SynchronizeFields(DBObject src) {
|
|
|
|
|
|
super.SynchronizeFields(src);
|
|
|
|
|
|
Test t = (Test) src;
|
|
|
|
|
|
min_dim = t.min_dim;
|
|
|
|
|
|
max_dim = t.max_dim;
|
|
|
|
|
|
args = t.args;
|
|
|
|
|
|
group_id = t.group_id;
|
2025-02-13 18:40:53 +03:00
|
|
|
|
extended_description = t.extended_description;
|
2025-03-07 00:21:43 +03:00
|
|
|
|
packedFilesJson=t.packedFilesJson;
|
2024-10-14 15:19:13 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
2023-09-17 22:13:42 +03:00
|
|
|
|
public void select(boolean flag) {
|
|
|
|
|
|
super.select(flag);
|
2024-10-15 15:13:57 +03:00
|
|
|
|
if (UI.isActive())
|
2024-10-15 02:32:52 +03:00
|
|
|
|
Global.mainModule.getUI().getMainWindow().ShowCheckedTestsCount();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
2023-11-17 00:04:21 +03:00
|
|
|
|
//-
|
|
|
|
|
|
public File getArchive() {
|
|
|
|
|
|
return new File(Global.TestsDirectory, id + ".zip");
|
|
|
|
|
|
}
|
|
|
|
|
|
//-
|
|
|
|
|
|
public File getServerPath() {
|
|
|
|
|
|
return new File(Global.TestsDirectory, String.valueOf(id));
|
|
|
|
|
|
}
|
|
|
|
|
|
public File getHomePath() {
|
2025-01-29 15:20:24 +03:00
|
|
|
|
return new File(Global.visualiser.getDownloadsDirectory(), String.valueOf(id));
|
2023-11-17 00:04:21 +03:00
|
|
|
|
}
|
2023-11-23 01:00:08 +03:00
|
|
|
|
//--
|
|
|
|
|
|
public File getTempArchive() {
|
|
|
|
|
|
return new File(Global.TempDirectory, temp_project_name + ".zip");
|
|
|
|
|
|
}
|
|
|
|
|
|
public File getTempProject() {
|
|
|
|
|
|
return new File(Global.TempDirectory, temp_project_name);
|
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
//--
|
2024-10-11 00:00:30 +03:00
|
|
|
|
Utils_.bytesToFile(project_archive_bytes, tmpArchive); // распаковка байтов.
|
2023-11-23 01:00:08 +03:00
|
|
|
|
//--
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
2025-03-07 03:10:05 +03:00
|
|
|
|
//todo проджект файлы тут не нужны. сделать с учетом джсона
|
2023-11-27 21:59:45 +03:00
|
|
|
|
public LinkedHashMap<LanguageName, Vector<ProjectFile>> getPrograms() {
|
2023-11-26 00:30:43 +03:00
|
|
|
|
LinkedHashMap<LanguageName, Vector<ProjectFile>> res = new LinkedHashMap<>();
|
|
|
|
|
|
//--
|
|
|
|
|
|
res.put(LanguageName.fortran, new Vector<>());
|
|
|
|
|
|
res.put(LanguageName.c, new Vector<>());
|
|
|
|
|
|
res.put(LanguageName.cpp, new Vector<>());
|
|
|
|
|
|
//--
|
2025-03-07 03:10:05 +03:00
|
|
|
|
TestFilesJson json = Utils_.gson.fromJson(packedFilesJson,TestFilesJson.class);
|
|
|
|
|
|
for (TestFileJson file : json.values) {
|
2023-11-26 00:30:43 +03:00
|
|
|
|
//--
|
2025-03-07 03:10:05 +03:00
|
|
|
|
if (file.type.equals(FileType.program) &&
|
|
|
|
|
|
(!file.language.equals(LanguageName.n)))
|
|
|
|
|
|
res.get(file.language).add(new ProjectFile(new File(file.name)));
|
2023-11-26 00:30:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
2024-10-20 13:34:38 +03:00
|
|
|
|
//-
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|