Search in sources :

Example 6 with PropertyContext

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

the class AbstractWidgetConverter method newOrphanSchema.

protected UiSchema newOrphanSchema(final PropertyContext ctx) {
    final UiSchema schema = new UiSchema();
    schema.setTitle(ctx.getProperty().getDisplayName());
    schema.setKey(ctx.getProperty().getPath());
    schema.setRequired(ctx.isRequired());
    schema.setPlaceholder(ctx.getProperty().getPlaceholder());
    if (actions != null) {
        ofNullable(ctx.getProperty().getMetadata().get("action::validation")).flatMap(v -> actions.stream().filter(a -> a.getName().equals(v) && "validation".equals(a.getType())).findFirst()).ifPresent(ref -> schema.setTriggers(singletonList(toTrigger(properties, ctx.getProperty(), ref))));
    }
    schema.setConditions(createConditions(ctx));
    return schema;
}
Also used : Iterator(java.util.Iterator) Optional.ofNullable(java.util.Optional.ofNullable) Collection(java.util.Collection) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) PropertyConverter(org.talend.sdk.component.form.internal.converter.PropertyConverter) Function(java.util.function.Function) Collections.singletonList(java.util.Collections.singletonList) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Stream(java.util.stream.Stream) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) ROOT(java.util.Locale.ROOT) AllArgsConstructor(lombok.AllArgsConstructor) Collectors.toSet(java.util.stream.Collectors.toSet) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema)

Example 7 with PropertyContext

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

the class DataListWidgetConverter method convert.

@Override
public CompletionStage<PropertyContext> convert(final CompletionStage<PropertyContext> cs) {
    return cs.thenApply(context -> {
        final UiSchema schema = newUiSchema(context);
        schema.setWidget("datalist");
        final JsonSchema jsonSchema = new JsonSchema();
        jsonSchema.setType("string");
        schema.setSchema(jsonSchema);
        if (context.getProperty().getValidation().getEnumValues() != null) {
            schema.setTitleMap(context.getProperty().getProposalDisplayNames() != null ? context.getProperty().getProposalDisplayNames().entrySet().stream().map(v -> {
                final UiSchema.NameValue nameValue = new UiSchema.NameValue();
                nameValue.setName(v.getKey());
                nameValue.setValue(v.getValue());
                return nameValue;
            }).collect(toList()) : context.getProperty().getValidation().getEnumValues().stream().sorted().map(v -> {
                final UiSchema.NameValue nameValue = new UiSchema.NameValue();
                nameValue.setName(v);
                nameValue.setValue(v);
                return nameValue;
            }).collect(toList()));
            jsonSchema.setEnumValues(context.getProperty().getValidation().getEnumValues());
        } else {
            schema.setTitleMap(emptyList());
            jsonSchema.setEnumValues(emptyList());
        }
        return context;
    });
}
Also used : UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Collectors.toList(java.util.stream.Collectors.toList) CompletionStage(java.util.concurrent.CompletionStage) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema)

Example 8 with PropertyContext

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

the class GridLayoutWidgetConverter method createLayout.

private CompletionStage<UiSchema> createLayout(final PropertyContext root, final String layout, final String layoutFilter) {
    final UiSchema uiSchema = newOrphanSchema(root);
    uiSchema.setItems(new ArrayList<>());
    final Collection<SimplePropertyDefinition> visitedProperties = new ArrayList<>();
    final Map<String, SimplePropertyDefinition> childProperties = properties.stream().filter(root::isDirectChild).collect(toMap(SimplePropertyDefinition::getName, identity()));
    return CompletableFuture.allOf(Stream.of(layout.split("\\|")).map(line -> line.split(",")).map(line -> {
        if (line.length == 1 && childProperties.containsKey(line[0])) {
            return new UiSchemaConverter(layoutFilter, family, uiSchema.getItems(), visitedProperties, client, properties, actions).convert(completedFuture(new PropertyContext(childProperties.get(line[0])))).thenApply(r -> uiSchema);
        } else if (line.length > 1) {
            final UiSchema schema = new UiSchema();
            schema.setWidget("columns");
            schema.setItems(new ArrayList<>());
            final UiSchemaConverter columnConverter = new UiSchemaConverter(layoutFilter, family, schema.getItems(), visitedProperties, client, properties, actions);
            return CompletableFuture.allOf(Stream.of(line).map(String::trim).map(childProperties::get).filter(Objects::nonNull).map(PropertyContext::new).map(CompletableFuture::completedFuture).map(columnConverter::convert).toArray(CompletableFuture[]::new)).thenApply(r -> {
                final Collection<UiSchema> items = uiSchema.getItems();
                synchronized (items) {
                    items.add(schema);
                }
                return uiSchema;
            });
        }
        return completedFuture(null);
    }).toArray(CompletableFuture[]::new)).thenApply(done -> {
        addActions(root, uiSchema, visitedProperties);
        return uiSchema;
    });
}
Also used : Optional.ofNullable(java.util.Optional.ofNullable) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Collection(java.util.Collection) CompletableFuture(java.util.concurrent.CompletableFuture) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) Client(org.talend.sdk.component.form.api.Client) ArrayList(java.util.ArrayList) Objects(java.util.Objects) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Collectors.toList(java.util.stream.Collectors.toList) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) Collectors.toMap(java.util.stream.Collectors.toMap) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) Map(java.util.Map) UiSchemaConverter(org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter) Function.identity(java.util.function.Function.identity) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) ArrayList(java.util.ArrayList) UiSchemaConverter(org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) CompletableFuture(java.util.concurrent.CompletableFuture) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) Objects(java.util.Objects)

Example 9 with PropertyContext

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

the class MultiSelectTagWidgetConverter method convert.

@Override
public CompletionStage<PropertyContext> convert(final CompletionStage<PropertyContext> cs) {
    return cs.thenCompose(context -> {
        final UiSchema schema = newUiSchema(context);
        schema.setWidget("multiSelectTag");
        schema.setRestricted(false);
        final String actionName = context.getProperty().getMetadata().get("action::dynamic_values");
        if (client != null && actionName != null) {
            return client.action(family, "dynamic_values", actionName, emptyMap()).exceptionally(e -> {
                log.warn(e.getMessage(), e);
                return emptyMap();
            }).thenApply(values -> {
                final List<UiSchema.NameValue> namedValues = ofNullable(values).map(v -> v.get("items")).filter(Collection.class::isInstance).map(c -> {
                    final Collection<?> dynamicValues = Collection.class.cast(c);
                    return dynamicValues.stream().filter(Map.class::isInstance).filter(m -> Map.class.cast(m).get("id") != null && Map.class.cast(m).get("id") instanceof String).map(Map.class::cast).map(entry -> {
                        final UiSchema.NameValue val = new UiSchema.NameValue();
                        val.setName((String) entry.get("id"));
                        val.setValue(entry.get("label") == null ? (String) entry.get("id") : (String) entry.get("label"));
                        return val;
                    }).collect(toList());
                }).orElse(emptyList());
                schema.setTitleMap(namedValues);
                return context;
            });
        } else {
            schema.setTitleMap(emptyList());
        }
        return CompletableFuture.completedFuture(context);
    });
}
Also used : Collections.emptyMap(java.util.Collections.emptyMap) Collections.emptyList(java.util.Collections.emptyList) Optional.ofNullable(java.util.Optional.ofNullable) Collection(java.util.Collection) CompletableFuture(java.util.concurrent.CompletableFuture) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) Client(org.talend.sdk.component.form.api.Client) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) CompletionStage(java.util.concurrent.CompletionStage) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) Map(java.util.Map) Collection(java.util.Collection) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema)

Example 10 with PropertyContext

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

the class ObjectArrayWidgetConverter method convert.

@Override
public CompletionStage<PropertyContext> convert(final CompletionStage<PropertyContext> cs) {
    return cs.thenCompose(context -> {
        final UiSchema arraySchema = newUiSchema(context);
        arraySchema.setTitle(context.getProperty().getDisplayName());
        arraySchema.setItems(new ArrayList<>());
        arraySchema.setItemWidget("collapsibleFieldset");
        final UiSchemaConverter converter = new UiSchemaConverter(gridLayoutFilter, family, arraySchema.getItems(), new ArrayList<>(), client, properties, actions);
        return CompletableFuture.allOf(nestedProperties.stream().map(p -> converter.convert(CompletableFuture.completedFuture(new PropertyContext(p)))).toArray(CompletableFuture[]::new)).thenApply(r -> context);
    });
}
Also used : UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) CompletionStage(java.util.concurrent.CompletionStage) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) Collection(java.util.Collection) UiSchemaConverter(org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter) CompletableFuture(java.util.concurrent.CompletableFuture) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) Client(org.talend.sdk.component.form.api.Client) ArrayList(java.util.ArrayList) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) UiSchemaConverter(org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema)

Aggregations

Collection (java.util.Collection)11 PropertyContext (org.talend.sdk.component.form.internal.converter.PropertyContext)11 SimplePropertyDefinition (org.talend.sdk.component.server.front.model.SimplePropertyDefinition)11 CompletionStage (java.util.concurrent.CompletionStage)9 ActionReference (org.talend.sdk.component.server.front.model.ActionReference)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 UiSchema (org.talend.sdk.component.form.model.uischema.UiSchema)8 Collectors.toList (java.util.stream.Collectors.toList)7 Map (java.util.Map)6 Optional.ofNullable (java.util.Optional.ofNullable)6 ArrayList (java.util.ArrayList)5 Client (org.talend.sdk.component.form.api.Client)5 List (java.util.List)4 Collectors.toSet (java.util.stream.Collectors.toSet)4 Stream (java.util.stream.Stream)4 AllArgsConstructor (lombok.AllArgsConstructor)4 PropertyConverter (org.talend.sdk.component.form.internal.converter.PropertyConverter)4 UiSchemaConverter (org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter)4 JsonSchema (org.talend.sdk.component.form.model.jsonschema.JsonSchema)4 Collections.emptyList (java.util.Collections.emptyList)3