Skip to content

Commit 7dce1e4

Browse files
committed
Реализовано заполнение и хранение стандартных реквизитов
1 parent 5016759 commit 7dce1e4

File tree

80 files changed

+21741
-3715
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+21741
-3715
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright (c) 2019 - 2025
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.children;
23+
24+
import com.github._1c_syntax.bsl.mdo.AccessRightsOwner;
25+
import com.github._1c_syntax.bsl.mdo.Attribute;
26+
import com.github._1c_syntax.bsl.mdo.support.AttributeKind;
27+
import com.github._1c_syntax.bsl.mdo.support.IndexingType;
28+
import com.github._1c_syntax.bsl.mdo.support.ObjectBelonging;
29+
import com.github._1c_syntax.bsl.mdo.support.RoleRight;
30+
import com.github._1c_syntax.bsl.support.SupportVariant;
31+
import com.github._1c_syntax.bsl.types.MdoReference;
32+
import com.github._1c_syntax.bsl.types.MultiLanguageString;
33+
import com.github._1c_syntax.bsl.types.MultiName;
34+
import com.github._1c_syntax.bsl.types.ValueTypeDescription;
35+
import lombok.AccessLevel;
36+
import lombok.Builder;
37+
import lombok.Builder.Default;
38+
import lombok.EqualsAndHashCode;
39+
import lombok.Getter;
40+
import lombok.ToString;
41+
import lombok.Value;
42+
43+
import java.util.List;
44+
45+
/**
46+
* Стандартный реквизит объекта
47+
*/
48+
@Value
49+
@Builder
50+
@ToString(of = {"uuid", "fullName"})
51+
@EqualsAndHashCode(of = {"uuid", "fullName"})
52+
public class StandardAttribute implements Attribute, AccessRightsOwner {
53+
54+
private static final List<RoleRight> POSSIBLE_RIGHTS = List.of(RoleRight.VIEW, RoleRight.EDIT);
55+
56+
/*
57+
* Для Attribute
58+
*/
59+
60+
/**
61+
* Равен UID владельца
62+
*/
63+
@Default
64+
String uuid = "";
65+
@Default
66+
MdoReference mdoReference = MdoReference.EMPTY;
67+
@Default
68+
String comment = "";
69+
@Default
70+
MultiLanguageString synonym = MultiLanguageString.EMPTY;
71+
@Default
72+
SupportVariant supportVariant = SupportVariant.NONE;
73+
@Default
74+
MdoReference owner = MdoReference.EMPTY;
75+
boolean passwordMode;
76+
@Default
77+
AttributeKind kind = AttributeKind.STANDARD;
78+
@Default
79+
@Getter(AccessLevel.NONE)
80+
ValueTypeDescription type = ValueTypeDescription.EMPTY;
81+
82+
/*
83+
* Свое
84+
*/
85+
86+
/**
87+
* Второе имя реквизита, на русском
88+
*/
89+
@Default
90+
MultiName fullName = MultiName.EMPTY;
91+
92+
/*
93+
* Свое
94+
*/
95+
96+
/**
97+
* Формат
98+
*/
99+
@Default
100+
MultiLanguageString format = MultiLanguageString.EMPTY;
101+
102+
/**
103+
* Формат редактирования
104+
*/
105+
@Default
106+
MultiLanguageString editFormat = MultiLanguageString.EMPTY;
107+
108+
/**
109+
* Выделять отрицательное
110+
*/
111+
boolean markNegatives;
112+
113+
/**
114+
* Маска
115+
*/
116+
@Default
117+
String mask = "";
118+
119+
/**
120+
* Многострочный режим
121+
*/
122+
boolean multiLine;
123+
124+
/**
125+
* Расширенное редактирование
126+
*/
127+
boolean extendedEdit;
128+
129+
/**
130+
* Заполнять из данных заполнения
131+
*/
132+
boolean fillFromFillingValue;
133+
134+
/**
135+
* Возвращает перечень возможных прав доступа
136+
*/
137+
public static List<RoleRight> possibleRights() {
138+
return POSSIBLE_RIGHTS;
139+
}
140+
141+
/**
142+
* Всегда собственный
143+
*/
144+
@Override
145+
public ObjectBelonging getObjectBelonging() {
146+
return ObjectBelonging.OWN;
147+
}
148+
149+
/**
150+
* Настроек индексирования у стандартных нет
151+
*/
152+
@Override
153+
public IndexingType getIndexing() {
154+
return IndexingType.DONT_INDEX;
155+
}
156+
157+
@Override
158+
public String getName() {
159+
return fullName.get();
160+
}
161+
162+
@Override
163+
public ValueTypeDescription getValueType() {
164+
return type;
165+
}
166+
167+
@Override
168+
public String getDescription(String code) {
169+
if (getSynonym().isEmpty()) {
170+
return fullName.get(code);
171+
}
172+
var description = getSynonym().get(code);
173+
if (description.isEmpty()) {
174+
description = getSynonym().getAny();
175+
}
176+
177+
if (description.isEmpty()) {
178+
description = fullName.get(code);
179+
}
180+
181+
return description;
182+
}
183+
}

src/main/java/com/github/_1c_syntax/bsl/reader/common/context/AbstractReaderContext.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
import java.nio.file.Path;
4141
import java.util.ArrayList;
4242
import java.util.Collections;
43+
import java.util.Comparator;
4344
import java.util.List;
45+
import java.util.Locale;
46+
import java.util.Map;
47+
import java.util.concurrent.ConcurrentHashMap;
4448

4549
/**
4650
* Сохраняемый контекст при чтении файла
@@ -76,6 +80,7 @@ public abstract class AbstractReaderContext {
7680
/**
7781
* Режим поддержки
7882
*/
83+
@Getter
7984
protected SupportVariant supportVariant;
8085

8186
/**
@@ -87,6 +92,7 @@ public abstract class AbstractReaderContext {
8792
/**
8893
* Ссылка на текущий объект
8994
*/
95+
@Getter
9096
protected MdoReference mdoReference = MdoReference.EMPTY;
9197

9298
/**
@@ -110,9 +116,24 @@ public abstract class AbstractReaderContext {
110116
@Getter
111117
private Object lastValue;
112118

119+
/**
120+
* всякие прочитанные атрибуты
121+
*/
122+
@Getter
123+
private final Map<String, Object> cache;
124+
113125
protected AbstractReaderContext(@NonNull HierarchicalStreamReader reader) {
114126
currentPath = ExtendXStream.getCurrentPath(reader);
115127
mdReader = ExtendXStream.getCurrentMDReader(reader);
128+
129+
cache = new ConcurrentHashMap<>();
130+
}
131+
132+
protected AbstractReaderContext(@NonNull Path currentPath, @NonNull MDReader mdReader) {
133+
this.currentPath = currentPath;
134+
this.mdReader = mdReader;
135+
136+
cache = new ConcurrentHashMap<>();
116137
}
117138

118139
/**
@@ -122,7 +143,10 @@ protected AbstractReaderContext(@NonNull HierarchicalStreamReader reader) {
122143
* @param value устанавливаемое значение
123144
*/
124145
public void setValue(String methodName, Object value) {
125-
TransformationUtils.setValue(builder, methodName, value);
146+
if (value != null) {
147+
TransformationUtils.setValue(builder, methodName, value);
148+
cache.put(methodName.toLowerCase(Locale.ROOT), value);
149+
}
126150
}
127151

128152
/**
@@ -142,6 +166,11 @@ public Object build() {
142166
return TransformationUtils.build(builder, currentPath);
143167
}
144168

169+
@SuppressWarnings("unchecked")
170+
public <T> T getFromCache(String key, T defaultValue) {
171+
return (T) cache.getOrDefault(key.toLowerCase(Locale.ROOT), defaultValue);
172+
}
173+
145174
protected void setValueModules() {
146175
var modules = readModules();
147176
if (!modules.isEmpty()) {
@@ -175,6 +204,7 @@ private List<Module> readModules() {
175204
}
176205
}
177206
);
207+
modules.sort(Comparator.comparing(Module::toString));
178208
return modules;
179209
}
180210
}

src/main/java/com/github/_1c_syntax/bsl/reader/common/context/MDReaderContext.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121
*/
2222
package com.github._1c_syntax.bsl.reader.common.context;
2323

24+
import com.github._1c_syntax.bsl.mdo.AttributeOwner;
2425
import com.github._1c_syntax.bsl.mdo.ChildrenOwner;
2526
import com.github._1c_syntax.bsl.mdo.Form;
2627
import com.github._1c_syntax.bsl.mdo.MDChild;
2728
import com.github._1c_syntax.bsl.mdo.ModuleOwner;
2829
import com.github._1c_syntax.bsl.mdo.Subsystem;
30+
import com.github._1c_syntax.bsl.mdo.children.StandardAttribute;
2931
import com.github._1c_syntax.bsl.mdo.support.TemplateType;
32+
import com.github._1c_syntax.bsl.reader.MDReader;
3033
import com.github._1c_syntax.bsl.reader.common.TransformationUtils;
34+
import com.github._1c_syntax.bsl.reader.common.context.std_attributes.StdAttributeFiller;
3135
import com.github._1c_syntax.bsl.supconf.ParseSupportData;
3236
import com.github._1c_syntax.bsl.types.MDOType;
3337
import com.github._1c_syntax.bsl.types.MdoReference;
@@ -39,6 +43,7 @@
3943
import lombok.ToString;
4044
import lombok.extern.slf4j.Slf4j;
4145

46+
import java.nio.file.Path;
4247
import java.util.ArrayList;
4348
import java.util.Collections;
4449
import java.util.List;
@@ -60,9 +65,11 @@ public class MDReaderContext extends AbstractReaderContext {
6065
private static final String SUPPORT_VALIANT_FIELD_NAME = "SupportVariant";
6166
private static final String DATA_FIELD_NAME = "data";
6267

68+
6369
/**
6470
* Коллекция билдеров для дочерних объектов, которые надо доделать
6571
*/
72+
@Getter
6673
private final Map<String, List<MDReaderContext>> childrenContexts;
6774

6875
/**
@@ -95,6 +102,15 @@ public MDReaderContext(@NonNull HierarchicalStreamReader reader) {
95102
childrenContexts = new ConcurrentHashMap<>();
96103
}
97104

105+
public MDReaderContext(@NonNull Path currentPath,
106+
@NonNull MDReader mdReader) {
107+
super(currentPath, mdReader);
108+
realClass = StandardAttribute.class;
109+
builder = TransformationUtils.builder(realClass);
110+
mdoType = MDOType.STANDARD_ATTRIBUTE;
111+
childrenContexts = new ConcurrentHashMap<>();
112+
}
113+
98114
@Override
99115
public final void setValue(String methodName, Object value) {
100116
if (value instanceof MDReaderContext child) {
@@ -106,8 +122,10 @@ public final void setValue(String methodName, Object value) {
106122

107123
@Override
108124
public Object build() {
109-
mdoReference = MdoReference.create(owner, mdoType, name);
110-
setValue(MDO_REFERENCE_FIELD_NAME, mdoReference);
125+
if (mdoReference.isEmpty()) {
126+
mdoReference = MdoReference.create(owner, mdoType, name);
127+
setValue(MDO_REFERENCE_FIELD_NAME, mdoReference);
128+
}
111129

112130
if (MDChild.class.isAssignableFrom(realClass)) {
113131
setValue(OWNER_FIELD_NAME, owner);
@@ -121,6 +139,10 @@ public Object build() {
121139
setValue(DATA_FIELD_NAME, mdReader.readFormData(currentPath, name, mdoType));
122140
}
123141

142+
if (AttributeOwner.class.isAssignableFrom(realClass)) {
143+
StdAttributeFiller.fill(this);
144+
}
145+
124146
if (ChildrenOwner.class.isAssignableFrom(realClass)) {
125147
setValueChildren();
126148
}

0 commit comments

Comments
 (0)