рефакторинг
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport;
|
||||
import Common.Visual.Fonts.VisualiserFonts;
|
||||
import Common.Visual.StatusEnum;
|
||||
|
||||
import java.io.Serializable;
|
||||
public enum BugReportState implements Serializable, StatusEnum {
|
||||
active,
|
||||
closed,
|
||||
draft;
|
||||
@Override
|
||||
public VisualiserFonts getFont() {
|
||||
switch (this) {
|
||||
case active:
|
||||
return VisualiserFonts.BadState;
|
||||
case closed:
|
||||
return VisualiserFonts.GoodState;
|
||||
default:
|
||||
return StatusEnum.super.getFont();
|
||||
}
|
||||
}
|
||||
public String getDescription() {
|
||||
switch (this) {
|
||||
case draft:
|
||||
return "черновик";
|
||||
case active:
|
||||
return "открыт";
|
||||
case closed:
|
||||
return "закрыт";
|
||||
default:
|
||||
return StatusEnum.super.getDescription();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport;
|
||||
import Common.Database.Tables.DBTable;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
import _VisualDVM.ComponentsServer.BugReport.UI.BugReportsForm;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
public class BugReportsDBTable extends DBTable<String, BugReport> {
|
||||
public BugReportsDBTable() {
|
||||
super(String.class, BugReport.class);
|
||||
}
|
||||
@Override
|
||||
public String getSingleDescription() {
|
||||
return "отчёт об ошибке";
|
||||
}
|
||||
@Override
|
||||
public String getPluralDescription() {
|
||||
return "отчёты об ошибках";
|
||||
}
|
||||
@Override
|
||||
protected DataSetControlForm createUI(JPanel mountPanel) {
|
||||
return new BugReportsForm(this, mountPanel);
|
||||
}
|
||||
public Vector<BugReport> getAllDrafts() throws Exception {
|
||||
return Data.values().stream().filter(bugReport -> bugReport.state.equals(BugReportState.draft)).collect(Collectors.toCollection(Vector::new));
|
||||
}
|
||||
//-
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport.Json;
|
||||
import _VisualDVM.ComponentsServer.BugReport.BugReport;
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.io.Serializable;
|
||||
public class BugReportAdditionJson implements Serializable {
|
||||
@Expose
|
||||
public String id = "";
|
||||
@Expose
|
||||
public String fieldName = "";
|
||||
@Expose
|
||||
public String textAddition ="";
|
||||
public BugReportAdditionJson(BugReport bugReport, String fieldName_in, String addition_in){
|
||||
id = bugReport.id;
|
||||
fieldName = fieldName_in;
|
||||
textAddition = addition_in;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport.Json;
|
||||
import com.google.gson.annotations.Expose;
|
||||
public class RecipientJson {
|
||||
@Expose
|
||||
public String address;
|
||||
public RecipientJson(String addres_in) {
|
||||
address= addres_in;
|
||||
}
|
||||
public RecipientJson() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport.Json;
|
||||
import _VisualDVM.ComponentsServer.Subscribes.Subscriber;
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
public class RecipientsJson {
|
||||
@Expose
|
||||
public List<RecipientJson> array = new Vector<>();
|
||||
public RecipientsJson() {
|
||||
}
|
||||
//при создании пакета.
|
||||
public RecipientsJson(Vector<? extends Subscriber> subscribers) {
|
||||
array = new Vector<>();
|
||||
for (Subscriber subscriber : subscribers)
|
||||
array.add(new RecipientJson(subscriber.address));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport.Json;
|
||||
import com.google.gson.annotations.Expose;
|
||||
public class VisualiserSettingJson {
|
||||
@Expose
|
||||
public String name;
|
||||
@Expose
|
||||
public String value;
|
||||
public VisualiserSettingJson(){
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport.Json;
|
||||
import _VisualDVM.ProjectData.SapforData.SapforProperties;
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
public class VisualiserSettingsJson {
|
||||
@Expose
|
||||
public List<VisualiserSettingJson> array = new Vector<>();
|
||||
public String getSummary() {
|
||||
SapforProperties properties = new SapforProperties(); //только для извлечения описаний.
|
||||
Vector<String> res = new Vector<>();
|
||||
for (VisualiserSettingJson setting : array) {
|
||||
try {
|
||||
res.add(properties.getFieldDescription(setting.name) + "=" + setting.value);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return String.join("\n", res);
|
||||
}
|
||||
}
|
||||
177
src/_VisualDVM/ComponentsServer/BugReport/UI/BugReportsForm.java
Normal file
177
src/_VisualDVM/ComponentsServer/BugReport/UI/BugReportsForm.java
Normal file
@@ -0,0 +1,177 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport.UI;
|
||||
import Common.Database.Tables.DataSet;
|
||||
import Common.Passes.PassCode_;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
import Common.Visual.Menus.DataMenuBar;
|
||||
import Common.Visual.Tables.ColumnInfo;
|
||||
import Common.Visual.Tables.RendererDate;
|
||||
import Common.Visual.Tables.RendererProgressBar;
|
||||
import Common.Visual.Tables.RendererStatusEnum;
|
||||
import _VisualDVM.ComponentsServer.BugReport.BugReport;
|
||||
import _VisualDVM.ComponentsServer.BugReport.BugReportState;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Passes.PassCode;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Comparator;
|
||||
public class BugReportsForm extends DataSetControlForm<BugReport> {
|
||||
//todo упразднить и раскидать по стандартным фильтрам. галки и столбцы
|
||||
public static String filterKey = "";
|
||||
public static String filterSenderName = "";
|
||||
public static String filterDescription = "";//ввести рендерер, чтобы значение столбца выдавало фулл описание и фильтр по столбцу работал
|
||||
public static String filterComment = "";
|
||||
public static String filterExecutor = "";
|
||||
public static String filterVersion = "";
|
||||
public static boolean filterOpenedOnly = false;
|
||||
public static boolean filterMyOnly = false;
|
||||
//-
|
||||
public BugReportsForm(DataSet<?, BugReport> dataSource_in, JPanel mountPanel_in) {
|
||||
super(dataSource_in, mountPanel_in);
|
||||
}
|
||||
@Override
|
||||
protected void createColumns() {
|
||||
AddColumns(
|
||||
new ColumnInfo<BugReport>("Описание") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.getDescriptionHeader();
|
||||
}
|
||||
@Override
|
||||
public int getMaxWidth() {
|
||||
return 600;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Отправитель") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.sender_name;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Исполнитель") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.executor;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Проект") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.project_version;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Завершенность") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.percentage;
|
||||
}
|
||||
@Override
|
||||
public Class getRendererClass() {
|
||||
return RendererProgressBar.class;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Дата создания") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.date;
|
||||
}
|
||||
@Override
|
||||
public Class getRendererClass() {
|
||||
return RendererDate.class;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Дата изменения") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.change_date;
|
||||
}
|
||||
@Override
|
||||
public Class getRendererClass() {
|
||||
return RendererDate.class;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Статус") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.state;
|
||||
}
|
||||
@Override
|
||||
public Class getRendererClass() {
|
||||
return RendererStatusEnum.class;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@Override
|
||||
protected boolean hasCheckBox() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected void ShowCurrentObject() throws Exception {
|
||||
super.ShowCurrentObject();
|
||||
Global.mainModule.getUI().getMainWindow().getCallbackWindow().ShowCurrentBugReport();
|
||||
}
|
||||
@Override
|
||||
protected void ShowNoCurrentObject() throws Exception {
|
||||
super.ShowNoCurrentObject();
|
||||
Global.mainModule.getUI().getMainWindow().getCallbackWindow().ShowNoCurrentBugReport();
|
||||
}
|
||||
@Override
|
||||
protected void MouseAction2() throws Exception {
|
||||
Global.mainModule.getPass(PassCode.OpenBugReportTestProject).Do();
|
||||
}
|
||||
@Override
|
||||
protected void createControl() {
|
||||
//https://stackoverflow.com/questions/9091208/jtable-enter-key
|
||||
super.createControl();
|
||||
final String solve = "Solve";
|
||||
KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
|
||||
control.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(enter, solve);
|
||||
control.getActionMap().put(solve, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Global.mainModule.getPass(PassCode.OpenBugReportTestProject).Do();
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public PassCode_ getDeletePassCode() {
|
||||
return PassCode.DeleteBugReport;
|
||||
}
|
||||
@Override
|
||||
public DataMenuBar createMenuBar() {
|
||||
return new DataMenuBar(dataSource.getPluralDescription(),
|
||||
PassCode.SynchronizeBugReports,
|
||||
PassCode.DownloadAllBugReportsArchives,
|
||||
PassCode.AddBugReport,
|
||||
PassCode.PublishBugReport,
|
||||
PassCode.OpenBugReportTestProject,
|
||||
PassCode.OpenBugReport,
|
||||
PassCode.UpdateBugReportProgress,
|
||||
PassCode.CloseBugReport,
|
||||
PassCode.DeleteBugReport);
|
||||
}
|
||||
@Override
|
||||
protected Comparator<BugReport> getDefaultComparator() {
|
||||
return (o1, o2) -> -(o1.getDate().compareTo(o2.getDate()));
|
||||
}
|
||||
@Override
|
||||
public boolean isObjectVisible(BugReport object) {
|
||||
return super.isObjectVisible(object) && (
|
||||
object.state.equals(BugReportState.draft) ||
|
||||
object.id.toUpperCase().contains(filterKey.toUpperCase())
|
||||
&& object.sender_name.toUpperCase().contains(filterSenderName.toUpperCase())
|
||||
&& object.description.toUpperCase().contains(filterDescription.toUpperCase())
|
||||
&& object.comment.toUpperCase().contains(filterComment.toUpperCase())
|
||||
&& object.executor.toUpperCase().contains(filterExecutor.toUpperCase())
|
||||
&& object.project_version.toUpperCase().contains(filterVersion.toUpperCase())
|
||||
&& (!filterOpenedOnly || object.state.equals(BugReportState.active))
|
||||
&& (!filterMyOnly ||
|
||||
(object.sender_address.equalsIgnoreCase(Global.mainModule.getAccount().email) ||
|
||||
object.executor_address.equalsIgnoreCase(Global.mainModule.getAccount().email)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user