use of org.talend.sdk.component.server.front.model.SimplePropertyDefinition in project component-runtime by Talend.
the class ComponentResourceTest method enumDisplayName.
@Test
void enumDisplayName() {
final ComponentDetailList details = base.path("component/details").queryParam("identifiers", client.getComponentId("jdbc", "output")).request(APPLICATION_JSON_TYPE).get(ComponentDetailList.class);
assertEquals(1, details.getDetails().size());
final SimplePropertyDefinition next = details.getDetails().iterator().next().getProperties().stream().filter(p -> p.getPath().equals("configuration.type")).findFirst().get();
assertNotNull(next.getProposalDisplayNames());
assertEquals(new HashMap<String, String>() {
{
// default
put("FAST", "FAST");
// configured
put("PRECISE", "Furious");
}
}, next.getProposalDisplayNames());
}
use of org.talend.sdk.component.server.front.model.SimplePropertyDefinition in project component-runtime by Talend.
the class PropertiesServiceTest method booleanDefault.
@Test
void booleanDefault() throws NoSuchMethodException {
final List<SimplePropertyDefinition> props = propertiesService.buildProperties(new ParameterModelService().buildParameterMetas(getClass().getDeclaredMethod("boolWrapper", BoolBool.class), null), Thread.currentThread().getContextClassLoader(), Locale.ROOT, null).collect(toList());
assertEquals("true", props.stream().filter(p -> p.getName().equals("val")).findFirst().get().getDefaultValue());
}
use of org.talend.sdk.component.server.front.model.SimplePropertyDefinition in project component-runtime by Talend.
the class PropertiesServiceTest method buildProperties.
@Test
void buildProperties() {
final String[] i18nPackages = { Config.class.getPackage().getName() };
final ParameterMeta host = new ParameterMeta(null, Config.class, ParameterMeta.Type.STRING, "configuration.host", "host", i18nPackages, emptyList(), null, emptyMap());
final ParameterMeta port = new ParameterMeta(null, Config.class, ParameterMeta.Type.NUMBER, "configuration.port", "port", i18nPackages, emptyList(), null, emptyMap());
final ParameterMeta username = new ParameterMeta(null, Config.class, ParameterMeta.Type.STRING, "configuration.username", "username", i18nPackages, emptyList(), null, emptyMap());
final ParameterMeta password = new ParameterMeta(null, Config.class, ParameterMeta.Type.STRING, "configuration.password", "password", i18nPackages, emptyList(), null, emptyMap());
final ParameterMeta config = new ParameterMeta(null, Config.class, ParameterMeta.Type.OBJECT, "configuration", "configuration", i18nPackages, asList(host, port, username, password), null, emptyMap());
final List<SimplePropertyDefinition> props = propertiesService.buildProperties(singletonList(config), getClass().getClassLoader(), Locale.getDefault(), null).collect(toList());
assertEquals(5, props.size());
assertEquals("Configuration", props.get(0).getDisplayName());
assertEquals("Server Host Name", props.get(1).getDisplayName());
assertEquals("Enter the server host name...", props.get(1).getPlaceholder());
assertEquals("Password", props.get(2).getDisplayName());
assertEquals("Server Port", props.get(3).getDisplayName());
assertEquals("Enter the server port...", props.get(3).getPlaceholder());
assertEquals("User Name", props.get(4).getDisplayName());
}
use of org.talend.sdk.component.server.front.model.SimplePropertyDefinition in project component-runtime by Talend.
the class ConfigurationTypeResource method createNode.
private Stream<ConfigTypeNode> createNode(final String parentId, final String family, final Stream<Config> configs, final FamilyBundle resourcesBundle, final Container container, final Locale locale, final Predicate<String> idFilter, final boolean lightPayload) {
final ClassLoader loader = container.getLoader();
if (configs == null) {
return Stream.empty();
}
return configs.flatMap(c -> {
final Stream<ConfigTypeNode> configNode;
if (idFilter.test(c.getId())) {
final ConfigTypeNode node = new ConfigTypeNode();
node.setId(c.getId());
node.setVersion(c.getVersion());
node.setConfigurationType(c.getKey().getConfigType());
node.setName(c.getKey().getConfigName());
node.setParentId(parentId);
node.setDisplayName(resourcesBundle.configurationDisplayName(c.getKey().getConfigType(), c.getKey().getConfigName()).orElse(c.getKey().getConfigName()));
if (!lightPayload) {
node.setActions(actionsService.findActions(family, container, locale, c));
// force configuration as root prefix
final int prefixLen = c.getMeta().getPath().length();
node.setProperties(propertiesService.buildProperties(singleton(c.getMeta()), loader, locale, null).map(p -> new SimplePropertyDefinition("configuration" + p.getPath().substring(prefixLen), p.getName(), p.getDisplayName(), p.getType(), p.getDefaultValue(), p.getValidation(), p.getMetadata(), p.getPlaceholder(), p.getProposalDisplayNames())).collect(toList()));
}
node.setEdges(c.getChildConfigs().stream().map(Config::getId).collect(toSet()));
configNode = Stream.of(node);
} else {
configNode = Stream.empty();
}
return Stream.concat(configNode, createNode(c.getId(), family, c.getChildConfigs().stream(), resourcesBundle, container, locale, idFilter, lightPayload));
});
}
use of org.talend.sdk.component.server.front.model.SimplePropertyDefinition in project component-runtime by Talend.
the class PropertiesConverter method convert.
@Override
public CompletionStage<PropertyContext> convert(final CompletionStage<PropertyContext> cs) {
return cs.thenCompose(context -> {
final SimplePropertyDefinition property = context.getProperty();
if ("object".equalsIgnoreCase(property.getType())) {
final Map<String, Object> childDefaults = new HashMap<>();
defaults.put(property.getName(), childDefaults);
final PropertiesConverter propertiesConverter = new PropertiesConverter(jsonb, childDefaults, properties);
return CompletableFuture.allOf(properties.stream().filter(context::isDirectChild).map(PropertyContext::new).map(CompletableFuture::completedFuture).map(propertiesConverter::convert).toArray(CompletableFuture[]::new)).thenApply(done -> context);
}
ofNullable(property.getMetadata().getOrDefault("ui::defaultvalue::value", property.getDefaultValue())).ifPresent(value -> {
if ("number".equalsIgnoreCase(property.getType())) {
defaults.put(property.getName(), Double.parseDouble(value));
} else if ("boolean".equalsIgnoreCase(property.getType())) {
defaults.put(property.getName(), Boolean.parseBoolean(value));
} else if ("array".equalsIgnoreCase(property.getType())) {
defaults.put(property.getName(), jsonb.fromJson(value, Object[].class));
} else if ("object".equalsIgnoreCase(property.getType())) {
defaults.put(property.getName(), jsonb.fromJson(value, Map.class));
} else {
defaults.put(property.getName(), value);
}
});
return CompletableFuture.completedFuture(context);
});
}
Aggregations