From 13c6931ecb3a8651eb82733487ada8022ea9345e Mon Sep 17 00:00:00 2001 From: undx Date: Thu, 6 Jun 2024 16:53:27 +0200 Subject: [PATCH 1/2] feat(TCOMP-2744): add @ReadOnly annotation --- .../api/configuration/ui/widget/ReadOnly.java | 33 +++++++++++++++++++ .../impl/widget/AbstractWidgetConverter.java | 3 ++ .../converter/impl/UiSchemaConverterTest.java | 5 +++ .../UiParameterEnricherTest.java | 19 +++++++++++ .../front/ComponentResourceImplTest.java | 24 +++++++++----- .../ConfigurationTypeResourceImplTest.java | 4 ++- .../component/server/test/InitTestInfra.java | 2 ++ .../server/test/jdbc/JdbcConfig.java | 9 +++++ .../server/test/jdbc/JdbcDataStore.java | 4 ++- .../ROOT/pages/_partials/generated_ui.adoc | 16 +++++++++ 10 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 component-api/src/main/java/org/talend/sdk/component/api/configuration/ui/widget/ReadOnly.java diff --git a/component-api/src/main/java/org/talend/sdk/component/api/configuration/ui/widget/ReadOnly.java b/component-api/src/main/java/org/talend/sdk/component/api/configuration/ui/widget/ReadOnly.java new file mode 100644 index 0000000000000..ad81d3c7c5098 --- /dev/null +++ b/component-api/src/main/java/org/talend/sdk/component/api/configuration/ui/widget/ReadOnly.java @@ -0,0 +1,33 @@ +/** + * Copyright (C) 2006-2024 Talend Inc. - www.talend.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.talend.sdk.component.api.configuration.ui.widget; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.talend.sdk.component.api.configuration.ui.meta.Ui; +import org.talend.sdk.component.api.meta.Documentation; + +@Ui +@Documentation("Mark a option as being read-only widget. User cannot modify widget.") +@Retention(RUNTIME) +@Target({ PARAMETER, FIELD }) +public @interface ReadOnly { +} diff --git a/component-form/component-form-core/src/main/java/org/talend/sdk/component/form/internal/converter/impl/widget/AbstractWidgetConverter.java b/component-form/component-form-core/src/main/java/org/talend/sdk/component/form/internal/converter/impl/widget/AbstractWidgetConverter.java index 8c28b357f7f57..41e4967617b46 100644 --- a/component-form/component-form-core/src/main/java/org/talend/sdk/component/form/internal/converter/impl/widget/AbstractWidgetConverter.java +++ b/component-form/component-form-core/src/main/java/org/talend/sdk/component/form/internal/converter/impl/widget/AbstractWidgetConverter.java @@ -172,6 +172,9 @@ protected UiSchema newOrphanSchema(final PropertyContext ctx) { if (Boolean.parseBoolean(ctx.getProperty().getMetadata().getOrDefault("documentation::tooltip", "false"))) { schema.setTooltip(ctx.getProperty().getMetadata().get("documentation::value")); } + if (Boolean.parseBoolean(ctx.getProperty().getMetadata().getOrDefault("ui::readonly", "false"))) { + schema.setReadOnly(true); + } if (actions != null) { final List triggers = Stream .concat(Stream diff --git a/component-form/component-form-core/src/test/java/org/talend/sdk/component/form/internal/converter/impl/UiSchemaConverterTest.java b/component-form/component-form-core/src/test/java/org/talend/sdk/component/form/internal/converter/impl/UiSchemaConverterTest.java index 8bb051d09f06d..eb0b5c94550a4 100644 --- a/component-form/component-form-core/src/test/java/org/talend/sdk/component/form/internal/converter/impl/UiSchemaConverterTest.java +++ b/component-form/component-form-core/src/test/java/org/talend/sdk/component/form/internal/converter/impl/UiSchemaConverterTest.java @@ -22,6 +22,7 @@ import static java.util.concurrent.CompletableFuture.completedFuture; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.HashMap; @@ -77,6 +78,7 @@ void listOfObject() throws Exception { void moduleListWithBeanList() throws Exception { final Map metadata = new HashMap<>(); metadata.put("ui::modulelist", "true"); + metadata.put("ui::readonly", "true"); final List properties = asList( new SimplePropertyDefinition("configuration", "configuration", "configuration", "OBJECT", null, NVAL, emptyMap(), null, NPROPS), @@ -89,13 +91,16 @@ void moduleListWithBeanList() throws Exception { assertEquals(1, schemas.size()); final UiSchema configuration = schemas.iterator().next(); assertNull(configuration.getKey()); + assertNull(configuration.getReadOnly()); assertEquals(1, configuration.getItems().size()); final UiSchema list = configuration.getItems().iterator().next(); + assertNull(list.getReadOnly()); assertEquals("configuration.drivers", list.getKey()); assertEquals("collapsibleFieldset", list.getItemWidget()); assertEquals(1, list.getItems().size()); final UiSchema name = list.getItems().iterator().next(); assertEquals("configuration.drivers[].path", name.getKey()); + assertTrue(name.getReadOnly()); // use text type in react ui form for the item, it mean ignore @ModuleList which only works for studio now assertEquals("text", name.getWidget()); } diff --git a/component-runtime-manager/src/test/java/org/talend/sdk/component/runtime/manager/reflect/parameterenricher/UiParameterEnricherTest.java b/component-runtime-manager/src/test/java/org/talend/sdk/component/runtime/manager/reflect/parameterenricher/UiParameterEnricherTest.java index b81b63223eb78..4826df2ea07f8 100644 --- a/component-runtime-manager/src/test/java/org/talend/sdk/component/runtime/manager/reflect/parameterenricher/UiParameterEnricherTest.java +++ b/component-runtime-manager/src/test/java/org/talend/sdk/component/runtime/manager/reflect/parameterenricher/UiParameterEnricherTest.java @@ -41,6 +41,7 @@ import org.talend.sdk.component.api.configuration.ui.widget.Credential; import org.talend.sdk.component.api.configuration.ui.widget.DateTime; import org.talend.sdk.component.api.configuration.ui.widget.ModuleList; +import org.talend.sdk.component.api.configuration.ui.widget.ReadOnly; import org.talend.sdk.component.api.configuration.ui.widget.Structure; import org.talend.sdk.component.api.service.configuration.LocalConfiguration; @@ -398,4 +399,22 @@ public Class annotationType() { return true; })); } + + @Test + void readOnly() { + assertEquals(new HashMap() { + + { + put("tcomp::ui::readonly", "true"); + } + }, enricher.onParameterAnnotation("testParam", String.class, new ReadOnly() { + + @Override + public Class annotationType() { + return ReadOnly.class; + } + + })); + } + } diff --git a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ComponentResourceImplTest.java b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ComponentResourceImplTest.java index 367466e900b53..069c1818dbc5c 100644 --- a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ComponentResourceImplTest.java +++ b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ComponentResourceImplTest.java @@ -328,7 +328,7 @@ void getIconIndex() { .accept(APPLICATION_SVG_XML_TYPE) .get(); assertNotNull(icons); - assertEquals(406, icons.getStatus()); + assertEquals(406, icons.getStatus()); // inexistant theme (no fallback) icons = base.path("component/icon/index") .queryParam("theme", "dak") @@ -357,7 +357,8 @@ void getIconIndex() { assertTrue(content.contains( "data-connector=\"standalone\" data-family=\"chain\" data-theme=\"light\" data-type=\"connector\" id=\"myicon-light\"")); assertTrue( - content.contains("data-family=\"file\" data-theme=\"light\" data-type=\"family\" id=\"file-family-light\"")); + content.contains( + "data-family=\"file\" data-theme=\"light\" data-type=\"family\" id=\"file-family-light\"")); // light theme content = base.path("component/icon/index") .queryParam("theme", "light") @@ -371,7 +372,8 @@ void getIconIndex() { assertTrue(content.contains( "data-connector=\"standalone\" data-family=\"chain\" data-theme=\"light\" data-type=\"connector\" id=\"myicon-light\"")); assertTrue( - content.contains("data-family=\"file\" data-theme=\"light\" data-type=\"family\" id=\"file-family-light\"")); + content.contains( + "data-family=\"file\" data-theme=\"light\" data-type=\"family\" id=\"file-family-light\"")); // dark theme content = base.path("component/icon/index") @@ -384,9 +386,11 @@ void getIconIndex() { content.startsWith( "")); assertTrue(content - .contains("data-connector=\"input\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\"")); + .contains( + "data-connector=\"input\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\"")); assertTrue(content - .contains("data-connector=\"output\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\"")); + .contains( + "data-connector=\"output\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\"")); // theme = all content = base.path("component/icon/index") .queryParam("theme", "all") @@ -399,13 +403,16 @@ void getIconIndex() { content.startsWith( "")); assertTrue(content - .contains("data-connector=\"input\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\"")); + .contains( + "data-connector=\"input\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\"")); assertTrue(content - .contains("data-connector=\"output\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\"")); + .contains( + "data-connector=\"output\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\"")); assertTrue(content.contains( "data-connector=\"standalone\" data-family=\"chain\" data-theme=\"light\" data-type=\"connector\" id=\"myicon-light\"")); assertTrue( - content.contains("data-family=\"file\" data-theme=\"dark\" data-type=\"family\" id=\"file-family-dark\"")); + content.contains( + "data-family=\"file\" data-theme=\"dark\" data-type=\"family\" id=\"file-family-dark\"")); } @Test @@ -612,6 +619,7 @@ void getStreamingDetails() { assertEquals(1, details.getDetails().size()); final ComponentDetail detail = details.getDetails().iterator().next(); assertEquals(1, detail.getProperties().size()); + // assertEquals(); assertThrows(IllegalArgumentException.class, () -> detail .getProperties() .stream() diff --git a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ConfigurationTypeResourceImplTest.java b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ConfigurationTypeResourceImplTest.java index 003b5c3dbb3ce..70733e28c42ac 100644 --- a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ConfigurationTypeResourceImplTest.java +++ b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ConfigurationTypeResourceImplTest.java @@ -75,7 +75,9 @@ void webSocketDetail() { assertEquals(1, index.getNodes().size()); final ConfigTypeNode jdbcConnection = index.getNodes().get("amRiYy1jb21wb25lbnQjamRiYyNkYXRhc3RvcmUjamRiYw"); assertNotNull(jdbcConnection); - assertEquals("[{\"description\":\"D1\",\"driver\":\"d1\"},{\"description\":\"D2\",\"driver\":\"d2\"}]", + assertEquals( + "[{\"dependencies\":[\"org.talend.db:zorglub:1.0:jar\"],\"description\":\"D1\",\"driver\":\"d1\"},{\"dependencies\":[\"org.talend.db:zorglub:1.0:jar\",\"a:b:1.0:jar\"],\"description\":\"D2\",\"driver\":\"d2\"}]", + jdbcConnection .getProperties() .stream() diff --git a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/test/InitTestInfra.java b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/test/InitTestInfra.java index 8178fbc16c5d7..f650abbaefc44 100644 --- a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/test/InitTestInfra.java +++ b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/test/InitTestInfra.java @@ -316,6 +316,8 @@ private File createJdbcPlugin(final File target) { "Documentation pour configurations description"); put("configuration.connection.configurations[].driver._documentation", "Documentation pour configurations conducteur"); + put("configuration.connection.configurations[].dependencies._documentation", + "Documentation pour configurations dependances"); put("configuration.connection.url._documentation", "Documentation pour hurle..."); put("configuration.driver._documentation", "Documentation pour conducteur..."); put("configuration.query._documentation", "Documentation pour requète..."); diff --git a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/test/jdbc/JdbcConfig.java b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/test/jdbc/JdbcConfig.java index b112a5e711370..a5b3ba98db8c2 100644 --- a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/test/jdbc/JdbcConfig.java +++ b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/test/jdbc/JdbcConfig.java @@ -16,8 +16,11 @@ package org.talend.sdk.component.server.test.jdbc; import java.io.Serializable; +import java.util.List; import org.talend.sdk.component.api.configuration.Option; +import org.talend.sdk.component.api.configuration.ui.widget.ModuleList; +import org.talend.sdk.component.api.configuration.ui.widget.ReadOnly; import org.talend.sdk.component.api.meta.Documentation; import lombok.AllArgsConstructor; @@ -36,4 +39,10 @@ public class JdbcConfig implements Serializable { @Option @Documentation(value = "Documentation for description (jdbcconfig) doc.", tooltip = true) private String description; + + @Option + @Documentation(value = "Documentation for dependencies (jdbcconfig) doc.", tooltip = true) + @ModuleList + @ReadOnly + private List dependencies; } diff --git a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/test/jdbc/JdbcDataStore.java b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/test/jdbc/JdbcDataStore.java index 882b6164a5703..276839b2aa33c 100644 --- a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/test/jdbc/JdbcDataStore.java +++ b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/test/jdbc/JdbcDataStore.java @@ -48,7 +48,9 @@ public class JdbcDataStore implements Serializable { @Option // to test tables @Documentation(value = "Documentation for Datastore configurations.", tooltip = true) - private List configurations = asList(new JdbcConfig("d1", "D1"), new JdbcConfig("d2", "D2")); + private List configurations = + asList(new JdbcConfig("d1", "D1", List.of("org.talend.db:zorglub:1.0:jar")), + new JdbcConfig("d2", "D2", List.of("org.talend.db:zorglub:1.0:jar", "a:b:1.0:jar"))); @Option @DateTime(dateFormat = "DD-MM-YYYY", useUTC = false, useSeconds = false) diff --git a/documentation/src/main/antora/modules/ROOT/pages/_partials/generated_ui.adoc b/documentation/src/main/antora/modules/ROOT/pages/_partials/generated_ui.adoc index 72899f76acfc3..090f95af09565 100644 --- a/documentation/src/main/antora/modules/ROOT/pages/_partials/generated_ui.adoc +++ b/documentation/src/main/antora/modules/ROOT/pages/_partials/generated_ui.adoc @@ -241,6 +241,22 @@ Mark a option as being represented by file or directory widget. Only for studio. ---- += @ReadOnly + +Mark a option as being read-only widget. User cannot modify widget. + +- API: `@org.talend.sdk.component.api.configuration.ui.widget.ReadOnly` + +== Snippets + +[source,js] +---- +{ + "ui::readonly":"true" +} +---- + + = @Structure Mark a List or List field as being represented as the component data selector. From f5743cf45b6f58acf2414ac63d669beb5dccc138 Mon Sep 17 00:00:00 2001 From: undx Date: Thu, 6 Jun 2024 16:55:32 +0200 Subject: [PATCH 2/2] feat(TCOMP-2744): remove comment --- .../sdk/component/server/front/ComponentResourceImplTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ComponentResourceImplTest.java b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ComponentResourceImplTest.java index 069c1818dbc5c..4cac7bf41eabb 100644 --- a/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ComponentResourceImplTest.java +++ b/component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ComponentResourceImplTest.java @@ -619,7 +619,6 @@ void getStreamingDetails() { assertEquals(1, details.getDetails().size()); final ComponentDetail detail = details.getDetails().iterator().next(); assertEquals(1, detail.getProperties().size()); - // assertEquals(); assertThrows(IllegalArgumentException.class, () -> detail .getProperties() .stream()