Files
VisualSapfor/src/Visual_DVM_2021/Passes/All/PublishTest.java

97 lines
3.8 KiB
Java
Raw Normal View History

2023-09-17 22:13:42 +03:00
package Visual_DVM_2021.Passes.All;
import Common.Constants;
2023-09-17 22:13:42 +03:00
import Common.Current;
import Common.UI.UI;
import Common.Utils.Utils;
import ProjectData.Project.db_project_info;
import TestingSystem.Test.Test;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Server.TestingSystemPass;
2023-09-17 22:13:42 +03:00
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.nio.file.Paths;
public class PublishTest extends TestingSystemPass<Test> {
@Override
public String getIconPath() {
return "/icons/RedAdd.png";
}
@Override
public String getButtonText() {
return "";
}
protected db_project_info project = null;
protected boolean setProject() {
if (Current.Check(Log, Current.Group, Current.Project) &&
checkSubdirectories()
2023-09-17 22:13:42 +03:00
&& UI.Question("Добавить текущий проект в глобальную базу тестов")) {
project = Current.getProject();
switch (project.languageName) {
case fortran:
return passes.get(PassCode_2021.SPF_GetMaxMinBlockDistribution).Do();
case c:
project.testMaxDim = Utils.getCProjectMaxDim(project);
return true;
default:
return false;
}
}
return false;
}
protected boolean checkSubdirectories() {
if (Current.getProject().hasSubdirectories()) {
Log.Writeln_("Запрещено добавлять тестовые проекты, содержащие подпапки!");
return false;
}
return true;
}
@Override
protected boolean canStart(Object... args) throws Exception {
project = null;
if (Current.getAccount().CheckRegistered(Log) && setProject()) {
2023-09-17 22:13:42 +03:00
target = new Test();
target.description = project.getLocalName() + " " + project.description;
target.dim = project.testMaxDim;
target.sender_name = Current.getAccount().name;
target.sender_address = Current.getAccount().email;
target.group_id = Current.getGroup().id;
if (fillObjectFields()) {
File src = Paths.get(System.getProperty("user.dir"), "Temp", String.valueOf(target.id)).toFile();
2023-09-17 22:13:42 +03:00
Utils.forceDeleteWithCheck(src);
FileUtils.forceMkdir(src);
if (project.db.files.Data.isEmpty()) {
UI.Info("Клонируемый проект не синхронизирован!!! Внутренняя ошибка.");
}
project.Clone(src, false);
FileUtils.copyFile(project.db.getFile(), Paths.get(src.getAbsolutePath(),
Constants.data, project.db.getFile().getName()).toFile());
2023-09-17 22:13:42 +03:00
//архивация.
File archive = Utils.getTempFileName("test_archive");
if (passes.get(PassCode_2021.ZipFolderPass).Do(src.getAbsolutePath(), archive.getAbsolutePath())) {
target.project_archive_bytes = Utils.packFile(archive);
return true;
}
}
}
return false;
}
//тест с именем
protected boolean fillObjectFields() throws Exception {
return server.db.tests.ShowAddObjectDialog(target);
}
@Override
protected void ServerAction() throws Exception {
PublishObject(target);
2023-09-17 22:13:42 +03:00
}
@Override
protected void performFinish() throws Exception {
super.performFinish();
passes.get(PassCode_2021.SynchronizeTests).Do();
}
@Override
protected void showDone() throws Exception {
super.showDone();
server.db.tests.ui_.Show(target.getPK());
}
}