рефакторинг бд файлов тестов.
This commit is contained in:
2025-03-20 17:48:18 +03:00
parent 3f4ef5f198
commit 0b5f8c6ec7
22 changed files with 374 additions and 359 deletions

View File

@@ -7,16 +7,15 @@ import _VisualDVM.ComponentsServer.UserAccount.UserAccount;
import _VisualDVM.Constants;
import _VisualDVM.Global;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.ProjectData.Files.ProjectFile;
import _VisualDVM.ServerObjectsCache.ConfigurationCache;
import _VisualDVM.ServerObjectsCache.VisualCaches;
import _VisualDVM.TestingSystem.Common.Configuration.Configuration;
import _VisualDVM.TestingSystem.Common.Group.Group;
import _VisualDVM.TestingSystem.Common.Group.GroupsDBTable;
import _VisualDVM.TestingSystem.Common.Test.Json.TestFileJson;
import _VisualDVM.TestingSystem.Common.Test.Json.TestFilesJson;
import _VisualDVM.TestingSystem.Common.Test.Test;
import _VisualDVM.TestingSystem.Common.Test.TestDBTable;
import _VisualDVM.TestingSystem.Common.TestFile.TestFile;
import _VisualDVM.TestingSystem.Common.TestFile.TestFilesDBTable;
import _VisualDVM.TestingSystem.Common.TestingPackageToKill.TestingPackagesToKillDBTable;
import _VisualDVM.TestingSystem.DVM.DVMConfiguration.DVMConfiguration;
import _VisualDVM.TestingSystem.DVM.DVMConfiguration.DVMConfigurationDBTable;
@@ -44,6 +43,7 @@ import java.util.Vector;
public class TestsDatabase extends SQLiteDatabase {
public DVMConfigurationDBTable dvmConfigurations;
public TestDBTable tests;
public TestFilesDBTable testsFiles;
public GroupsDBTable groups;
public DVMPackageDBTable dvmPackages;
public SapforPackageDBTable sapforPackages;
@@ -67,6 +67,7 @@ public class TestsDatabase extends SQLiteDatabase {
addTable(dvmConfigurations = new DVMConfigurationDBTable());
addTable(groups = new GroupsDBTable());
addTable(tests = new TestDBTable());
addTable(testsFiles = new TestFilesDBTable());
addTable(dvmPackages = new DVMPackageDBTable());
addTable(sapforPackages = new SapforPackageDBTable());
addTable(testingPackagesToKill = new TestingPackagesToKillDBTable());
@@ -189,28 +190,25 @@ public class TestsDatabase extends SQLiteDatabase {
break;
}
}
public void SaveTestFromSingleFile(ServerSapfor sapfor, Group group, Test test, File file) throws Exception {
public void importTestFile(Test test, File file) throws Exception {
File testDirectory = new File(Global.TestsDirectory, String.valueOf(test.id));
Utils_.CheckAndCleanDirectory(testDirectory);
File testFile = Paths.get(testDirectory.getAbsolutePath(), file.getName()).toFile();
FileUtils.copyFile(file, testFile);
//----
DetectTestMinMaxDim(sapfor, group, test);
File dst = Paths.get(testDirectory.getAbsolutePath(), file.getName()).toFile();
FileUtils.copyFile(file, dst);
}
//---
//---
public void CreateTestFromSingleFile(UserAccount account, ServerSapfor sapfor, Group group, File file, String testDescription) throws Exception {
Test test = new Test();
test.description = testDescription;
test.sender_name = account.name;
test.sender_address = account.email;
test.group_id = group.id;
TestFilesJson testFilesJson = new TestFilesJson();
testFilesJson.values.add(new TestFileJson(new ProjectFile(file)));
test.packedFilesJson = Utils_.gson.toJson(testFilesJson);
Insert(test);
//->>
SaveTestFromSingleFile(sapfor, group, test, file);
importTestFile(test, file);
TestFile testFile = new TestFile(test,file);
Insert(testFile);
//--
DetectTestMinMaxDim(sapfor, group, test);
}
public void RefreshGroup(UserAccount account, ServerSapfor sapfor, Pair<Group, Vector<File>> groupData) throws Exception {
Group group = groupData.getKey();
@@ -226,11 +224,11 @@ public class TestsDatabase extends SQLiteDatabase {
} else {
for (File file : files) {
String testDescription = Utils_.getNameWithoutExtension(file.getName()) + "_" + group.language.getDVMCompile();
Test oldTest = tests.getTestByDescription(oldGroup.id, testDescription);
Test oldTest = tests.getStandardTestByDescription(oldGroup.id, testDescription);
if (oldTest == null) {
CreateTestFromSingleFile(account, sapfor, oldGroup, file, testDescription);
CreateTestFromSingleFile(account, sapfor, oldGroup, file, testDescription);
} else {
SaveTestFromSingleFile(sapfor, group, oldTest, file);
importTestFile(oldTest, file);
}
}
}
@@ -348,4 +346,41 @@ public class TestsDatabase extends SQLiteDatabase {
dvmSettings.ShowUI();
super.ResetUI();
}
public void saveTestFiles(Test test) throws Exception{
for (TestFile file : test.files) {
file.test_id = test.id;
Insert(file);
}
test.files = null;
}
public void DeleteTestFiles(Test test) throws Exception {
Vector<TestFile> files = getVectorByFK(test, TestFile.class);
for (TestFile file : files)
Delete(file);
}
public void Patch() throws Exception{
//файлы тестов.
/*
Vector<TestFile> testFiles = new Vector<>();
for (Test test:tests.Data.values()){
TestFilesJson json = Utils_.gson.fromJson(test.packedFilesJson, TestFilesJson.class);
for (TestFileJson testFileJson: json.values){
TestFile testFile = new TestFile();
//-
testFile.test_id = test.id;
testFile.name = testFileJson.name;
testFile.style = testFileJson.style;
testFile.languageName = testFileJson.language;
testFile.fileType= testFileJson.type;
//--
testFiles.add(testFile);
}
}
BeginTransaction();
for (TestFile testFile: testFiles){
Insert(testFile);
}
Commit();
*/
}
}