Skip to content

Commit

Permalink
Merge pull request #14622 from glefloch/fix/14484
Browse files Browse the repository at this point in the history
Enhance dev console for hibernate-search extension
  • Loading branch information
glefloch authored Feb 1, 2021
2 parents d0f762b + a02781a commit 237b725
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<a href="{urlbase}/entities" class="badge badge-light">
<i class="fa fa-search fa-fw"></i>
Indexed entities <span class="badge badge-light">{info:entities.size()}</span></a>
<br>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{#include main}
{#title}Index Entities{/title}
{#body}
<form method="post" enctype="application/x-www-form-urlencoded">
<input id="index" type="submit" class="btn btn-primary mb-2" value="Reindex Entities" >
<table id="table" class="table table-striped">
<thead class="thead-dark">
<tr>
<th scope="col">
<div class="custom-control">
<input type="checkbox" class="form-check-input" id="check-all">
</div>
</th>
<th scope="col">Entity</th>
</tr>
</thead>
<tbody>
{#for entity in info:entities}
<tr>
<td>
<div class="custom-control">
<input type="checkbox" class="form-check-input checkbox" name="{entity}" id="{entity}">
</div>
</td>
<td>{entity}</td>
</tr>
{/for}
</tbody>
</table>
</form>
<script type="text/javascript">
jQuery('#check-all').change(function() {
if (this.checked) {
jQuery('.checkbox').prop('checked', true);
} else {
jQuery('.checkbox').prop('checked', false);
}
});
</script>
{/body}
{/include}
10 changes: 10 additions & 0 deletions extensions/hibernate-search-orm-elasticsearch/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>svm</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http</artifactId>
<optional>true</optional>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<RoutingContext> 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));
}
};
}
}
Original file line number Diff line number Diff line change
@@ -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<List<String>> {
@Override
public List<String> get() {
return searchMapping().allIndexedEntities().stream().map(SearchIndexedEntity::jpaName).sorted()
.collect(Collectors.toList());

}

public static SearchMapping searchMapping() {
return Arc.container().instance(SearchMapping.class).get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
</title>
</head>
<body>
<script src="{frameworkRootPath}/dev/resources/js/jquery-3.5.1.min.js"></script>
<script src="{frameworkRootPath}/dev/resources/js/bootstrap.bundle.min.js"></script>
<nav class="navbar sticky-top navbar-dark bg-dark">
<a class="navbar-brand" href="{frameworkRootPath}/dev/">
<img src="{frameworkRootPath}/dev/resources/images/quarkus_icon_rgb_reverse.svg" width="40" height="30" class="d-inline-block align-middle" alt="Quarkus"/>
Expand Down Expand Up @@ -59,8 +61,6 @@
{/if}
{#insert body/}
</div>
<script src="{frameworkRootPath}/dev/resources/js/jquery-3.5.1.min.js"></script>
<script src="{frameworkRootPath}/dev/resources/js/bootstrap.bundle.min.js"></script>
{|
<script>
if (jQuery(".alert").length) {
Expand Down

0 comments on commit 237b725

Please sign in to comment.