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);
}
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;
});
});
}
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;
});
}
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);
});
}
Aggregations