@Test public void testNamedBy_privileges() { List<PrivilegeDefinition> defs = JsonCnd.getPrivilegesFromJson(obj() .key("jcr:canDo", obj()) .key("jcr:willDo", obj() .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, false)) .key("jcr:wouldDoBut", obj() .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, true)) .key("jcr:none", obj() .key(JsonCnd.PRIVILEGE_KEY_CONTAINS, arr())) .key("jcr:rw", obj() .key(JsonCnd.PRIVILEGE_KEY_CONTAINS, arr("jcr:read", "jcr:write", "jcr:addChildNodes"))) .key("jcr:mightRw", obj() .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, true) .key(JsonCnd.PRIVILEGE_KEY_CONTAINS, arr("jcr:read", "jcr:write", "jcr:removeNode"))) .get(), getMapping()); final List<String> jcrNames = Arrays.asList("jcr:canDo", "jcr:willDo", "jcr:wouldDoBut", "jcr:none", "jcr:rw", "jcr:mightRw", "jcr:read", "jcr:write", "jcr:addChildNodes", "jcr:removeNode"); final Set<Name> expectNamedBy = jcrNames.stream().map(uncheck1(resolver::getQName)).collect(Collectors.toSet()); final Set<Name> actualNamedBy = defs.stream().flatMap(JsonCnd::namedBy).collect(Collectors.toSet()); assertEquals("expect namedBy", expectNamedBy, actualNamedBy); }
@SuppressWarnings("WeakerAccess") public static List<PrivilegeDefinition> getPrivilegesFromJson(final @NotNull JsonValue json, final @NotNull NamespaceMapping mapping) { if (json.getValueType() == JsonValue.ValueType.ARRAY) { return JavaxJson.mapArrayOfStrings(json.asJsonArray(), zipKeysWithValueFunc(constantly1(() -> JsonValue.EMPTY_JSON_OBJECT)), true) .stream() .map(mapEntry(uncheck2(privDefinitionMapper(mapping)))) .collect(Collectors.toList()); } else if (json.getValueType() == JsonValue.ValueType.OBJECT) { return JavaxJson.mapObjectValues(json.asJsonObject(), uncheck2(privDefinitionMapper(mapping)), true); } else { return Collections.emptyList(); } }
JsonCnd { @SuppressWarnings("WeakerAccess") public static List<PrivilegeDefinition> getPrivilegesFromJson(final @NotNull JsonValue json, final @NotNull NamespaceMapping mapping) { if (json.getValueType() == JsonValue.ValueType.ARRAY) { return JavaxJson.mapArrayOfStrings(json.asJsonArray(), zipKeysWithValueFunc(constantly1(() -> JsonValue.EMPTY_JSON_OBJECT)), true) .stream() .map(mapEntry(uncheck2(privDefinitionMapper(mapping)))) .collect(Collectors.toList()); } else if (json.getValueType() == JsonValue.ValueType.OBJECT) { return JavaxJson.mapObjectValues(json.asJsonObject(), uncheck2(privDefinitionMapper(mapping)), true); } else { return Collections.emptyList(); } } }
JsonCnd { @SuppressWarnings("WeakerAccess") public static List<PrivilegeDefinition> getPrivilegesFromJson(final @NotNull JsonValue json, final @NotNull NamespaceMapping mapping) { if (json.getValueType() == JsonValue.ValueType.ARRAY) { return JavaxJson.mapArrayOfStrings(json.asJsonArray(), zipKeysWithValueFunc(constantly1(() -> JsonValue.EMPTY_JSON_OBJECT)), true) .stream() .map(mapEntry(uncheck2(privDefinitionMapper(mapping)))) .collect(Collectors.toList()); } else if (json.getValueType() == JsonValue.ValueType.OBJECT) { return JavaxJson.mapObjectValues(json.asJsonObject(), uncheck2(privDefinitionMapper(mapping)), true); } else { return Collections.emptyList(); } } private  JsonCnd(); }
JsonCnd { @SuppressWarnings("WeakerAccess") public static List<PrivilegeDefinition> getPrivilegesFromJson(final @NotNull JsonValue json, final @NotNull NamespaceMapping mapping) { if (json.getValueType() == JsonValue.ValueType.ARRAY) { return JavaxJson.mapArrayOfStrings(json.asJsonArray(), zipKeysWithValueFunc(constantly1(() -> JsonValue.EMPTY_JSON_OBJECT)), true) .stream() .map(mapEntry(uncheck2(privDefinitionMapper(mapping)))) .collect(Collectors.toList()); } else if (json.getValueType() == JsonValue.ValueType.OBJECT) { return JavaxJson.mapObjectValues(json.asJsonObject(), uncheck2(privDefinitionMapper(mapping)), true); } else { return Collections.emptyList(); } } 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 { @SuppressWarnings("WeakerAccess") public static List<PrivilegeDefinition> getPrivilegesFromJson(final @NotNull JsonValue json, final @NotNull NamespaceMapping mapping) { if (json.getValueType() == JsonValue.ValueType.ARRAY) { return JavaxJson.mapArrayOfStrings(json.asJsonArray(), zipKeysWithValueFunc(constantly1(() -> JsonValue.EMPTY_JSON_OBJECT)), true) .stream() .map(mapEntry(uncheck2(privDefinitionMapper(mapping)))) .collect(Collectors.toList()); } else if (json.getValueType() == JsonValue.ValueType.OBJECT) { return JavaxJson.mapObjectValues(json.asJsonObject(), uncheck2(privDefinitionMapper(mapping)), true); } else { return Collections.emptyList(); } } 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; }