Skip to content

Commit d96d411

Browse files
committed
Добавил формы
1 parent 3eb537a commit d96d411

File tree

4 files changed

+122
-11
lines changed

4 files changed

+122
-11
lines changed

src/main/java/com/github/_1c_syntax/mdclasses/mdo/MDObjectBase.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import lombok.experimental.SuperBuilder;
1212

1313
import java.net.URI;
14+
import java.util.ArrayList;
15+
import java.util.List;
1416
import java.util.Map;
1517

1618
import static com.github._1c_syntax.mdclasses.metadata.utils.MapExtension.getOrEmptyString;
@@ -28,6 +30,8 @@ public class MDObjectBase {
2830
protected URI mdoURI;
2931
protected Map<URI, ModuleType> modulesByType;
3032

33+
protected List<Form> forms;
34+
3135
public abstract static class MDObjectBaseBuilder
3236
<C extends MDObjectBase, B extends MDObjectBase.MDObjectBaseBuilder<C, B>> {
3337

@@ -40,6 +44,23 @@ protected MDObjectBaseBuilder<C, B> properties(Map<String, Object> properties) {
4044

4145
return this.self();
4246
}
47+
48+
@JsonProperty("forms")
49+
protected MDObjectBaseBuilder<C, B> forms(Map<String, Object> properties) {
50+
51+
if (forms == null) {
52+
forms = new ArrayList<>();
53+
}
54+
forms.add(
55+
Form.builder()
56+
.comment(getOrEmptyString(properties, "comment"))
57+
.uuid(getOrEmptyString(properties, "uuid"))
58+
.name(getOrEmptyString(properties, "name"))
59+
.build());
60+
61+
return this.self();
62+
}
63+
4364
}
4465

4566
public void setMdoURI(URI uri) {
@@ -51,6 +72,13 @@ public void setMdoURI(URI uri) {
5172
public void setModulesByType(Map<URI, ModuleType> modulesByType) {
5273
if (this.modulesByType == null) {
5374
this.modulesByType = modulesByType;
75+
// todo реализовать заполнение для форм
76+
}
77+
}
78+
79+
public void setForms(List<Form> forms) {
80+
if (this.forms == null) {
81+
this.forms = forms;
5482
}
5583
}
5684

src/main/java/com/github/_1c_syntax/mdclasses/metadata/utils/MDOUtils.java

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github._1c_syntax.mdclasses.metadata.utils;
22

3+
import com.github._1c_syntax.mdclasses.mdo.Form;
34
import com.github._1c_syntax.mdclasses.mdo.MDObjectBase;
45
import com.github._1c_syntax.mdclasses.mdo.MetaDataObject;
56
import com.github._1c_syntax.mdclasses.metadata.additional.ConfigurationSource;
@@ -321,12 +322,14 @@ public static MDObjectBase getMDObject(ConfigurationSource configurationSource,
321322
}
322323

323324
if (mdo != null) {
325+
var mdoFolder = getMDOTypeFolderByMDOPath(configurationSource, mdoPath);
324326
mdo.setMdoURI(mdoPath.toUri());
325327
mdo.setModulesByType(getModuleTypesByMDOPath(
326328
configurationSource,
327329
mdoPath,
328-
getMDOTypeFolderByMDOPath(configurationSource, mdoPath),
330+
mdoFolder,
329331
type));
332+
updateMDOForms(configurationSource, mdo, type, mdoFolder);
330333
}
331334

332335
return mdo;
@@ -389,22 +392,23 @@ public static Map<URI, ModuleType> getModuleTypesByPath(ConfigurationSource conf
389392
return modulesByType;
390393
}
391394

395+
/**
396+
* MDOModuleTypes
397+
*/
398+
392399
@SneakyThrows
393400
private static Map<URI, ModuleType> getChildrenMDOModuleTypes(ConfigurationSource configurationSource,
394-
Path folder,
395-
String name,
396-
String subDir,
401+
Path rootPath,
397402
ModuleType moduleType) {
398403
Map<URI, ModuleType> modulesByType = new HashMap<>();
399404

400-
var rootPath = Paths.get(folder.toString(), name, subDir);
401405
if (rootPath.toFile().exists()) {
402406
try (Stream<Path> files = Files.walk(rootPath, 1)) {
403407
files
404408
.filter((Path f) -> Files.isDirectory(f))
405409
.forEach(mdoPath -> {
406-
var formName = FilenameUtils.getBaseName(mdoPath.toString());
407-
var modulePath = getModulePath(configurationSource, rootPath, formName, moduleType);
410+
var name = FilenameUtils.getBaseName(mdoPath.toString());
411+
var modulePath = getModulePath(configurationSource, rootPath, name, moduleType);
408412
if (modulePath != null && modulePath.toFile().exists()) {
409413
modulesByType.put(modulePath.toUri(), moduleType);
410414
}
@@ -415,21 +419,27 @@ private static Map<URI, ModuleType> getChildrenMDOModuleTypes(ConfigurationSourc
415419
return modulesByType;
416420
}
417421

418-
419422
private static Map<URI, ModuleType> getFormsMDOModuleTypes(ConfigurationSource configurationSource,
420423
Path folder,
421424
String name) {
422-
return getChildrenMDOModuleTypes(configurationSource, folder, name, "Forms", ModuleType.FormModule);
425+
return getChildrenMDOModuleTypes(configurationSource,
426+
Paths.get(folder.toString(), name, "Forms"),
427+
ModuleType.FormModule);
423428
}
424429

425430
private static Map<URI, ModuleType> getCommandsMDOModuleTypes(ConfigurationSource configurationSource,
426431
Path folder,
427432
String name) {
428433

429-
return getChildrenMDOModuleTypes(configurationSource, folder, name,
430-
"Commands", ModuleType.CommandModule);
434+
return getChildrenMDOModuleTypes(configurationSource,
435+
Paths.get(folder.toString(), name, "Commands"),
436+
ModuleType.CommandModule);
431437
}
432438

439+
/**
440+
* Children
441+
*/
442+
433443
public static Map<String, MDObjectBase> getChildren(ConfigurationSource configurationSource,
434444
Path rootPath,
435445
MDOType type) {
@@ -494,6 +504,53 @@ private List<String> getChildrenNamesInFolder(ConfigurationSource configurationS
494504
return childrenNames;
495505
}
496506

507+
private void updateMDOForms(ConfigurationSource configurationSource, MDObjectBase mdo, MDOType type, Path folder) {
508+
if (!type.isMayHaveForm() || folder == null) {
509+
return;
510+
}
511+
var formFolder = Paths.get(folder.toString(), mdo.getName(), "Forms");
512+
if (!formFolder.toFile().exists()) {
513+
return;
514+
}
515+
516+
// для EDT пока ничего не делаем, MDO для формы нету
517+
if (configurationSource != ConfigurationSource.EDT) {
518+
List<Form> mdoForms = new ArrayList<>();
519+
getMDOFilesInFolder(configurationSource, formFolder)
520+
.forEach(mdoFile -> {
521+
Form mdoForm = null;
522+
var xmlMapper = ObjectMapperFactory.createXmlMapper();
523+
try {
524+
MetaDataObject metaDataObject = xmlMapper.readValue(mdoFile.toFile(), MetaDataObject.class);
525+
mdoForm = metaDataObject.getForm();
526+
} catch (IOException e) {
527+
LOGGER.error(e.getMessage(), e);
528+
}
529+
if (mdoForm != null) {
530+
mdoForms.add(mdoForm);
531+
}
532+
});
533+
534+
mdo.setForms(mdoForms);
535+
}
536+
537+
if (mdo.getForms() != null) {
538+
mdo.getForms().forEach(form -> {
539+
Map<URI, ModuleType> modulesByType = new HashMap<>();
540+
var modulePath = getModulePath(configurationSource, formFolder, form.getName(), ModuleType.FormModule);
541+
if (modulePath != null && modulePath.toFile().exists()) {
542+
modulesByType.put(modulePath.toUri(), ModuleType.FormModule);
543+
}
544+
545+
form.setModulesByType(modulesByType);
546+
});
547+
}
548+
}
549+
550+
/**
551+
* Other
552+
*/
553+
497554
@SneakyThrows
498555
private List<Path> getMDOFilesInFolder(ConfigurationSource configurationSource, Path folder) {
499556
List<Path> childrenNames = new ArrayList<>();

src/test/java/com/github/_1c_syntax/mdclasses/mdo/MetaDataObjectTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ void metaDataObjectTestEDT() {
4747
assertThat(mdo instanceof Catalog).isTrue();
4848
assertThat(mdo.getName()).isEqualTo("Справочник1");
4949
assertThat(mdo.getUuid()).isEqualTo("eeef463d-d5e7-42f2-ae53-10279661f59d");
50+
assertThat(mdo.getForms()).isNotEmpty();
51+
assertThat(mdo.getForms()).hasSize(3);
52+
assertThat(mdo.getForms().stream().anyMatch(form -> form.getName().equals("ФормаЭлемента"))).isTrue();
5053

5154
mdo = MDOUtils.getMDObject(ConfigurationSource.EDT, MDOType.CHART_OF_ACCOUNTS, getMDOPathEDT("ChartsOfAccounts/ПланСчетов1/ПланСчетов1.mdo"));
5255
assertThat(mdo).isNotNull();
@@ -143,6 +146,11 @@ void metaDataObjectTestEDT() {
143146
assertThat(mdo instanceof Document).isTrue();
144147
assertThat(mdo.getName()).isEqualTo("Документ1");
145148
assertThat(mdo.getUuid()).isEqualTo("ce4fb46b-4af7-493e-9fcb-76ad8c4f8acd");
149+
assertThat(mdo.getForms()).isNotNull();
150+
var forms = mdo.getForms();
151+
assertThat(forms).hasSize(3);
152+
assertThat(forms.stream().anyMatch(form -> form.getName().equals("ФормаДокумента"))).isTrue();
153+
assertThat(forms.stream().anyMatch(form -> !form.getModulesByType().isEmpty())).isTrue();
146154

147155
mdo = MDOUtils.getMDObject(ConfigurationSource.EDT, MDOType.ENUM, getMDOPathEDT("Enums/Перечисление1/Перечисление1.mdo"));
148156
assertThat(mdo).isNotNull();
@@ -303,6 +311,9 @@ void metaDataObjectTestDesigner() {
303311
assertThat(mdo instanceof Catalog).isTrue();
304312
assertThat(mdo.getName()).isEqualTo("Справочник1");
305313
assertThat(mdo.getUuid()).isEqualTo("eeef463d-d5e7-42f2-ae53-10279661f59d");
314+
assertThat(mdo.getForms()).isNotEmpty();
315+
assertThat(mdo.getForms()).hasSize(3);
316+
assertThat(mdo.getForms().stream().anyMatch(form -> form.getName().equals("ФормаЭлемента"))).isTrue();
306317

307318
mdo = MDOUtils.getMDObject(ConfigurationSource.DESIGNER, MDOType.CHART_OF_ACCOUNTS, getMDOPathDesigner("ChartsOfAccounts/ПланСчетов1.xml"));
308319
assertThat(mdo).isNotNull();
@@ -400,6 +411,15 @@ void metaDataObjectTestDesigner() {
400411
assertThat(mdo.getName()).isEqualTo("Документ1");
401412
assertThat(mdo.getUuid()).isEqualTo("ce4fb46b-4af7-493e-9fcb-76ad8c4f8acd");
402413

414+
mdo = MDOUtils.getMDObject(ConfigurationSource.DESIGNER, MDOType.DOCUMENT, getMDOPathDesigner("Documents/ПоступлениеТоваровУслуг.xml"));
415+
assertThat(mdo).isNotNull();
416+
assertThat(mdo instanceof Document).isTrue();
417+
assertThat(mdo.getForms()).isNotNull();
418+
var forms = mdo.getForms();
419+
assertThat(forms).hasSize(6);
420+
assertThat(forms.stream().anyMatch(form -> form.getName().equals("ФормаПодбораТоваровИзЗаказа"))).isTrue();
421+
assertThat(forms.stream().anyMatch(form -> !form.getModulesByType().isEmpty())).isTrue();
422+
403423
mdo = MDOUtils.getMDObject(ConfigurationSource.DESIGNER, MDOType.ENUM, getMDOPathDesigner("Enums/Перечисление1.xml"));
404424
assertThat(mdo).isNotNull();
405425
assertThat(mdo instanceof MDOEnum).isTrue();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
3+
&НаКлиенте
4+
Процедура ВнешнееСобытие(Источник, Событие, Данные)
5+
//TODO: Вставить содержимое обработчика
6+
КонецПроцедуры

0 commit comments

Comments
 (0)