@Test void uiSchema() throws Exception { final Ui payload = service.convert(load("jdbc.json"), "en", null).toCompletableFuture().get(); final Collection<UiSchema> uiSchema = payload.getUiSchema(); assertNotNull(uiSchema); assertEquals(1, uiSchema.size()); assertUiSchema(uiSchema.iterator().next(), "fieldset", "Configuration", null, 2, schema -> { final List<UiSchema> items = new ArrayList<>(schema.getItems()); items.sort(Comparator.comparing(UiSchema::getTitle)); final Iterator<UiSchema> it = items.iterator(); assertUiSchema(it.next(), "fieldset", "JDBC Connection", null, 5, connection -> { final List<UiSchema> connectionItems = new ArrayList<>(connection.getItems()); connectionItems.sort(Comparator.comparing(UiSchema::getTitle)); final Iterator<UiSchema> connectionIt = connectionItems.iterator(); assertUiSchema(connectionIt.next(), "button", "Validate Connection", "configuration.connection_1", 0, validateDataStore -> { assertEquals(1, validateDataStore.getTriggers().size()); final UiSchema.Trigger trigger = validateDataStore.getTriggers().iterator().next(); assertEquals(1, trigger.getParameters().size()); assertEquals(singleton("configuration.connection"), trigger.getParameters().stream().map(UiSchema.Parameter::getPath).collect(toSet())); assertEquals(singleton("datastore"), trigger.getParameters().stream().map(UiSchema.Parameter::getKey).collect(toSet())); }); assertUiSchema(connectionIt.next(), "datalist", "driver", "configuration.connection.driver", 0, driver -> { assertTrue(driver.getRestricted()); assertNotNull(driver.getTriggers()); assertEquals(1, driver.getTriggers().size()); final Collection<UiSchema.NameValue> titleMap = driver.getTitleMap(); assertEquals(1, titleMap.size()); final UiSchema.NameValue firstTitleMap = titleMap.iterator().next(); assertEquals("some.driver.Jdbc", firstTitleMap.getValue()); assertEquals("Jdbc driver", firstTitleMap.getName()); final UiSchema.Trigger trigger = driver.getTriggers().iterator().next(); assertEquals("driver", trigger.getAction()); assertEquals("jdbc", trigger.getFamily()); assertEquals("validation", trigger.getType()); assertEquals(1, trigger.getParameters().size()); final UiSchema.Parameter parameter = trigger.getParameters().iterator().next(); assertEquals("value", parameter.getKey()); assertEquals("configuration.connection.driver", parameter.getPath()); }); assertUiSchema(connectionIt.next(), "text", "password", "configuration.connection.password", 0, pwd -> { assertEquals("password", pwd.getType()); }); assertUiSchema(connectionIt.next(), "text", "url", "configuration.connection.url", 0, url -> { }); assertUiSchema(connectionIt.next(), "text", "username", "configuration.connection.username", 0, username -> { }); assertFalse(connectionIt.hasNext()); }); assertUiSchema(it.next(), "fieldset", "query", null, 2, query -> { final List<UiSchema> queryItems = new ArrayList<>(query.getItems()); queryItems.sort(Comparator.comparing(UiSchema::getKey)); final Iterator<UiSchema> queryIt = queryItems.iterator(); assertUiSchema(queryIt.next(), "text", "query", "configuration.query.query", 0, q -> { }); assertUiSchema(queryIt.next(), "text", "timeout", "configuration.query.timeout", 0, timeout -> { }); assertFalse(queryIt.hasNext()); }); assertFalse(it.hasNext()); }); }
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();  }