use of org.talend.sdk.component.server.front.model.SimplePropertyDefinition 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.server.front.model.SimplePropertyDefinition in project component-runtime by Talend.
the class JsonSchemaConverter method convert.
@Override
public CompletionStage<PropertyContext> convert(final CompletionStage<PropertyContext> cs) {
return cs.thenCompose(context -> {
final JsonSchema jsonSchema = new JsonSchema();
jsonSchema.setTitle(context.getProperty().getDisplayName());
final String type = context.getProperty().getType();
switch(type.toLowerCase(ROOT)) {
case "enum":
return new EnumPropertyConverter(jsonSchema).convert(CompletableFuture.completedFuture(context)).thenCompose(c -> postHandling(context, jsonSchema, type));
case "array":
return new ArrayPropertyConverter(jsonb, jsonSchema, properties).convert(CompletableFuture.completedFuture(context)).thenCompose(c -> postHandling(context, jsonSchema, type));
default:
if (context.getProperty().getPath().endsWith("[]")) {
return CompletableFuture.completedFuture(context);
}
jsonSchema.setType(type.toLowerCase(ROOT));
jsonSchema.setRequired(properties.stream().filter(context::isDirectChild).filter(nested -> new PropertyContext(nested).isRequired()).map(SimplePropertyDefinition::getName).collect(toSet()));
return CompletableFuture.completedFuture(context).thenCompose(c -> postHandling(context, jsonSchema, type));
}
});
}
use of org.talend.sdk.component.server.front.model.SimplePropertyDefinition 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));
}
});
}
use of org.talend.sdk.component.server.front.model.SimplePropertyDefinition in project component-runtime by Talend.
the class ArrayPropertyConverter method convert.
@Override
public CompletionStage<PropertyContext> convert(final CompletionStage<PropertyContext> cs) {
return cs.thenCompose(context -> {
jsonSchema.setType(context.getProperty().getType().toLowerCase(ROOT));
final String prefix = context.getProperty().getPath() + "[]";
final List<SimplePropertyDefinition> arrayElements = properties.stream().filter(child -> child.getPath().startsWith(prefix)).collect(toList());
if (arrayElements.stream().anyMatch(e -> e.getPath().startsWith(prefix + '.'))) {
// complex object
final JsonSchema items = new JsonSchema();
items.setType("object");
items.setProperties(new HashMap<>());
jsonSchema.setItems(items);
return CompletableFuture.allOf(arrayElements.stream().map(PropertyContext::new).map(CompletableFuture::completedFuture).map(e -> new JsonSchemaConverter(jsonb, items, emptyList()).convert(e)).toArray(CompletableFuture[]::new)).thenApply(done -> context);
} else if (!arrayElements.isEmpty()) {
// primitive
final String type = arrayElements.get(0).getType();
final JsonSchema item = new JsonSchema();
item.setTitle(jsonSchema.getTitle());
item.setType("enum".equalsIgnoreCase(type) ? "string" : type.toLowerCase(ROOT));
jsonSchema.setItems(item);
}
return CompletableFuture.completedFuture(context);
});
}
use of org.talend.sdk.component.server.front.model.SimplePropertyDefinition 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;
});
});
}
Aggregations