diff --git a/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/devconsole/DevConsoleProcessor.java b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/devconsole/DevConsoleProcessor.java new file mode 100644 index 0000000000000..94d1c46300e91 --- /dev/null +++ b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/devconsole/DevConsoleProcessor.java @@ -0,0 +1,25 @@ +package io.quarkus.hibernate.search.orm.elasticsearch.devconsole; + +import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT; + +import io.quarkus.deployment.IsDevelopment; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.annotations.Record; +import io.quarkus.devconsole.spi.DevConsoleRouteBuildItem; +import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem; +import io.quarkus.hibernate.search.orm.elasticsearch.runtime.devconsole.HibernateSearchDevConsoleRecorder; +import io.quarkus.hibernate.search.orm.elasticsearch.runtime.devconsole.HibernateSearchSupplier; + +public class DevConsoleProcessor { + + @BuildStep(onlyIf = IsDevelopment.class) + public DevConsoleRuntimeTemplateInfoBuildItem collectBeanInfo() { + return new DevConsoleRuntimeTemplateInfoBuildItem("entities", new HibernateSearchSupplier()); + } + + @BuildStep + @Record(value = STATIC_INIT, optional = true) + DevConsoleRouteBuildItem invokeEndpoint(HibernateSearchDevConsoleRecorder recorder) { + return new DevConsoleRouteBuildItem("entities", "POST", recorder.indexEntity()); + } +} diff --git a/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/resources/dev-templates/embedded.html b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/resources/dev-templates/embedded.html new file mode 100644 index 0000000000000..192a385b27b1a --- /dev/null +++ b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/resources/dev-templates/embedded.html @@ -0,0 +1,4 @@ + + + Indexed entities {info:entities.size()} +
diff --git a/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/resources/dev-templates/entities.html b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/resources/dev-templates/entities.html new file mode 100644 index 0000000000000..3f81b7ba4ba15 --- /dev/null +++ b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/resources/dev-templates/entities.html @@ -0,0 +1,41 @@ +{#include main} +{#title}Index Entities{/title} +{#body} +
+ + + + + + + + + + {#for entity in info:entities} + + + + + {/for} + +
+
+ +
+
Entity
+
+ +
+
{entity}
+
+ +{/body} +{/include} diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/pom.xml b/extensions/hibernate-search-orm-elasticsearch/runtime/pom.xml index 0cef80b35aaa5..55696ce4d6f35 100644 --- a/extensions/hibernate-search-orm-elasticsearch/runtime/pom.xml +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/pom.xml @@ -37,6 +37,16 @@ org.graalvm.nativeimage svm + + io.vertx + vertx-web + true + + + io.quarkus + quarkus-vertx-http + true + diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/devconsole/HibernateSearchDevConsoleRecorder.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/devconsole/HibernateSearchDevConsoleRecorder.java new file mode 100644 index 0000000000000..cd49ef9553ef3 --- /dev/null +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/devconsole/HibernateSearchDevConsoleRecorder.java @@ -0,0 +1,37 @@ +package io.quarkus.hibernate.search.orm.elasticsearch.runtime.devconsole; + +import java.time.Duration; +import java.util.stream.Collectors; + +import org.hibernate.search.mapper.orm.entity.SearchIndexedEntity; +import org.hibernate.search.mapper.orm.mapping.SearchMapping; + +import io.quarkus.devconsole.runtime.spi.DevConsolePostHandler; +import io.quarkus.runtime.annotations.Recorder; +import io.vertx.core.Handler; +import io.vertx.core.MultiMap; +import io.vertx.ext.web.RoutingContext; + +@Recorder +public class HibernateSearchDevConsoleRecorder { + + public Handler indexEntity() { + return new DevConsolePostHandler() { + @Override + protected void handlePostAsync(RoutingContext event, MultiMap form) throws Exception { + if (form.isEmpty()) { + return; + } + SearchMapping searchMapping = HibernateSearchSupplier.searchMapping(); + searchMapping.scope(Object.class, + searchMapping.allIndexedEntities().stream() + .map(SearchIndexedEntity::jpaName) + .filter(form::contains) + .collect(Collectors.toList())) + .massIndexer() + .startAndWait(); + flashMessage(event, "Entities successfully reindexed", Duration.ofSeconds(10)); + } + }; + } +} diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/devconsole/HibernateSearchSupplier.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/devconsole/HibernateSearchSupplier.java new file mode 100644 index 0000000000000..4666a20a0f97f --- /dev/null +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/devconsole/HibernateSearchSupplier.java @@ -0,0 +1,23 @@ +package io.quarkus.hibernate.search.orm.elasticsearch.runtime.devconsole; + +import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +import org.hibernate.search.mapper.orm.entity.SearchIndexedEntity; +import org.hibernate.search.mapper.orm.mapping.SearchMapping; + +import io.quarkus.arc.Arc; + +public class HibernateSearchSupplier implements Supplier> { + @Override + public List get() { + return searchMapping().allIndexedEntities().stream().map(SearchIndexedEntity::jpaName).sorted() + .collect(Collectors.toList()); + + } + + public static SearchMapping searchMapping() { + return Arc.container().instance(SearchMapping.class).get(); + } +} diff --git a/extensions/vertx-http/deployment/src/main/resources/dev-templates/main.html b/extensions/vertx-http/deployment/src/main/resources/dev-templates/main.html index a38578c0c4c41..92402c5f62c8d 100644 --- a/extensions/vertx-http/deployment/src/main/resources/dev-templates/main.html +++ b/extensions/vertx-http/deployment/src/main/resources/dev-templates/main.html @@ -25,6 +25,8 @@ + +