Search in sources :

Example 1 with DataListWidgetConverter

use of org.talend.sdk.component.form.internal.converter.impl.widget.DataListWidgetConverter in project component-runtime by Talend.

the class UiSchemaConverter method convert.

@Override
public CompletionStage<PropertyContext> convert(final CompletionStage<PropertyContext> cs) {
    return cs.thenCompose(context -> {
        final String type = context.getProperty().getType().toLowerCase(Locale.ROOT);
        switch(type) {
            case "object":
                final Map<String, String> gridLayouts = context.getProperty().getMetadata().entrySet().stream().filter(e -> e.getKey().startsWith("ui::gridlayout::") && e.getKey().endsWith("::value")).collect(toMap(e -> e.getKey().substring("ui::gridlayout::".length(), e.getKey().length() - "::value".length()), Map.Entry::getValue, (a, b) -> {
                    throw new IllegalArgumentException("Can't merge " + a + " and " + b);
                }, () -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER)));
                if (!gridLayouts.isEmpty()) {
                    return new GridLayoutWidgetConverter(schemas, properties, actions, client, family, gridLayoutFilter != null && gridLayouts.containsKey(gridLayoutFilter) ? singletonMap(gridLayoutFilter, gridLayouts.get(gridLayoutFilter)) : gridLayouts).convert(CompletableFuture.completedFuture(context));
                }
                return new FieldSetWidgetConverter(schemas, properties, actions, client, family).convert(CompletableFuture.completedFuture(context));
            case "boolean":
                includedProperties.add(context.getProperty());
                return new ToggleWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
            case "enum":
                includedProperties.add(context.getProperty());
                return new DataListWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
            case "number":
                includedProperties.add(context.getProperty());
                return new NumberWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
            case "array":
                includedProperties.add(context.getProperty());
                final String nestedPrefix = context.getProperty().getPath() + "[].";
                final int from = nestedPrefix.length();
                final Collection<SimplePropertyDefinition> nested = properties.stream().filter(prop -> prop.getPath().startsWith(nestedPrefix) && prop.getPath().indexOf('.', from) < 0).collect(toList());
                if (!nested.isEmpty()) {
                    return new ObjectArrayWidgetConverter(schemas, properties, actions, nested, family, client, gridLayoutFilter).convert(CompletableFuture.completedFuture(context));
                }
                return new MultiSelectTagWidgetConverter(schemas, properties, actions, client, family).convert(CompletableFuture.completedFuture(context));
            case "string":
            default:
                if (context.getProperty().getPath().endsWith("[]")) {
                    return CompletableFuture.completedFuture(context);
                }
                includedProperties.add(context.getProperty());
                if ("true".equalsIgnoreCase(context.getProperty().getMetadata().get("ui::credential"))) {
                    return new CredentialWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
                } else if (context.getProperty().getMetadata().containsKey("ui::code::value")) {
                    return new CodeWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
                } else if (context.getProperty().getMetadata() != null && context.getProperty().getMetadata().containsKey("action::dynamic_values")) {
                    return new MultiSelectTagWidgetConverter(schemas, properties, actions, client, family).convert(CompletableFuture.completedFuture(context));
                } else if (context.getProperty().getMetadata().containsKey("ui::textarea") && Boolean.valueOf(context.getProperty().getMetadata().get("ui::textarea"))) {
                    return new TextAreaWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
                }
                return new TextWidgetConverter(schemas, properties, actions).convert(CompletableFuture.completedFuture(context));
        }
    });
}
Also used : ObjectArrayWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.ObjectArrayWidgetConverter) CredentialWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.CredentialWidgetConverter) CompletableFuture(java.util.concurrent.CompletableFuture) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) PropertyConverter(org.talend.sdk.component.form.internal.converter.PropertyConverter) TextWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.TextWidgetConverter) FieldSetWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.FieldSetWidgetConverter) MultiSelectTagWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.MultiSelectTagWidgetConverter) DataListWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.DataListWidgetConverter) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) Collectors.toMap(java.util.stream.Collectors.toMap) Locale(java.util.Locale) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) NumberWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.NumberWidgetConverter) Collection(java.util.Collection) TextAreaWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.TextAreaWidgetConverter) GridLayoutWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.GridLayoutWidgetConverter) Client(org.talend.sdk.component.form.api.Client) ToggleWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.ToggleWidgetConverter) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Collectors.toList(java.util.stream.Collectors.toList) CompletionStage(java.util.concurrent.CompletionStage) TreeMap(java.util.TreeMap) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) AllArgsConstructor(lombok.AllArgsConstructor) CodeWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.CodeWidgetConverter) CredentialWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.CredentialWidgetConverter) TextAreaWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.TextAreaWidgetConverter) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) CodeWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.CodeWidgetConverter) NumberWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.NumberWidgetConverter) TreeMap(java.util.TreeMap) DataListWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.DataListWidgetConverter) MultiSelectTagWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.MultiSelectTagWidgetConverter) TextWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.TextWidgetConverter) ToggleWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.ToggleWidgetConverter) ObjectArrayWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.ObjectArrayWidgetConverter) FieldSetWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.FieldSetWidgetConverter) GridLayoutWidgetConverter(org.talend.sdk.component.form.internal.converter.impl.widget.GridLayoutWidgetConverter) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) TreeMap(java.util.TreeMap)

Aggregations

Collection (java.util.Collection)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Client (org.talend.sdk.component.form.api.Client)1 PropertyContext (org.talend.sdk.component.form.internal.converter.PropertyContext)1 PropertyConverter (org.talend.sdk.component.form.internal.converter.PropertyConverter)1 CodeWidgetConverter (org.talend.sdk.component.form.internal.converter.impl.widget.CodeWidgetConverter)1 CredentialWidgetConverter (org.talend.sdk.component.form.internal.converter.impl.widget.CredentialWidgetConverter)1 DataListWidgetConverter (org.talend.sdk.component.form.internal.converter.impl.widget.DataListWidgetConverter)1 FieldSetWidgetConverter (org.talend.sdk.component.form.internal.converter.impl.widget.FieldSetWidgetConverter)1 GridLayoutWidgetConverter (org.talend.sdk.component.form.internal.converter.impl.widget.GridLayoutWidgetConverter)1 MultiSelectTagWidgetConverter (org.talend.sdk.component.form.internal.converter.impl.widget.MultiSelectTagWidgetConverter)1 NumberWidgetConverter (org.talend.sdk.component.form.internal.converter.impl.widget.NumberWidgetConverter)1