Skip to content

#221 / Упорядоченный список метаданных #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/main/java/com/github/_1c_syntax/mdclasses/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.github._1c_syntax.mdclasses.mdo.support.LanguageContent;
import com.github._1c_syntax.mdclasses.mdo.support.MDOModule;
import com.github._1c_syntax.mdclasses.mdo.support.MDOReference;
import com.github._1c_syntax.mdclasses.mdo.support.MDOType;
import com.github._1c_syntax.mdclasses.mdo.support.ModuleType;
import com.github._1c_syntax.mdclasses.mdo.support.ObjectBelonging;
import com.github._1c_syntax.mdclasses.mdo.support.ScriptVariant;
Expand All @@ -57,6 +58,7 @@
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -177,6 +179,10 @@ public class Configuration {
* Дочерние объекты конфигурации с MDO ссылками на них
*/
private Map<MDOReference, AbstractMDObjectBase> childrenByMdoRef;
/**
* Упорядоченный список объектов метаданных верхнего уровня в разрезе типов метаданных
*/
private Map<MDOType, List<AbstractMDObjectBase>> orderedTopMDObjects;
/**
* Дочерние общие модули
*/
Expand Down Expand Up @@ -205,6 +211,7 @@ protected Configuration() {
commonModules = Collections.emptyMap();
languages = Collections.emptyMap();
modulesByMDORef = Collections.emptyMap();
orderedTopMDObjects = Collections.emptyMap();
roles = Collections.emptyList();
copyrights = Collections.emptyList();
detailedInformation = Collections.emptyList();
Expand All @@ -228,9 +235,12 @@ protected Configuration() {
}

protected Configuration(MDConfiguration mdoConfiguration, ConfigurationSource source, Path path) {
var allChildren = getAllChildren(mdoConfiguration);

configurationSource = source;
children = getAllChildren(mdoConfiguration);
children = new HashSet<>(allChildren);
childrenByMdoRef = new HashMap<>();
orderedTopMDObjects = getOrderedTopObjectsByChildren(allChildren);
commonModules = new CaseInsensitiveMap<>();
languages = new HashMap<>();
roles = new ArrayList<>();
Expand Down Expand Up @@ -426,20 +436,27 @@ private static void computeModules(Map<URI, ModuleType> modulesType,
modulesMDORef.put(mdo.getMdoReference().getMdoRef(), modulesTypesAndURIs);
}

private static Set<AbstractMDObjectBase> getAllChildren(MDConfiguration mdoConfiguration) {
Set<AbstractMDObjectBase> allChildren = mdoConfiguration.getChildren().stream()
private static List<AbstractMDObjectBase> getAllChildren(MDConfiguration mdoConfiguration) {
List<AbstractMDObjectBase> allChildren = mdoConfiguration.getChildren().stream()
.filter(Either::isRight).map(Either::get)
.collect(Collectors.toSet());
.collect(Collectors.toList());

allChildren.addAll(allChildren.stream()
.filter(MDOHasChildren.class::isInstance)
.map(MDOHasChildren.class::cast)
.map(MDOHasChildren::getChildren)
.flatMap(Collection::stream)
.collect(Collectors.toSet()));
.collect(Collectors.toList()));

allChildren.add(mdoConfiguration);
return allChildren;
}

private static Map<MDOType, List<AbstractMDObjectBase>> getOrderedTopObjectsByChildren(
List<AbstractMDObjectBase> children) {

return children.stream().collect(Collectors.groupingBy(AbstractMDObjectBase::getType));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -172,6 +173,7 @@ void testEDT() {
modulesByType = configuration.getModulesByMDORef("WSReference.WSСсылка");
assertThat(modulesByType).isEmpty();

checkOrderedCommonModules(configuration);
}

@Test
Expand Down Expand Up @@ -436,6 +438,8 @@ void testDesigner() {
.get().getMdoReference());
assertThat(modulesByType).hasSize(1)
.containsKey(ModuleType.CommonModule);

checkOrderedCommonModules(configuration);
}

@Test
Expand Down Expand Up @@ -661,4 +665,19 @@ private void checkChildCount(Configuration configuration, MDOType type, int coun
.filteredOn(mdObjectBase -> mdObjectBase.getType() == type).hasSize(count);
}

private static void checkOrderedCommonModules(Configuration configuration) {
var orderedCommonModules = configuration.getOrderedTopMDObjects().get(MDOType.COMMON_MODULE);
checkPosition(orderedCommonModules, "ПростойОбщийМодуль", 0);
checkPosition(orderedCommonModules, "ГлобальныйОбщийМодуль", 1);
checkPosition(orderedCommonModules, "ОбщийМодульВызовСервера", 2);
checkPosition(orderedCommonModules, "ОбщийМодульПовтИспВызов", 3);
checkPosition(orderedCommonModules, "ОбщийМодульПовтИспСеанс", 4);
checkPosition(orderedCommonModules, "ОбщийМодульПолныйеПрава", 5);
}

private static void checkPosition(List<AbstractMDObjectBase> children, String name, int position) {
var child = children.get(position);
assertThat(child.getName()).isEqualTo(name);
}

}