Files
VisualSapfor/src/_VisualDVM/Passes/All/AddBugReport.java

95 lines
4.6 KiB
Java
Raw Normal View History

2024-10-14 12:14:01 +03:00
package _VisualDVM.Passes.All;
2024-10-14 15:19:13 +03:00
import Common.Database.Database;
import Common.Passes.AddObjectPass;
2024-10-11 00:00:30 +03:00
import Common.Utils.Utils_;
import Common.Visual.UI_;
import _VisualDVM.Global;
2024-10-09 22:21:57 +03:00
import _VisualDVM.GlobalData.Account.AccountRole;
2024-10-14 15:19:13 +03:00
import _VisualDVM.Passes.PassCode;
2024-10-09 22:21:57 +03:00
import _VisualDVM.Repository.BugReport.BugReport;
import _VisualDVM.Repository.BugReport.BugReportInterface;
import _VisualDVM.Repository.BugReport.BugReportState;
import _VisualDVM.Repository.Component.ComponentType;
2023-09-17 22:13:42 +03:00
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Date;
import java.util.Vector;
public class AddBugReport extends AddObjectPass<BugReport> {
public AddBugReport() {
super(BugReport.class);
}
@Override
protected Database getDb() {
return Global.componentsServer.db;
}
@Override
public boolean canStart(Object... args) throws Exception {
if (Global.mainModule.getAccount().role.equals(AccountRole.Undefined)) {
2023-09-17 22:13:42 +03:00
Log.Writeln_("Для создания отчёта требуется регистрация");
return false;
}
if (Global.mainModule.HasProject()) {
String version = Global.mainModule.getProject().Home.getAbsolutePath().substring(Global.mainModule.getRoot().Home.getParent().length());
2023-09-17 22:13:42 +03:00
if (version.toCharArray()[0] == '\\') version = version.substring(1);
target = new BugReport(Global.mainModule.getAccount().name, Global.mainModule.getAccount().email,
2023-09-17 22:13:42 +03:00
"Черновик отчёта об ошибке.\nЗаполните описание ошибочной ситуации, и нажмите 'Опубликовать'", version);
return true;
} else {
2024-10-11 00:00:30 +03:00
if (UI_.Warning("Создать отчёт об ошибке без прикрепления проекта.")) {
2023-09-17 22:13:42 +03:00
target = new BugReport();
target.genName();
target.sender_name = Global.mainModule.getAccount().name;
target.sender_address = Global.mainModule.getAccount().email;
2023-09-17 22:13:42 +03:00
target.project_version = "";
target.visualiser_version = Global.visualiser.version;
target.sapfor_version = Global.Components.get(ComponentType.Sapfor_F).version;
2024-10-14 15:19:13 +03:00
target.sapfor_settings = (Global.mainModule.getDb()).settings.getSapforSettingsText();
2023-09-17 22:13:42 +03:00
target.percentage = 0;
target.description = "Черновик отчёта об ошибке.\nЗаполните описание ошибочной ситуации, и нажмите 'Опубликовать'";
target.date = new Date().getTime();
target.change_date = new Date().getTime();
target.state = BugReportState.draft;
target.owner = null;
return true;
}
}
return false;
}
@Override
protected void performPreparation() throws Exception {
Global.mainModule.getSapfor().ResetAllAnalyses();
2023-09-17 22:13:42 +03:00
}
@Override
protected void body() throws Exception {
super.body();
if (!target.project_version.isEmpty()) {
Global.mainModule.getRoot().cleanDepAndGCOVR(); //удаление депов и гкова
2023-09-17 22:13:42 +03:00
//логи во вложения.
File attachementsDir = Global.mainModule.getProject().getAttachmentsDirectory();
2023-09-17 22:13:42 +03:00
Vector<File> logs = new Vector<>();
2024-10-11 00:00:30 +03:00
logs.add(Utils_.MainLog.getLogFile());
2023-09-17 22:13:42 +03:00
logs.add(Paths.get(Global.ComponentsDirectory.getAbsolutePath(), "Sapfor_log.txt").toFile());
logs.add(Paths.get(Global.ComponentsDirectory.getAbsolutePath(), "Server_log.txt").toFile());
logs.add(Global.Components.get(ComponentType.Visualizer_2).getLogFile());
for (File file : logs) {
if (file.exists())
Files.copy(file.toPath(), Paths.get(attachementsDir.getAbsolutePath(), file.getName()), StandardCopyOption.REPLACE_EXISTING);
}
//запаковка рута
Global.mainModule.getPass(PassCode.ZipFolderPass).Do(Global.mainModule.getRoot().Home.getAbsolutePath(), BugReportInterface.getArchiveFile(target).getAbsolutePath());
2023-09-17 22:13:42 +03:00
}
}
@Override
protected boolean validate() {
2024-10-11 00:00:30 +03:00
double size = Utils_.getFileSizeMegaBytes(BugReportInterface.getArchiveFile(target));
2023-09-17 22:13:42 +03:00
if (size > 100) {
Log.Writeln_("Размер запакованного вложения " + size + " Мб превышает 100 Мб");
return false;
}
return super.validate();
}
}