From 7cc0be54904b9b4c21e85e2113ae3943a5ca6d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 1 Mar 2021 12:05:05 +0100 Subject: [PATCH 1/2] Avoid NPE in dev console when there aren't any indexed entities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yoann Rodière --- .../devconsole/HibernateSearchDevConsoleRecorder.java | 11 ++++++++--- .../runtime/devconsole/HibernateSearchSupplier.java | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) 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 index cd49ef9553ef3..8fd3fa32ad1f4 100644 --- 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 @@ -7,6 +7,7 @@ import org.hibernate.search.mapper.orm.mapping.SearchMapping; import io.quarkus.devconsole.runtime.spi.DevConsolePostHandler; +import io.quarkus.devconsole.runtime.spi.FlashScopeUtil; import io.quarkus.runtime.annotations.Recorder; import io.vertx.core.Handler; import io.vertx.core.MultiMap; @@ -22,9 +23,13 @@ protected void handlePostAsync(RoutingContext event, MultiMap form) throws Excep if (form.isEmpty()) { return; } - SearchMapping searchMapping = HibernateSearchSupplier.searchMapping(); - searchMapping.scope(Object.class, - searchMapping.allIndexedEntities().stream() + SearchMapping mapping = HibernateSearchSupplier.searchMapping(); + if (mapping == null) { + flashMessage(event, "There aren't any indexed entities!", FlashScopeUtil.FlashMessageStatus.ERROR); + return; + } + mapping.scope(Object.class, + mapping.allIndexedEntities().stream() .map(SearchIndexedEntity::jpaName) .filter(form::contains) .collect(Collectors.toList())) 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 index 4666a20a0f97f..1f6cb8579a691 100644 --- 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 @@ -1,5 +1,6 @@ package io.quarkus.hibernate.search.orm.elasticsearch.runtime.devconsole; +import java.util.Collections; import java.util.List; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -12,7 +13,11 @@ public class HibernateSearchSupplier implements Supplier> { @Override public List get() { - return searchMapping().allIndexedEntities().stream().map(SearchIndexedEntity::jpaName).sorted() + SearchMapping mapping = searchMapping(); + if (mapping == null) { + return Collections.emptyList(); + } + return mapping.allIndexedEntities().stream().map(SearchIndexedEntity::jpaName).sorted() .collect(Collectors.toList()); } From 05e7d506899fbf7d4d3b6b50684ae107b9630a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 1 Mar 2021 13:29:05 +0100 Subject: [PATCH 2/2] Avoid confusion between entity instances and entity types in the HSearch devcard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yoann Rodière --- .../orm/elasticsearch/devconsole/DevConsoleProcessor.java | 4 ++-- .../src/main/resources/dev-templates/embedded.html | 4 ++-- .../dev-templates/{entities.html => entity-types.html} | 8 ++++---- .../devconsole/HibernateSearchDevConsoleRecorder.java | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) rename extensions/hibernate-search-orm-elasticsearch/deployment/src/main/resources/dev-templates/{entities.html => entity-types.html} (85%) 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 index 94d1c46300e91..a4e2f90932ed4 100644 --- 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 @@ -14,12 +14,12 @@ public class DevConsoleProcessor { @BuildStep(onlyIf = IsDevelopment.class) public DevConsoleRuntimeTemplateInfoBuildItem collectBeanInfo() { - return new DevConsoleRuntimeTemplateInfoBuildItem("entities", new HibernateSearchSupplier()); + return new DevConsoleRuntimeTemplateInfoBuildItem("entityTypes", new HibernateSearchSupplier()); } @BuildStep @Record(value = STATIC_INIT, optional = true) DevConsoleRouteBuildItem invokeEndpoint(HibernateSearchDevConsoleRecorder recorder) { - return new DevConsoleRouteBuildItem("entities", "POST", recorder.indexEntity()); + return new DevConsoleRouteBuildItem("entity-types", "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 index 192a385b27b1a..7f7027a3cb8cc 100644 --- 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 @@ -1,4 +1,4 @@ - + - Indexed entities {info:entities.size()} + Indexed entity types {info:entityTypes.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/entity-types.html similarity index 85% rename from extensions/hibernate-search-orm-elasticsearch/deployment/src/main/resources/dev-templates/entities.html rename to extensions/hibernate-search-orm-elasticsearch/deployment/src/main/resources/dev-templates/entity-types.html index 3f81b7ba4ba15..a257afacb8225 100644 --- 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/entity-types.html @@ -11,18 +11,18 @@ - Entity + Entity type - {#for entity in info:entities} + {#for entityType in info:entityTypes}
- +
- {entity} + {entityType} {/for} 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 index 8fd3fa32ad1f4..c472dac77e565 100644 --- 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 @@ -25,7 +25,7 @@ protected void handlePostAsync(RoutingContext event, MultiMap form) throws Excep } SearchMapping mapping = HibernateSearchSupplier.searchMapping(); if (mapping == null) { - flashMessage(event, "There aren't any indexed entities!", FlashScopeUtil.FlashMessageStatus.ERROR); + flashMessage(event, "There aren't any indexed entity types!", FlashScopeUtil.FlashMessageStatus.ERROR); return; } mapping.scope(Object.class,