перевод инфы о файлах в джсон. попутно задел под пользовательские типы файлов стиль язык
134 lines
5.3 KiB
Java
134 lines
5.3 KiB
Java
package _VisualDVM.TestingSystem.Common.Test;
|
||
import Common.CommonConstants;
|
||
import Common.Database.Objects.DBObject;
|
||
import Common.Database.Objects.riDBObject;
|
||
import Common.Database.RepositoryRefuseException;
|
||
import Common.Utils.Utils_;
|
||
import Common.Visual.UI;
|
||
import _VisualDVM.Global;
|
||
import _VisualDVM.Passes.All.UnzipFolderPass;
|
||
import _VisualDVM.Passes.All.ZipFolderPass;
|
||
import _VisualDVM.ProjectData.Files.FileState;
|
||
import _VisualDVM.ProjectData.Files.FileType;
|
||
import _VisualDVM.ProjectData.Files.ProjectFile;
|
||
import _VisualDVM.ProjectData.LanguageName;
|
||
import _VisualDVM.TestingSystem.Common.Test.Json.TestFileJson;
|
||
import _VisualDVM.TestingSystem.Common.Test.Json.TestFilesJson;
|
||
import com.sun.org.glassfish.gmbal.Description;
|
||
import org.apache.commons.io.FileUtils;
|
||
|
||
import java.io.File;
|
||
import java.util.LinkedHashMap;
|
||
import java.util.Vector;
|
||
public class Test extends riDBObject {
|
||
@Description("DEFAULT 0")
|
||
public int min_dim = 0; //мин размерность теста.
|
||
@Description("DEFAULT 0")
|
||
public int max_dim = 0; //макс размерность теста.
|
||
@Description("DEFAULT ''")
|
||
public String args = ""; //аргументы командной строки. на всякий случай поле зарезервирую. пусть будут.
|
||
@Description("DEFAULT -1")
|
||
public int group_id = CommonConstants.Nan;
|
||
//@Description("DEFAULT ''")
|
||
//public String files = ""; //файлы теста
|
||
@Description("DEFAULT ''")
|
||
public String extended_description="";
|
||
@Description("DEFAULT ''")
|
||
public String packedFilesJson = "";
|
||
//--------------------------------------------->>>
|
||
@Description("IGNORE")
|
||
public String temp_project_name = "";
|
||
@Description("IGNORE")
|
||
public byte[] project_archive_bytes = null;
|
||
//--------------------------------------------->>>
|
||
public Test(Test test) {
|
||
this.SynchronizeFields(test);
|
||
}
|
||
public Test() {
|
||
}
|
||
@Override
|
||
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;
|
||
extended_description = t.extended_description;
|
||
packedFilesJson=t.packedFilesJson;
|
||
}
|
||
@Override
|
||
public void select(boolean flag) {
|
||
super.select(flag);
|
||
if (UI.isActive())
|
||
Global.mainModule.getUI().getMainWindow().ShowCheckedTestsCount();
|
||
}
|
||
//-
|
||
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.getDownloadsDirectory(), 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 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_.bytesToFile(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;
|
||
}
|
||
//todo проджект файлы тут не нужны. сделать с учетом джсона
|
||
public LinkedHashMap<LanguageName, Vector<ProjectFile>> getPrograms() {
|
||
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<>());
|
||
//--
|
||
TestFilesJson json = Utils_.gson.fromJson(packedFilesJson,TestFilesJson.class);
|
||
for (TestFileJson file : json.values) {
|
||
//--
|
||
if (file.type.equals(FileType.program) &&
|
||
(!file.language.equals(LanguageName.n)))
|
||
res.get(file.language).add(new ProjectFile(new File(file.name)));
|
||
}
|
||
return res;
|
||
}
|
||
//-
|
||
}
|