Skip to content

Commit 4c2e544

Browse files
authored
Merge pull request #548 from johnnyshut/feature/546
feat: Добавлена ​​поддержка CodeSeries и CheckUnique в Catalog
2 parents b735f51 + d8e4aab commit 4c2e544

File tree

14 files changed

+150
-11
lines changed

14 files changed

+150
-11
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build/
2+
bin/
23
.gradle/
34

45
/.idea/sonarlint/
@@ -20,3 +21,5 @@ Gradle_*.xml
2021
**/ConfigDumpInfo.xml
2122
**/.metadata/
2223
benchmark-results/**
24+
25+
.vscode/

src/main/java/com/github/_1c_syntax/bsl/mdo/Catalog.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.github._1c_syntax.bsl.mdo.children.ObjectCommand;
2525
import com.github._1c_syntax.bsl.mdo.children.ObjectForm;
2626
import com.github._1c_syntax.bsl.mdo.children.ObjectTemplate;
27+
import com.github._1c_syntax.bsl.mdo.support.CodeSeries;
2728
import com.github._1c_syntax.bsl.mdo.support.ObjectBelonging;
2829
import com.github._1c_syntax.bsl.mdo.support.RoleRight;
2930
import com.github._1c_syntax.bsl.mdo.utils.LazyLoader;
@@ -114,6 +115,24 @@ public class Catalog implements ReferenceObject, AccessRightsOwner {
114115
@Singular("addOwners")
115116
List<MdoReference> owners;
116117

118+
/**
119+
* Проверять уникальность кода справочника.
120+
* Определяет, нужно ли проверять уникальность кода справочника.
121+
* Если значение равно false, то код справочника должен быть уникальным в пределах области,
122+
* определяемой свойством {@link #codeSeries}.
123+
*/
124+
@Default
125+
boolean checkUnique = false;
126+
127+
/**
128+
* Серия кодов справочника.
129+
* Определяет область действия уникальности кода справочника.
130+
* Значение по умолчанию: {@link CodeSeries#WHOLE_CATALOG}.
131+
* Для формата EDT: если поле отсутствует, автоматически устанавливается значение WHOLE_CATALOG.
132+
*/
133+
@Default
134+
CodeSeries codeSeries = CodeSeries.WHOLE_CATALOG;
135+
117136
/**
118137
* Возвращает перечень возможных прав доступа
119138
*/
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright (c) 2019 - 2025
5+
* Tymko Oleg <[email protected]>, Maximov Valery <[email protected]> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* MDClasses is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* MDClasses is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with MDClasses.
21+
*/
22+
package com.github._1c_syntax.bsl.mdo.support;
23+
24+
import java.util.Locale;
25+
import java.util.Map;
26+
27+
import com.github._1c_syntax.bsl.types.EnumWithName;
28+
import com.github._1c_syntax.bsl.types.MultiName;
29+
30+
import lombok.Getter;
31+
import lombok.ToString;
32+
import lombok.experimental.Accessors;
33+
34+
/**
35+
* Серия кодов справочника.
36+
* Определяет область действия уникальности кода справочника.
37+
*/
38+
@ToString(of = "fullName")
39+
public enum CodeSeries implements EnumWithName {
40+
/**
41+
* Весь справочник - уникальность кода проверяется во всем справочнике
42+
*/
43+
WHOLE_CATALOG("WholeCatalog", "ВесьСправочник"),
44+
/**
45+
* В пределах подчинения - уникальность кода проверяется в пределах подчинения
46+
*/
47+
WITHIN_SUBORDINATION("WithinSubordination", "ВПределахПодчинения"),
48+
/**
49+
* В пределах подчинения владельцу - уникальность кода проверяется в пределах подчинения владельцу
50+
*/
51+
WITHIN_OWNER_SUBORDINATION("WithinOwnerSubordination", "ВПределахПодчиненияВладельцу");
52+
53+
private static final Map<String, CodeSeries> KEYS = EnumWithName.computeKeys(values());
54+
55+
/**
56+
* Полное имя элемента перечисления (на русском и английском языках)
57+
*/
58+
@Getter
59+
@Accessors(fluent = true)
60+
private final MultiName fullName;
61+
62+
/**
63+
* Конструктор элемента перечисления
64+
*
65+
* @param nameEn Английское имя элемента
66+
* @param nameRu Русское имя элемента
67+
*/
68+
CodeSeries(String nameEn, String nameRu) {
69+
this.fullName = MultiName.create(nameEn, nameRu);
70+
}
71+
72+
/**
73+
* Ищет элемент перечисления по именам (рус, анг).
74+
* Поиск выполняется без учета регистра.
75+
*
76+
* @param string Имя искомого элемента
77+
* @return Найденное значение, если не найден - то WHOLE_CATALOG
78+
*/
79+
public static CodeSeries valueByName(String string) {
80+
return KEYS.getOrDefault(string.toLowerCase(Locale.ROOT), WHOLE_CATALOG);
81+
}
82+
}
83+

src/main/java/com/github/_1c_syntax/bsl/reader/common/xstream/ExtendXStream.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.github._1c_syntax.bsl.mdo.storage.form.FormElementType;
3232
import com.github._1c_syntax.bsl.mdo.support.ApplicationRunMode;
3333
import com.github._1c_syntax.bsl.mdo.support.AutoRecordType;
34+
import com.github._1c_syntax.bsl.mdo.support.CodeSeries;
3435
import com.github._1c_syntax.bsl.mdo.support.ConfigurationExtensionPurpose;
3536
import com.github._1c_syntax.bsl.mdo.support.DataLockControlMode;
3637
import com.github._1c_syntax.bsl.mdo.support.DataSeparation;
@@ -273,6 +274,7 @@ protected void setupConverters() {
273274
registerConverter(new EnumConverter<>(FormElementType.class));
274275
registerConverter(new EnumConverter<>(InterfaceCompatibilityMode.class));
275276
registerConverter(new EnumConverter<>(DateFractions.class));
277+
registerConverter(new EnumConverter<>(CodeSeries.class));
276278
}
277279

278280
private void init() {

src/test/java/com/github/_1c_syntax/bsl/mdo/CatalogTest.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,30 @@ void testSSL(ArgumentsAccessor argumentsAccessor) {
156156
assertThat(stdAttribute.getValueType().contains(PrimitiveValueType.STRING)).isTrue();
157157
}
158158

159+
/**
160+
* Проверяет, что для справочника "Заметки" поле checkUnique установлено в false.
161+
* <p>
162+
* В формате Designer: в XML файле явно указано {@code <CheckUnique>false</CheckUnique>}.
163+
* В формате EDT: в XML файле поле отсутствует, используется значение по умолчанию false.
164+
*
165+
* @param argumentsAccessor параметры теста (формат, имя пакета, ссылка на MDO, постфикс фикстуры)
166+
*/
167+
@ParameterizedTest
168+
@CsvSource({
169+
"true, ssl_3_1, Catalogs.Заметки, _edt",
170+
"false, ssl_3_1, Catalogs.Заметки"
171+
})
172+
void testCheckUniqueFalse(ArgumentsAccessor argumentsAccessor) {
173+
var mdo = MDTestUtils.getMDWithSimpleTest(argumentsAccessor);
174+
assertThat(mdo)
175+
.isInstanceOf(Catalog.class);
176+
177+
var catalog = (Catalog) mdo;
178+
assertThat(catalog.isCheckUnique())
179+
.as("Поле checkUnique должно быть false для справочника Заметки")
180+
.isFalse();
181+
}
182+
159183
@ParameterizedTest
160184
@CsvSource({
161185
"true, ssl_3_1, Catalogs.ВерсииФайлов, _edt",
@@ -166,14 +190,4 @@ void testSSLFixture(ArgumentsAccessor argumentsAccessor) {
166190
assertThat(mdo)
167191
.isInstanceOf(Catalog.class);
168192
}
169-
170-
// private void checkExtInfo(FormDataOLD formData) {
171-
// var extInfo = (DynamicListExtInfo) formData.getAttributes().get(1).getExtInfo();
172-
// assertThat(extInfo)
173-
// .isNotNull()
174-
// .isInstanceOf(DynamicListExtInfo.class);
175-
//
176-
// assertThat(extInfo.isCustomQuery()).isTrue();
177-
// assertThat(extInfo.getQuery().getTextQuery()).isNotEmpty();
178-
// }
179-
}
193+
}

src/test/resources/fixtures/mdclasses/Catalogs.Справочник1.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,8 @@
12191219
"name": "Справочник1",
12201220
"objectBelonging": "OWN",
12211221
"owners": [],
1222+
"checkUnique": true,
1223+
"codeSeries": "WHOLE_CATALOG",
12221224
"possibleRights": [
12231225
{
12241226
"default": {

src/test/resources/fixtures/mdclasses/Catalogs.Справочник1_edt.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,8 @@
12191219
"name": "Справочник1",
12201220
"objectBelonging": "OWN",
12211221
"owners": [],
1222+
"checkUnique": true,
1223+
"codeSeries": "WHOLE_CATALOG",
12221224
"possibleRights": [
12231225
{
12241226
"default": {

src/test/resources/fixtures/mdclasses/Configuration.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@
666666
"explanation": {
667667
"@reference": "/com.github._1c_syntax.bsl.mdclasses.Configuration/XDTOPackages/com.github._1c_syntax.bsl.mdo.XDTOPackage/synonym"
668668
},
669+
"checkUnique": true,
670+
"codeSeries": "WHOLE_CATALOG",
669671
"owners": []
670672
}
671673
],

src/test/resources/fixtures/mdclasses/Configuration_edt.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@
666666
"explanation": {
667667
"@reference": "/com.github._1c_syntax.bsl.mdclasses.Configuration/XDTOPackages/com.github._1c_syntax.bsl.mdo.XDTOPackage/synonym"
668668
},
669+
"checkUnique": true,
670+
"codeSeries": "WHOLE_CATALOG",
669671
"owners": []
670672
}
671673
],

src/test/resources/fixtures/mdclasses_3_24/Configuration_edt.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@
666666
"explanation": {
667667
"@reference": "/com.github._1c_syntax.bsl.mdclasses.Configuration/XDTOPackages/com.github._1c_syntax.bsl.mdo.XDTOPackage/synonym"
668668
},
669+
"checkUnique": true,
670+
"codeSeries": "WHOLE_CATALOG",
669671
"owners": []
670672
}
671673
],

0 commit comments

Comments
 (0)