2024-10-08 23:45:06 +03:00
|
|
|
package _VisualDVM.ServerObjectsCache;
|
2024-10-07 00:58:29 +03:00
|
|
|
import Common.Utils.CommonUtils;
|
|
|
|
|
import _VisualDVM.Global;
|
2024-10-09 22:21:57 +03:00
|
|
|
import _VisualDVM.TestingSystem.Common.Configuration.Configuration;
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Group.Group;
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Group.Json.GroupJson;
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Group.Json.GroupsJson;
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Settings.Json.SettingsArrayJson;
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Settings.Json.SettingsJson;
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Test.Json.TestJson;
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Test.Json.TestsJson;
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Test.Test;
|
2024-09-18 13:37:11 +03:00
|
|
|
|
2024-09-28 21:47:17 +03:00
|
|
|
import java.util.LinkedHashMap;
|
2024-09-18 13:37:11 +03:00
|
|
|
import java.util.Vector;
|
2024-10-01 17:33:08 +03:00
|
|
|
public class ConfigurationCache extends VisualCache {
|
2024-09-18 13:37:11 +03:00
|
|
|
public GroupsJson groupsJson = null;
|
|
|
|
|
public TestsJson testsJson = null;
|
2024-09-28 21:47:17 +03:00
|
|
|
public SettingsArrayJson settingsJson = null;
|
|
|
|
|
public String settingsSummary = null;
|
2024-10-01 17:33:08 +03:00
|
|
|
public Vector<String> groupsSummary = null;
|
2024-09-18 13:37:11 +03:00
|
|
|
//--
|
|
|
|
|
public ConfigurationCache(Configuration configuration) {
|
2024-09-18 22:58:38 +03:00
|
|
|
if (configuration.packedGroupsJson.isEmpty()) {
|
2024-09-18 13:37:11 +03:00
|
|
|
groupsJson = new GroupsJson(); //просто пустой
|
2024-10-01 17:33:08 +03:00
|
|
|
} else {
|
2024-10-07 00:58:29 +03:00
|
|
|
groupsJson = CommonUtils.gson.fromJson(configuration.packedGroupsJson, GroupsJson.class);
|
2024-09-18 22:58:38 +03:00
|
|
|
}
|
2024-09-18 13:37:11 +03:00
|
|
|
//--
|
|
|
|
|
if (testsJson == null) {
|
|
|
|
|
if (configuration.packedTestsJson.isEmpty())
|
|
|
|
|
testsJson = new TestsJson(); //просто пустой
|
|
|
|
|
else
|
2024-10-07 00:58:29 +03:00
|
|
|
testsJson = CommonUtils.gson.fromJson(configuration.packedTestsJson, TestsJson.class);
|
2024-09-18 13:37:11 +03:00
|
|
|
}
|
|
|
|
|
//-
|
2024-09-28 21:47:17 +03:00
|
|
|
if (settingsJson == null) {
|
|
|
|
|
if (configuration.packedSettingsJson.isEmpty())
|
|
|
|
|
settingsJson = new SettingsArrayJson(); //просто пустой
|
|
|
|
|
else
|
2024-10-07 00:58:29 +03:00
|
|
|
settingsJson = CommonUtils.gson.fromJson(configuration.packedSettingsJson, SettingsArrayJson.class);
|
2024-09-28 21:47:17 +03:00
|
|
|
}
|
|
|
|
|
//-
|
|
|
|
|
LinkedHashMap<String, Vector<String>> gmap = new LinkedHashMap<>();
|
2024-10-01 17:33:08 +03:00
|
|
|
for (GroupJson groupJson : groupsJson.array) {
|
2024-09-28 21:47:17 +03:00
|
|
|
Vector<String> vector = null;
|
2024-10-01 17:33:08 +03:00
|
|
|
if (gmap.containsKey(groupJson.language)) {
|
2024-09-28 21:47:17 +03:00
|
|
|
vector = gmap.get(groupJson.language);
|
2024-10-01 17:33:08 +03:00
|
|
|
} else {
|
2024-09-28 21:47:17 +03:00
|
|
|
vector = new Vector<>();
|
|
|
|
|
gmap.put(groupJson.language, vector);
|
|
|
|
|
}
|
|
|
|
|
vector.add(groupJson.description);
|
|
|
|
|
}
|
|
|
|
|
groupsSummary = new Vector<>();
|
2024-10-01 17:33:08 +03:00
|
|
|
for (String language : gmap.keySet()) {
|
|
|
|
|
groupsSummary.add(language + ": " + String.join(";", gmap.get(language)));
|
2024-09-28 21:47:17 +03:00
|
|
|
}
|
|
|
|
|
Vector<String> settingsDescriptionsVector = new Vector<>();
|
|
|
|
|
for (SettingsJson settingsJson : settingsJson.array)
|
|
|
|
|
settingsDescriptionsVector.add(settingsJson.description);
|
|
|
|
|
settingsSummary = String.join(";", settingsDescriptionsVector);
|
2024-09-18 13:37:11 +03:00
|
|
|
}
|
|
|
|
|
public int getTestsCount() {
|
|
|
|
|
return testsJson.array.size();
|
|
|
|
|
}
|
2024-10-01 17:33:08 +03:00
|
|
|
public Vector<Group> getGroups() {
|
2024-09-18 13:37:11 +03:00
|
|
|
Vector<Group> groups = new Vector<>();
|
2024-10-01 17:33:08 +03:00
|
|
|
for (GroupJson groupJson : groupsJson.array) {
|
2024-09-18 13:37:11 +03:00
|
|
|
if (Global.testingServer.db.groups.containsKey(groupJson.id))
|
|
|
|
|
groups.add(Global.testingServer.db.groups.get(groupJson.id));
|
|
|
|
|
}
|
|
|
|
|
return groups;
|
|
|
|
|
}
|
2024-10-01 17:33:08 +03:00
|
|
|
public Vector<Test> getTests() {
|
2024-09-18 13:37:11 +03:00
|
|
|
Vector<Test> tests = new Vector<>();
|
2024-10-01 17:33:08 +03:00
|
|
|
for (TestJson testJson : testsJson.array) {
|
2024-09-18 13:37:11 +03:00
|
|
|
if (Global.testingServer.db.tests.containsKey(testJson.id))
|
|
|
|
|
tests.add(Global.testingServer.db.tests.get(testJson.id));
|
|
|
|
|
}
|
|
|
|
|
return tests;
|
|
|
|
|
}
|
2024-10-01 17:33:08 +03:00
|
|
|
public Vector<Test> getGroupTests(Group group) {
|
|
|
|
|
Vector<Test> tests = new Vector<>();
|
|
|
|
|
for (TestJson testJson : testsJson.array) {
|
|
|
|
|
if (Global.testingServer.db.tests.containsKey(testJson.id)) {
|
|
|
|
|
Test test = Global.testingServer.db.tests.get(testJson.id);
|
|
|
|
|
if (test.group_id == group.id)
|
|
|
|
|
tests.add(test);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tests;
|
|
|
|
|
}
|
2024-09-18 13:37:11 +03:00
|
|
|
}
|