package Visual_DVM_2021.Passes.All; import Common.Constants; 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; import org.apache.commons.io.FileUtils; import java.io.File; import java.nio.file.Paths; public class PublishTest extends TestingSystemPass { @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() && 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()) { 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(); 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()); //архивация. 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); } @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()); } }