This is an automated email from the ASF dual-hosted git repository.
wmedvedeo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-kogito-apps.git
The following commit(s) were added to refs/heads/main by this push:
new a41b85404 Fix kie-issues#1981: Add an optional property to add a
custom UI to Data Index (#2232)
a41b85404 is described below
commit a41b854040b673c7f0b074ef38dc5634c9f1c65b
Author: Ricardo Zanini <[email protected]>
AuthorDate: Thu Jun 12 10:41:09 2025 -0300
Fix kie-issues#1981: Add an optional property to add a custom UI to Data
Index (#2232)
* Fix kie-issues#1981: Add an optional property to add a custom UI to Data
Index
Signed-off-by: Ricardo Zanini <[email protected]>
* Add missing license headers to rat-excludes
Signed-off-by: Ricardo Zanini <[email protected]>
---------
Signed-off-by: Ricardo Zanini <[email protected]>
---
.rat-excludes | 4 ++
.../index/service/vertx/IndexRouteRegistrar.java | 62 ++++++++++++++++++++++
.../index/service/vertx/VertxRouterSetup.java | 13 +++--
.../index/service/vertx/VertxRouterSetupTest.java | 3 ++
.../kie/kogito/index/service/CustomUIPageIT.java | 48 +++++++++++++++++
.../src/test/resources/application.properties | 5 +-
.../src/test/resources/ui/index.html | 1 +
.../src/test/resources/ui/styles.css | 1 +
8 files changed, 132 insertions(+), 5 deletions(-)
diff --git a/.rat-excludes b/.rat-excludes
index c6e655f26..1d0970d2c 100644
--- a/.rat-excludes
+++ b/.rat-excludes
@@ -104,3 +104,7 @@ application.properties
org.eclipse.microprofile.config.spi.ConfigSource
#
trusty/trusty-service/trusty-service-common/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
org.mockito.plugins.MockMaker
+#
data-index/data-index-service/data-index-service-inmemory/src/test/resources/ui/index.html
+index.html
+#
data-index/data-index-service/data-index-service-inmemory/src/test/resources/ui/styles.css
+styles.css
\ No newline at end of file
diff --git
a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/vertx/IndexRouteRegistrar.java
b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/vertx/IndexRouteRegistrar.java
new file mode 100644
index 000000000..c7481beab
--- /dev/null
+++
b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/vertx/IndexRouteRegistrar.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.kie.kogito.index.service.vertx;
+
+import java.util.Optional;
+
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+
+import io.quarkus.runtime.StartupEvent;
+import io.vertx.ext.web.Router;
+import io.vertx.ext.web.handler.StaticHandler;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.event.Observes;
+
+@ApplicationScoped
+public class IndexRouteRegistrar {
+
+ public static final String CONFIG_KEY_UI_PATH =
"kogito.data-index.ui.path";
+
+ @ConfigProperty(name = CONFIG_KEY_UI_PATH, defaultValue = "")
+ Optional<String> directory;
+
+ /**
+ * Configures the UI Page in case we find a directory to serve.
+ * This path MUST have an index.html file to serve as the static index
page for the Data Index service.
+ * / -> points to the custom /ui/index.html
+ * /index.html -> points to the custom /ui/index.html
+ * /ui/* -> points to our directory and serves everything
+ */
+ void onStart(@Observes StartupEvent ev, Router router) {
+ directory.ifPresent(dir -> {
+ router.route("/")
+ .handler(ctx -> ctx.response()
+ .putHeader("Location", "/ui/index.html")
+ .setStatusCode(302)
+ .end());
+
+
router.route("/index.html").handler(StaticHandler.create(dir).setIndexPage("index.html"));
+
+ router.route("/ui/*")
+ .handler(StaticHandler.create(dir)
+ .setIndexPage("index.html"));
+ });
+ }
+}
diff --git
a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/vertx/VertxRouterSetup.java
b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/vertx/VertxRouterSetup.java
index 6aa35416b..f05c85b78 100644
---
a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/vertx/VertxRouterSetup.java
+++
b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/vertx/VertxRouterSetup.java
@@ -39,29 +39,34 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
+import static
org.kie.kogito.index.service.vertx.IndexRouteRegistrar.CONFIG_KEY_UI_PATH;
+
@ApplicationScoped
public class VertxRouterSetup {
- @Inject
@ConfigProperty(name = "quarkus.oidc.enabled", defaultValue = "false")
Boolean authEnabled;
- @Inject
@ConfigProperty(name = "kogito.data-index.vertx-graphql.ui.path",
defaultValue = "/graphiql")
String graphUIPath;
+ @ConfigProperty(name = CONFIG_KEY_UI_PATH, defaultValue = "")
+ Optional<String> indexUIPath;
+
@Inject
Vertx vertx;
void setupRouter(@Observes Router router) {
router.route().handler(LoggerHandler.create());
- GraphiQLHandler graphiQLHandler = GraphiQLHandler.create(new
GraphiQLHandlerOptions().setEnabled(true));
+ GraphiQLHandler graphiQLHandler = GraphiQLHandler.create(vertx, new
GraphiQLHandlerOptions().setEnabled(true));
if (Boolean.TRUE.equals(authEnabled)) {
addGraphiqlRequestHeader(graphiQLHandler);
}
router.route().handler(BodyHandler.create());
router.route(graphUIPath + "/*").handler(graphiQLHandler);
- router.route("/").handler(ctx -> ctx.response().putHeader("location",
graphUIPath + "/").setStatusCode(302).end());
+ if (indexUIPath.isEmpty()) {
+ router.route("/").handler(ctx ->
ctx.response().putHeader("location", graphUIPath +
"/").setStatusCode(302).end());
+ }
router.route().handler(FaviconHandler.create(vertx));
}
diff --git
a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/vertx/VertxRouterSetupTest.java
b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/vertx/VertxRouterSetupTest.java
index a880f33be..c407fed11 100644
---
a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/vertx/VertxRouterSetupTest.java
+++
b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/vertx/VertxRouterSetupTest.java
@@ -18,6 +18,7 @@
*/
package org.kie.kogito.index.service.vertx;
+import java.util.Optional;
import java.util.function.Function;
import org.junit.jupiter.api.BeforeEach;
@@ -83,6 +84,7 @@ public class VertxRouterSetupTest {
public void testAuthEnabledTrue() {
vertxRouterSetup.authEnabled = true;
vertxRouterSetup.graphUIPath = "/graphiql";
+ vertxRouterSetup.indexUIPath = Optional.empty();
vertxRouterSetup.setupRouter(routerMock);
verify(vertxRouterSetup).addGraphiqlRequestHeader(any());
@@ -92,6 +94,7 @@ public class VertxRouterSetupTest {
public void testAuthEnabledFalse() {
vertxRouterSetup.authEnabled = false;
vertxRouterSetup.graphUIPath = "/graphiql";
+ vertxRouterSetup.indexUIPath = Optional.empty();
vertxRouterSetup.setupRouter(routerMock);
verify(vertxRouterSetup, never()).addGraphiqlRequestHeader(any());
diff --git
a/data-index/data-index-service/data-index-service-inmemory/src/test/java/org/kie/kogito/index/service/CustomUIPageIT.java
b/data-index/data-index-service/data-index-service-inmemory/src/test/java/org/kie/kogito/index/service/CustomUIPageIT.java
new file mode 100644
index 000000000..5fb812f34
--- /dev/null
+++
b/data-index/data-index-service/data-index-service-inmemory/src/test/java/org/kie/kogito/index/service/CustomUIPageIT.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.kie.kogito.index.service;
+
+import org.junit.jupiter.api.Test;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+
+import static org.hamcrest.Matchers.equalTo;
+
+@QuarkusTest
+public class CustomUIPageIT {
+ /**
+ * Override the property to point to our test resources' directory.
+ * Make sure you have src/test/resources/static-test/index.html and
+ * src/test/resources/static-test/styles.css in place.
+ */
+ @Test
+ public void testIndexHtmlServedAtRoot() {
+ // Expect the content of src/test/resources/static-test/index.html
+
RestAssured.given().when().get("/ui/index.html").then().statusCode(200).body(equalTo("<html><body><h1>Test
Index</h1></body></html>"));
+
RestAssured.given().when().get("/index.html").then().statusCode(200).body(equalTo("<html><body><h1>Test
Index</h1></body></html>"));
+
RestAssured.given().when().get("/").then().statusCode(200).body(equalTo("<html><body><h1>Test
Index</h1></body></html>"));
+ }
+
+ @Test
+ public void testCssServed() {
+ // Expect the content of src/test/resources/static-test/styles.css
+
RestAssured.given().when().get("/ui/styles.css").then().statusCode(200).body(equalTo("body
{ background: #fff; }"));
+ }
+}
diff --git
a/data-index/data-index-service/data-index-service-inmemory/src/test/resources/application.properties
b/data-index/data-index-service/data-index-service-inmemory/src/test/resources/application.properties
index 052692f8a..a31453e9f 100644
---
a/data-index/data-index-service/data-index-service-inmemory/src/test/resources/application.properties
+++
b/data-index/data-index-service/data-index-service-inmemory/src/test/resources/application.properties
@@ -52,4 +52,7 @@ quarkus.oidc.auth-server-url=none
%keycloak-test.quarkus.oidc.web-app-tenant.application-type=web-app
# Not using Dev service in test, but rather
org.kie.kogito.testcontainers.quarkus.KeycloakQuarkusTestResource
-quarkus.keycloak.devservices.enabled=false
\ No newline at end of file
+quarkus.keycloak.devservices.enabled=false
+
+# UI WebPage
+kogito.data-index.ui.path=ui
\ No newline at end of file
diff --git
a/data-index/data-index-service/data-index-service-inmemory/src/test/resources/ui/index.html
b/data-index/data-index-service/data-index-service-inmemory/src/test/resources/ui/index.html
new file mode 100644
index 000000000..78b760f12
--- /dev/null
+++
b/data-index/data-index-service/data-index-service-inmemory/src/test/resources/ui/index.html
@@ -0,0 +1 @@
+<html><body><h1>Test Index</h1></body></html>
\ No newline at end of file
diff --git
a/data-index/data-index-service/data-index-service-inmemory/src/test/resources/ui/styles.css
b/data-index/data-index-service/data-index-service-inmemory/src/test/resources/ui/styles.css
new file mode 100644
index 000000000..0c10f6314
--- /dev/null
+++
b/data-index/data-index-service/data-index-service-inmemory/src/test/resources/ui/styles.css
@@ -0,0 +1 @@
+body { background: #fff; }
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]