Files
VisualSapfor/src/_VisualDVM/Passes/All/AddBugReport.java
02090095 7178ecbc9c ++
убирание джсон запакованных полей у баг репортов
2025-03-27 15:31:26 +03:00

94 lines
4.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package _VisualDVM.Passes.All;
import Common.Database.Database;
import Common.Passes.AddObjectPass;
import Common.Utils.Utils_;
import Common.Visual.UI;
import _VisualDVM.ComponentsServer.BugReport.BugReport;
import _VisualDVM.ComponentsServer.BugReport.BugReportState;
import _VisualDVM.ComponentsServer.Component.ComponentType;
import _VisualDVM.ComponentsServer.UserAccount.AccountRole;
import _VisualDVM.Global;
import _VisualDVM.Passes.PassCode;
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)) {
Log.Writeln_("Для создания отчёта требуется регистрация");
return false;
}
if (Global.mainModule.HasProject()) {
String version = Global.mainModule.getProject().Home.getAbsolutePath().substring(Global.mainModule.getRoot().Home.getParent().length());
if (version.toCharArray()[0] == '\\') version = version.substring(1);
target = new BugReport(Global.mainModule.getAccount().name, Global.mainModule.getAccount().email,
"Черновик отчёта об ошибке.\nЗаполните описание ошибочной ситуации, и нажмите 'Опубликовать'", version);
return true;
} else {
if (UI.Warning("Создать отчёт об ошибке без прикрепления проекта.")) {
target = new BugReport();
target.genName();
target.sender_name = Global.mainModule.getAccount().name;
target.sender_address = Global.mainModule.getAccount().email;
target.project_version = "";
target.visualiser_version = Global.visualiser.version;
target.sapfor_version = Global.components.get(ComponentType.Sapfor_F).version;
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();
}
@Override
protected void body() throws Exception {
super.body();
if (!target.project_version.isEmpty()) {
Global.mainModule.getRoot().cleanDepAndGCOVR(); //удаление депов и гкова
//логи во вложения.
File attachementsDir = Global.mainModule.getProject().getAttachmentsDirectory();
Vector<File> logs = new Vector<>();
logs.add(Utils_.MainLog.getLogFile());
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(),
target.getArchiveFile().getAbsolutePath());
}
}
@Override
protected boolean validate() {
double size = Utils_.getFileSizeMegaBytes(target.getArchiveFile());
if (size > 100) {
Log.Writeln_("Размер запакованного вложения " + size + " Мб превышает 100 Мб");
return false;
}
return super.validate();
}
}