@Test public void testGetPrivilegesFromJson() { List<PrivilegeDefinition> oneDef = JsonCnd.getPrivilegesFromJson(key("nt:canDo", obj() .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, true) .key(JsonCnd.PRIVILEGE_KEY_CONTAINS, arr("jcr:read", "jcr:write"))).get(), JsonCnd.BUILTIN_MAPPINGS); assertEquals("size is ", 1, oneDef.size()); assertEquals("name is", "canDo", oneDef.get(0).getName().getLocalName()); assertEquals("uri is", Name.NS_NT_URI, oneDef.get(0).getName().getNamespaceURI()); List<PrivilegeDefinition> oneName = JsonCnd.getPrivilegesFromJson(arr("nt:canDo").get(), JsonCnd.BUILTIN_MAPPINGS); assertEquals("size is ", 1, oneName.size()); assertEquals("name is", "canDo", oneName.get(0).getName().getLocalName()); assertEquals("uri is", Name.NS_NT_URI, oneName.get(0).getName().getNamespaceURI()); List<PrivilegeDefinition> jsonNull = JsonCnd.getPrivilegesFromJson(wrap(null), JsonCnd.BUILTIN_MAPPINGS); assertEquals("size is ", 0, jsonNull.size()); 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:wontDo", null) .key("jcr:none", obj() .key(JsonCnd.PRIVILEGE_KEY_CONTAINS, arr())) .key("jcr:rw", obj() .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, false) .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 Map<String, PrivilegeDefinition> defMap = defs.stream() .collect(Collectors.toMap(compose1(PrivilegeDefinition::getName, uncheck1(resolver::getJCRName)), def -> def)); final PrivilegeDefinition canDo = defMap.get("jcr:canDo"); assertNotNull("canDo not null", canDo); assertFalse("canDo not abstract", canDo.isAbstract()); assertEquals("canDo contains nothing", Collections.emptySet(), canDo.getDeclaredAggregateNames()); final PrivilegeDefinition willDo = defMap.get("jcr:willDo"); assertNotNull("willDo not null", willDo); assertFalse("willDo not abstract", willDo.isAbstract()); assertEquals("willDo contains nothing", Collections.emptySet(), willDo.getDeclaredAggregateNames()); final PrivilegeDefinition wouldDoBut = defMap.get("jcr:wouldDoBut"); assertNotNull("wouldDoBut not null", wouldDoBut); assertTrue("wouldDoBut is abstract", wouldDoBut.isAbstract()); assertEquals("wouldDoBut contains nothing", Collections.emptySet(), wouldDoBut.getDeclaredAggregateNames()); final PrivilegeDefinition wontDo = defMap.get("jcr:wontDo"); assertNull("wontDo is null", wontDo); final PrivilegeDefinition none = defMap.get("jcr:none"); assertNotNull("none not null", none); assertFalse("none not abstract", none.isAbstract()); assertEquals("none contains nothing", Collections.emptySet(), none.getDeclaredAggregateNames()); final PrivilegeDefinition rw = defMap.get("jcr:rw"); assertNotNull("rw not null", rw); assertFalse("rw not abstract", rw.isAbstract()); assertEquals("rw contains nothing", Stream.of("jcr:read", "jcr:write", "jcr:addChildNodes") .map(uncheck1(resolver::getQName)).collect(Collectors.toSet()), rw.getDeclaredAggregateNames()); final PrivilegeDefinition mightRw = defMap.get("jcr:mightRw"); assertNotNull("mightRw not null", mightRw); assertTrue("mightRw is abstract", mightRw.isAbstract()); assertEquals("mightRw contains nothing", Stream.of("jcr:read", "jcr:write", "jcr:removeNode") .map(uncheck1(resolver::getQName)).collect(Collectors.toSet()), mightRw.getDeclaredAggregateNames()); }
@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; }