187 lines
8.3 KiB
Java
187 lines
8.3 KiB
Java
package Visual_DVM_2021.Passes.All;
|
||
import Common.CommonConstants;
|
||
import Common.Current_;
|
||
import Common.Utils.Utils_;
|
||
import Common.Visual.UI_;
|
||
import _VisualDVM.Current;
|
||
import Common.Database.Database;
|
||
import _VisualDVM.Global;
|
||
import _VisualDVM.Repository.Server.ServerCode;
|
||
import _VisualDVM.Repository.Server.ServerExchangeUnit_2021;
|
||
import _VisualDVM.TestingSystem.Common.TasksPackageState;
|
||
import _VisualDVM.TestingSystem.Common.Test.Test;
|
||
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforConfiguration_json;
|
||
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforPackage_json;
|
||
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforTest_json;
|
||
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforTestingSet_json;
|
||
import _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
|
||
import _VisualDVM.TestingSystem.SAPFOR.SapforPackage.SapforPackage;
|
||
import _VisualDVM.TestingSystem.SAPFOR.SapforTask.SapforTask;
|
||
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapforState;
|
||
import Common.Passes.AddObjectPass;
|
||
import Visual_DVM_2021.Passes.Server.TestingSystemPass;
|
||
|
||
import java.util.Vector;
|
||
public class CloneSapforPackage extends AddObjectPass<SapforPackage> {
|
||
Vector<SapforPackage> srcPackages;
|
||
//--
|
||
Vector<String> inexistingTests;
|
||
Vector<String> inexistingConfigurations;
|
||
//--
|
||
public CloneSapforPackage() {
|
||
super(SapforPackage.class);
|
||
}
|
||
protected SapforTestingSet_json cloneTestingSet(SapforTestingSet_json src) {
|
||
SapforTestingSet_json dst = new SapforTestingSet_json();
|
||
dst.id = target.package_json.getMaxSetId();
|
||
//--
|
||
for (SapforTest_json src_TestJson : src.tests) {
|
||
if (Global.testingServer.db.tests.containsKey(src_TestJson.id)) {
|
||
Test test = Global.testingServer.db.tests.get(src_TestJson.id);
|
||
SapforTest_json testJson = new SapforTest_json();
|
||
//--
|
||
testJson.id = test.id;
|
||
testJson.description = test.description;
|
||
testJson.group_description = src_TestJson.group_description;
|
||
//--
|
||
dst.tests.add(testJson);
|
||
//--
|
||
} else {
|
||
inexistingTests.add(String.valueOf(src_TestJson.id));
|
||
}
|
||
}
|
||
//--
|
||
for (SapforConfiguration_json src_configuration : src.configurations) {
|
||
if (Global.testingServer.db.sapforConfigurations.containsKey(src_configuration.id)) {
|
||
SapforConfiguration configuration = Global.testingServer.db.sapforConfigurations.get(src_configuration.id);
|
||
SapforConfiguration_json configurationJson = new SapforConfiguration_json();
|
||
//--
|
||
configurationJson.id = configuration.id;
|
||
configurationJson.name = configuration.description;
|
||
configurationJson.flags = src_configuration.flags;
|
||
configurationJson.codes.addAll(src_configuration.codes);
|
||
//--
|
||
dst.configurations.add(configurationJson);
|
||
} else {
|
||
inexistingConfigurations.add(String.valueOf(src_configuration.id));
|
||
}
|
||
}
|
||
return dst;
|
||
}
|
||
@Override
|
||
public String getIconPath() {
|
||
return "/icons/MultiFiles.png";
|
||
}
|
||
@Override
|
||
protected Database getDb() {
|
||
return Global.testingServer.db;
|
||
}
|
||
@Override
|
||
protected boolean canStart(Object... args) throws Exception {
|
||
srcPackages = new Vector<>();
|
||
if (!Current.getAccount().CheckRegistered(Log))
|
||
return false;
|
||
//--
|
||
if (!Current_.Check(Log, Current.ServerSapfor))
|
||
return false;
|
||
if (!Current.getServerSapfor().state.equals(ServerSapforState.Done)) {
|
||
Log.Writeln_("Выбранная версия SAPFOR не собрана!");
|
||
return false;
|
||
}
|
||
//--
|
||
srcPackages = Global.testingServer.db.sapforPackages.getCheckedOrCurrent();
|
||
if (srcPackages.isEmpty()) {
|
||
Log.Writeln_("Не отмечено или не выбрано ни одного пакета SAPFOR");
|
||
return false;
|
||
}
|
||
// todo изменить чтобы можно было.
|
||
for (SapforPackage sapforPackage : Global.testingServer.db.sapforPackages.Data.values()) {
|
||
if (sapforPackage.state.equals(TasksPackageState.Draft)) {
|
||
Log.Writeln_("Может существовать только один пакет, готовящийся к публикации.");
|
||
return false;
|
||
}
|
||
}
|
||
//--
|
||
Vector<Integer> src_ids = new Vector<>();
|
||
Vector<SapforPackage_json> src_jsons = new Vector<>();
|
||
for (SapforPackage src : srcPackages) {
|
||
if (src.state.equals(TasksPackageState.Draft)) {
|
||
Log.Writeln_("Пакет " + Utils_.Brackets(src.id) + " является черновиком.");
|
||
return false;
|
||
}
|
||
src_ids.add(src.id);
|
||
}
|
||
TestingSystemPass getJsonsPass = new TestingSystemPass() {
|
||
@Override
|
||
public String getDescription() {
|
||
return "Получить информацию о задачах исходных пакетов";
|
||
}
|
||
@Override
|
||
protected void ServerAction() throws Exception {
|
||
Command(new ServerExchangeUnit_2021(ServerCode.GetSapforPackagesJson, null, src_ids));
|
||
src_jsons.addAll((Vector<SapforPackage_json>) response.object);
|
||
}
|
||
};
|
||
if (!getJsonsPass.Do())
|
||
return false;
|
||
//--
|
||
inexistingTests = new Vector<>();
|
||
inexistingConfigurations = new Vector<>();
|
||
//--
|
||
target = new SapforPackage();
|
||
target.id = CommonConstants.Nan;
|
||
//-
|
||
target.sender_name = Current.getAccount().name;
|
||
target.sender_address = Current.getAccount().email;
|
||
//-
|
||
target.drv = Current.getServerSapfor().call_command;
|
||
target.version = Current.getServerSapfor().version;
|
||
target.kernels = 1; //Global.properties.TestingKernels;
|
||
target.needsEmail = Global.properties.EmailOnTestingProgress ? 1 : 0;
|
||
//--
|
||
target.sapforId = Current.getServerSapfor().id;
|
||
//--
|
||
target.kernels =1; // Global.properties.TestingKernels;
|
||
target.needsEmail = Global.properties.EmailOnTestingProgress ? 1 : 0;
|
||
//--
|
||
target.package_json = new SapforPackage_json();
|
||
///-------------------------------
|
||
target.package_json.kernels = target.kernels;
|
||
target.package_json.sapfor_drv = target.drv;
|
||
//--
|
||
//- заполнение testing_set
|
||
/*
|
||
for (SapforPackage_json srcPackage : src_jsons) {
|
||
//--
|
||
for (SapforTestingSet_json src : srcPackage.testingSets) {
|
||
SapforTestingSet_json dst = cloneTestingSet(src);
|
||
//--
|
||
Vector<SapforTask> new_tasks = target.getActualTestingSetTasks(dst);
|
||
if (!new_tasks.isEmpty()) {
|
||
target.package_json.testingSets.add(dst);
|
||
target.package_json.tasks.addAll(new_tasks);
|
||
} PerformAutoSapforTesting
|
||
}
|
||
}
|
||
*/
|
||
for (SapforTask task : target.package_json.tasks) {
|
||
task.id = target.package_json.getMaxTaskId();
|
||
}
|
||
target.tasksCount = target.package_json.tasks.size();
|
||
/*
|
||
target.testsNames = String.join(";", target.package_json.getTestsNames());
|
||
target.configurationsNames = String.join(";", target.package_json.getConfigurationsNames());
|
||
*/
|
||
//--
|
||
return inexistingTests.isEmpty() && inexistingConfigurations.isEmpty() ||
|
||
UI_.Question(
|
||
(inexistingTests.isEmpty() ? "" : (inexistingTests.size() + " тестов отсутствует;")) +
|
||
(inexistingConfigurations.isEmpty() ? "" : (inexistingConfigurations.size() + " конфигураций отсутствует;")) +
|
||
"Будет добавлено " + target.package_json.tasks.size() + " задач. Продолжить"
|
||
);
|
||
}
|
||
@Override
|
||
protected void body() throws Exception {
|
||
Global.testingServer.db.sapforPackages.Data.put(target.id, target);
|
||
}
|
||
} |