-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14622 from glefloch/fix/14484
Enhance dev console for hibernate-search extension
- Loading branch information
Showing
7 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...in/java/io/quarkus/hibernate/search/orm/elasticsearch/devconsole/DevConsoleProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...ernate-search-orm-elasticsearch/deployment/src/main/resources/dev-templates/embedded.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
41 changes: 41 additions & 0 deletions
41
...ernate-search-orm-elasticsearch/deployment/src/main/resources/dev-templates/entities.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ernate/search/orm/elasticsearch/runtime/devconsole/HibernateSearchDevConsoleRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
}; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...uarkus/hibernate/search/orm/elasticsearch/runtime/devconsole/HibernateSearchSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters