создание группы из папки.

This commit is contained in:
2023-11-20 22:10:21 +03:00
parent 0cfa94eba8
commit 577803515e
10 changed files with 126 additions and 34 deletions

10
.idea/workspace.xml generated
View File

@@ -7,11 +7,15 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment=""> <list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateGroupFromDirectory.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ProjectData/Project/db_project_info.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ProjectData/Project/db_project_info.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Common/UI/Menus_2023/GroupsMenuBar/GroupsMenuBar.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Common/UI/Menus_2023/GroupsMenuBar/GroupsMenuBar.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/TestingSystem/SAPFOR/PerformSapforTask.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/TestingSystem/SAPFOR/PerformSapforTask.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Common/Utils/Utils.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Common/Utils/Utils.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateTestFromDirectory.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateTestFromDirectory.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateTestFromDirectory.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateTestFromDirectory.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/PublishTestProject.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/PublishTestProject.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateTestsGroupFromSelectedVersions.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateTestsGroupFromSelectedVersions.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/OpenCurrentProject.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/OpenCurrentProject.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/PublishTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/PublishTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/PassCode_2021.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/PassCode_2021.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />

View File

@@ -11,6 +11,7 @@ public class GroupsMenuBar extends DataMenuBar {
public GroupsMenuBar() { public GroupsMenuBar() {
super("группы", PassCode_2021.SynchronizeTests, PassCode_2021.ConvertCorrectnessTests, super("группы", PassCode_2021.SynchronizeTests, PassCode_2021.ConvertCorrectnessTests,
PassCode_2021.PublishGroup, PassCode_2021.PublishGroup,
PassCode_2021.CreateGroupFromDirectory,
PassCode_2021.EditGroup, PassCode_2021.EditGroup,
PassCode_2021.DeleteGroup PassCode_2021.DeleteGroup
); );

View File

@@ -3,6 +3,8 @@ import Common.Constants;
import Common.Current; import Common.Current;
import Common.Global; import Common.Global;
import Common.UI.UI; import Common.UI.UI;
import Common.Utils.Files.VDirectoryChooser;
import GlobalData.Settings.SettingName;
import GlobalData.Tasks.TaskState; import GlobalData.Tasks.TaskState;
import ProjectData.Files.DBProjectFile; import ProjectData.Files.DBProjectFile;
import ProjectData.Project.db_project_info; import ProjectData.Project.db_project_info;
@@ -70,6 +72,12 @@ public class Utils {
if (c == f) return true; if (c == f) return true;
return false; 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() { public static void init() {
for (char f : Constants.forbidden_file_name_characters) for (char f : Constants.forbidden_file_name_characters)
Constants.all_forbidden_characters_string += f + " "; Constants.all_forbidden_characters_string += f + " ";
@@ -1016,7 +1024,6 @@ public class Utils {
public static int fromBoolean(boolean flag) { public static int fromBoolean(boolean flag) {
return flag ? 1 : 0; return flag ? 1 : 0;
} }
public static void keepNewFiles(File directory, int count) throws Exception { public static void keepNewFiles(File directory, int count) throws Exception {
if (count > 0) { if (count > 0) {
File[] old_ = directory.listFiles(pathname -> pathname.isFile()); File[] old_ = directory.listFiles(pathname -> pathname.isFile());
@@ -1111,5 +1118,11 @@ public class Utils {
} }
return res; 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);
}
} }

View 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) + "\е является папкой!");
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);
}
}
}

View File

@@ -1,12 +1,9 @@
package Visual_DVM_2021.Passes.All; package Visual_DVM_2021.Passes.All;
import Common.Constants; import Common.Constants;
import Common.Current; import Common.Current;
import Common.Global;
import Common.Utils.Files.VDirectoryChooser; import Common.Utils.Files.VDirectoryChooser;
import Common.Utils.Utils; import Common.Utils.Utils;
import GlobalData.Settings.SettingName;
import ProjectData.Project.db_project_info; import ProjectData.Project.db_project_info;
import TestingSystem.Common.Group.Group;
import TestingSystem.Common.Test.Test; import TestingSystem.Common.Test.Test;
import Visual_DVM_2021.Passes.PassCode_2021; import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021; import Visual_DVM_2021.Passes.Pass_2021;
@@ -14,7 +11,7 @@ import Visual_DVM_2021.Passes.Pass_2021;
import java.io.File; import java.io.File;
public class CreateTestFromDirectory extends Pass_2021<Test> { public class CreateTestFromDirectory extends Pass_2021<Test> {
db_project_info project = null; db_project_info project = null;
Group group= null; int group_id;
File dir; File dir;
VDirectoryChooser directoryChooser = new VDirectoryChooser("Выбор домашней папки теста"); VDirectoryChooser directoryChooser = new VDirectoryChooser("Выбор домашней папки теста");
@Override @Override
@@ -29,28 +26,22 @@ public class CreateTestFromDirectory extends Pass_2021<Test> {
protected boolean needsAnimation() { protected boolean needsAnimation() {
return true; 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 @Override
protected boolean canStart(Object... args) throws Exception { protected boolean canStart(Object... args) throws Exception {
group = null; group_id = Constants.Nan;
project = null; project = null;
dir = null; dir = null;
target = null; target = null;
//- //-
if (args.length == 0) { if (args.length == 0) {
restoreBrowserPath(); Utils.RestoreSelectedDirectory(directoryChooser);
if (!Current.Check(Log, Current.Group)) if (!Current.Check(Log, Current.Group))
return false; return false;
group = Current.getGroup(); group_id = Current.getGroup().id;
dir = directoryChooser.ShowDialog(); dir = directoryChooser.ShowDialog();
} else { } else {
dir = (File) args[0]; dir = (File) args[0];
group = (Group) args[1]; group_id = (int) args[1];
} }
//- //-
if (dir == null) if (dir == null)
@@ -81,6 +72,6 @@ public class CreateTestFromDirectory extends Pass_2021<Test> {
@Override @Override
protected void performDone() throws Exception { protected void performDone() throws Exception {
super.performDone(); super.performDone();
passes.get(PassCode_2021.PublishTest).Do(project,group); passes.get(PassCode_2021.PublishTest).Do(project,group_id);
} }
} }

View File

@@ -76,7 +76,7 @@ public class CreateTestsGroupFromSelectedVersions extends Pass_2021<Vector<db_pr
//на случай если версия в текущем сеансе еще не открывалась. //на случай если версия в текущем сеансе еще не открывалась.
vizTestProject.Open(); vizTestProject.Open();
vizTestProject.Close(); 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 @Override

View File

@@ -32,12 +32,6 @@ public class OpenCurrentProject extends Pass_2021<db_project_info> {
protected boolean needsAnimation() { protected boolean needsAnimation() {
return true; 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() { boolean needsOpen() {
return !Current.HasProject() || !Current.getProject().Home.equals(dir); return !Current.HasProject() || !Current.getProject().Home.equals(dir);
} }
@@ -48,7 +42,7 @@ public class OpenCurrentProject extends Pass_2021<db_project_info> {
dir = null; dir = null;
target = null; target = null;
if (args.length == 0) { if (args.length == 0) {
restoreBrowserPath(); Utils.RestoreSelectedDirectory(directoryChooser);
dir = directoryChooser.ShowDialog(); dir = directoryChooser.ShowDialog();
} else { } else {
Object arg = args[0]; Object arg = args[0];

View File

@@ -4,7 +4,18 @@ import TestingSystem.Common.Group.Group;
import TestingSystem.Common.TestingServer; import TestingSystem.Common.TestingServer;
import Visual_DVM_2021.Passes.Server.PublishServerObject; import Visual_DVM_2021.Passes.Server.PublishServerObject;
public class PublishGroup extends PublishServerObject<TestingServer, Group> { public class PublishGroup extends PublishServerObject<TestingServer, Group> {
String group_description;
public PublishGroup() { public PublishGroup() {
super(Global.testingServer, Group.class); 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();
}
} }

View File

@@ -1,25 +1,27 @@
package Visual_DVM_2021.Passes.All; package Visual_DVM_2021.Passes.All;
import Common.Constants;
import Common.Current; import Common.Current;
import Common.Global; import Common.Global;
import Common.UI.UI; import Common.UI.UI;
import Common.Utils.Utils; import Common.Utils.Utils;
import ProjectData.Project.db_project_info; import ProjectData.Project.db_project_info;
import TestingSystem.Common.Group.Group;
import TestingSystem.Common.Test.Test; import TestingSystem.Common.Test.Test;
import TestingSystem.Common.TestingServer; import TestingSystem.Common.TestingServer;
import Visual_DVM_2021.Passes.PassCode_2021; import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Server.PublishServerObject; import Visual_DVM_2021.Passes.Server.PublishServerObject;
public class PublishTest extends PublishServerObject<TestingServer, Test> { public class PublishTest extends PublishServerObject<TestingServer, Test> {
boolean from_current_project; boolean from_current_project;
protected Group group = null; protected int group_id;
protected db_project_info project = null; protected db_project_info project = null;
public PublishTest() { public PublishTest() {
super(Global.testingServer, Test.class); super(Global.testingServer, Test.class);
} }
@Override @Override
public boolean fillObjectFields() throws Exception { public boolean fillObjectFields() throws Exception {
target.description = project.getLocalName() + " " + project.description; target.description = project.getLocalName();
target.group_id = group.id; if (!project.description.isEmpty())
target.description += " " + project.description;
target.group_id = group_id;
if (from_current_project) { if (from_current_project) {
target.dim = project.testMaxDim; target.dim = project.testMaxDim;
return super.fillObjectFields(); return super.fillObjectFields();
@@ -36,19 +38,23 @@ public class PublishTest extends PublishServerObject<TestingServer, Test> {
} }
} }
@Override @Override
protected void performPreparation() throws Exception {
target.description = Utils.ReplaceForbiddenSymbols(target.description);
}
@Override
protected boolean canStart(Object... args) throws Exception { protected boolean canStart(Object... args) throws Exception {
group = null; group_id = Constants.Nan;
project = null; project = null;
if (args.length == 0) { if (args.length == 0) {
from_current_project = true; from_current_project = true;
if (Current.Check(Log, Current.Group, Current.Project) && UI.Question("Добавить текущий проект в глобальную базу тестов")) { if (Current.Check(Log, Current.Group, Current.Project) && UI.Question("Добавить текущий проект в глобальную базу тестов")) {
project = Current.getProject(); project = Current.getProject();
group= Current.getGroup(); group_id = Current.getGroup().id;
} }
} else { } else {
from_current_project = false; from_current_project = false;
project = (db_project_info) args[0]; project = (db_project_info) args[0];
group = (Group) args[1]; group_id = (int) args[1];
} }
//-- //--
if (project == null) if (project == null)

View File

@@ -298,6 +298,7 @@ public enum PassCode_2021 {
AbortTaskPackage, AbortTaskPackage,
//-- //--
CreateTestFromDirectory, CreateTestFromDirectory,
CreateGroupFromDirectory,
//-> //->
TestPass; TestPass;
public String getDescription() { public String getDescription() {