Search in sources :

Example 6 with UiSchema

use of org.talend.sdk.component.form.model.uischema.UiSchema in project component-runtime by Talend.

the class UiSpecServiceTest method gridLayout.

@Test
void gridLayout() throws Exception {
    final Ui payload = service.convert(load("rest-api.json")).toCompletableFuture().get();
    final UiSchema tableDataSet = payload.getUiSchema().iterator().next();
    assertEquals(2, tableDataSet.getItems().size());
    final Iterator<UiSchema> tableDataSetIt = tableDataSet.getItems().iterator();
    final UiSchema tableDataSetMain = tableDataSetIt.next();
    assertEquals("Main", tableDataSetMain.getTitle());
    assertEquals(5, tableDataSetMain.getItems().size());
    assertEquals(asList("dataStore", "commonConfig", "Query", "Ordered", "Order"), tableDataSetMain.getItems().stream().map(UiSchema::getTitle).collect(toList()));
    final Iterator<UiSchema> mainIt = tableDataSetMain.getItems().iterator();
    final UiSchema dataStore = mainIt.next();
    Iterator<UiSchema> dataStoreIt = dataStore.getItems().iterator();
    dataStoreIt.next();
    final UiSchema credentials = dataStoreIt.next();
    assertEquals("columns", credentials.getWidget());
    assertEquals(asList("Username", "Password"), credentials.getItems().stream().map(UiSchema::getTitle).collect(toList()));
    final UiSchema tableDataSetAdvanced = tableDataSetIt.next();
    assertEquals("Advanced", tableDataSetAdvanced.getTitle());
}
Also used : Ui(org.talend.sdk.component.form.model.Ui) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Test(org.junit.jupiter.api.Test)

Example 7 with UiSchema

use of org.talend.sdk.component.form.model.uischema.UiSchema 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 8 with UiSchema

use of org.talend.sdk.component.form.model.uischema.UiSchema in project component-runtime by Talend.

the class CodeWidgetConverter method convert.

@Override
public CompletionStage<PropertyContext> convert(final CompletionStage<PropertyContext> cs) {
    return cs.thenApply(context -> {
        final UiSchema schema = newUiSchema(context);
        final String codeLang = context.getProperty().getMetadata().get("ui::code::value");
        schema.setWidget("code");
        schema.setOptions(singletonMap("language", codeLang));
        return context;
    });
}
Also used : UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema)

Example 9 with UiSchema

use of org.talend.sdk.component.form.model.uischema.UiSchema in project component-runtime by Talend.

the class CredentialWidgetConverter method convert.

@Override
public CompletionStage<PropertyContext> convert(final CompletionStage<PropertyContext> cs) {
    return cs.thenApply(context -> {
        final UiSchema schema = newUiSchema(context);
        schema.setWidget("text");
        schema.setType("password");
        return context;
    });
}
Also used : UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema)

Example 10 with UiSchema

use of org.talend.sdk.component.form.model.uischema.UiSchema 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)

Aggregations

UiSchema (org.talend.sdk.component.form.model.uischema.UiSchema)18 Collection (java.util.Collection)9 ArrayList (java.util.ArrayList)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 CompletionStage (java.util.concurrent.CompletionStage)7 Collectors.toList (java.util.stream.Collectors.toList)7 SimplePropertyDefinition (org.talend.sdk.component.server.front.model.SimplePropertyDefinition)7 Stream (java.util.stream.Stream)6 PropertyContext (org.talend.sdk.component.form.internal.converter.PropertyContext)6 ActionReference (org.talend.sdk.component.server.front.model.ActionReference)6 Map (java.util.Map)5 Optional.ofNullable (java.util.Optional.ofNullable)5 Test (org.junit.jupiter.api.Test)5 Ui (org.talend.sdk.component.form.model.Ui)5 Collections.singletonList (java.util.Collections.singletonList)4 List (java.util.List)4 Collectors.toSet (java.util.stream.Collectors.toSet)4 Client (org.talend.sdk.component.form.api.Client)4 Iterator (java.util.Iterator)3 UiSchemaConverter (org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter)3