From 404fced7e291e33928726d0659533b8db2f5a503 Mon Sep 17 00:00:00 2001 From: Viktor Gukov Date: Tue, 13 Oct 2020 17:39:15 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=80=D0=B0=D0=B2=20=D0=B4=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=83=D0=BF=D0=B0=20=D1=85=D1=80=D0=B0=D0=BD=D1=8F=D1=89=D0=B8?= =?UTF-8?q?=D1=85=D1=81=D1=8F=20=D0=B2=20=D1=80=D0=BE=D0=BB=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_1c_syntax/mdclasses/mdo/ObjectRight.java | 45 +++++++++++ .../_1c_syntax/mdclasses/mdo/Right.java | 37 +++++++++ .../github/_1c_syntax/mdclasses/mdo/Role.java | 6 +- .../_1c_syntax/mdclasses/mdo/RoleData.java | 52 +++++++++++++ .../mdclasses/unmarshal/XStreamFactory.java | 47 +---------- .../mdclasses/utils/MDOFactory.java | 53 +++++++------ .../mdclasses/utils/MDOPathUtils.java | 19 +++++ .../mdclasses/mdo/RoleDataTest.java | 78 +++++++++++++++++++ 8 files changed, 263 insertions(+), 74 deletions(-) create mode 100644 src/main/java/com/github/_1c_syntax/mdclasses/mdo/ObjectRight.java create mode 100644 src/main/java/com/github/_1c_syntax/mdclasses/mdo/Right.java create mode 100644 src/main/java/com/github/_1c_syntax/mdclasses/mdo/RoleData.java create mode 100644 src/test/java/com/github/_1c_syntax/mdclasses/mdo/RoleDataTest.java diff --git a/src/main/java/com/github/_1c_syntax/mdclasses/mdo/ObjectRight.java b/src/main/java/com/github/_1c_syntax/mdclasses/mdo/ObjectRight.java new file mode 100644 index 000000000..bab051c97 --- /dev/null +++ b/src/main/java/com/github/_1c_syntax/mdclasses/mdo/ObjectRight.java @@ -0,0 +1,45 @@ +/* + * This file is a part of MDClasses. + * + * Copyright © 2019 - 2020 + * Tymko Oleg , Maximov Valery and contributors + * + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * MDClasses is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * MDClasses is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with MDClasses. + */ +package com.github._1c_syntax.mdclasses.mdo; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamImplicit; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.Collections; +import java.util.List; + +/** + * POJO представление прав доступа объекта метаданных, содержащихся в конкретной роли + */ +@Getter +@Setter +@NoArgsConstructor +public class ObjectRight { + private String name = ""; + + @XStreamAlias("right") + @XStreamImplicit + List rights = Collections.emptyList(); +} diff --git a/src/main/java/com/github/_1c_syntax/mdclasses/mdo/Right.java b/src/main/java/com/github/_1c_syntax/mdclasses/mdo/Right.java new file mode 100644 index 000000000..f9d59353a --- /dev/null +++ b/src/main/java/com/github/_1c_syntax/mdclasses/mdo/Right.java @@ -0,0 +1,37 @@ +/* + * This file is a part of MDClasses. + * + * Copyright © 2019 - 2020 + * Tymko Oleg , Maximov Valery and contributors + * + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * MDClasses is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * MDClasses is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with MDClasses. + */ +package com.github._1c_syntax.mdclasses.mdo; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * POJO представление конкретного права доступа, находящегося в роли + */ +@Getter +@Setter +@NoArgsConstructor +public class Right { + private String name = ""; + private boolean value = false; +} diff --git a/src/main/java/com/github/_1c_syntax/mdclasses/mdo/Role.java b/src/main/java/com/github/_1c_syntax/mdclasses/mdo/Role.java index afd860445..8f308e978 100644 --- a/src/main/java/com/github/_1c_syntax/mdclasses/mdo/Role.java +++ b/src/main/java/com/github/_1c_syntax/mdclasses/mdo/Role.java @@ -23,17 +23,19 @@ import com.github._1c_syntax.mdclasses.mdo.wrapper.DesignerMDO; import com.github._1c_syntax.mdclasses.metadata.additional.MDOType; +import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; -import lombok.Value; -@Value +@Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true, onlyExplicitlyIncluded = true) @NoArgsConstructor public class Role extends MDObjectBase { + private RoleData roleData; + public Role(DesignerMDO designerMDO) { super(designerMDO); } diff --git a/src/main/java/com/github/_1c_syntax/mdclasses/mdo/RoleData.java b/src/main/java/com/github/_1c_syntax/mdclasses/mdo/RoleData.java new file mode 100644 index 000000000..6b4f9bda2 --- /dev/null +++ b/src/main/java/com/github/_1c_syntax/mdclasses/mdo/RoleData.java @@ -0,0 +1,52 @@ +/* + * This file is a part of MDClasses. + * + * Copyright © 2019 - 2020 + * Tymko Oleg , Maximov Valery and contributors + * + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * MDClasses is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * MDClasses is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with MDClasses. + */ +package com.github._1c_syntax.mdclasses.mdo; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamImplicit; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.Collections; +import java.util.List; + + +/** + * POJO представление данных конкретной роли + */ +@NoArgsConstructor +@Getter +@Setter +public class RoleData { + + @XStreamAlias("setForNewObjects") + private boolean setForNewObjects = false; + @XStreamAlias("setForAttributesByDefault") + private boolean setForAttributesByDefault = false; + @XStreamAlias("independentRightsOfChildObjects") + private boolean independentRightsOfChildObjects = false; + + @XStreamAlias("object") + @XStreamImplicit + List objectRights = Collections.emptyList(); +} diff --git a/src/main/java/com/github/_1c_syntax/mdclasses/unmarshal/XStreamFactory.java b/src/main/java/com/github/_1c_syntax/mdclasses/unmarshal/XStreamFactory.java index 07231f3af..d4590b6d2 100644 --- a/src/main/java/com/github/_1c_syntax/mdclasses/unmarshal/XStreamFactory.java +++ b/src/main/java/com/github/_1c_syntax/mdclasses/unmarshal/XStreamFactory.java @@ -21,51 +21,7 @@ */ package com.github._1c_syntax.mdclasses.unmarshal; -import com.github._1c_syntax.mdclasses.mdo.AccountingRegister; -import com.github._1c_syntax.mdclasses.mdo.AccumulationRegister; -import com.github._1c_syntax.mdclasses.mdo.BusinessProcess; -import com.github._1c_syntax.mdclasses.mdo.CalculationRegister; -import com.github._1c_syntax.mdclasses.mdo.Catalog; -import com.github._1c_syntax.mdclasses.mdo.ChartOfAccounts; -import com.github._1c_syntax.mdclasses.mdo.ChartOfCalculationTypes; -import com.github._1c_syntax.mdclasses.mdo.ChartOfCharacteristicTypes; -import com.github._1c_syntax.mdclasses.mdo.CommandGroup; -import com.github._1c_syntax.mdclasses.mdo.CommonAttribute; -import com.github._1c_syntax.mdclasses.mdo.CommonCommand; -import com.github._1c_syntax.mdclasses.mdo.CommonForm; -import com.github._1c_syntax.mdclasses.mdo.CommonModule; -import com.github._1c_syntax.mdclasses.mdo.CommonPicture; -import com.github._1c_syntax.mdclasses.mdo.CommonTemplate; -import com.github._1c_syntax.mdclasses.mdo.Constant; -import com.github._1c_syntax.mdclasses.mdo.DataProcessor; -import com.github._1c_syntax.mdclasses.mdo.DefinedType; -import com.github._1c_syntax.mdclasses.mdo.Document; -import com.github._1c_syntax.mdclasses.mdo.DocumentJournal; -import com.github._1c_syntax.mdclasses.mdo.DocumentNumerator; -import com.github._1c_syntax.mdclasses.mdo.EventSubscription; -import com.github._1c_syntax.mdclasses.mdo.ExchangePlan; -import com.github._1c_syntax.mdclasses.mdo.FilterCriterion; -import com.github._1c_syntax.mdclasses.mdo.FunctionalOption; -import com.github._1c_syntax.mdclasses.mdo.FunctionalOptionsParameter; -import com.github._1c_syntax.mdclasses.mdo.HTTPService; -import com.github._1c_syntax.mdclasses.mdo.InformationRegister; -import com.github._1c_syntax.mdclasses.mdo.MDOConfiguration; -import com.github._1c_syntax.mdclasses.mdo.MDOEnum; -import com.github._1c_syntax.mdclasses.mdo.MDObjectComplex; -import com.github._1c_syntax.mdclasses.mdo.Report; -import com.github._1c_syntax.mdclasses.mdo.Role; -import com.github._1c_syntax.mdclasses.mdo.ScheduledJob; -import com.github._1c_syntax.mdclasses.mdo.Sequence; -import com.github._1c_syntax.mdclasses.mdo.SessionParameter; -import com.github._1c_syntax.mdclasses.mdo.SettingsStorage; -import com.github._1c_syntax.mdclasses.mdo.Style; -import com.github._1c_syntax.mdclasses.mdo.StyleItem; -import com.github._1c_syntax.mdclasses.mdo.Subsystem; -import com.github._1c_syntax.mdclasses.mdo.TabularSection; -import com.github._1c_syntax.mdclasses.mdo.Task; -import com.github._1c_syntax.mdclasses.mdo.WSReference; -import com.github._1c_syntax.mdclasses.mdo.WebService; -import com.github._1c_syntax.mdclasses.mdo.XDTOPackage; +import com.github._1c_syntax.mdclasses.mdo.*; import com.github._1c_syntax.mdclasses.mdo.wrapper.DesignerChildObjects; import com.github._1c_syntax.mdclasses.mdo.wrapper.DesignerWrapper; import com.github._1c_syntax.mdclasses.metadata.additional.ConfigurationExtensionPurpose; @@ -250,6 +206,7 @@ private void addClassAliases(XStream xStream) { xStream.alias("mdclass:Enum", MDOEnum.class); xStream.alias("mdclass:Report", Report.class); xStream.alias("mdclass:Role", Role.class); + xStream.alias("Rights", RoleData.class); xStream.alias("mdclass:ScheduledJob", ScheduledJob.class); xStream.alias("mdclass:Sequence", Sequence.class); xStream.alias("mdclass:SessionParameter", SessionParameter.class); diff --git a/src/main/java/com/github/_1c_syntax/mdclasses/utils/MDOFactory.java b/src/main/java/com/github/_1c_syntax/mdclasses/utils/MDOFactory.java index 97b1ac70e..773958a87 100644 --- a/src/main/java/com/github/_1c_syntax/mdclasses/utils/MDOFactory.java +++ b/src/main/java/com/github/_1c_syntax/mdclasses/utils/MDOFactory.java @@ -21,40 +21,17 @@ */ package com.github._1c_syntax.mdclasses.utils; -import com.github._1c_syntax.mdclasses.mdo.Command; -import com.github._1c_syntax.mdclasses.mdo.Form; -import com.github._1c_syntax.mdclasses.mdo.HTTPService; -import com.github._1c_syntax.mdclasses.mdo.HTTPServiceURLTemplate; -import com.github._1c_syntax.mdclasses.mdo.Language; -import com.github._1c_syntax.mdclasses.mdo.MDOAttribute; -import com.github._1c_syntax.mdclasses.mdo.MDOConfiguration; -import com.github._1c_syntax.mdclasses.mdo.MDObjectBSL; -import com.github._1c_syntax.mdclasses.mdo.MDObjectBase; -import com.github._1c_syntax.mdclasses.mdo.MDObjectComplex; -import com.github._1c_syntax.mdclasses.mdo.Subsystem; -import com.github._1c_syntax.mdclasses.mdo.TabularSection; -import com.github._1c_syntax.mdclasses.mdo.Template; -import com.github._1c_syntax.mdclasses.mdo.WEBServiceOperation; -import com.github._1c_syntax.mdclasses.mdo.WebService; +import com.github._1c_syntax.mdclasses.mdo.*; import com.github._1c_syntax.mdclasses.mdo.wrapper.DesignerWrapper; -import com.github._1c_syntax.mdclasses.metadata.additional.ConfigurationSource; -import com.github._1c_syntax.mdclasses.metadata.additional.MDOModule; -import com.github._1c_syntax.mdclasses.metadata.additional.MDOReference; -import com.github._1c_syntax.mdclasses.metadata.additional.MDOType; -import com.github._1c_syntax.mdclasses.metadata.additional.ModuleType; -import com.github._1c_syntax.mdclasses.metadata.additional.ScriptVariant; +import com.github._1c_syntax.mdclasses.metadata.additional.*; import com.github._1c_syntax.mdclasses.unmarshal.XStreamFactory; import io.vavr.control.Either; import lombok.experimental.UtilityClass; -import lombok.extern.slf4j.Slf4j; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; /** @@ -125,11 +102,33 @@ public Optional readMDObject(ConfigurationSource configurationSour setIncludedSubsystems((MDOConfiguration) mdoValue); }); } + + // загрузка данных роли + if (mdoValue instanceof Role) { + var roleDataPath = MDOPathUtils.getRoleDataPath(configurationSource, + mdoPath.getParent().toString(), mdoValue.getName()); + var roleDataOptional = readRoleData(roleDataPath); + roleDataOptional.ifPresent(((Role) mdoValue)::setRoleData); + } }); return mdo; } + /** + * Читает данные роли из файла Rights + * + * @param roleDataPath - путь к файлу прав роли. + * @return {@code Optional} POJO представление данных ролей + */ + private static Optional readRoleData(Path roleDataPath) { + if (Files.notExists(roleDataPath)) { + return Optional.empty(); + } + + return Optional.ofNullable((RoleData) XStreamFactory.fromXML(roleDataPath.toFile())); + } + /** * Читает объект по его файлу описания, но не выполняет чтение дочерних элементов * diff --git a/src/main/java/com/github/_1c_syntax/mdclasses/utils/MDOPathUtils.java b/src/main/java/com/github/_1c_syntax/mdclasses/utils/MDOPathUtils.java index 0a4ac83d0..90b9b10d1 100644 --- a/src/main/java/com/github/_1c_syntax/mdclasses/utils/MDOPathUtils.java +++ b/src/main/java/com/github/_1c_syntax/mdclasses/utils/MDOPathUtils.java @@ -265,4 +265,23 @@ private Path getModulePathDesigner(Path folder, String name, ModuleType moduleTy return Paths.get(folder.toString(), subdirectory, moduleType.getFileName()); } + /** + * Получает путь к файлу прав роли для любого формата относительного базового каталога, + * и имени объекта + * + * @param configurationSource - формат данных, конфигуратор или EDT + * @param basePath - базовый каталог конфигурации + * @param mdoName - имя объекта метаданных, без расширения + * @return - путь к файлу прав конкретной роли + */ + public static Path getRoleDataPath(ConfigurationSource configurationSource, String basePath, String mdoName) { + Path path; + if (configurationSource == ConfigurationSource.EDT) { + path = Path.of(basePath, "Rights.rights"); + } else { + path = Path.of(basePath, mdoName, "Ext", "Rights.xml"); + } + + return path; + } } diff --git a/src/test/java/com/github/_1c_syntax/mdclasses/mdo/RoleDataTest.java b/src/test/java/com/github/_1c_syntax/mdclasses/mdo/RoleDataTest.java new file mode 100644 index 000000000..ee8361e74 --- /dev/null +++ b/src/test/java/com/github/_1c_syntax/mdclasses/mdo/RoleDataTest.java @@ -0,0 +1,78 @@ +/* + * This file is a part of MDClasses. + * + * Copyright © 2019 - 2020 + * Tymko Oleg , Maximov Valery and contributors + * + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * MDClasses is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * MDClasses is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with MDClasses. + */ +package com.github._1c_syntax.mdclasses.mdo; + +import com.github._1c_syntax.mdclasses.metadata.additional.ConfigurationSource; +import com.github._1c_syntax.mdclasses.metadata.additional.MDOType; +import com.github._1c_syntax.mdclasses.utils.MDOFactory; +import org.junit.jupiter.api.Test; + +import java.nio.file.Paths; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class RoleDataTest { + + private static final String SRC_EDT = "src/test/resources/metadata/edt/src"; + private static final String SRC_DESIGNER = "src/test/resources/metadata/original"; + + @Test + void testRoleDataEdt() { + var mdo = MDOFactory.readMDObject(ConfigurationSource.EDT, + MDOType.ROLE, Paths.get(SRC_EDT, "Roles/Роль1/Роль1.mdo")); + assertThat(mdo).isPresent(); + Role role = (Role) mdo.get(); + testRole(role); + } + + @Test + void testRoleDataDesigner() { + var mdo = MDOFactory.readMDObject(ConfigurationSource.DESIGNER, + MDOType.ROLE, Paths.get(SRC_DESIGNER, "Roles/Роль1.xml")); + assertThat(mdo).isPresent(); + Role role = (Role) mdo.get(); + testRole(role); + } + + + private void testRole(Role role) { + + RoleData roleData = role.getRoleData(); + assertThat(roleData).isNotNull(); + + List objectRights = roleData.getObjectRights(); + assertThat(objectRights).hasSize(3); + + ObjectRight confRights = objectRights.get(0); + assertThat(confRights.getName()).isEqualTo("Configuration.Конфигурация"); + assertThat(confRights.getRights()).hasSize(18); + + ObjectRight documentRights = objectRights.get(1); + assertThat(documentRights.getName()).isEqualTo("Document.Документ1"); + assertThat(documentRights.getRights()).hasSize(18); + + ObjectRight catalogRights = objectRights.get(2); + assertThat(catalogRights.getName()).isEqualTo("Catalog.Справочник1"); + assertThat(catalogRights.getRights()).hasSize(16); + } +}