2024-09-18 13:37:11 +03:00
|
|
|
package Common.UI.VisualCache;
|
|
|
|
|
import Common.Global;
|
|
|
|
|
import Common.Utils.Utils;
|
|
|
|
|
import TestingSystem.Common.Configuration.Configuration;
|
|
|
|
|
import TestingSystem.Common.Group.Group;
|
|
|
|
|
import TestingSystem.Common.Group.Json.GroupJson;
|
|
|
|
|
import TestingSystem.Common.Group.Json.GroupsJson;
|
2024-09-28 21:47:17 +03:00
|
|
|
import TestingSystem.Common.Settings.Json.SettingsArrayJson;
|
|
|
|
|
import TestingSystem.Common.Settings.Json.SettingsJson;
|
2024-09-18 13:37:11 +03:00
|
|
|
import TestingSystem.Common.Test.Json.TestJson;
|
|
|
|
|
import TestingSystem.Common.Test.Json.TestsJson;
|
|
|
|
|
import TestingSystem.Common.Test.Test;
|
|
|
|
|
|
2024-09-28 21:47:17 +03:00
|
|
|
import java.util.LinkedHashMap;
|
2024-09-18 13:37:11 +03:00
|
|
|
import java.util.Vector;
|
|
|
|
|
public class ConfigurationCache extends VisualCache{
|
|
|
|
|
public GroupsJson groupsJson = null;
|
|
|
|
|
public TestsJson testsJson = null;
|
2024-09-28 21:47:17 +03:00
|
|
|
public SettingsArrayJson settingsJson = null;
|
|
|
|
|
public String settingsSummary = null;
|
|
|
|
|
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-09-18 22:58:38 +03:00
|
|
|
}
|
|
|
|
|
else {
|
2024-09-18 13:37:11 +03:00
|
|
|
groupsJson = Utils.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
|
|
|
|
|
testsJson = Utils.gson.fromJson(configuration.packedTestsJson, TestsJson.class);
|
|
|
|
|
}
|
|
|
|
|
//-
|
2024-09-28 21:47:17 +03:00
|
|
|
if (settingsJson == null) {
|
|
|
|
|
if (configuration.packedSettingsJson.isEmpty())
|
|
|
|
|
settingsJson = new SettingsArrayJson(); //просто пустой
|
|
|
|
|
else
|
|
|
|
|
settingsJson = Utils.gson.fromJson(configuration.packedSettingsJson, SettingsArrayJson.class);
|
|
|
|
|
}
|
|
|
|
|
//-
|
|
|
|
|
LinkedHashMap<String, Vector<String>> gmap = new LinkedHashMap<>();
|
|
|
|
|
for (GroupJson groupJson: groupsJson.array){
|
|
|
|
|
Vector<String> vector = null;
|
|
|
|
|
if (gmap.containsKey(groupJson.language)){
|
|
|
|
|
vector = gmap.get(groupJson.language);
|
|
|
|
|
}else {
|
|
|
|
|
vector = new Vector<>();
|
|
|
|
|
gmap.put(groupJson.language, vector);
|
|
|
|
|
}
|
|
|
|
|
vector.add(groupJson.description);
|
|
|
|
|
}
|
|
|
|
|
groupsSummary = new Vector<>();
|
|
|
|
|
for (String language: gmap.keySet()){
|
|
|
|
|
groupsSummary.add(language+": "+String.join(";", gmap.get(language)));
|
|
|
|
|
}
|
|
|
|
|
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-09-28 21:47:17 +03:00
|
|
|
public String getSettingsDescriptions() {
|
|
|
|
|
return settingsSummary;
|
2024-09-18 13:37:11 +03:00
|
|
|
}
|
|
|
|
|
public Vector<Group> getGroups(){
|
|
|
|
|
Vector<Group> groups = new Vector<>();
|
|
|
|
|
for (GroupJson groupJson : groupsJson.array){
|
|
|
|
|
if (Global.testingServer.db.groups.containsKey(groupJson.id))
|
|
|
|
|
groups.add(Global.testingServer.db.groups.get(groupJson.id));
|
|
|
|
|
}
|
|
|
|
|
return groups;
|
|
|
|
|
}
|
|
|
|
|
public Vector<Test> getTests(){
|
|
|
|
|
Vector<Test> tests = new Vector<>();
|
|
|
|
|
for (TestJson testJson : testsJson.array){
|
|
|
|
|
if (Global.testingServer.db.tests.containsKey(testJson.id))
|
|
|
|
|
tests.add(Global.testingServer.db.tests.get(testJson.id));
|
|
|
|
|
}
|
|
|
|
|
return tests;
|
|
|
|
|
}
|
|
|
|
|
}
|