Search in sources :

Example 1 with UiSchema

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

the class UiSpecServiceTest method condition.

@Test
void condition() throws Exception {
    final Ui payload = service.convert(load("rest-api.json")).toCompletableFuture().get();
    final UiSchema root = payload.getUiSchema().iterator().next();
    final Collection<UiSchema.Condition> conditions = root.getItems().stream().filter(i -> i.getTitle().equals("Main")).findFirst().get().getItems().stream().filter(i -> i.getTitle().equals("Order")).findFirst().get().getConditions();
    assertEquals(1, conditions.size());
    final UiSchema.Condition condition = conditions.iterator().next();
    assertEquals("tableDataSet.ordered", condition.getPath());
    assertEquals(singletonList(true), condition.getValues());
    // typed serialization
    try (final Jsonb jsonb = JsonbBuilder.create()) {
        assertEquals("{\"path\":\"tableDataSet.ordered\",\"values\":[true]}", jsonb.toJson(condition));
    }
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Disabled(org.junit.jupiter.api.Disabled) JsonbConfig(javax.json.bind.JsonbConfig) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) ConfigTypeNodes(org.talend.sdk.component.server.front.model.ConfigTypeNodes) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collectors.toSet(java.util.stream.Collectors.toSet) JsonbBuilder(javax.json.bind.JsonbBuilder) Iterator(java.util.Iterator) Collection(java.util.Collection) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) Ui(org.talend.sdk.component.form.model.Ui) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Jsonb(javax.json.bind.Jsonb) Comparator(java.util.Comparator) InputStream(java.io.InputStream) Jsonb(javax.json.bind.Jsonb) Ui(org.talend.sdk.component.form.model.Ui) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Test(org.junit.jupiter.api.Test)

Example 2 with UiSchema

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

the class UiSpecServiceTest method triggerRelativeParameters.

@Test
void triggerRelativeParameters() throws Exception {
    final Ui payload = service.convert(load("relative-params.json")).toCompletableFuture().get();
    final Collection<UiSchema> schema = payload.getUiSchema();
    final UiSchema.Trigger driverTrigger = schema.iterator().next().getItems().stream().filter(c -> c.getTitle().equals("JDBC Connection")).findFirst().orElseThrow(() -> new IllegalArgumentException("No connection")).getItems().iterator().next().getTriggers().iterator().next();
    assertEquals("driver", driverTrigger.getAction());
    // here is what the test validates: the parameters are flattened and translated
    // for the ui
    assertEquals(3, driverTrigger.getParameters().size(), driverTrigger.toString());
    final Iterator<UiSchema.Parameter> params = driverTrigger.getParameters().iterator();
    assertTrue(params.hasNext());
    assertTriggerParameter(params.next(), "value.driver", "configuration.connection.driver");
    assertTriggerParameter(params.next(), "query.timeout", "configuration.query.timeout");
    assertTriggerParameter(params.next(), "query.sql", "configuration.query.sql");
}
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 3 with UiSchema

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

the class UiSpecServiceTest method uiSchema.

@Test
void uiSchema() throws Exception {
    final Ui payload = service.convert(load("jdbc.json")).toCompletableFuture().get();
    final Collection<UiSchema> uiSchema = payload.getUiSchema();
    assertNotNull(uiSchema);
    assertEquals(1, uiSchema.size());
    assertUiSchema(uiSchema.iterator().next(), "fieldset", "Configuration", "configuration", 2, schema -> {
        final List<UiSchema> items = new ArrayList<>(schema.getItems());
        items.sort(Comparator.comparing(UiSchema::getTitle));
        final Iterator<UiSchema> it = items.iterator();
        assertUiSchema(it.next(), "fieldset", "JDBC Connection", "configuration.connection", 5, connection -> {
            final List<UiSchema> connectionItems = new ArrayList<>(connection.getItems());
            connectionItems.sort(Comparator.comparing(UiSchema::getTitle));
            final Iterator<UiSchema> connectionIt = connectionItems.iterator();
            assertUiSchema(connectionIt.next(), "button", "Validate Datastore", "button_healthcheck_configuration.connection", 0, validateDataStore -> {
                assertEquals(1, validateDataStore.getTriggers().size());
                final UiSchema.Trigger trigger = validateDataStore.getTriggers().iterator().next();
                assertEquals(4, trigger.getParameters().size());
                assertEquals(Stream.of("driver", "password", "url", "username").map(p -> "configuration.connection." + p).collect(toSet()), trigger.getParameters().stream().map(UiSchema.Parameter::getPath).collect(toSet()));
                assertEquals(Stream.of("driver", "password", "url", "username").map(p -> "datastore." + p).collect(toSet()), trigger.getParameters().stream().map(UiSchema.Parameter::getKey).collect(toSet()));
            });
            assertUiSchema(connectionIt.next(), "multiSelectTag", "driver", "configuration.connection.driver", 0, driver -> {
                assertNotNull(driver.getTriggers());
                assertEquals(1, driver.getTriggers().size());
                final Collection<UiSchema.NameValue> titleMap = driver.getTitleMap();
                assertEquals(1, titleMap.size());
                final UiSchema.NameValue firstTitleMap = titleMap.iterator().next();
                assertEquals("some.driver.Jdbc", firstTitleMap.getName());
                assertEquals("Jdbc driver", firstTitleMap.getValue());
                final UiSchema.Trigger trigger = driver.getTriggers().iterator().next();
                assertEquals("driver", trigger.getAction());
                assertEquals("jdbc", trigger.getFamily());
                assertEquals("validation", trigger.getType());
                assertEquals(1, trigger.getParameters().size());
                final UiSchema.Parameter parameter = trigger.getParameters().iterator().next();
                assertEquals("value", parameter.getKey());
                assertEquals("configuration.connection.driver", parameter.getPath());
            });
            assertUiSchema(connectionIt.next(), "text", "password", "configuration.connection.password", 0, pwd -> {
                assertEquals("password", pwd.getType());
            });
            assertUiSchema(connectionIt.next(), "text", "url", "configuration.connection.url", 0, url -> {
            });
            assertUiSchema(connectionIt.next(), "text", "username", "configuration.connection.username", 0, username -> {
            });
            assertFalse(connectionIt.hasNext());
        });
        assertUiSchema(it.next(), "fieldset", "query", "configuration.query", 2, query -> {
            final List<UiSchema> queryItems = new ArrayList<>(query.getItems());
            queryItems.sort(Comparator.comparing(UiSchema::getKey));
            final Iterator<UiSchema> queryIt = queryItems.iterator();
            assertUiSchema(queryIt.next(), "text", "query", "configuration.query.query", 0, q -> {
            });
            assertUiSchema(queryIt.next(), "text", "timeout", "configuration.query.timeout", 0, timeout -> {
            });
            assertFalse(queryIt.hasNext());
        });
        assertFalse(it.hasNext());
    });
}
Also used : Ui(org.talend.sdk.component.form.model.Ui) ArrayList(java.util.ArrayList) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Test(org.junit.jupiter.api.Test)

Example 4 with UiSchema

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

the class UiSpecServiceTest method guessSchema.

@Test
void guessSchema() throws Exception {
    final Ui payload = service.convert(load("rest-api.json")).toCompletableFuture().get();
    final UiSchema root = payload.getUiSchema().iterator().next();
    final UiSchema advanced = root.getItems().stream().filter(i -> i.getTitle().equals("Advanced")).findFirst().get();
    final UiSchema commongConfig = advanced.getItems().stream().filter(i -> i.getTitle().equals("commonConfig")).findFirst().get();
    assertTrue(commongConfig.getItems().stream().anyMatch(i -> i.getKey().equals("button_schema_tableDataSet.commonConfig")));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Disabled(org.junit.jupiter.api.Disabled) JsonbConfig(javax.json.bind.JsonbConfig) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) ConfigTypeNodes(org.talend.sdk.component.server.front.model.ConfigTypeNodes) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collectors.toSet(java.util.stream.Collectors.toSet) JsonbBuilder(javax.json.bind.JsonbBuilder) Iterator(java.util.Iterator) Collection(java.util.Collection) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) Ui(org.talend.sdk.component.form.model.Ui) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Jsonb(javax.json.bind.Jsonb) Comparator(java.util.Comparator) InputStream(java.io.InputStream) Ui(org.talend.sdk.component.form.model.Ui) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Test(org.junit.jupiter.api.Test)

Example 5 with UiSchema

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

the class GridLayoutWidgetConverter method convert.

@Override
public CompletionStage<PropertyContext> convert(final CompletionStage<PropertyContext> cs) {
    return cs.thenCompose(context -> {
        // if we have a single tab we don't wrap the forms in tabs otherwise we do
        if (layouts.size() == 1) {
            final Map.Entry<String, String> first = layouts.entrySet().iterator().next();
            return createLayout(context, first.getValue(), first.getKey()).thenApply(uiSchema -> {
                synchronized (schemas) {
                    schemas.add(uiSchema);
                }
                return context;
            });
        } else {
            // if we have multiple tabs, priority is MAIN/ADVANCED pair first
            // but if they are not present then we use all layouts
            final Collection<String> tabs = (layouts.containsKey("Main") ? Stream.of("Main", "Advanced") : layouts.keySet().stream()).collect(toList());
            final UiSchema schema = newUiSchema(context);
            schema.setTitle(null);
            schema.setWidget("tabs");
            final Collection<UiSchema> resolvedLayouts = new ArrayList<>();
            return CompletableFuture.allOf(tabs.stream().sorted((o1, o2) -> {
                if (o1.equals(o2)) {
                    return 0;
                }
                if ("Main".equalsIgnoreCase(o1)) {
                    return -1;
                }
                if ("Main".equalsIgnoreCase(o2)) {
                    return 1;
                }
                final int compareToIgnoreCase = o1.compareToIgnoreCase(o2);
                if (compareToIgnoreCase == 0) {
                    return o1.compareTo(o2);
                }
                return compareToIgnoreCase;
            }).map(tab -> ofNullable(layouts.get(tab)).map(layoutStr -> createLayout(context, layoutStr, tab).thenApply(layout -> {
                layout.setTitle(tab);
                synchronized (resolvedLayouts) {
                    resolvedLayouts.add(layout);
                }
                return layout;
            })).orElse(null)).filter(Objects::nonNull).toArray(CompletableFuture[]::new)).thenApply(done -> {
                schema.setItems(resolvedLayouts);
                return context;
            });
        }
    });
}
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) ArrayList(java.util.ArrayList) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) 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