@Test void configuration() throws Exception { final ConfigTypeNodes load = load("config.json", ConfigTypeNodes.class); final String family = load .getNodes() .entrySet() .stream() .filter(e -> e.getValue().getParentId() == null) .map(e -> e.getValue().getId()) .findFirst() .orElseThrow(() -> new IllegalArgumentException("No family")); final Ui payload = service .convert(family, "en", load .getNodes() .values() .stream() .filter(e -> "U2VydmljZU5vdyNkYXRhc3RvcmUjYmFzaWNBdXRo".equals(e.getId())) .findFirst() .orElseThrow(() -> new IllegalArgumentException( "No U2VydmljZU5vdyNkYXRhc3RvcmUjYmFzaWNBdXRo config")), null) .toCompletableFuture() .get(); assertTrue(payload.getJsonSchema().getProperties().containsKey("dataStore"), "dataStore"); assertEquals(3, payload.getUiSchema().iterator().next().getItems().size()); final Set<String> uiSchemaKeys = flattenUiSchema(payload.getUiSchema().stream()) .map(UiSchema::getKey) .filter(it -> Stream .of("dataStore", "button_healthcheck_dataStore") .noneMatch(ignored -> ignored.equals(it))) .filter(Objects::nonNull) .collect(toSet()); final Set<String> jsonSchemaKeys = flattenJsonSchema(Stream.of(new Pair("", payload.getJsonSchema()))) .map(it -> it.prefix) .filter(it -> Stream.of("", "dataStore").noneMatch(ignored -> ignored.equals(it))) .collect(toSet()); uiSchemaKeys.remove("dataStore_1"); assertEquals(uiSchemaKeys, jsonSchemaKeys); }
public CompletionStage<Ui> convert(final String family, final String lang, final ConfigTypeNode node, final T context) { final Collection<String> rootProperties = node.getProperties().stream().map(SimplePropertyDefinition::getPath).collect(toSet()); rootProperties .removeIf(path -> node.getProperties().stream().anyMatch(p -> path.startsWith(p.getPath() + '.'))); if (rootProperties.isEmpty()) { log.warn("No root properties for configuration node {} (family={})", node.getId(), family); } final Collection<SimplePropertyDefinition> props; final Predicate<SimplePropertyDefinition> isRootProperty; if (rootProperties.size() == 1 && rootProperties.iterator().next().startsWith("configuration.")) { final String root = rootProperties.iterator().next(); final SimplePropertyDefinition def = node.getProperties().stream().filter(prop -> prop.getPath().equals(root)).findFirst().get(); props = node .getProperties() .stream() .map(prop -> new SimplePropertyDefinition(def.getName() + prop.getPath().substring(root.length()), prop.getName(), prop.getDisplayName(), prop.getType(), prop.getDefaultValue(), prop.getValidation(), prop.getMetadata(), prop.getPlaceholder(), prop.getProposalDisplayNames())) .collect(toList()); isRootProperty = p -> p.getPath().equals(def.getName()); } else { props = node.getProperties(); isRootProperty = p -> rootProperties.contains(p.getPath()); } return convert(node::getDisplayName, () -> family, () -> props, node::getActions, isRootProperty, context, lang); }
UiSpecService implements AutoCloseable { public CompletionStage<Ui> convert(final String family, final String lang, final ConfigTypeNode node, final T context) { final Collection<String> rootProperties = node.getProperties().stream().map(SimplePropertyDefinition::getPath).collect(toSet()); rootProperties .removeIf(path -> node.getProperties().stream().anyMatch(p -> path.startsWith(p.getPath() + '.'))); if (rootProperties.isEmpty()) { log.warn("No root properties for configuration node {} (family={})", node.getId(), family); } final Collection<SimplePropertyDefinition> props; final Predicate<SimplePropertyDefinition> isRootProperty; if (rootProperties.size() == 1 && rootProperties.iterator().next().startsWith("configuration.")) { final String root = rootProperties.iterator().next(); final SimplePropertyDefinition def = node.getProperties().stream().filter(prop -> prop.getPath().equals(root)).findFirst().get(); props = node .getProperties() .stream() .map(prop -> new SimplePropertyDefinition(def.getName() + prop.getPath().substring(root.length()), prop.getName(), prop.getDisplayName(), prop.getType(), prop.getDefaultValue(), prop.getValidation(), prop.getMetadata(), prop.getPlaceholder(), prop.getProposalDisplayNames())) .collect(toList()); isRootProperty = p -> p.getPath().equals(def.getName()); } else { props = node.getProperties(); isRootProperty = p -> rootProperties.contains(p.getPath()); } return convert(node::getDisplayName, () -> family, () -> props, node::getActions, isRootProperty, context, lang); } }
UiSpecService implements AutoCloseable { public CompletionStage<Ui> convert(final String family, final String lang, final ConfigTypeNode node, final T context) { final Collection<String> rootProperties = node.getProperties().stream().map(SimplePropertyDefinition::getPath).collect(toSet()); rootProperties .removeIf(path -> node.getProperties().stream().anyMatch(p -> path.startsWith(p.getPath() + '.'))); if (rootProperties.isEmpty()) { log.warn("No root properties for configuration node {} (family={})", node.getId(), family); } final Collection<SimplePropertyDefinition> props; final Predicate<SimplePropertyDefinition> isRootProperty; if (rootProperties.size() == 1 && rootProperties.iterator().next().startsWith("configuration.")) { final String root = rootProperties.iterator().next(); final SimplePropertyDefinition def = node.getProperties().stream().filter(prop -> prop.getPath().equals(root)).findFirst().get(); props = node .getProperties() .stream() .map(prop -> new SimplePropertyDefinition(def.getName() + prop.getPath().substring(root.length()), prop.getName(), prop.getDisplayName(), prop.getType(), prop.getDefaultValue(), prop.getValidation(), prop.getMetadata(), prop.getPlaceholder(), prop.getProposalDisplayNames())) .collect(toList()); isRootProperty = p -> p.getPath().equals(def.getName()); } else { props = node.getProperties(); isRootProperty = p -> rootProperties.contains(p.getPath()); } return convert(node::getDisplayName, () -> family, () -> props, node::getActions, isRootProperty, context, lang); } UiSpecService(final Client client);  UiSpecService(final Client client, final Jsonb jsonb); }
UiSpecService implements AutoCloseable { public CompletionStage<Ui> convert(final String family, final String lang, final ConfigTypeNode node, final T context) { final Collection<String> rootProperties = node.getProperties().stream().map(SimplePropertyDefinition::getPath).collect(toSet()); rootProperties .removeIf(path -> node.getProperties().stream().anyMatch(p -> path.startsWith(p.getPath() + '.'))); if (rootProperties.isEmpty()) { log.warn("No root properties for configuration node {} (family={})", node.getId(), family); } final Collection<SimplePropertyDefinition> props; final Predicate<SimplePropertyDefinition> isRootProperty; if (rootProperties.size() == 1 && rootProperties.iterator().next().startsWith("configuration.")) { final String root = rootProperties.iterator().next(); final SimplePropertyDefinition def = node.getProperties().stream().filter(prop -> prop.getPath().equals(root)).findFirst().get(); props = node .getProperties() .stream() .map(prop -> new SimplePropertyDefinition(def.getName() + prop.getPath().substring(root.length()), prop.getName(), prop.getDisplayName(), prop.getType(), prop.getDefaultValue(), prop.getValidation(), prop.getMetadata(), prop.getPlaceholder(), prop.getProposalDisplayNames())) .collect(toList()); isRootProperty = p -> p.getPath().equals(def.getName()); } else { props = node.getProperties(); isRootProperty = p -> rootProperties.contains(p.getPath()); } return convert(node::getDisplayName, () -> family, () -> props, node::getActions, isRootProperty, context, lang); } UiSpecService(final Client client);  UiSpecService(final Client client, final Jsonb jsonb); UiSpecService<T> withConverter(final CustomPropertyConverter converter); CompletionStage<Ui> convert(final String family, final String lang, final ConfigTypeNode node,
            final T context); CompletionStage<Ui> convert(final ComponentDetail detail, final String lang, final T context); @Override void close(); }
UiSpecService implements AutoCloseable { public CompletionStage<Ui> convert(final String family, final String lang, final ConfigTypeNode node, final T context) { final Collection<String> rootProperties = node.getProperties().stream().map(SimplePropertyDefinition::getPath).collect(toSet()); rootProperties .removeIf(path -> node.getProperties().stream().anyMatch(p -> path.startsWith(p.getPath() + '.'))); if (rootProperties.isEmpty()) { log.warn("No root properties for configuration node {} (family={})", node.getId(), family); } final Collection<SimplePropertyDefinition> props; final Predicate<SimplePropertyDefinition> isRootProperty; if (rootProperties.size() == 1 && rootProperties.iterator().next().startsWith("configuration.")) { final String root = rootProperties.iterator().next(); final SimplePropertyDefinition def = node.getProperties().stream().filter(prop -> prop.getPath().equals(root)).findFirst().get(); props = node .getProperties() .stream() .map(prop -> new SimplePropertyDefinition(def.getName() + prop.getPath().substring(root.length()), prop.getName(), prop.getDisplayName(), prop.getType(), prop.getDefaultValue(), prop.getValidation(), prop.getMetadata(), prop.getPlaceholder(), prop.getProposalDisplayNames())) .collect(toList()); isRootProperty = p -> p.getPath().equals(def.getName()); } else { props = node.getProperties(); isRootProperty = p -> rootProperties.contains(p.getPath()); } return convert(node::getDisplayName, () -> family, () -> props, node::getActions, isRootProperty, context, lang); } UiSpecService(final Client client);  UiSpecService(final Client client, final Jsonb jsonb); UiSpecService<T> withConverter(final CustomPropertyConverter converter); CompletionStage<Ui> convert(final String family, final String lang, final ConfigTypeNode node,
            final T context); CompletionStage<Ui> convert(final ComponentDetail detail, final String lang, final T context); @Override void close();  }