@Test public void testAggregateNodeTypes() { final List<URL> cnds = Stream.of("a", "bb", "b", "c", "d", "e", "f") .map(letter -> new File(baseDir, letter + ".cnd")) .map(compose1(File::toURI, uncheck1(URI::toURL))) .collect(Collectors.toList()); final List<Result<NodeTypeSet>> setsWithError = JsonCnd.readNodeTypes(getMapping(), cnds); final NodeTypeSet aggregate = JsonCnd.aggregateNodeTypes(getMapping(), setsWithError.stream() .collect(Result.tryCollect(Collectors.toList())) .getOrDefault(Collections.emptyList())); final Name bPrimaryType = NameFactoryImpl.getInstance() .create("http: final Name bProperty = NameFactoryImpl.getInstance() .create("http: assertTrue("expect b:primaryType", aggregate.getNodeTypes().containsKey(bPrimaryType)); assertTrue("b:primaryType should define b:property", Stream.of(aggregate.getNodeTypes().get(bPrimaryType).getPropertyDefs()) .anyMatch(def -> bProperty.equals(def.getName()))); }
public static NodeTypeSet aggregateNodeTypes(final @NotNull NamespaceMapping mapping, final @NotNull List<NodeTypeSet> nodeTypeSets) { final NamespaceMapping aggregateMapping = new NamespaceMapping(mapping); final Set<Name> builtinTypes = BUILTIN_NODETYPES.stream() .map(uncheck1(BUILTIN_RESOLVER::getQName)) .collect(Collectors.toSet()); final Map<Name, List<QNodeTypeDefinition>> unfilteredTypes = nodeTypeSets.stream().flatMap( compose1(compose1(NodeTypeSet::getNodeTypes, Map::entrySet), Set::stream)) .filter(testKey(inSet(builtinTypes).negate())) .map(mapValue(Collections::singletonList)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> { final List<QNodeTypeDefinition> combined = new ArrayList<>(left); combined.addAll(right); return combined; })); final Set<Name> unfilteredNames = unfilteredTypes.keySet(); final Map<Name, QNodeTypeDefinition> satisfied = unfilteredTypes.entrySet().stream() .map(mapValue(types -> types.stream() .filter(type -> type.getDependencies().stream() .noneMatch(inSet(builtinTypes).or(inSet(unfilteredNames)).negate())) )) .map(mapValue(Stream::findFirst)) .filter(testValue(Optional::isPresent)) .collect(Collectors.toMap(Map.Entry::getKey, compose1(Map.Entry::getValue, Optional::get))); final Set<Name> unsatisfiedNames = unfilteredNames.stream().filter(inSet(satisfied.keySet()).negate()) .collect(Collectors.toSet()); if (!unsatisfiedNames.isEmpty()) { LOGGER.debug("[aggregateNodeTypes] unsatisfied node type names: {}", unsatisfiedNames.toString()); } unsatisfiedNames.stream() .map(name -> toEntry(name, unfilteredTypes.getOrDefault(name, Collections.emptyList()).stream().findFirst())) .filter(testValue(Optional::isPresent)) .map(mapValue(Optional::get)) .forEach(entry -> satisfied.put(entry.getKey(), entry.getValue())); return new DefaultNodeTypeSet("<aggregate>", satisfied.values(), aggregateMapping); }
JsonCnd { public static NodeTypeSet aggregateNodeTypes(final @NotNull NamespaceMapping mapping, final @NotNull List<NodeTypeSet> nodeTypeSets) { final NamespaceMapping aggregateMapping = new NamespaceMapping(mapping); final Set<Name> builtinTypes = BUILTIN_NODETYPES.stream() .map(uncheck1(BUILTIN_RESOLVER::getQName)) .collect(Collectors.toSet()); final Map<Name, List<QNodeTypeDefinition>> unfilteredTypes = nodeTypeSets.stream().flatMap( compose1(compose1(NodeTypeSet::getNodeTypes, Map::entrySet), Set::stream)) .filter(testKey(inSet(builtinTypes).negate())) .map(mapValue(Collections::singletonList)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> { final List<QNodeTypeDefinition> combined = new ArrayList<>(left); combined.addAll(right); return combined; })); final Set<Name> unfilteredNames = unfilteredTypes.keySet(); final Map<Name, QNodeTypeDefinition> satisfied = unfilteredTypes.entrySet().stream() .map(mapValue(types -> types.stream() .filter(type -> type.getDependencies().stream() .noneMatch(inSet(builtinTypes).or(inSet(unfilteredNames)).negate())) )) .map(mapValue(Stream::findFirst)) .filter(testValue(Optional::isPresent)) .collect(Collectors.toMap(Map.Entry::getKey, compose1(Map.Entry::getValue, Optional::get))); final Set<Name> unsatisfiedNames = unfilteredNames.stream().filter(inSet(satisfied.keySet()).negate()) .collect(Collectors.toSet()); if (!unsatisfiedNames.isEmpty()) { LOGGER.debug("[aggregateNodeTypes] unsatisfied node type names: {}", unsatisfiedNames.toString()); } unsatisfiedNames.stream() .map(name -> toEntry(name, unfilteredTypes.getOrDefault(name, Collections.emptyList()).stream().findFirst())) .filter(testValue(Optional::isPresent)) .map(mapValue(Optional::get)) .forEach(entry -> satisfied.put(entry.getKey(), entry.getValue())); return new DefaultNodeTypeSet("<aggregate>", satisfied.values(), aggregateMapping); } }
JsonCnd { public static NodeTypeSet aggregateNodeTypes(final @NotNull NamespaceMapping mapping, final @NotNull List<NodeTypeSet> nodeTypeSets) { final NamespaceMapping aggregateMapping = new NamespaceMapping(mapping); final Set<Name> builtinTypes = BUILTIN_NODETYPES.stream() .map(uncheck1(BUILTIN_RESOLVER::getQName)) .collect(Collectors.toSet()); final Map<Name, List<QNodeTypeDefinition>> unfilteredTypes = nodeTypeSets.stream().flatMap( compose1(compose1(NodeTypeSet::getNodeTypes, Map::entrySet), Set::stream)) .filter(testKey(inSet(builtinTypes).negate())) .map(mapValue(Collections::singletonList)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> { final List<QNodeTypeDefinition> combined = new ArrayList<>(left); combined.addAll(right); return combined; })); final Set<Name> unfilteredNames = unfilteredTypes.keySet(); final Map<Name, QNodeTypeDefinition> satisfied = unfilteredTypes.entrySet().stream() .map(mapValue(types -> types.stream() .filter(type -> type.getDependencies().stream() .noneMatch(inSet(builtinTypes).or(inSet(unfilteredNames)).negate())) )) .map(mapValue(Stream::findFirst)) .filter(testValue(Optional::isPresent)) .collect(Collectors.toMap(Map.Entry::getKey, compose1(Map.Entry::getValue, Optional::get))); final Set<Name> unsatisfiedNames = unfilteredNames.stream().filter(inSet(satisfied.keySet()).negate()) .collect(Collectors.toSet()); if (!unsatisfiedNames.isEmpty()) { LOGGER.debug("[aggregateNodeTypes] unsatisfied node type names: {}", unsatisfiedNames.toString()); } unsatisfiedNames.stream() .map(name -> toEntry(name, unfilteredTypes.getOrDefault(name, Collections.emptyList()).stream().findFirst())) .filter(testValue(Optional::isPresent)) .map(mapValue(Optional::get)) .forEach(entry -> satisfied.put(entry.getKey(), entry.getValue())); return new DefaultNodeTypeSet("<aggregate>", satisfied.values(), aggregateMapping); } private  JsonCnd(); }
JsonCnd { public static NodeTypeSet aggregateNodeTypes(final @NotNull NamespaceMapping mapping, final @NotNull List<NodeTypeSet> nodeTypeSets) { final NamespaceMapping aggregateMapping = new NamespaceMapping(mapping); final Set<Name> builtinTypes = BUILTIN_NODETYPES.stream() .map(uncheck1(BUILTIN_RESOLVER::getQName)) .collect(Collectors.toSet()); final Map<Name, List<QNodeTypeDefinition>> unfilteredTypes = nodeTypeSets.stream().flatMap( compose1(compose1(NodeTypeSet::getNodeTypes, Map::entrySet), Set::stream)) .filter(testKey(inSet(builtinTypes).negate())) .map(mapValue(Collections::singletonList)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> { final List<QNodeTypeDefinition> combined = new ArrayList<>(left); combined.addAll(right); return combined; })); final Set<Name> unfilteredNames = unfilteredTypes.keySet(); final Map<Name, QNodeTypeDefinition> satisfied = unfilteredTypes.entrySet().stream() .map(mapValue(types -> types.stream() .filter(type -> type.getDependencies().stream() .noneMatch(inSet(builtinTypes).or(inSet(unfilteredNames)).negate())) )) .map(mapValue(Stream::findFirst)) .filter(testValue(Optional::isPresent)) .collect(Collectors.toMap(Map.Entry::getKey, compose1(Map.Entry::getValue, Optional::get))); final Set<Name> unsatisfiedNames = unfilteredNames.stream().filter(inSet(satisfied.keySet()).negate()) .collect(Collectors.toSet()); if (!unsatisfiedNames.isEmpty()) { LOGGER.debug("[aggregateNodeTypes] unsatisfied node type names: {}", unsatisfiedNames.toString()); } unsatisfiedNames.stream() .map(name -> toEntry(name, unfilteredTypes.getOrDefault(name, Collections.emptyList()).stream().findFirst())) .filter(testValue(Optional::isPresent)) .map(mapValue(Optional::get)) .forEach(entry -> satisfied.put(entry.getKey(), entry.getValue())); return new DefaultNodeTypeSet("<aggregate>", satisfied.values(), aggregateMapping); } private  JsonCnd(); @SuppressWarnings("WeakerAccess") static List<QNodeTypeDefinition> getQTypesFromJson(final @NotNull JsonObject json,
                      final @NotNull NamespaceMapping mapping); @SuppressWarnings("WeakerAccess") static List<PrivilegeDefinition> getPrivilegesFromJson(final @NotNull JsonValue json,
                          final @NotNull NamespaceMapping mapping); static JsonObject toJson(final @NotNull List<QNodeTypeDefinition> ntDefs,
                                    final @NotNull NamespaceMapping mapping); static JsonValue privilegesToJson(final @NotNull List<PrivilegeDefinition> privDefs,
                                             final @NotNull NamespaceMapping mapping); static List<JcrNs> toJcrNsList(final @NotNull NamespaceMapping mapping,
                                          final @NotNull NamespaceMappingRequest request); static Function<NodeTypeDefinition, QNodeTypeDefinition> adaptToQ(final @NotNull Session session); static Stream<Name> namedBy(final @NotNull QNodeTypeDefinition def); static Stream<Name> namedBy(final @NotNull PrivilegeDefinition def); static NamespaceMapping toNamespaceMapping(final List<JcrNs> jcrNsList); static @NotNull Stream<String> streamNsPrefix(final @NotNull String name); static List<Result<NodeTypeSet>> readNodeTypes(final @NotNull NamespaceMapping mapping,
                                                          final @NotNull List<URL> cndUrls); static NodeTypeSet aggregateNodeTypes(final @NotNull NamespaceMapping mapping,
                                                 final @NotNull List<NodeTypeSet> nodeTypeSets); }
JsonCnd { public static NodeTypeSet aggregateNodeTypes(final @NotNull NamespaceMapping mapping, final @NotNull List<NodeTypeSet> nodeTypeSets) { final NamespaceMapping aggregateMapping = new NamespaceMapping(mapping); final Set<Name> builtinTypes = BUILTIN_NODETYPES.stream() .map(uncheck1(BUILTIN_RESOLVER::getQName)) .collect(Collectors.toSet()); final Map<Name, List<QNodeTypeDefinition>> unfilteredTypes = nodeTypeSets.stream().flatMap( compose1(compose1(NodeTypeSet::getNodeTypes, Map::entrySet), Set::stream)) .filter(testKey(inSet(builtinTypes).negate())) .map(mapValue(Collections::singletonList)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> { final List<QNodeTypeDefinition> combined = new ArrayList<>(left); combined.addAll(right); return combined; })); final Set<Name> unfilteredNames = unfilteredTypes.keySet(); final Map<Name, QNodeTypeDefinition> satisfied = unfilteredTypes.entrySet().stream() .map(mapValue(types -> types.stream() .filter(type -> type.getDependencies().stream() .noneMatch(inSet(builtinTypes).or(inSet(unfilteredNames)).negate())) )) .map(mapValue(Stream::findFirst)) .filter(testValue(Optional::isPresent)) .collect(Collectors.toMap(Map.Entry::getKey, compose1(Map.Entry::getValue, Optional::get))); final Set<Name> unsatisfiedNames = unfilteredNames.stream().filter(inSet(satisfied.keySet()).negate()) .collect(Collectors.toSet()); if (!unsatisfiedNames.isEmpty()) { LOGGER.debug("[aggregateNodeTypes] unsatisfied node type names: {}", unsatisfiedNames.toString()); } unsatisfiedNames.stream() .map(name -> toEntry(name, unfilteredTypes.getOrDefault(name, Collections.emptyList()).stream().findFirst())) .filter(testValue(Optional::isPresent)) .map(mapValue(Optional::get)) .forEach(entry -> satisfied.put(entry.getKey(), entry.getValue())); return new DefaultNodeTypeSet("<aggregate>", satisfied.values(), aggregateMapping); } private  JsonCnd(); @SuppressWarnings("WeakerAccess") static List<QNodeTypeDefinition> getQTypesFromJson(final @NotNull JsonObject json,
                      final @NotNull NamespaceMapping mapping); @SuppressWarnings("WeakerAccess") static List<PrivilegeDefinition> getPrivilegesFromJson(final @NotNull JsonValue json,
                          final @NotNull NamespaceMapping mapping); static JsonObject toJson(final @NotNull List<QNodeTypeDefinition> ntDefs,
                                    final @NotNull NamespaceMapping mapping); static JsonValue privilegesToJson(final @NotNull List<PrivilegeDefinition> privDefs,
                                             final @NotNull NamespaceMapping mapping); static List<JcrNs> toJcrNsList(final @NotNull NamespaceMapping mapping,
                                          final @NotNull NamespaceMappingRequest request); static Function<NodeTypeDefinition, QNodeTypeDefinition> adaptToQ(final @NotNull Session session); static Stream<Name> namedBy(final @NotNull QNodeTypeDefinition def); static Stream<Name> namedBy(final @NotNull PrivilegeDefinition def); static NamespaceMapping toNamespaceMapping(final List<JcrNs> jcrNsList); static @NotNull Stream<String> streamNsPrefix(final @NotNull String name); static List<Result<NodeTypeSet>> readNodeTypes(final @NotNull NamespaceMapping mapping,
                                                          final @NotNull List<URL> cndUrls); static NodeTypeSet aggregateNodeTypes(final @NotNull NamespaceMapping mapping,
                                                 final @NotNull List<NodeTypeSet> nodeTypeSets); static final NamespaceMapping BUILTIN_MAPPINGS; static final List<String> BUILTIN_NODETYPES; static final List<String> BUILTIN_PRIVILEGES; }