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