Files
VisualSapfor/src/TestingSystem/Common/Configuration/Configuration.java

114 lines
3.9 KiB
Java
Raw Normal View History

2024-09-16 22:15:21 +03:00
package TestingSystem.Common.Configuration;
2024-09-14 00:18:27 +03:00
import Common.Database.DBObject;
import Common.Database.riDBObject;
import Common.Global;
import Common.Utils.Utils;
import TestingSystem.Common.Group.Group;
import TestingSystem.Common.Test.Test;
import com.sun.org.glassfish.gmbal.Description;
2024-09-14 00:18:27 +03:00
import java.util.LinkedHashMap;
2024-09-14 00:18:27 +03:00
import java.util.Vector;
public class Configuration extends riDBObject {
//конфигурация = данные для пакета.
//группы
//тесты
//настройки тестируемого объекта
//пакет = запуск конфигурация + тестируемый объект
//---
@Description("DEFAULT ''")
public String packedGroupsIds = "";
@Description("DEFAULT ''")
public String packedTestsIds = "";
//---
@Description("DEFAULT ''")
public String packedGroupsNames = "";
//---
@Description("DEFAULT 0")
public int groupsCount = 0;
@Description("DEFAULT 0")
public int testsCount = 0;
//--
public int maxtime = 300;
@Description("DEFAULT 0")
public int autoTesting = 0;
public String printAuto(){
return autoTesting>0? "Да":"Нет";
}
2024-09-14 00:18:27 +03:00
//--
public String getFlags(){return "";}
public Vector<String> getFlagsArray(){return new Vector<>();}
public Vector<String> getGroupsNamesArray(){
return Utils.unpack_s(packedGroupsNames,"\n");
}
2024-09-14 00:18:27 +03:00
//--
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
Configuration c = (Configuration) src;
//--
packedGroupsIds = c.packedGroupsIds;
packedTestsIds = c.packedTestsIds;
//-
packedGroupsNames = c.packedGroupsNames;
//-
groupsCount = c.groupsCount;
testsCount = c.testsCount;
//-
2024-09-14 00:18:27 +03:00
maxtime = c.maxtime;
autoTesting= c.autoTesting;
}
//-
public void saveGroups(Vector<Group> new_groups) {
Vector<String> res = new Vector<>();
Vector<String> names = new Vector<>();
for (Group group : new_groups) {
res.add(String.valueOf(group.id));
names.add(group.description);
}
packedGroupsIds = String.join("\n", res);
packedGroupsNames = String.join("\n", names);
groupsCount = new_groups.size();
}
public void saveTests(Vector<Test> new_tests) {
Vector<String> res = new Vector<>();
for (Test test : new_tests)
res.add(String.valueOf(test.id));
packedTestsIds = String.join("\n", res);
testsCount = new_tests.size();
}
//--
public Vector<Group> getGroups() {
Vector<Group> res = new Vector<>();
for (int o_id : Utils.unpackIntegers(packedGroupsIds, "\n"))
if (Global.testingServer.db.groups.containsKey(o_id))
res.add(Global.testingServer.db.groups.get(o_id));
return res;
}
public Vector<Test> getTests() {
Vector<Test> res = new Vector<>();
for (int o_id : Utils.unpackIntegers(packedTestsIds, "\n"))
if (Global.testingServer.db.tests.containsKey(o_id))
res.add(Global.testingServer.db.tests.get(o_id));
return res;
}
public Vector<Test> getTests(Vector<Group> groups, LinkedHashMap<Integer, Vector<Test>> testByGroups) {
Vector<Test> res = new Vector<>();
for (int o_id : Utils.unpackIntegers(packedTestsIds, "\n"))
if (Global.testingServer.db.tests.containsKey(o_id))
res.add(Global.testingServer.db.tests.get(o_id));
//--
for (Group group: groups){
Vector<Test> groupTests = new Vector<>();
for (Test test:res){
if (test.group_id==group.id)
groupTests.add(test);
}
testByGroups.put(group.id, groupTests);
}
//--
return res;
2024-09-14 00:18:27 +03:00
}
}