Skip to content

Commit 2f3f9c6

Browse files
committed
Реализован метод формирования пользовательского представления объекта на основании синонима. Поддерживается для всех MD\MDClass
1 parent 70f005e commit 2f3f9c6

File tree

6 files changed

+205
-82
lines changed

6 files changed

+205
-82
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,33 @@ default MDOType getMdoType() {
7575
*/
7676
String getComment();
7777

78+
/**
79+
* Представление объекта, формируемое на основании синонима для русского языка.
80+
* Если синонима для русского нет, вернет иной синоним при его наличии. В противном случае вернет имя.
81+
*/
82+
default String getDescription() {
83+
return getDescription("ru");
84+
}
85+
86+
/**
87+
* Представление объекта, формируемое на основании синонима для указанного языка.
88+
* Если синонима для указанного языка нет, вернет иной синоним при его наличии. В противном случае вернет имя.
89+
*
90+
* @param code Код языка
91+
*/
92+
default String getDescription(String code) {
93+
if (getSynonym().isEmpty()) {
94+
return getName();
95+
}
96+
var description = getSynonym().get(code);
97+
if (description.isEmpty()) {
98+
description = getSynonym().getAny();
99+
}
100+
101+
if (description.isEmpty()) {
102+
description = getName();
103+
}
104+
105+
return description;
106+
}
78107
}

src/main/java/com/github/_1c_syntax/bsl/mdo/support/MultiLanguageString.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,25 @@ public static MultiLanguageString of(@NonNull List<MultiLanguageString> strings)
8282
public @NonNull String get(@NonNull String lang) {
8383
return content.getOrDefault(lang, "");
8484
}
85+
86+
/**
87+
* Возвращает первое попавшееся содержимое мультиязычной строки
88+
*
89+
* @return Одно из значений мультиязычной строки
90+
*/
91+
public @NonNull String getAny() {
92+
if (content.isEmpty()) {
93+
return "";
94+
}
95+
return content.entrySet().iterator().next().getValue();
96+
}
97+
98+
/**
99+
* Возвращает признак пустоты мультиязычной строки
100+
*
101+
* @return Если пустая, тогда true
102+
*/
103+
public boolean isEmpty() {
104+
return this == EMPTY;
105+
}
85106
}

src/test/java/com/github/_1c_syntax/bsl/mdclasses/ConfigurationTest.java

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
/*
2-
* This file is a part of MDClasses.
3-
*
4-
* Copyright (c) 2019 - 2024
5-
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> 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.mdclasses;
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright (c) 2019 - 2024
5+
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> 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.mdclasses;
2323

2424
import com.github._1c_syntax.bsl.mdo.BusinessProcess;
2525
import com.github._1c_syntax.bsl.mdo.Form;
@@ -167,6 +167,12 @@ void testFullSSL(ArgumentsAccessor argumentsAccessor) {
167167
.hasSize(726);
168168
assertThat(cf.getPlainChildren().stream().filter(md -> md instanceof Form form && form.getData().isEmpty()))
169169
.isEmpty();
170+
171+
assertThat(cf.getSynonym().isEmpty()).isFalse();
172+
assertThat(cf.getSynonym().get("ru")).isEqualTo("Библиотека стандартных подсистем, редакция 3.1");
173+
assertThat(cf.getDescription()).isEqualTo("Библиотека стандартных подсистем, редакция 3.1");
174+
assertThat(cf.getDescription("ru")).isEqualTo("Библиотека стандартных подсистем, редакция 3.1");
175+
assertThat(cf.getDescription("en")).isEqualTo("Библиотека стандартных подсистем, редакция 3.1");
170176
}
171177

172178
@ParameterizedTest
@@ -398,6 +404,7 @@ private static void checkChildrenSSL(Configuration cf) {
398404
cf.getAccountingRegisters().size() + cf.getCalculationRegisters().size() +
399405
cf.getBusinessProcesses().size() + cf.getTasks().size() +
400406
cf.getExternalDataSources().size());
407+
401408
}
402409

403410
private static void checkChildrenMdclasses(Configuration cf) {

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

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,35 @@
2020
* License along with MDClasses.
2121
*/
2222
package com.github._1c_syntax.bsl.mdo;
23-
24-
import com.github._1c_syntax.bsl.test_utils.MDTestUtils;
25-
import org.junit.jupiter.params.ParameterizedTest;
26-
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
27-
import org.junit.jupiter.params.provider.CsvSource;
28-
29-
class AccountingRegisterTest {
30-
@ParameterizedTest
31-
@CsvSource(
32-
{
33-
"true, mdclasses, AccountingRegisters.РегистрБухгалтерии1",
34-
"false, mdclasses, AccountingRegisters.РегистрБухгалтерии1"
35-
}
36-
)
37-
void test(ArgumentsAccessor argumentsAccessor) {
38-
var mdo = MDTestUtils.getMDWithSimpleTest(argumentsAccessor);
39-
}
40-
}
23+
24+
import com.github._1c_syntax.bsl.test_utils.MDTestUtils;
25+
import org.junit.jupiter.params.ParameterizedTest;
26+
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
27+
import org.junit.jupiter.params.provider.CsvSource;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
class AccountingRegisterTest {
32+
@ParameterizedTest
33+
@CsvSource(
34+
{
35+
"true, mdclasses, AccountingRegisters.РегистрБухгалтерии1",
36+
"false, mdclasses, AccountingRegisters.РегистрБухгалтерии1"
37+
}
38+
)
39+
void test(ArgumentsAccessor argumentsAccessor) {
40+
var mdo = MDTestUtils.getMDWithSimpleTest(argumentsAccessor);
41+
42+
var accountingRegister = (AccountingRegister) mdo;
43+
44+
assertThat(accountingRegister.getSynonym().isEmpty()).isFalse();
45+
assertThat(accountingRegister.getSynonym().get("ru")).isEqualTo("Регистр бухгалтерии");
46+
assertThat(accountingRegister.getSynonym().get("en")).isEqualTo("Accounting register");
47+
assertThat(accountingRegister.getSynonym().get("by")).isEmpty();
48+
49+
assertThat(accountingRegister.getDescription()).isEqualTo("Регистр бухгалтерии");
50+
assertThat(accountingRegister.getDescription("ru")).isEqualTo("Регистр бухгалтерии");
51+
assertThat(accountingRegister.getDescription("en")).isEqualTo("Accounting register");
52+
assertThat(accountingRegister.getDescription("by")).isNotEmpty().isNotEqualTo("РегистрБухгалтерии1");
53+
}
54+
}

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

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,58 @@
2020
* License along with MDClasses.
2121
*/
2222
package com.github._1c_syntax.bsl.mdo;
23-
24-
import com.github._1c_syntax.bsl.test_utils.MDTestUtils;
25-
import org.junit.jupiter.params.ParameterizedTest;
26-
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
27-
import org.junit.jupiter.params.provider.CsvSource;
28-
29-
class BusinessProcessTest {
30-
@ParameterizedTest
31-
@CsvSource(
32-
{
33-
"true, mdclasses, BusinessProcesses.БизнесПроцесс1, _edt",
34-
"false, mdclasses, BusinessProcesses.БизнесПроцесс1",
35-
"true, ssl_3_1, BusinessProcesses.Задание, _edt",
36-
"false, ssl_3_1, BusinessProcesses.Задание"
37-
}
38-
)
39-
void test(ArgumentsAccessor argumentsAccessor) {
40-
var mdo = MDTestUtils.getMDWithSimpleTest(argumentsAccessor);
41-
}
42-
}
23+
24+
import com.github._1c_syntax.bsl.test_utils.MDTestUtils;
25+
import org.junit.jupiter.params.ParameterizedTest;
26+
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
27+
import org.junit.jupiter.params.provider.CsvSource;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
class BusinessProcessTest {
32+
@ParameterizedTest
33+
@CsvSource(
34+
{
35+
"true, mdclasses, BusinessProcesses.БизнесПроцесс1, _edt",
36+
"false, mdclasses, BusinessProcesses.БизнесПроцесс1"
37+
}
38+
)
39+
void test(ArgumentsAccessor argumentsAccessor) {
40+
var mdo = MDTestUtils.getMDWithSimpleTest(argumentsAccessor);
41+
42+
var businessProcess = (BusinessProcess) mdo;
43+
44+
assertThat(businessProcess.getSynonym().isEmpty()).isTrue();
45+
assertThat(businessProcess.getSynonym().get("ru")).isEmpty();
46+
assertThat(businessProcess.getSynonym().get("en")).isEmpty();
47+
assertThat(businessProcess.getSynonym().getAny()).isEmpty();
48+
49+
assertThat(businessProcess.getDescription()).isEqualTo("БизнесПроцесс1");
50+
assertThat(businessProcess.getDescription("ru")).isEqualTo("БизнесПроцесс1");
51+
assertThat(businessProcess.getDescription("en")).isEqualTo("БизнесПроцесс1");
52+
}
53+
54+
@ParameterizedTest
55+
@CsvSource(
56+
{
57+
"true, ssl_3_1, BusinessProcesses.Задание, _edt",
58+
"false, ssl_3_1, BusinessProcesses.Задание"
59+
}
60+
)
61+
void testSSL_3_1(ArgumentsAccessor argumentsAccessor) {
62+
var mdo = MDTestUtils.getMDWithSimpleTest(argumentsAccessor);
63+
64+
var businessProcess = (BusinessProcess) mdo;
65+
66+
assertThat(businessProcess.getSynonym().isEmpty()).isFalse();
67+
assertThat(businessProcess.getSynonym().get("ru")).isEqualTo("Задание");
68+
assertThat(businessProcess.getSynonym().get("en")).isEmpty();
69+
assertThat(businessProcess.getSynonym().getAny()).isEqualTo("Задание");
70+
71+
assertThat(businessProcess.getDescription()).isEqualTo("Задание");
72+
assertThat(businessProcess.getDescription("ru")).isEqualTo("Задание");
73+
assertThat(businessProcess.getDescription("en")).isEqualTo("Задание");
74+
assertThat(businessProcess.getDescription("")).isEqualTo("Задание");
75+
assertThat(businessProcess.getDescription("пыщь")).isEqualTo("Задание");
76+
}
77+
}

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

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
/*
2-
* This file is a part of MDClasses.
3-
*
4-
* Copyright (c) 2019 - 2024
5-
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> 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;
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright (c) 2019 - 2024
5+
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> 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;
2323

2424
import com.github._1c_syntax.bsl.mdo.children.ObjectAttribute;
2525
import com.github._1c_syntax.bsl.mdo.children.ObjectCommand;
2626
import com.github._1c_syntax.bsl.mdo.children.ObjectForm;
2727
import com.github._1c_syntax.bsl.test_utils.MDTestUtils;
28+
import com.github._1c_syntax.bsl.types.MdoReference;
2829
import org.junit.jupiter.params.ParameterizedTest;
2930
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
3031
import org.junit.jupiter.params.provider.CsvSource;
@@ -111,6 +112,22 @@ void testSSL(ArgumentsAccessor argumentsAccessor) {
111112
.noneMatch(child -> child instanceof ObjectCommand)
112113
.noneMatch(child -> child instanceof ObjectForm)
113114
;
115+
116+
assertThat(catalog.getSynonym().isEmpty()).isFalse();
117+
assertThat(catalog.getSynonym().get("ru")).isEqualTo("Заметки");
118+
assertThat(catalog.getDescription()).isEqualTo("Заметки");
119+
assertThat(catalog.getDescription("ru")).isEqualTo("Заметки");
120+
assertThat(catalog.getDescription("en")).isEqualTo("Заметки");
121+
122+
var child = catalog.findChild(MdoReference.create("Catalog.Заметки.Attribute.Автор"));
123+
assertThat(child).isPresent();
124+
var attribute = (ObjectAttribute) child.get();
125+
assertThat(attribute.getSynonym().isEmpty()).isFalse();
126+
assertThat(attribute.getSynonym().get("ru")).isEqualTo("Автор");
127+
assertThat(attribute.getDescription()).isEqualTo("Автор");
128+
assertThat(attribute.getDescription("ru")).isEqualTo("Автор");
129+
assertThat(attribute.getDescription("en")).isEqualTo("Автор");
130+
114131
}
115132

116133
// private void checkExtInfo(FormDataOLD formData) {

0 commit comments

Comments
 (0)