создание группы из папки.
This commit is contained in:
@@ -11,6 +11,7 @@ public class GroupsMenuBar extends DataMenuBar {
|
||||
public GroupsMenuBar() {
|
||||
super("группы", PassCode_2021.SynchronizeTests, PassCode_2021.ConvertCorrectnessTests,
|
||||
PassCode_2021.PublishGroup,
|
||||
PassCode_2021.CreateGroupFromDirectory,
|
||||
PassCode_2021.EditGroup,
|
||||
PassCode_2021.DeleteGroup
|
||||
);
|
||||
|
||||
@@ -3,6 +3,8 @@ import Common.Constants;
|
||||
import Common.Current;
|
||||
import Common.Global;
|
||||
import Common.UI.UI;
|
||||
import Common.Utils.Files.VDirectoryChooser;
|
||||
import GlobalData.Settings.SettingName;
|
||||
import GlobalData.Tasks.TaskState;
|
||||
import ProjectData.Files.DBProjectFile;
|
||||
import ProjectData.Project.db_project_info;
|
||||
@@ -70,6 +72,12 @@ public class Utils {
|
||||
if (c == f) return true;
|
||||
return false;
|
||||
}
|
||||
public static String ReplaceForbiddenSymbols(String name) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (char c : name.toCharArray())
|
||||
res.append(isForbidden(c) ? '_' : c);
|
||||
return res.toString();
|
||||
}
|
||||
public static void init() {
|
||||
for (char f : Constants.forbidden_file_name_characters)
|
||||
Constants.all_forbidden_characters_string += f + " ";
|
||||
@@ -1016,7 +1024,6 @@ public class Utils {
|
||||
public static int fromBoolean(boolean flag) {
|
||||
return flag ? 1 : 0;
|
||||
}
|
||||
|
||||
public static void keepNewFiles(File directory, int count) throws Exception {
|
||||
if (count > 0) {
|
||||
File[] old_ = directory.listFiles(pathname -> pathname.isFile());
|
||||
@@ -1111,5 +1118,11 @@ public class Utils {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public static void RestoreSelectedDirectory(VDirectoryChooser directoryChooser) {
|
||||
String last_dir_home =
|
||||
Global.db.settings.get(SettingName.ProjectsSearchDirectory).Value;
|
||||
if (!last_dir_home.isEmpty())
|
||||
directoryChooser.SetCurrentDirectory(last_dir_home);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
71
src/Visual_DVM_2021/Passes/All/CreateGroupFromDirectory.java
Normal file
71
src/Visual_DVM_2021/Passes/All/CreateGroupFromDirectory.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package Visual_DVM_2021.Passes.All;
|
||||
import Common.Constants;
|
||||
import Common.Utils.Files.VDirectoryChooser;
|
||||
import Common.Utils.Utils;
|
||||
import TestingSystem.Common.Group.Group;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
|
||||
import java.io.File;
|
||||
public class CreateGroupFromDirectory extends Pass_2021<Group> {
|
||||
File dir = null;
|
||||
File[] files = null;
|
||||
int group_id ;
|
||||
VDirectoryChooser directoryChooser = new VDirectoryChooser("Выбор домашней папки группы");
|
||||
@Override
|
||||
public String getIconPath() {
|
||||
return "/icons/CreateProject.png";
|
||||
}
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return "";
|
||||
}
|
||||
@Override
|
||||
protected boolean needsAnimation() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
dir = null;
|
||||
files = null;
|
||||
target = null;
|
||||
group_id = Constants.Nan;
|
||||
//-
|
||||
Utils.RestoreSelectedDirectory(directoryChooser);
|
||||
dir = directoryChooser.ShowDialog();
|
||||
//-
|
||||
if (dir == null)
|
||||
return false;
|
||||
//--
|
||||
if (!dir.isDirectory()) {
|
||||
Log.Writeln_(Utils.Brackets(dir) + "\nне является папкой!");
|
||||
return false;
|
||||
}
|
||||
//-
|
||||
if (dir.getName().equals(Constants.data)) {
|
||||
Log.Writeln_(Utils.Brackets(dir) + "\nявляется служебной папкой визуализатора!");
|
||||
return false;
|
||||
}
|
||||
files = dir.listFiles(File::isDirectory);
|
||||
if (files == null) {
|
||||
Log.Writeln_("Ошибка при получении списка папок");
|
||||
return false;
|
||||
}
|
||||
if (files.length == 0) {
|
||||
Log.Writeln_("В выбранной папке не найдено ни одной папки");
|
||||
return false;
|
||||
}
|
||||
PublishGroup pass = (PublishGroup) passes.get(PassCode_2021.PublishGroup);
|
||||
if (pass.Do(dir.getName().toUpperCase())) {
|
||||
group_id = (int) pass.pk;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected void body() throws Exception {
|
||||
for (File file : files) {
|
||||
passes.get(PassCode_2021.CreateTestFromDirectory).Do(file, group_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
package Visual_DVM_2021.Passes.All;
|
||||
import Common.Constants;
|
||||
import Common.Current;
|
||||
import Common.Global;
|
||||
import Common.Utils.Files.VDirectoryChooser;
|
||||
import Common.Utils.Utils;
|
||||
import GlobalData.Settings.SettingName;
|
||||
import ProjectData.Project.db_project_info;
|
||||
import TestingSystem.Common.Group.Group;
|
||||
import TestingSystem.Common.Test.Test;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
@@ -14,7 +11,7 @@ import Visual_DVM_2021.Passes.Pass_2021;
|
||||
import java.io.File;
|
||||
public class CreateTestFromDirectory extends Pass_2021<Test> {
|
||||
db_project_info project = null;
|
||||
Group group= null;
|
||||
int group_id;
|
||||
File dir;
|
||||
VDirectoryChooser directoryChooser = new VDirectoryChooser("Выбор домашней папки теста");
|
||||
@Override
|
||||
@@ -29,28 +26,22 @@ public class CreateTestFromDirectory extends Pass_2021<Test> {
|
||||
protected boolean needsAnimation() {
|
||||
return true;
|
||||
}
|
||||
void restoreBrowserPath() {
|
||||
String last_dir_home =
|
||||
Global.db.settings.get(SettingName.ProjectsSearchDirectory).Value;
|
||||
if (!last_dir_home.isEmpty())
|
||||
directoryChooser.SetCurrentDirectory(last_dir_home);
|
||||
}
|
||||
@Override
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
group = null;
|
||||
group_id = Constants.Nan;
|
||||
project = null;
|
||||
dir = null;
|
||||
target = null;
|
||||
//-
|
||||
if (args.length == 0) {
|
||||
restoreBrowserPath();
|
||||
Utils.RestoreSelectedDirectory(directoryChooser);
|
||||
if (!Current.Check(Log, Current.Group))
|
||||
return false;
|
||||
group = Current.getGroup();
|
||||
group_id = Current.getGroup().id;
|
||||
dir = directoryChooser.ShowDialog();
|
||||
} else {
|
||||
dir = (File) args[0];
|
||||
group = (Group) args[1];
|
||||
group_id = (int) args[1];
|
||||
}
|
||||
//-
|
||||
if (dir == null)
|
||||
@@ -81,6 +72,6 @@ public class CreateTestFromDirectory extends Pass_2021<Test> {
|
||||
@Override
|
||||
protected void performDone() throws Exception {
|
||||
super.performDone();
|
||||
passes.get(PassCode_2021.PublishTest).Do(project,group);
|
||||
passes.get(PassCode_2021.PublishTest).Do(project,group_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class CreateTestsGroupFromSelectedVersions extends Pass_2021<Vector<db_pr
|
||||
//на случай если версия в текущем сеансе еще не открывалась.
|
||||
vizTestProject.Open();
|
||||
vizTestProject.Close();
|
||||
if (!passes.get(PassCode_2021.PublishTest).Do(vizTestProject, Current.getGroup())) break;
|
||||
if (!passes.get(PassCode_2021.PublishTest).Do(vizTestProject, Current.getGroup().id)) break;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -32,12 +32,6 @@ public class OpenCurrentProject extends Pass_2021<db_project_info> {
|
||||
protected boolean needsAnimation() {
|
||||
return true;
|
||||
}
|
||||
void restoreBrowserPath() {
|
||||
String last_dir_home =
|
||||
Global.db.settings.get(SettingName.ProjectsSearchDirectory).Value;
|
||||
if (!last_dir_home.isEmpty())
|
||||
directoryChooser.SetCurrentDirectory(last_dir_home);
|
||||
}
|
||||
boolean needsOpen() {
|
||||
return !Current.HasProject() || !Current.getProject().Home.equals(dir);
|
||||
}
|
||||
@@ -48,7 +42,7 @@ public class OpenCurrentProject extends Pass_2021<db_project_info> {
|
||||
dir = null;
|
||||
target = null;
|
||||
if (args.length == 0) {
|
||||
restoreBrowserPath();
|
||||
Utils.RestoreSelectedDirectory(directoryChooser);
|
||||
dir = directoryChooser.ShowDialog();
|
||||
} else {
|
||||
Object arg = args[0];
|
||||
|
||||
@@ -4,7 +4,18 @@ import TestingSystem.Common.Group.Group;
|
||||
import TestingSystem.Common.TestingServer;
|
||||
import Visual_DVM_2021.Passes.Server.PublishServerObject;
|
||||
public class PublishGroup extends PublishServerObject<TestingServer, Group> {
|
||||
String group_description;
|
||||
public PublishGroup() {
|
||||
super(Global.testingServer, Group.class);
|
||||
}
|
||||
@Override
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
group_description = (args.length > 0) ? (String) args[0] : "";
|
||||
return super.canStart(args);
|
||||
}
|
||||
@Override
|
||||
public boolean fillObjectFields() throws Exception {
|
||||
target.description = group_description;
|
||||
return super.fillObjectFields();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
package Visual_DVM_2021.Passes.All;
|
||||
import Common.Constants;
|
||||
import Common.Current;
|
||||
import Common.Global;
|
||||
import Common.UI.UI;
|
||||
import Common.Utils.Utils;
|
||||
import ProjectData.Project.db_project_info;
|
||||
import TestingSystem.Common.Group.Group;
|
||||
import TestingSystem.Common.Test.Test;
|
||||
import TestingSystem.Common.TestingServer;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import Visual_DVM_2021.Passes.Server.PublishServerObject;
|
||||
public class PublishTest extends PublishServerObject<TestingServer, Test> {
|
||||
boolean from_current_project;
|
||||
protected Group group = null;
|
||||
protected int group_id;
|
||||
protected db_project_info project = null;
|
||||
public PublishTest() {
|
||||
super(Global.testingServer, Test.class);
|
||||
}
|
||||
@Override
|
||||
public boolean fillObjectFields() throws Exception {
|
||||
target.description = project.getLocalName() + " " + project.description;
|
||||
target.group_id = group.id;
|
||||
target.description = project.getLocalName();
|
||||
if (!project.description.isEmpty())
|
||||
target.description += " " + project.description;
|
||||
target.group_id = group_id;
|
||||
if (from_current_project) {
|
||||
target.dim = project.testMaxDim;
|
||||
return super.fillObjectFields();
|
||||
@@ -36,19 +38,23 @@ public class PublishTest extends PublishServerObject<TestingServer, Test> {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void performPreparation() throws Exception {
|
||||
target.description = Utils.ReplaceForbiddenSymbols(target.description);
|
||||
}
|
||||
@Override
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
group = null;
|
||||
group_id = Constants.Nan;
|
||||
project = null;
|
||||
if (args.length == 0) {
|
||||
from_current_project = true;
|
||||
if (Current.Check(Log, Current.Group, Current.Project) && UI.Question("Добавить текущий проект в глобальную базу тестов")) {
|
||||
project = Current.getProject();
|
||||
group= Current.getGroup();
|
||||
group_id = Current.getGroup().id;
|
||||
}
|
||||
} else {
|
||||
from_current_project = false;
|
||||
project = (db_project_info) args[0];
|
||||
group = (Group) args[1];
|
||||
group_id = (int) args[1];
|
||||
}
|
||||
//--
|
||||
if (project == null)
|
||||
|
||||
@@ -298,6 +298,7 @@ public enum PassCode_2021 {
|
||||
AbortTaskPackage,
|
||||
//--
|
||||
CreateTestFromDirectory,
|
||||
CreateGroupFromDirectory,
|
||||
//->
|
||||
TestPass;
|
||||
public String getDescription() {
|
||||
|
||||
Reference in New Issue
Block a user