Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid NPE in dev console when there aren't any indexed entities with the Hibernate Search extension enabled #15375

Merged
merged 2 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<a href="{urlbase}/entities" class="badge badge-light">
<a href="{urlbase}/entity-types" class="badge badge-light">
<i class="fa fa-search fa-fw"></i>
Indexed entities <span class="badge badge-light">{info:entities.size()}</span></a>
Indexed entity types <span class="badge badge-light">{info:entityTypes.size()}</span></a>
<br>
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
<input type="checkbox" class="form-check-input" id="check-all">
</div>
</th>
<th scope="col">Entity</th>
<th scope="col">Entity type</th>
</tr>
</thead>
<tbody>
{#for entity in info:entities}
{#for entityType in info:entityTypes}
<tr>
<td>
<div class="custom-control">
<input type="checkbox" class="form-check-input checkbox" name="{entity}" id="{entity}">
<input type="checkbox" class="form-check-input checkbox" name="{entityType}" id="{entityType}">
</div>
</td>
<td>{entity}</td>
<td>{entityType}</td>
</tr>
{/for}
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 entity types!", FlashScopeUtil.FlashMessageStatus.ERROR);
return;
}
mapping.scope(Object.class,
mapping.allIndexedEntities().stream()
.map(SearchIndexedEntity::jpaName)
.filter(form::contains)
.collect(Collectors.toList()))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +13,11 @@
public class HibernateSearchSupplier implements Supplier<List<String>> {
@Override
public List<String> 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());

}
Expand Down