Files
VisualSapfor/src/_VisualDVM/ComponentsServer/BugReport/BugReport.java

214 lines
8.7 KiB
Java
Raw Normal View History

2025-02-18 16:21:20 +03:00
package _VisualDVM.ComponentsServer.BugReport;
import Common.Database.Objects.DBObject;
import Common.Database.Objects.rDBObject;
2024-10-22 13:36:57 +03:00
import Common.Utils.TextLog;
import Common.Utils.Utils_;
import Common.Utils.Vector_;
2025-02-18 16:21:20 +03:00
import _VisualDVM.ComponentsServer.BugReport.Json.RecipientJson;
import _VisualDVM.ComponentsServer.BugReport.Json.RecipientsJson;
import _VisualDVM.ComponentsServer.BugReport.Json.VisualiserSettingsJson;
2025-03-27 12:45:55 +03:00
import _VisualDVM.ComponentsServer.BugReportSetting.BugReportSetting;
2025-02-18 16:21:20 +03:00
import _VisualDVM.ComponentsServer.Component.ComponentType;
2025-02-20 00:39:59 +03:00
import _VisualDVM.ComponentsServer.Recipient.Recipient;
import _VisualDVM.ComponentsServer.UserAccount.UserAccount;
import _VisualDVM.Constants;
import _VisualDVM.Global;
import _VisualDVM.ProjectData.SapforData.SapforProperties;
2023-09-17 22:13:42 +03:00
import com.sun.org.glassfish.gmbal.Description;
import java.io.File;
2024-10-22 13:36:57 +03:00
import java.nio.file.Paths;
2023-09-17 22:13:42 +03:00
import java.util.Date;
2024-10-22 13:36:57 +03:00
import java.util.Vector;
2023-09-17 22:13:42 +03:00
public class BugReport extends rDBObject {
public String project_version = "";
public long visualiser_version = -1;
public long sapfor_version = -1;
public String comment = "";
@Description("DEFAULT ''")
public String packedRecipientsJson = "";
2025-03-27 12:45:55 +03:00
@Description("IGNORE")
public String packedSettingsJson = ""; //todo вывести.
public Vector<BugReportSetting> settings=null;
2023-09-17 22:13:42 +03:00
public String executor = "";
@Description("DEFAULT ''")
public String executor_address = "";
public BugReportState state;
public int percentage = 0;
//-
@Description("IGNORE")
public String descriptionAdditionDraft = "";
@Description("IGNORE")
public String commentAdditionDraft = "";
@Description("IGNORE")
public File owner = null;
@Description("IGNORE")
public byte[] packed_archive = null;
2023-09-17 22:13:42 +03:00
public BugReport() {
}
2024-10-14 15:19:13 +03:00
public BugReport(BugReport src) {
this.SynchronizeFields(src);
}
public BugReport(String sender_name_in, String sender_address_in, String description_in, String version_in) {
genName();
sender_name = sender_name_in;
sender_address = sender_address_in;
project_version = version_in;
2025-01-29 15:20:24 +03:00
visualiser_version = Global.visualiser.version;
sapfor_version = Global.components.get(ComponentType.Sapfor_F).version;
2025-03-27 12:45:55 +03:00
settings = Global.mainModule.getProject().sapforProperties.toBugReportSettings();
2024-10-14 15:19:13 +03:00
percentage = 0;
description = description_in;
date = new Date().getTime();
change_date = new Date().getTime();
state = BugReportState.draft;
owner = Global.mainModule.getProject().Home;
}
2023-09-17 22:13:42 +03:00
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
BugReport b = (BugReport) src;
change_date = b.change_date;
description = b.description;
comment = b.comment;
packedRecipientsJson = b.packedRecipientsJson;
2023-09-17 22:13:42 +03:00
state = b.state;
percentage = b.percentage;
//-
executor = b.executor;
executor_address = b.executor_address;
project_version = b.project_version;
visualiser_version = b.visualiser_version;
sapfor_version = b.sapfor_version;
2025-03-27 12:45:55 +03:00
// packedSettingsJson = b.packedSettingsJson;
2023-09-17 22:13:42 +03:00
//-
descriptionAdditionDraft = b.descriptionAdditionDraft;
commentAdditionDraft = b.commentAdditionDraft;
owner = b.owner;
}
2024-10-22 13:36:57 +03:00
//--
public File getArchiveFile() {
return Paths.get(System.getProperty("user.dir"), "Bugs", id + ".zip").toFile();
}
public String getDescriptionHeader() {
if (description != null) {
String[] data = description.split("\n");
return (data.length > 0) ? data[0] : "";
} else return "";
}
public boolean CheckNotDraft(TextLog log) {
if (state.equals(BugReportState.draft)) {
log.Writeln_("Отчёт об ошибке является черновиком");
return false;
}
return true;
}
public String getMailTitlePrefix() {
return "Ошибка " + Utils_.Brackets(id) + ", автор " + Utils_.Brackets(sender_name) + " : ";
}
public File[] getAttachements() {
File[] project_attachements = Global.mainModule.getProject().getAttachmentsDirectory().listFiles();
File[] res = new File[project_attachements.length + 1];
res[0] = getArchiveFile();
for (int i = 0; i < project_attachements.length; ++i)
res[i + 1] = project_attachements[i];
return res;
}
public boolean CheckDraft(TextLog log) {
if (!state.equals(BugReportState.draft)) {
log.Writeln("Отчёт об ошибке не является черновиком. Он уже опубликован");
return false;
}
return true;
}
public String getNewMailText() {
String res = String.join("\n",
"Описание:", description, getPassport()
);
return res;
}
public String getSettingsSummary() {
Vector<String> res = new Vector_<String>(
(Global.mainModule.getAccount().isAdmin() ? ("Адрес отправителя: " + sender_address + "\n") : ""),
"Версия SAPFOR: " + sapfor_version,
"Версия визуализатора: " + visualiser_version,
"----------------------------------"
);
2025-03-27 12:45:55 +03:00
//--
Vector<BugReportSetting> settings_ = Global.componentsServer.db.getVectorByFK(this, BugReportSetting.class);
SapforProperties dummy = new SapforProperties();
for (BugReportSetting bugReportSetting : settings_)
res.add(dummy.getFieldDescription(bugReportSetting.name) + "=" + Utils_.DQuotes(bugReportSetting.value));
//--
return String.join("\n", res);
2024-10-22 13:36:57 +03:00
}
public String getPassport() {
return String.join("\n",
Constants.separator,
2024-10-22 13:36:57 +03:00
"Отправитель: " + sender_name,
"Исполнитель: " + executor,
"Проект: " + project_version,
Constants.separator,
2024-10-22 13:36:57 +03:00
getSettingsSummary(),
Constants.separator);
2024-10-22 13:36:57 +03:00
}
public boolean isNoneProject() {
return project_version.isEmpty();
}
//--->
2025-02-20 00:39:59 +03:00
public void CheckRecipients() {
for (Recipient recipient : Global.componentsServer.db.recipients.Data.values())
recipient.Select(packedRecipientsJson.contains(recipient.email));
}
2025-02-20 00:39:59 +03:00
public void saveRecipientsAsJson(Vector<Recipient> recipients) {
packedRecipientsJson = Utils_.gson.toJson(new RecipientsJson(recipients));
}
public Vector<String> getRecipients() {
Vector<String> res = new Vector<>();
if (packedRecipientsJson.isEmpty()) return res;
RecipientsJson recipients = Utils_.gson.fromJson(packedRecipientsJson, RecipientsJson.class);
for (RecipientJson recipientJson : recipients.array) {
res.add(recipientJson.address);
}
return res;
}
public VisualiserSettingsJson getSettingsJson() {
return packedSettingsJson.isEmpty() ? new VisualiserSettingsJson() : Utils_.gson.fromJson(packedSettingsJson, VisualiserSettingsJson.class);
}
public SapforProperties getPropertiesJson() {
return packedSettingsJson.isEmpty() ? new SapforProperties() : Utils_.gson.fromJson(packedSettingsJson, SapforProperties.class);
}
public boolean canAppend(UserAccount account, TextLog log) {
if (account.CheckRegistered(log)) {
if (account.email.equals(sender_address) || account.email.equals(executor_address)) {
return true;
} else {
switch (account.role) {
case Admin:
case Developer:
return true;
default:
if (log != null)
log.Writeln_("Вы не являетесь автором, исполнителем, разработчиком, или администратором");
return false;
}
}
}
return false;
}
public boolean canModify(UserAccount account, TextLog log) {
if (account.CheckRegistered(log)) {
switch (account.role) {
case Admin:
case Developer:
return true;
default:
if (account.email.equals(sender_address)) return true;
if (log != null) log.Writeln_("Вы не являетесь автором, разработчиком, или администратором");
return false;
}
}
return false;
}
2023-09-17 22:13:42 +03:00
}