@Test public void testPrivilegesToJson() { List<PrivilegeDefinition> arrDefs = JsonCnd.getPrivilegesFromJson(arr("jcr:read", "jcr:write").get(), getMapping()); assertEquals("arr defs are", arr("jcr:read", "jcr:write").get(), JsonCnd.privilegesToJson(arrDefs, getMapping())); List<PrivilegeDefinition> objDefs = 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_CONTAINS, arr("jcr:read", "jcr:write", "jcr:addChildNodes")) .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, false)) .key("jcr:mightRw", obj() .key(JsonCnd.PRIVILEGE_KEY_CONTAINS, arr("jcr:read", "jcr:write", "jcr:removeNode")) .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, true)) .get(), getMapping()); JsonObject expectJson = obj() .key("jcr:canDo", obj()) .key("jcr:mightRw", obj() .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, true) .key(JsonCnd.PRIVILEGE_KEY_CONTAINS, arr("jcr:read", "jcr:write", "jcr:removeNode"))) .key("jcr:none", obj()) .key("jcr:rw", obj() .key(JsonCnd.PRIVILEGE_KEY_CONTAINS, arr("jcr:read", "jcr:write", "jcr:addChildNodes"))) .key("jcr:willDo", obj()) .key("jcr:wouldDoBut", obj() .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, true)) .get(); assertEquals("obj defs are", expectJson, JsonCnd.privilegesToJson(objDefs, getMapping())); }
public static JsonValue privilegesToJson(final @NotNull List<PrivilegeDefinition> privDefs, final @NotNull NamespaceMapping mapping) { final NamePathResolver resolver = new DefaultNamePathResolver(mapping); if (privDefs.stream().allMatch(def -> !def.isAbstract() && def.getDeclaredAggregateNames().isEmpty())) { return privDefs.stream() .map(compose1(PrivilegeDefinition::getName, uncheck1(jcrNameOrResidual(resolver)))) .map(JavaxJson::wrap) .sorted(Comparator.comparing(JSON_VALUE_STRING)) .collect(JsonCollectors.toJsonArray()); } return privDefs.stream() .map(def -> toEntry(def, (JsonValue) obj() .key(PRIVILEGE_KEY_ABSTRACT).opt(def.isAbstract(), false) .key(PRIVILEGE_KEY_CONTAINS) .opt(def.getDeclaredAggregateNames().stream() .map(uncheck1(jcrNameOrResidual(resolver))) .collect(Collectors.toList())) .get())) .map(mapKey(compose1(PrivilegeDefinition::getName, uncheck1(jcrNameOrResidual(resolver))))) .sorted(Map.Entry.comparingByKey()) .collect(JsonCollectors.toJsonObject()); }
JsonCnd { public static JsonValue privilegesToJson(final @NotNull List<PrivilegeDefinition> privDefs, final @NotNull NamespaceMapping mapping) { final NamePathResolver resolver = new DefaultNamePathResolver(mapping); if (privDefs.stream().allMatch(def -> !def.isAbstract() && def.getDeclaredAggregateNames().isEmpty())) { return privDefs.stream() .map(compose1(PrivilegeDefinition::getName, uncheck1(jcrNameOrResidual(resolver)))) .map(JavaxJson::wrap) .sorted(Comparator.comparing(JSON_VALUE_STRING)) .collect(JsonCollectors.toJsonArray()); } return privDefs.stream() .map(def -> toEntry(def, (JsonValue) obj() .key(PRIVILEGE_KEY_ABSTRACT).opt(def.isAbstract(), false) .key(PRIVILEGE_KEY_CONTAINS) .opt(def.getDeclaredAggregateNames().stream() .map(uncheck1(jcrNameOrResidual(resolver))) .collect(Collectors.toList())) .get())) .map(mapKey(compose1(PrivilegeDefinition::getName, uncheck1(jcrNameOrResidual(resolver))))) .sorted(Map.Entry.comparingByKey()) .collect(JsonCollectors.toJsonObject()); } }
JsonCnd { public static JsonValue privilegesToJson(final @NotNull List<PrivilegeDefinition> privDefs, final @NotNull NamespaceMapping mapping) { final NamePathResolver resolver = new DefaultNamePathResolver(mapping); if (privDefs.stream().allMatch(def -> !def.isAbstract() && def.getDeclaredAggregateNames().isEmpty())) { return privDefs.stream() .map(compose1(PrivilegeDefinition::getName, uncheck1(jcrNameOrResidual(resolver)))) .map(JavaxJson::wrap) .sorted(Comparator.comparing(JSON_VALUE_STRING)) .collect(JsonCollectors.toJsonArray()); } return privDefs.stream() .map(def -> toEntry(def, (JsonValue) obj() .key(PRIVILEGE_KEY_ABSTRACT).opt(def.isAbstract(), false) .key(PRIVILEGE_KEY_CONTAINS) .opt(def.getDeclaredAggregateNames().stream() .map(uncheck1(jcrNameOrResidual(resolver))) .collect(Collectors.toList())) .get())) .map(mapKey(compose1(PrivilegeDefinition::getName, uncheck1(jcrNameOrResidual(resolver))))) .sorted(Map.Entry.comparingByKey()) .collect(JsonCollectors.toJsonObject()); } private  JsonCnd(); }
JsonCnd { public static JsonValue privilegesToJson(final @NotNull List<PrivilegeDefinition> privDefs, final @NotNull NamespaceMapping mapping) { final NamePathResolver resolver = new DefaultNamePathResolver(mapping); if (privDefs.stream().allMatch(def -> !def.isAbstract() && def.getDeclaredAggregateNames().isEmpty())) { return privDefs.stream() .map(compose1(PrivilegeDefinition::getName, uncheck1(jcrNameOrResidual(resolver)))) .map(JavaxJson::wrap) .sorted(Comparator.comparing(JSON_VALUE_STRING)) .collect(JsonCollectors.toJsonArray()); } return privDefs.stream() .map(def -> toEntry(def, (JsonValue) obj() .key(PRIVILEGE_KEY_ABSTRACT).opt(def.isAbstract(), false) .key(PRIVILEGE_KEY_CONTAINS) .opt(def.getDeclaredAggregateNames().stream() .map(uncheck1(jcrNameOrResidual(resolver))) .collect(Collectors.toList())) .get())) .map(mapKey(compose1(PrivilegeDefinition::getName, uncheck1(jcrNameOrResidual(resolver))))) .sorted(Map.Entry.comparingByKey()) .collect(JsonCollectors.toJsonObject()); } 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 JsonValue privilegesToJson(final @NotNull List<PrivilegeDefinition> privDefs, final @NotNull NamespaceMapping mapping) { final NamePathResolver resolver = new DefaultNamePathResolver(mapping); if (privDefs.stream().allMatch(def -> !def.isAbstract() && def.getDeclaredAggregateNames().isEmpty())) { return privDefs.stream() .map(compose1(PrivilegeDefinition::getName, uncheck1(jcrNameOrResidual(resolver)))) .map(JavaxJson::wrap) .sorted(Comparator.comparing(JSON_VALUE_STRING)) .collect(JsonCollectors.toJsonArray()); } return privDefs.stream() .map(def -> toEntry(def, (JsonValue) obj() .key(PRIVILEGE_KEY_ABSTRACT).opt(def.isAbstract(), false) .key(PRIVILEGE_KEY_CONTAINS) .opt(def.getDeclaredAggregateNames().stream() .map(uncheck1(jcrNameOrResidual(resolver))) .collect(Collectors.toList())) .get())) .map(mapKey(compose1(PrivilegeDefinition::getName, uncheck1(jcrNameOrResidual(resolver))))) .sorted(Map.Entry.comparingByKey()) .collect(JsonCollectors.toJsonObject()); } 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; }