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