11package com .github ._1c_syntax .mdclasses .metadata .utils ;
22
3+ import com .github ._1c_syntax .mdclasses .mdo .Form ;
34import com .github ._1c_syntax .mdclasses .mdo .MDObjectBase ;
45import com .github ._1c_syntax .mdclasses .mdo .MetaDataObject ;
56import 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 <>();
0 commit comments