Search in sources :

Example 1 with SimplePropertyDefinition

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());
}
Also used : ComponentDetailList(org.talend.sdk.component.server.front.model.ComponentDetailList) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) Test(org.junit.jupiter.api.Test)

Example 2 with SimplePropertyDefinition

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());
}
Also used : SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) ParameterModelService(org.talend.sdk.component.runtime.manager.reflect.ParameterModelService) Test(org.junit.jupiter.api.Test)

Example 3 with SimplePropertyDefinition

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());
}
Also used : ParameterMeta(org.talend.sdk.component.runtime.manager.ParameterMeta) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) Test(org.junit.jupiter.api.Test)

Example 4 with SimplePropertyDefinition

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));
    });
}
Also used : ConfigTypeNode(org.talend.sdk.component.server.front.model.ConfigTypeNode) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) Config(org.talend.sdk.component.design.extension.repository.Config)

Example 5 with SimplePropertyDefinition

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);
    });
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) HashMap(java.util.HashMap)

Aggregations

SimplePropertyDefinition (org.talend.sdk.component.server.front.model.SimplePropertyDefinition)12 CompletableFuture (java.util.concurrent.CompletableFuture)7 Collection (java.util.Collection)6 PropertyContext (org.talend.sdk.component.form.internal.converter.PropertyContext)6 CompletionStage (java.util.concurrent.CompletionStage)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 UiSchema (org.talend.sdk.component.form.model.uischema.UiSchema)4 ActionReference (org.talend.sdk.component.server.front.model.ActionReference)4 Optional.ofNullable (java.util.Optional.ofNullable)3 Collectors.toList (java.util.stream.Collectors.toList)3 Collectors.toSet (java.util.stream.Collectors.toSet)3 Jsonb (javax.json.bind.Jsonb)3 AllArgsConstructor (lombok.AllArgsConstructor)3 Test (org.junit.jupiter.api.Test)3 PropertyConverter (org.talend.sdk.component.form.internal.converter.PropertyConverter)3 UiSchemaConverter (org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter)3 JsonSchema (org.talend.sdk.component.form.model.jsonschema.JsonSchema)3 List (java.util.List)2