Search in sources :

Example 1 with ActionReference

use of org.talend.sdk.component.server.front.model.ActionReference 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);
}
Also used : PropertiesConverter(org.talend.sdk.component.form.internal.converter.impl.PropertiesConverter) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) Supplier(java.util.function.Supplier) JsonbConfig(javax.json.bind.JsonbConfig) ArrayList(java.util.ArrayList) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) Map(java.util.Map) JsonSchemaConverter(org.talend.sdk.component.form.internal.converter.impl.JsonSchemaConverter) Collectors.toSet(java.util.stream.Collectors.toSet) JsonbBuilder(javax.json.bind.JsonbBuilder) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) Collection(java.util.Collection) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) CompletionStage(java.util.concurrent.CompletionStage) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) Ui(org.talend.sdk.component.form.model.Ui) UiSchemaConverter(org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter) Jsonb(javax.json.bind.Jsonb) ConfigTypeNode(org.talend.sdk.component.server.front.model.ConfigTypeNode) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) UiSchemaConverter(org.talend.sdk.component.form.internal.converter.impl.UiSchemaConverter) CompletableFuture(java.util.concurrent.CompletableFuture) JsonSchemaConverter(org.talend.sdk.component.form.internal.converter.impl.JsonSchemaConverter) Ui(org.talend.sdk.component.form.model.Ui) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) PropertiesConverter(org.talend.sdk.component.form.internal.converter.impl.PropertiesConverter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ActionReference

use of org.talend.sdk.component.server.front.model.ActionReference in project component-runtime by Talend.

the class ComponentResourceTest method getDetails.

@Test
void getDetails() {
    final ComponentDetailList details = base.path("component/details").queryParam("identifiers", client.fetchIndex().getComponents().stream().filter(c -> c.getId().getFamily().equals("chain") && c.getId().getName().equals("list")).findFirst().orElseThrow(() -> new IllegalArgumentException("no chain#list component")).getId().getId()).request(APPLICATION_JSON_TYPE).get(ComponentDetailList.class);
    assertEquals(1, details.getDetails().size());
    final ComponentDetail detail = details.getDetails().iterator().next();
    assertEquals("the-test-component", detail.getId().getPlugin());
    assertEquals("chain", detail.getId().getFamily());
    assertEquals("list", detail.getId().getName());
    assertEquals("The List Component", detail.getDisplayName());
    final Collection<ActionReference> remoteActions = detail.getActions();
    assertEquals(1, remoteActions.size());
    final ActionReference action = remoteActions.iterator().next();
    assertEquals("default", action.getName());
    assertEquals("healthcheck", action.getType());
    assertEquals(6, action.getProperties().size());
    assertValidation("remote.urls", detail, validation -> validation.getMinItems() == 1);
    assertValidation("remote.urls", detail, validation -> validation.getUniqueItems() != null && validation.getUniqueItems());
    assertValidation("remote.user.user", detail, validation -> validation.getMinLength() != null && validation.getMinLength() == 2);
    assertValidation("remote.user.password", detail, validation -> validation.getMaxLength() != null && validation.getMaxLength() == 8);
    assertValidation("remote.user.password", detail, validation -> validation.getRequired() != null && validation.getRequired());
    // for now
    assertEquals(0, detail.getLinks().size());
/*
         * final Link link = detail.getLinks().iterator().next(); assertEquals("Detail", link.getName());
         * assertEquals("/component/...", link.getPath());
         */
}
Also used : MonoMeecrowaveConfig(org.apache.meecrowave.junit5.MonoMeecrowaveConfig) JarFile(java.util.jar.JarFile) Collections.singletonList(java.util.Collections.singletonList) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) MediaType(javax.ws.rs.core.MediaType) Link(org.talend.sdk.component.server.front.model.Link) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) Map(java.util.Map) ComponentDetailList(org.talend.sdk.component.server.front.model.ComponentDetailList) Predicate(java.util.function.Predicate) Collection(java.util.Collection) WebsocketClient(org.talend.sdk.component.server.test.websocket.WebsocketClient) DependencyDefinition(org.talend.sdk.component.server.front.model.DependencyDefinition) StandardCharsets(java.nio.charset.StandardCharsets) TestInfo(org.junit.jupiter.api.TestInfo) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) Base64(java.util.Base64) List(java.util.List) APPLICATION_OCTET_STREAM_TYPE(javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE) ComponentClient(org.talend.sdk.component.server.test.ComponentClient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TemporaryFolder(org.talend.sdk.component.junit.base.junit5.TemporaryFolder) PropertyValidation(org.talend.sdk.component.server.front.model.PropertyValidation) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Dependencies(org.talend.sdk.component.server.front.model.Dependencies) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) Entity.entity(javax.ws.rs.client.Entity.entity) DeploymentException(javax.websocket.DeploymentException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) WithTemporaryFolder(org.talend.sdk.component.junit.base.junit5.WithTemporaryFolder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ComponentIndex(org.talend.sdk.component.server.front.model.ComponentIndex) ComponentIndices(org.talend.sdk.component.server.front.model.ComponentIndices) File(java.io.File) Consumer(java.util.function.Consumer) IO(org.apache.ziplock.IO) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) WebTarget(javax.ws.rs.client.WebTarget) Comparator(java.util.Comparator) InputStream(java.io.InputStream) ComponentDetailList(org.talend.sdk.component.server.front.model.ComponentDetailList) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) Test(org.junit.jupiter.api.Test)

Example 3 with ActionReference

use of org.talend.sdk.component.server.front.model.ActionReference in project component-runtime by Talend.

the class ObjectWidgetConverter method addActions.

protected void addActions(final PropertyContext root, final UiSchema uiSchema, final Collection<SimplePropertyDefinition> includedProperties) {
    final Optional<SimplePropertyDefinition> schemaBinding = includedProperties.stream().filter(p -> "OUT".equals(p.getMetadata().get("ui::structure::type"))).findFirst();
    final Collection<UiSchema> items = uiSchema.getItems();
    if (schemaBinding.isPresent()) {
        SimplePropertyDefinition bindingProp = schemaBinding.get();
        final String schemaActionName = ofNullable(bindingProp.getMetadata().get("action::schema")).filter(n -> !n.isEmpty()).orElse("default");
        actions.stream().filter(a -> a.getName().equals(schemaActionName) && "schema".equals(a.getType())).findFirst().ifPresent(ref -> {
            final UiSchema.Trigger trigger = toTrigger(properties, root.getProperty(), ref);
            trigger.setOptions(singletonList(new UiSchema.Option.Builder().withPath(bindingProp.getPath().replace("[]", "")).withType("array".equalsIgnoreCase(bindingProp.getType()) ? "array" : "object").build()));
            if (trigger.getParameters() == null || trigger.getParameters().isEmpty()) {
                // find the matching dataset
                Optional<SimplePropertyDefinition> findParameters = properties.stream().filter(nested -> ref.getName().equals(nested.getMetadata().get("configurationtype::name")) && "dataset".equals(nested.getMetadata().get("configurationtype::type"))).findFirst();
                if (!findParameters.isPresent()) {
                    // if not ambiguous grab the unique dataset
                    final Collection<SimplePropertyDefinition> datasets = properties.stream().filter(nested -> "dataset".equals(nested.getMetadata().get("configurationtype::type"))).collect(toSet());
                    if (datasets.size() == 1) {
                        findParameters = of(datasets.iterator().next());
                    }
                }
                findParameters.ifPresent(dataset -> {
                    final UiSchema.Parameter parameter = new UiSchema.Parameter();
                    parameter.setKey(ofNullable(ref.getProperties()).orElse(Collections.emptyList()).stream().filter(p -> !p.getPath().contains(".")).findFirst().map(SimplePropertyDefinition::getName).orElse("dataset"));
                    parameter.setPath(dataset.getPath());
                    trigger.setParameters(toParams(properties, dataset, ref, dataset.getPath()));
                });
            }
            final UiSchema button = new UiSchema();
            button.setKey("button_schema_" + root.getProperty().getPath());
            button.setTitle("Guess Schema");
            button.setWidget("button");
            button.setTriggers(singletonList(trigger));
            synchronized (items) {
                items.add(button);
            }
        });
    }
    ofNullable(root.getProperty().getMetadata().get("action::healthcheck")).flatMap(v -> (actions == null ? Stream.<ActionReference>empty() : actions.stream()).filter(a -> a.getName().equals(v) && "healthcheck".equals(a.getType())).findFirst()).ifPresent(ref -> {
        final UiSchema.Trigger trigger = toTrigger(properties, root.getProperty(), ref);
        if (trigger.getParameters() == null || trigger.getParameters().isEmpty()) {
            // find the matching dataset
            properties.stream().filter(nested -> "datastore".equals(nested.getMetadata().get("configurationtype::type")) && ref.getName().equals(nested.getMetadata().get("configurationtype::name"))).findFirst().ifPresent(datastore -> trigger.setParameters(toParams(properties, datastore, ref, datastore.getPath())));
        }
        final UiSchema button = new UiSchema();
        button.setKey("button_healthcheck_" + root.getProperty().getPath());
        button.setTitle("Validate Datastore");
        button.setWidget("button");
        button.setTriggers(singletonList(trigger));
        synchronized (items) {
            items.add(button);
        }
    });
}
Also used : UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Stream(java.util.stream.Stream) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) Optional.ofNullable(java.util.Optional.ofNullable) Optional.of(java.util.Optional.of) Collection(java.util.Collection) Optional(java.util.Optional) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) Collections(java.util.Collections) Collectors.toSet(java.util.stream.Collectors.toSet) Collections.singletonList(java.util.Collections.singletonList) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema)

Aggregations

Collection (java.util.Collection)3 ActionReference (org.talend.sdk.component.server.front.model.ActionReference)3 SimplePropertyDefinition (org.talend.sdk.component.server.front.model.SimplePropertyDefinition)3 ArrayList (java.util.ArrayList)2 Collections.singletonList (java.util.Collections.singletonList)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Predicate (java.util.function.Predicate)2 Collectors.toSet (java.util.stream.Collectors.toSet)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Base64 (java.util.Base64)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1