рефакторинг
This commit is contained in:
212
src/_VisualDVM/ComponentsServer/BugReport/BugReport.java
Normal file
212
src/_VisualDVM/ComponentsServer/BugReport/BugReport.java
Normal file
@@ -0,0 +1,212 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.Objects.rDBObject;
|
||||
import Common.Utils.TextLog;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Utils.Vector_;
|
||||
import _VisualDVM.ComponentsServer.BugReport.Json.RecipientJson;
|
||||
import _VisualDVM.ComponentsServer.BugReport.Json.RecipientsJson;
|
||||
import _VisualDVM.ComponentsServer.BugReport.Json.VisualiserSettingsJson;
|
||||
import _VisualDVM.ComponentsServer.Component.ComponentType;
|
||||
import _VisualDVM.ComponentsServer.Subscribes.Subscriber;
|
||||
import _VisualDVM.Constants;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.GlobalData.Account.Account;
|
||||
import _VisualDVM.ProjectData.SapforData.SapforProperties;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
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 = "";
|
||||
@Description("DEFAULT ''")
|
||||
public String packedSettingsJson = ""; //устарело. (?)
|
||||
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;
|
||||
public BugReport() {
|
||||
}
|
||||
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;
|
||||
visualiser_version = Global.visualiser.version;
|
||||
sapfor_version = Global.components.get(ComponentType.Sapfor_F).version;
|
||||
packedSettingsJson = Utils_.gson.toJson(Global.mainModule.getProject().sapforProperties);
|
||||
percentage = 0;
|
||||
description = description_in;
|
||||
date = new Date().getTime();
|
||||
change_date = new Date().getTime();
|
||||
state = BugReportState.draft;
|
||||
owner = Global.mainModule.getProject().Home;
|
||||
}
|
||||
@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;
|
||||
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;
|
||||
packedSettingsJson = b.packedSettingsJson;
|
||||
//-
|
||||
descriptionAdditionDraft = b.descriptionAdditionDraft;
|
||||
commentAdditionDraft = b.commentAdditionDraft;
|
||||
owner = b.owner;
|
||||
}
|
||||
//--
|
||||
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.HasAccount() ? (Global.mainModule.getAccount().isAdmin() ? ("Адрес отправителя: " + sender_address + "\n") : "") : ""),
|
||||
"Версия SAPFOR: " + sapfor_version,
|
||||
"Версия визуализатора: " + visualiser_version,
|
||||
"----------------------------------"
|
||||
);
|
||||
if (!project_version.isEmpty()) {
|
||||
if (visualiser_version < 1134) {
|
||||
res.add(getSettingsJson().getSummary());
|
||||
} else {
|
||||
res.add(getPropertiesJson().getSummary());
|
||||
}
|
||||
}
|
||||
return String.join("\n", res);
|
||||
}
|
||||
public String getPassport() {
|
||||
return String.join("\n",
|
||||
Constants.separator,
|
||||
"Отправитель: " + sender_name,
|
||||
"Исполнитель: " + executor,
|
||||
"Проект: " + project_version,
|
||||
Constants.separator,
|
||||
getSettingsSummary(),
|
||||
Constants.separator);
|
||||
}
|
||||
public boolean isNoneProject() {
|
||||
return project_version.isEmpty();
|
||||
}
|
||||
//--->
|
||||
public void CheckSubscribers() {
|
||||
for (Subscriber subscriber : Global.componentsServer.db.subscribers.Data.values())
|
||||
subscriber.Select(packedRecipientsJson.contains(subscriber.address));
|
||||
}
|
||||
public void saveRecipientsAsJson(Vector<Subscriber> subscribers) {
|
||||
packedRecipientsJson = Utils_.gson.toJson(new RecipientsJson(subscribers));
|
||||
}
|
||||
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(Account 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(Account 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user