@Test void jsonSchema() throws Exception { final Ui payload = service.convert(load("jdbc.json"), "en", null).toCompletableFuture().get(); final JsonSchema jsonSchema = payload.getJsonSchema(); assertNotNull(jsonSchema); assertEquals("JDBC Input", jsonSchema.getTitle()); assertEquals("object", jsonSchema.getType()); assertEquals(1, jsonSchema.getProperties().size()); assertProperty(jsonSchema.getProperties().get("configuration"), "object", "Configuration", p -> { final Map<String, JsonSchema> nestedProperties = p.getProperties(); assertEquals(2, nestedProperties.size()); assertTrue(TreeMap.class.isInstance(nestedProperties)); assertEquals(asList("connection", "query"), new ArrayList<>(nestedProperties.keySet())); assertProperty(nestedProperties.get("query"), "object", "query", q -> { final Map<String, JsonSchema> queryNestedProperties = q.getProperties(); assertEquals(2, queryNestedProperties.size()); assertProperty(queryNestedProperties.get("query"), "string", "query", query -> assertNull(query.getProperties())); assertProperty(queryNestedProperties.get("timeout"), "number", "timeout", timeout -> assertNull(timeout.getProperties())); }); assertProperty(nestedProperties.get("connection"), "object", "JDBC Connection", q -> { final Map<String, JsonSchema> queryNestedProperties = q.getProperties(); assertEquals(4, queryNestedProperties.size()); assertProperty(queryNestedProperties.get("password"), "string", "password", pwd -> assertNull(pwd.getProperties())); assertProperty(queryNestedProperties.get("driver"), "string", "driver", driver -> assertNull(driver.getProperties())); assertProperty(queryNestedProperties.get("url"), "string", "url", url -> assertNull(url.getProperties())); assertProperty(queryNestedProperties.get("username"), "string", "username", username -> { assertNull(username.getProperties()); assertEquals("sa", username.getDefaultValue()); }); }); }); }
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();  }