промежуточный. на стороне сервера реализовано создание тестов на основе версий.

This commit is contained in:
2025-02-11 21:28:35 +03:00
parent 4ef8d4b52c
commit 25eabf6852
6 changed files with 144 additions and 64 deletions

View File

@@ -5,6 +5,7 @@ import Common.Database.Objects.riDBObject;
import Common.Database.RepositoryRefuseException;
import Common.Utils.TextLog;
import Common.Utils.Utils_;
import Common.Utils.Vector_;
import _VisualDVM.Constants;
import _VisualDVM.Global;
import _VisualDVM.GlobalData.Account.Account;
@@ -29,10 +30,12 @@ import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage_json;
import _VisualDVM.TestingSystem.DVM.DVMSettings.DVMSettings;
import _VisualDVM.TestingSystem.DVM.DVMTestingChecker;
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforPackage_json;
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforVersion_json;
import _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
import _VisualDVM.TestingSystem.SAPFOR.SapforPackage.SapforPackage;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.SapforSettings;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettingsCommand.SapforSettingsCommand;
import _VisualDVM.TestingSystem.SAPFOR.SapforTask.SapforTask;
import _VisualDVM.TestingSystem.SAPFOR.SapforTestingPlanner;
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapforState;
@@ -104,8 +107,8 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
}
}
@Override
protected void afterCloneAction(riDBObject src, riDBObject dst) throws Exception{
if (src instanceof SapforSettings){
protected void afterCloneAction(riDBObject src, riDBObject dst) throws Exception {
if (src instanceof SapforSettings) {
Vector<PassCode> codes = new Vector<>();
for (SapforSettingsCommand command : db.sapforSettingsCommands.Data.values())
if (command.sapforsettings_id == src.id) codes.add(command.passCode);
@@ -133,8 +136,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
db.Update(sapforConfiguration);
}
}
}
else if (object instanceof DVMSettings) {
} else if (object instanceof DVMSettings) {
DVMSettings dvmSettings = (DVMSettings) object;
//-
for (DVMConfiguration dvmConfiguration : db.dvmConfigurations.Data.values()) {
@@ -142,8 +144,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
db.Update(dvmConfiguration);
}
}
}
else if (object instanceof SapforSettings) {
} else if (object instanceof SapforSettings) {
SapforSettings sapforSettings = (SapforSettings) object;
for (SapforConfiguration sapforConfiguration : db.sapforConfigurations.Data.values()) {
if (sapforConfiguration.tryUpdateSettings(sapforSettings)) {
@@ -170,8 +171,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
}
}
//--
}
else if (object instanceof Group) {
} else if (object instanceof Group) {
Group group = (Group) object;
LinkedHashMap<Integer, Test> groupTests = db.getMapByFKi(group, Test.class);
//--
@@ -193,7 +193,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
Utils_.forceDeleteWithCheck(group_test.getArchive());
Utils_.forceDeleteWithCheck(group_test.getServerPath());
}
//--
} else if (object instanceof ServerSapfor) {
Utils_.forceDeleteWithCheck(
@@ -208,9 +207,9 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
} else if (object instanceof SapforPackage) {
SapforPackage sapforPackage = (SapforPackage) object;
//--
for (SapforConfiguration sapforConfiguration: db.sapforConfigurations.Data.values()){
if (sapforConfiguration.ethalon_id==sapforPackage.id){
sapforConfiguration.ethalon_id= CommonConstants.Nan;
for (SapforConfiguration sapforConfiguration : db.sapforConfigurations.Data.values()) {
if (sapforConfiguration.ethalon_id == sapforPackage.id) {
sapforConfiguration.ethalon_id = CommonConstants.Nan;
db.Update(sapforConfiguration);
}
}
@@ -257,7 +256,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
//основа
@Override
public int getPort() {
return Constants.TestingServerPort;
return Constants.TestingServerPort;
}
@Override
protected void startAdditionalThreads() {
@@ -281,7 +280,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
"Не удалось запустить автоматическое тестирование версии " + request.arg + " системы SAPFOR",
Log.toString()
);
for (String address: Constants.admins_mails){
for (String address : Constants.admins_mails) {
Email(message, address);
}
break;
@@ -375,7 +374,8 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
GetSapforMaxVersion();
break;
case TestCode:
checkUnpackedTests();
Print("Получить финальные версии пакета тестирования SAPFOR");
JoinSapforPackageToGroup();
break;
default:
throw new RepositoryRefuseException("Неподдерживаемый код: " + code);
@@ -745,18 +745,101 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
//--
return target;
}
public void checkUnpackedTests() throws Exception{
for (Test test: db.tests.Data.values()){
public void checkUnpackedTests() throws Exception {
for (Test test : db.tests.Data.values()) {
File testHome = test.getServerPath();
if (!testHome.exists()){
throw new RepositoryRefuseException(test.id+" не существует папка");
if (!testHome.exists()) {
throw new RepositoryRefuseException(test.id + " не существует папка");
}
File testArchive = test.getArchive();
if (!testArchive.exists()){
throw new RepositoryRefuseException(test.id+" не существует архив");
if (!testArchive.exists()) {
throw new RepositoryRefuseException(test.id + " не существует архив");
}
}
response = new ServerExchangeUnit_2021(ServerCode.OK);
}
public Vector<String> getSapforTaskResults(SapforTask task) throws Exception {
Vector<String> res = new Vector<>();
//--
if (!task.variants.isEmpty()) {
for (SapforVersion_json version_json : task.variants) {
res.add(version_json.version);
}
} else {
if (!task.versions.isEmpty()) {
res.add(task.versions.lastElement().version);
}
}
return res;
}
private void JoinSapforPackageToGroup() throws Exception {
String[] packed = request.arg.split("\n");
int groupId = Integer.parseInt(packed[0]);
int packageId = Integer.parseInt(packed[1]);
if (!db.sapforPackages.containsKey(packageId))
throw new RepositoryRefuseException("Пакета с ключом " + packageId + " не существует!");
if (!db.groups.containsKey(groupId))
throw new RepositoryRefuseException("Группы с ключом " + groupId + " не существует!");
//--
SapforPackage sapforPackage = db.sapforPackages.get(packageId);
Group group = db.groups.get(groupId);
//--
SapforPackage_json json = Utils_.jsonFromFile(sapforPackage.getJsonFile(), SapforPackage_json.class);
LinkedHashMap<String, File> versions = new LinkedHashMap<>();
Vector<String> paths = new Vector<>();
for (SapforTask task : json.tasks) {
File task_root = Paths.get(
sapforPackage.getLocalWorkspace().getAbsolutePath(),
String.valueOf(task.set_id),
String.valueOf(task.sapfor_configuration_id)
).toFile();
for (String path : getSapforTaskResults(task)) {
File versionProject = Paths.get(task_root.getAbsolutePath(), path).toFile();
Vector<String> name_parts = new Vector_<>(
String.valueOf(task.id),
task.test_description,
versionProject.getName()
);
versions.put(String.join("_", name_parts),versionProject);
paths.add(versionProject.getAbsolutePath());
}
}
ZipFolderPass zip = new ZipFolderPass();
//создание тестов.
for (String description : versions.keySet()) {
File src = versions.get(description);
File [] files = src.listFiles(pathname -> !pathname.isDirectory());
if (files!=null && files.length>0){
//--
Vector<String> filesNames = new Vector<>();
for (File file: files)
filesNames.add(file.getName());
//--
Test test = new Test();
test.group_id = group.id;
test.description = description;
test.files = String.join("\n", filesNames);
db.Insert(test);
//---
File testProject = new File(Global.TestsDirectory, String.valueOf(test.id));
File testArchive = new File(Global.TestsDirectory, test.id + ".zip");
//---
if (testProject.exists())
FileUtils.forceDelete(testProject);
if (testArchive.exists())
FileUtils.forceDelete(testArchive);
//---
FileUtils.moveDirectory(src, testProject);
//---
if (!zip.Do(testProject.getAbsolutePath(), testArchive.getAbsolutePath())) {
db.Delete(test);
throw new RepositoryRefuseException("Не удалось переписать архив проекта");
}
}
}
//-
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object= paths;
}
}