(control) Add filter dropdown to message queue table

This makes inspecting the queues for processes much easier, as it's otherwise
often these important messages are drowned out by FSM chatter.
This commit is contained in:
Viktor Lofgren 2024-01-12 18:46:17 +01:00
parent 83776a8dce
commit c0fb9e17e8
2 changed files with 58 additions and 8 deletions

View File

@ -15,10 +15,7 @@ import spark.Spark;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
@Singleton
public class MessageQueueService {
@ -61,7 +58,7 @@ public class MessageQueueService {
}
public Object listMessageQueueModel(Request request, Response response) {
public Object listMessageQueueModel(Request request, Response response) throws SQLException {
String inboxParam = request.queryParams("inbox");
String instanceParam = request.queryParams("instance");
String afterParam = request.queryParams("after");
@ -71,7 +68,7 @@ public class MessageQueueService {
List<MessageQueueEntry> entries;
String mqFilter = "filter=none";
if (inboxParam != null) {
if (inboxParam != null && !inboxParam.isBlank()) {
mqFilter = "inbox=" + inboxParam;
entries = getEntriesForInbox(inboxParam, afterId, 20);
}
@ -90,11 +87,47 @@ public class MessageQueueService {
else
next = "";
List<String> inboxes = getAllInboxes();
return Map.of("messages", entries,
"next", next,
"filterInbox", Objects.requireNonNullElse(inboxParam, ""),
"inboxes", inboxes,
"mqFilter", mqFilter);
}
private List<String> getAllInboxes() throws SQLException {
List<String> inboxes = new ArrayList<>();
try (var conn = dataSource.getConnection();
var query = conn.prepareStatement("""
SELECT DISTINCT RECIPIENT_INBOX
FROM MESSAGE_QUEUE
WHERE RECIPIENT_INBOX IS NOT NULL
"""))
{
var rs = query.executeQuery();
while (rs.next()) {
inboxes.add(rs.getString(1));
}
}
// Remove transient inboxes
inboxes.removeIf(inbox -> inbox.contains("//"));
// Sort inboxes so that fsm inboxes are last
Comparator<String> comparator = (o1, o2) -> {
int diff = Boolean.compare(o1.startsWith("fsm:"), o2.startsWith("fsm:"));
if (diff != 0)
return diff;
return o1.compareTo(o2);
};
inboxes.sort(comparator);
return inboxes;
}
public Object newMessageModel(Request request, Response response) {
String idParam = request.queryParams("id");
if (null == idParam)

View File

@ -11,7 +11,23 @@
<th>Created<br>Updated</th>
</tr>
<tr>
<td colspan="6" style="padding: 0.5ch">
<td colspan="2"></td>
<td>
{{#if inboxes}}
<div class="btn-group">
<button type="button" class="btn btn-secondary btn-sm dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Filter
</button>
<ul class="dropdown-menu">
{{#each inboxes}}
<li><a class="dropdown-item" href="/message-queue?inbox={{this}}">{{this}}&nbsp;</a></li>
{{/each}}
</ul>
</div>
{{/if}}
</td>
<td colspan="3" style="padding: 0.5ch">
<a style="float:right" href="/message-queue/new">[Add Message]</a>
</td>
</tr>
@ -47,7 +63,8 @@
{{/each}}
<tfoot>
<tr>
<td colspan="6" style="padding: 0.5ch">
<td colspan="6"></td>
<td colspan="1" style="padding: 0.5ch">
{{#if next}}<a href="?after={{next}}&{{mqFilter}}" style="float:right">Next</a>{{/if}}
</td>
</tr>