рефакторинг дополнения полей багов
This commit is contained in:
@@ -1,23 +1,16 @@
|
||||
package _VisualDVM.Passes.All;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Passes.Pass;
|
||||
import Common.Properties;
|
||||
import Common.Utils.Utils_;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Passes.PassCode;
|
||||
import _VisualDVM.Passes.Server.ClientPass;
|
||||
import _VisualDVM.Repository.BugReport.BugReport;
|
||||
import _VisualDVM.Repository.BugReport.Json.BugReportAdditionJson;
|
||||
import _VisualDVM.Repository.EmailMessage;
|
||||
import _VisualDVM.Repository.RepositoryServer;
|
||||
import _VisualDVM.Repository.Server.ComponentsServer;
|
||||
import _VisualDVM.Repository.Server.ServerCode;
|
||||
import _VisualDVM.Repository.Server.ServerExchangeUnit_2021;
|
||||
import com.google.gson.JsonObject;
|
||||
import javafx.util.Pair;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
public class AppendBugReportField extends ClientPass<ComponentsServer,BugReport> {
|
||||
public class AppendBugReportField extends ClientPass<ComponentsServer, BugReport> {
|
||||
String fieldName;
|
||||
String oldValue;
|
||||
String addition;
|
||||
@@ -35,7 +28,7 @@ public class AppendBugReportField extends ClientPass<ComponentsServer,BugReport>
|
||||
return "";
|
||||
}
|
||||
protected boolean canUpdate() {
|
||||
return target.canModify(Global.mainModule.getAccount(),Log);
|
||||
return target.canModify(Global.mainModule.getAccount(), Log);
|
||||
}
|
||||
@Override
|
||||
protected ComponentsServer getServer() {
|
||||
@@ -53,26 +46,19 @@ public class AppendBugReportField extends ClientPass<ComponentsServer,BugReport>
|
||||
Log.Writeln_("Дополнение не может быть пустым.");
|
||||
return false;
|
||||
}
|
||||
addition = Utils_.Brackets(Utils_.print_date(
|
||||
new Date())) + " " + Global.mainModule.getAccount().name
|
||||
+ " : " + addition;
|
||||
return canUpdate();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected void body() throws Exception {
|
||||
//todo возможно оформить это единственной командой на сервере.
|
||||
BugReport actual= getServer().getActual(target, BugReport.class);
|
||||
BugReport actual =
|
||||
(BugReport) getServer().ClientRequest(ServerCode.AppendBugReportTextField, "", new BugReportAdditionJson(target, fieldName, addition));
|
||||
target.SynchronizeFields(actual);
|
||||
oldValue = (String) BugReport.class.getField(fieldName).get(target);
|
||||
newValue = oldValue + "\n" + Utils_.Brackets(Utils_.print_date(
|
||||
new Date())) + " " + Global.mainModule.getAccount().name
|
||||
+ " : " + addition;
|
||||
//2. дописываем нужное поле.
|
||||
BugReport.class.getField(fieldName).set(target, newValue);
|
||||
//обновляем дату.
|
||||
target.change_date = new Date().getTime();
|
||||
Global.componentsServer.db.Update(target);
|
||||
//3. отправляем на сервер
|
||||
getServer().ClientRequest(ServerCode.UpdateBugReportField, fieldName, target);
|
||||
}
|
||||
@Override
|
||||
protected void showFinish() throws Exception {
|
||||
@@ -96,7 +82,7 @@ public class AppendBugReportField extends ClientPass<ComponentsServer,BugReport>
|
||||
message_text = target.comment;
|
||||
break;
|
||||
}
|
||||
EmailMessage message= new EmailMessage(
|
||||
EmailMessage message = new EmailMessage(
|
||||
message_header + " " + Utils_.Brackets(Global.mainModule.getAccount().name),
|
||||
message_text
|
||||
);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package _VisualDVM.Repository.BugReport.Json;
|
||||
import _VisualDVM.Repository.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;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
package _VisualDVM.Repository.Server;
|
||||
import Common.CommonConstants;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.RepositoryRefuseException;
|
||||
import Common.Utils.Utils_;
|
||||
@@ -15,6 +14,7 @@ import _VisualDVM.Passes.All.UnzipFolderPass;
|
||||
import _VisualDVM.Passes.All.ZipFolderPass;
|
||||
import _VisualDVM.ProjectData.LanguageName;
|
||||
import _VisualDVM.Repository.BugReport.BugReport;
|
||||
import _VisualDVM.Repository.BugReport.Json.BugReportAdditionJson;
|
||||
import _VisualDVM.Repository.BugReportsDatabase;
|
||||
import _VisualDVM.Repository.Component.ComponentType;
|
||||
import _VisualDVM.Repository.EmailMessage;
|
||||
@@ -27,6 +27,7 @@ import org.apache.commons.io.FileUtils;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
@@ -178,6 +179,7 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
} else
|
||||
throw new RepositoryRefuseException("Баг репорт с ключом " + oldBugReport.id + " не существует.");
|
||||
break;
|
||||
//todo вывести устарело
|
||||
case UpdateBugReportField: //нужно для дополнений полей
|
||||
//-
|
||||
BugReport oldBugReport_ = (BugReport) request.object;
|
||||
@@ -192,6 +194,11 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
} else
|
||||
throw new RepositoryRefuseException("Баг репорт с ключом " + oldBugReport_.id + " не существует.");
|
||||
break;
|
||||
//--
|
||||
case AppendBugReportTextField:
|
||||
AppendBugReportField();
|
||||
break;
|
||||
//--
|
||||
case ReceiveBugReportsDatabase:
|
||||
Print("Получить базу данных баг репортов");
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
@@ -406,6 +413,22 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void AppendBugReportField() throws Exception{
|
||||
BugReportAdditionJson transport = (BugReportAdditionJson) request.object;
|
||||
Print("Дополнить поле " + request.arg + " баг репорта " + transport.id);
|
||||
if (db.bugReports.containsKey(transport.id)){
|
||||
BugReport actual = db.bugReports.get(transport.id);
|
||||
Field field = BugReport.class.getField(transport.fieldName);
|
||||
field.set(actual,field.get(actual)+"\n"+ transport.textAddition);
|
||||
actual.change_date = new Date().getTime();
|
||||
db.Update(actual);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = actual;
|
||||
}
|
||||
else
|
||||
throw new RepositoryRefuseException("Баг репорт с ключом " + transport.id + " не существует.");
|
||||
|
||||
}
|
||||
@Override
|
||||
protected void startAdditionalThreads() {
|
||||
backUp.start();
|
||||
|
||||
@@ -12,6 +12,7 @@ public enum ServerCode {
|
||||
//-
|
||||
UpdateBugReportField,
|
||||
UpdateBugReport,
|
||||
AppendBugReportTextField,
|
||||
//-
|
||||
Email,
|
||||
ReceiveAllArchives,
|
||||
|
||||
Reference in New Issue
Block a user