Переделана публикация текущего проекта как теста, из за автоинкремента делается после создания объекта бд.

This commit is contained in:
2023-11-17 00:58:58 +03:00
parent beb1359544
commit 01fcc59597
9 changed files with 88 additions and 176 deletions

View File

@@ -234,6 +234,7 @@ public abstract class RepositoryServer<D extends Database> {
db.InsertWithCheck(dbObject);
PublishAction(dbObject);
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = (Serializable) dbObject.getPK();
break;
case CheckObjectExistense:
p = (Pair<Class, Object>) request.object;
@@ -294,6 +295,7 @@ public abstract class RepositoryServer<D extends Database> {
db.Insert(dbObject); //проверка не нужна,АИ гарантирует что ключ уникален.
PublishAction(dbObject);
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = (Serializable) dbObject.getPK(); //чтобы пользователь знал, какой ключ.
break;
//</editor-fold>
case EXIT:

View File

@@ -5,7 +5,6 @@ import Common.Database.DBObject;
import Common.Database.riDBObject;
import Common.Global;
import Common.UI.UI;
import GlobalData.User.UserState;
import com.sun.org.glassfish.gmbal.Description;
import java.io.File;
@@ -16,8 +15,6 @@ public class Test extends riDBObject {
public String args = ""; //аргументы командной строки. на всякий случай поле зарезервирую. пусть будут.
@Description("DEFAULT -1")
public int group_id = Constants.Nan;
@Description("DEFAULT 'initial'")
public UserState state = UserState.initial; //загружен ли тестовый проект.
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);

View File

@@ -14,18 +14,18 @@ import Repository.RepositoryRefuseException;
import Repository.RepositoryServer;
import Repository.Server.ServerCode;
import Repository.Server.ServerExchangeUnit_2021;
import TestingSystem.DVM.UserConnection;
import TestingSystem.SAPFOR.SapforTask.SapforTask;
import TestingSystem.SAPFOR.SapforTasksPackage.SapforTasksPackage;
import TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
import TestingSystem.Common.Group.Group;
import TestingSystem.Common.TasksPackageToKill.TasksPackageToKill;
import TestingSystem.Common.Test.Test;
import TestingSystem.Common.Test.TestType;
import TestingSystem.DVM.Tasks.TestCompilationTask;
import TestingSystem.DVM.Tasks.TestRunTask;
import TestingSystem.DVM.Tasks.TestTask;
import TestingSystem.DVM.TasksPackage.TasksPackage;
import TestingSystem.Common.TasksPackageToKill.TasksPackageToKill;
import TestingSystem.Common.Test.Test;
import TestingSystem.Common.Test.TestType;
import TestingSystem.DVM.UserConnection;
import TestingSystem.SAPFOR.SapforTask.SapforTask;
import TestingSystem.SAPFOR.SapforTasksPackage.SapforTasksPackage;
import TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
import Visual_DVM_2021.Passes.All.DownloadRepository;
import Visual_DVM_2021.Passes.All.UnzipFolderPass;
import Visual_DVM_2021.Passes.All.ZipFolderPass;
@@ -117,15 +117,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
}
}
}
} else if (object instanceof Test) {
Test new_test = (Test) object;
// Utils.unpackFile(new_test.project_archive_bytes, new_test.getArchive());
//распаковать архив в папку с тестами. для тестирования удобнее хранить их уже открытыми.
UnzipFolderPass unzipFolderPass = new UnzipFolderPass();
if (!unzipFolderPass.Do(
new_test.getArchive().getAbsolutePath(),
new_test.getServerPath().getParentFile().getAbsolutePath()))
throw new RepositoryRefuseException("Не удалось распаковать Тест с id " + new_test.id);
}
}
@Override
@@ -285,6 +276,28 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
DBObject dbObject = null;
Test test = null;
switch (code) {
case PublishTestProject:
Print("Прикрепить проект к тесту " + request.arg);
System.out.println("Прикрепить проект к тесту " + request.arg);
int test_id = Integer.parseInt(request.arg);
if (db.tests.containsKey(test_id)) {
test = db.tests.get(test_id);
Utils.unpackFile((byte[]) request.object, test.getArchive());
UnzipFolderPass unzipFolderPass = new UnzipFolderPass();
if (!unzipFolderPass.Do(
test.getArchive().getAbsolutePath(),
Global.TestsDirectory.getAbsolutePath())) {
db.Delete(test);
throw new RepositoryRefuseException(
"Не удалось прикрепить проект к тесту с id " + test.id
+ "\nТест будет удален"
);
}
} else {
throw new RepositoryRefuseException("Не существует теста с ключом " + Utils.Brackets(request.arg));
}
response = new ServerExchangeUnit_2021(ServerCode.OK);
break;
case EmailSapforAssembly:
Print("Сообщить о сборке SAPFOR для пользователя " + request.arg);
Vector<String> assembly_info = (Vector<String>) request.object;

View File

@@ -44,22 +44,6 @@ public class PublishTest extends PublishServerObject<TestingServer, Test> {
@Override
protected void performDone() throws Exception {
super.performDone();
// passes.get()
passes.get(PassCode_2021.PublishTestProject).Do(project, pk);
}
//--
/*
if (super.fillObjectFields()) {
File src = Utils.getTempFileName("test"); //id самого теста неизвестен.
Utils.CheckAndCleanDirectory(src);
project.Clone(src, false);
FileUtils.copyFile(project.db.getFile(),
Paths.get(src.getAbsolutePath(),Constants.data, project.db.getFile().getName()).toFile());
//архивация.
File archive = Utils.getTempFileName("test");
if (passes.get(PassCode_2021.ZipFolderPass).Do(src.getAbsolutePath(), archive.getAbsolutePath())) {
target.project_archive_bytes = Utils.packFile(archive);
return true;
}
}
*/
}

View File

@@ -1,16 +1,48 @@
package Visual_DVM_2021.Passes.All;
import Common.Constants;
import Common.Global;
import Common.Utils.Utils;
import ProjectData.Project.db_project_info;
import TestingSystem.Common.Test.Test;
import Repository.Server.ServerCode;
import Repository.Server.ServerExchangeUnit_2021;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.PassException;
import Visual_DVM_2021.Passes.Server.TestingSystemPass;
public class PublishTestProject extends TestingSystemPass<Test> {
protected db_project_info project = null;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.nio.file.Paths;
public class PublishTestProject extends TestingSystemPass<db_project_info> {
Object test_id;
byte[] bytes = null;
@Override
protected boolean canStart(Object... args) throws Exception {
target = (Test) args[0];
project= (db_project_info) args[1];
target = (db_project_info) args[0];
test_id = args[1];
bytes = null;
return true;
}
@Override
protected void performPreparation() throws Exception {
File src = new File(Global.TempDirectory, String.valueOf(test_id));
Utils.CheckAndCleanDirectory(src);
target.Clone(src, false);
FileUtils.copyFile(target.db.getFile(),
Paths.get(src.getAbsolutePath(), Constants.data, target.db.getFile().getName()).toFile());
//архивация.
File archive = Utils.getTempFileName(String.valueOf(test_id));
//---
if (passes.get(PassCode_2021.ZipFolderPass).Do(src.getAbsolutePath(), archive.getAbsolutePath())) {
bytes = Utils.packFile(archive);
} else throw new PassException("Не удалось создать архив проекта");
}
@Override
protected void ServerAction() throws Exception {
Command(new ServerExchangeUnit_2021(ServerCode.PublishTestProject, String.valueOf(test_id), bytes));
}
@Override
protected void performFail() throws Exception {
super.performFail();
passes.get(PassCode_2021.SynchronizeTests).Do();
}
}

View File

@@ -22,4 +22,8 @@ public class EditServerObject<S extends RepositoryServer, D extends riDBObject>
protected void ServerAction() throws Exception {
EditObject(target);
}
@Override
protected void showDone() throws Exception {
getDb().tables.get(d).ui_.Show(target.getPK());
}
}

View File

@@ -3,6 +3,7 @@ import Common.Current;
import Common.Database.riDBObject;
import Repository.RepositoryServer;
public class PublishServerObject<S extends RepositoryServer, D extends riDBObject> extends ServerObjectPass<S, D> {
protected Object pk = null;
public PublishServerObject(S server_in, Class<D> d_in) {
super(server_in, d_in);
}
@@ -13,6 +14,7 @@ public class PublishServerObject<S extends RepositoryServer, D extends riDBObjec
//--
@Override
protected boolean canStart(Object... args) throws Exception {
pk = null;
if (Current.getAccount().CheckRegistered(Log)) {
target = d.newInstance();
target.sender_name = Current.getAccount().name;
@@ -25,5 +27,11 @@ public class PublishServerObject<S extends RepositoryServer, D extends riDBObjec
@Override
protected void ServerAction() throws Exception {
PublishObject(target);
pk = response.object;
}
@Override
protected void showDone() throws Exception {
super.showDone();
getDb().tables.get(d).ui_.Show(pk);
}
}

View File

@@ -23,11 +23,6 @@ public abstract class ServerObjectPass <S extends RepositoryServer, D extends DB
super.performFinish();
passes.get(getDb().getSynchronizePassCode()).Do();
}
@Override
protected void showDone() throws Exception {
super.showDone();
getDb().tables.get(d).ui_.Show(target.getPK());
}
//-
public boolean fillObjectFields() throws Exception {
return getDb().tables.get(d).ShowAddObjectDialog(target);