Search in sources :

Example 1 with UiSchemaConverter

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

the class UiSpecService method convert.

private CompletionStage<Ui> convert(final Supplier<String> displayName, final Supplier<String> family, final Supplier<Collection<SimplePropertyDefinition>> properties, final Supplier<Collection<ActionReference>> actions, final Predicate<SimplePropertyDefinition> isRootProperty) {
    final Collection<SimplePropertyDefinition> props = properties.get();
    final Ui ui = new Ui();
    ui.setUiSchema(new ArrayList<>());
    ui.setProperties(new HashMap<>());
    ui.setJsonSchema(new JsonSchema());
    ui.getJsonSchema().setTitle(displayName.get());
    ui.getJsonSchema().setType("object");
    ui.getJsonSchema().setRequired(props.stream().filter(isRootProperty).filter(p -> new PropertyContext(p).isRequired()).map(SimplePropertyDefinition::getName).collect(toSet()));
    final JsonSchemaConverter jsonSchemaConverter = new JsonSchemaConverter(jsonb, ui.getJsonSchema(), props);
    final UiSchemaConverter uiSchemaConverter = new UiSchemaConverter(null, family.get(), ui.getUiSchema(), new ArrayList<>(), client, props, actions.get());
    final PropertiesConverter propertiesConverter = new PropertiesConverter(jsonb, Map.class.cast(ui.getProperties()), props);
    return CompletableFuture.allOf(props.stream().filter(Objects::nonNull).filter(isRootProperty).map(PropertyContext::new).map(CompletableFuture::completedFuture).map(jsonSchemaConverter::convert).map(uiSchemaConverter::convert).map(propertiesConverter::convert).toArray(CompletableFuture[]::new)).thenApply(r -> ui);
}
Also used : PropertiesConverter(org.talend.sdk.component.form.internal.converter.impl.PropertiesConverter) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) Supplier(java.util.function.Supplier) JsonbConfig(javax.json.bind.JsonbConfig) ArrayList(java.util.ArrayList) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) Map(java.util.Map) JsonSchemaConverter(org.talend.sdk.component.form.internal.converter.impl.JsonSchemaConverter) Collectors.toSet(java.util.stream.Collectors.toSet) JsonbBuilder(javax.json.bind.JsonbBuilder) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) Collection(java.util.Collection) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) CompletionStage(java.util.concurrent.CompletionStage) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) Ui(org.talend.sdk.component.form.model.Ui) UiSchemaConverter(org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter) Jsonb(javax.json.bind.Jsonb) ConfigTypeNode(org.talend.sdk.component.server.front.model.ConfigTypeNode) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) UiSchemaConverter(org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter) CompletableFuture(java.util.concurrent.CompletableFuture) JsonSchemaConverter(org.talend.sdk.component.form.internal.converter.impl.JsonSchemaConverter) Ui(org.talend.sdk.component.form.model.Ui) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) PropertiesConverter(org.talend.sdk.component.form.internal.converter.impl.PropertiesConverter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with UiSchemaConverter

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

the class FieldSetWidgetConverter method convert.

@Override
public CompletionStage<PropertyContext> convert(final CompletionStage<PropertyContext> cs) {
    return cs.thenCompose(context -> {
        final UiSchema uiSchema = newUiSchema(context);
        uiSchema.setWidget("fieldset");
        uiSchema.setItems(new ArrayList<>());
        final List<SimplePropertyDefinition> properties = new ArrayList<>();
        final UiSchemaConverter uiSchemaConverter = new UiSchemaConverter(null, family, uiSchema.getItems(), properties, client, this.properties, actions);
        // Create Nested UI Items
        return CompletableFuture.allOf(this.properties.stream().filter(context::isDirectChild).map(PropertyContext::new).map(CompletableFuture::completedFuture).map(uiSchemaConverter::convert).toArray(CompletableFuture[]::new)).thenApply(done -> {
            addActions(context, uiSchema, properties);
            return context;
        });
    });
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) 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)

Example 3 with UiSchemaConverter

use of org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter 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 4 with UiSchemaConverter

use of org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter 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

ArrayList (java.util.ArrayList)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 UiSchemaConverter (org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter)4 SimplePropertyDefinition (org.talend.sdk.component.server.front.model.SimplePropertyDefinition)4 Collection (java.util.Collection)3 CompletionStage (java.util.concurrent.CompletionStage)3 PropertyContext (org.talend.sdk.component.form.internal.converter.PropertyContext)3 UiSchema (org.talend.sdk.component.form.model.uischema.UiSchema)3 ActionReference (org.talend.sdk.component.server.front.model.ActionReference)3 Map (java.util.Map)2 Objects (java.util.Objects)2 Client (org.talend.sdk.component.form.api.Client)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Optional.ofNullable (java.util.Optional.ofNullable)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 Function.identity (java.util.function.Function.identity)1 Predicate (java.util.function.Predicate)1 Supplier (java.util.function.Supplier)1 Collectors.toList (java.util.stream.Collectors.toList)1