рефакторинг. прописал стандартную проверку существования объекта в бд сервера
This commit is contained in:
12
.idea/workspace.xml
generated
12
.idea/workspace.xml
generated
@@ -7,21 +7,9 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/DVM/DVMConfigurationGroup/DVMConfigurationGroup.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/DVM/DVMConfigurationGroup/DVMConfigurationGroupsDBTable.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/ComponentsServer/ComponentsServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/ComponentsServer/ComponentsServer.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Constants.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Constants.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Passes/All/DeleteUserAccount.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Passes/All/DeleteUserAccount.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Passes/All/EditUserAccount.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Passes/All/EditUserAccount.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Passes/All/PublishUserAccount.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Passes/All/PublishUserAccount.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Passes/Server/DeleteServerObject.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Passes/Server/DeleteServerObject.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Passes/Server/EditServerObject.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Passes/Server/EditServerObject.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Passes/Server/PublishServerObject.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Passes/Server/PublishServerObject.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Passes/Server/ServerObjectPass.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Passes/Server/ServerObjectPass.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Repository/Server/RepositoryServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Repository/Server/RepositoryServer.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Repository/Server/ServerCode.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Repository/Server/ServerCode.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/Common/Test/Test.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/Common/Test/Test.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/Common/TestingServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/Common/TestingServer.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
|
||||
@@ -8,7 +8,6 @@ import _VisualDVM.ComponentsServer.BugReport.Json.BugReportAdditionJson;
|
||||
import _VisualDVM.ComponentsServer.Component.ComponentType;
|
||||
import _VisualDVM.ComponentsServer.Component.Json.ComponentPublicationInfoJson;
|
||||
import _VisualDVM.ComponentsServer.Component.Json.ComponentVersionsInfoJson;
|
||||
import _VisualDVM.ComponentsServer.SubscriberWorkspace.SubscriberWorkspace;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.AccountRole;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.UserAccount;
|
||||
import _VisualDVM.Constants;
|
||||
@@ -25,7 +24,6 @@ import org.apache.commons.io.FileUtils;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
@@ -133,14 +131,13 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
}
|
||||
void AppendBugReportField() throws Exception {
|
||||
BugReportAdditionJson transport = (BugReportAdditionJson) request.object;
|
||||
if (db.bugReports.containsKey(transport.id)) {
|
||||
checkExistense(transport.id, BugReport.class);
|
||||
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.object = actual;
|
||||
} else throw new RepositoryRefuseException("Баг репорт с ключом " + transport.id + " не существует.");
|
||||
}
|
||||
void ReceiveAllArchives() throws Exception {
|
||||
ZipFolderPass zip = new ZipFolderPass();
|
||||
@@ -159,13 +156,11 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
}
|
||||
void UpdateBugReport() throws Exception {
|
||||
BugReport oldBugReport = (BugReport) request.object;
|
||||
if (db.bugReports.containsKey(oldBugReport.id)) {
|
||||
checkExistense(oldBugReport.id, BugReport.class);
|
||||
BugReport bugReport = db.bugReports.get(oldBugReport.id);
|
||||
bugReport.SynchronizeFields(oldBugReport);
|
||||
bugReport.change_date = new Date().getTime();
|
||||
db.Update(bugReport);
|
||||
} else
|
||||
throw new RepositoryRefuseException("Баг репорт с ключом " + oldBugReport.id + " не существует.");
|
||||
}
|
||||
//--
|
||||
void GetComponentsBackUps() throws Exception {
|
||||
|
||||
@@ -377,6 +377,17 @@ public abstract class RepositoryServer<D extends Database> {
|
||||
public Database getDb() {
|
||||
return db;
|
||||
}
|
||||
public void checkExistense(Database database, Object pk, Class d_class) throws Exception {
|
||||
if (!database.getTable(d_class).containsKey(pk))
|
||||
throw new RepositoryRefuseException(
|
||||
database.getTable(d_class).getSingleDescription()+
|
||||
" с ключом "+
|
||||
Utils_.Brackets(pk.toString())+
|
||||
" не существует");
|
||||
}
|
||||
public void checkExistense(Object pk, Class d_class) throws Exception {
|
||||
checkExistense(db, pk, d_class);
|
||||
}
|
||||
//-------------
|
||||
void publishObject_(Database database, DBObject dbObject) throws Exception {
|
||||
beforePublishAction(dbObject);
|
||||
|
||||
@@ -143,15 +143,12 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
@Override
|
||||
protected void afterCloneAction(riDBObject src, riDBObject dst) throws Exception {
|
||||
if (src instanceof SapforSettings) {
|
||||
Vector<PassCode> codes = new Vector<>();
|
||||
for (SapforSettingsCommand command : db.sapforSettingsCommands.Data.values())
|
||||
if (command.sapforsettings_id == src.id) codes.add(command.passCode);
|
||||
//--
|
||||
for (PassCode code : codes) {
|
||||
SapforSettingsCommand command = new SapforSettingsCommand();
|
||||
command.sapforsettings_id = dst.id;
|
||||
command.passCode = code;
|
||||
db.Insert(command);
|
||||
SapforSettings sapforSettings = (SapforSettings) src;
|
||||
for (SapforSettingsCommand src_command : db.getVectorByFK(sapforSettings, SapforSettingsCommand.class)) {
|
||||
SapforSettingsCommand dst_command = new SapforSettingsCommand();
|
||||
dst_command.sapforsettings_id = dst.id;
|
||||
dst_command.passCode = src_command.passCode;
|
||||
db.Insert(dst_command);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -291,9 +288,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
}
|
||||
void PerformAutoSapforTesting() throws Exception {
|
||||
int sapforId = Integer.parseInt(request.arg);
|
||||
if (!db.serverSapfors.containsKey(sapforId)) {
|
||||
throw new RepositoryRefuseException("Версия SAPFOR " + sapforId + " не существует.");
|
||||
}
|
||||
checkExistense(sapforId, ServerSapfor.class);
|
||||
ServerSapfor sapfor = db.serverSapfors.get(sapforId);
|
||||
TextLog Log = new TextLog();
|
||||
SapforPackage autoPackage = tryAutoSapforTesting(sapfor, Log);
|
||||
@@ -310,7 +305,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
}
|
||||
void DownloadTest() throws Exception {
|
||||
int test_id = Integer.parseInt(request.arg);
|
||||
if (db.tests.containsKey(test_id)) {
|
||||
checkExistense(test_id, Test.class);
|
||||
Test test = db.tests.get(test_id);
|
||||
File archive = new File(Global.TempDirectory, Utils_.getDateName(String.valueOf(test.id)));
|
||||
ZipFolderPass zipFolderPass = new ZipFolderPass();
|
||||
@@ -318,8 +313,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
throw new RepositoryRefuseException("Не удалось заархивировать тест");
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK, "", Utils_.fileToBytes(archive));
|
||||
FileUtils.forceDelete(archive);
|
||||
} else
|
||||
throw new RepositoryRefuseException("Теста с именем " + request.arg + " не существует");
|
||||
}
|
||||
void ReceiveTestsDatabase() throws Exception {
|
||||
response.object = Utils_.fileToBytes(db.getFile());
|
||||
@@ -449,8 +442,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
Vector<Integer> ids = (Vector<Integer>) request.object;
|
||||
Vector<Pair<Integer, Pair<byte[], byte[]>>> res = new Vector<>();
|
||||
for (int dvmPackage_id : ids) {
|
||||
if (!db.dvmPackages.containsKey(dvmPackage_id))
|
||||
throw new RepositoryRefuseException("Не найдено пакета тестирования DVM с ключом " + dvmPackage_id);
|
||||
checkExistense(dvmPackage_id, DVMPackage.class);
|
||||
DVMPackage dvmPackage = db.dvmPackages.get(dvmPackage_id);
|
||||
File workspace = dvmPackage.getLocalWorkspace();
|
||||
File results_zip = new File(workspace, "results.zip");
|
||||
@@ -461,8 +453,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
}
|
||||
void DownloadSapforPackage() throws Exception {
|
||||
int sapforPackage_id = (int) request.object;
|
||||
if (!db.sapforPackages.containsKey(sapforPackage_id))
|
||||
throw new RepositoryRefuseException("Не найдено пакета тестирования SAPFOR с ключом " + sapforPackage_id);
|
||||
checkExistense(sapforPackage_id, SapforPackage.class);
|
||||
SapforPackage sapforPackage = db.sapforPackages.get(sapforPackage_id);
|
||||
File workspace = sapforPackage.getLocalWorkspace();
|
||||
File results_zip = Utils.getTempFileName("results");
|
||||
@@ -544,25 +535,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
void GetSapforActualVersion() throws Exception {
|
||||
File versionFile = new File(Global.TempDirectory, "version.h");
|
||||
if (versionFile.exists())
|
||||
FileUtils.forceDelete(versionFile);
|
||||
//1. Получить версию из репозитория.
|
||||
Utils.startScript(Global.TempDirectory,
|
||||
Global.TempDirectory,
|
||||
"get_version",
|
||||
"wget --user dvmhuser --password dvmh2013 -P " +
|
||||
Utils_.DQuotes(Global.TempDirectory.getAbsolutePath()) +
|
||||
" http://svn.dvm-system.org/svn/dvmhrepo/sapfor/experts/Sapfor_2017/_src/Utils/version.h"
|
||||
).waitFor();
|
||||
if (!versionFile.exists())
|
||||
throw new RepositoryRefuseException("Не удалось загрузить текущую версию SAPFOR из репозитория!");
|
||||
int current_version = Sapfor.readVersionFromCode(versionFile);
|
||||
int max_installed_version = db.getInstalledSapforMaxVersion();
|
||||
if (max_installed_version == current_version)
|
||||
throw new RepositoryRefuseException("Версия " + max_installed_version + " уже установлена");
|
||||
}
|
||||
//---
|
||||
int getSapforActualVersion() throws Exception {
|
||||
File versionFile = new File(Global.TempDirectory, "version.h");
|
||||
@@ -651,10 +623,8 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
String[] packed = request.arg.split("\n");
|
||||
int groupId = Integer.parseInt(packed[0]);
|
||||
int packageId = Integer.parseInt(packed[1]);
|
||||
if (!db.sapforPackages.containsKey(packageId))
|
||||
throw new RepositoryRefuseException("Пакета с ключом " + packageId + " не существует!");
|
||||
if (!db.groups.containsKey(groupId))
|
||||
throw new RepositoryRefuseException("Группы с ключом " + groupId + " не существует!");
|
||||
checkExistense(packageId, SapforPackage.class);
|
||||
checkExistense(groupId, Group.class);
|
||||
//--
|
||||
SapforPackage sapforPackage = db.sapforPackages.get(packageId);
|
||||
Group group = db.groups.get(groupId);
|
||||
@@ -692,7 +662,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
}
|
||||
//создание тестов.
|
||||
ServerSapfor serverSapfor = db.serverSapfors.getLastDoneVersion();
|
||||
Vector<Test> tests = new Vector<>();
|
||||
for (String name : versions.keySet()) {
|
||||
File src = versions.get(name);
|
||||
File[] files = src.listFiles(pathname -> !pathname.isDirectory());
|
||||
@@ -725,7 +694,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
FileUtils.forceDelete(testProject);
|
||||
FileUtils.copyDirectory(src, testProject);
|
||||
//---
|
||||
tests.add(test);
|
||||
db.DetectTestMinMaxDim(serverSapfor, group, test);
|
||||
}
|
||||
}
|
||||
@@ -734,9 +702,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
Pair<DVMPackage, byte[]> p = (Pair<DVMPackage, byte[]>) request.object;
|
||||
DVMPackage src = p.getKey();
|
||||
byte[] packed_file = p.getValue();
|
||||
//todo написать стандартное исключение на несуществование объекта с ключом
|
||||
if (!db.dvmPackages.containsKey(src.id))
|
||||
throw new RepositoryRefuseException("не существует пакета с ключом " + src.id);
|
||||
checkExistense(src.id, DVMPackage.class);
|
||||
DVMPackage dst = db.dvmPackages.get(src.id);
|
||||
dst.SynchronizeFields(src);
|
||||
db.Update(dst);
|
||||
@@ -745,8 +711,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
void DetectTestsMinMaxDim() throws Exception {
|
||||
Vector<Object> keys = (Vector<Object>) request.object;
|
||||
for (Object key : keys) {
|
||||
if (!db.tests.containsKey(key))
|
||||
throw new RepositoryRefuseException("не существует пакета с ключом " + key);
|
||||
checkExistense(key, Test.class);
|
||||
}
|
||||
ServerSapfor serverSapfor = db.serverSapfors.getLastDoneVersion();
|
||||
for (Object key : keys) {
|
||||
@@ -757,8 +722,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
}
|
||||
void GetDVMPackageCredentials() throws Exception {
|
||||
int package_id = (int) request.object;
|
||||
if (!db.dvmPackages.containsKey(package_id))
|
||||
throw new RepositoryRefuseException("Не найден пакет с ключом " + Utils_.Brackets(package_id));
|
||||
checkExistense(package_id,DVMPackage.class);
|
||||
DVMPackageCredentials res = machines_db.dvmPackagesCredentials.getForPackageId(package_id);
|
||||
if (res == null)
|
||||
throw new RepositoryRefuseException("Не найдено учетных данных для пакета " + Utils_.Brackets(package_id));
|
||||
|
||||
Reference in New Issue
Block a user