From 16f585d60d6d5db1e6c49b745933f1cc81ed28f7 Mon Sep 17 00:00:00 2001 From: bbimber Date: Fri, 30 Oct 2026 07:01:42 -0700 Subject: [PATCH] Promote methods to AbstractNotification --- .../notification/AbstractNotification.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/LDK/api-src/org/labkey/api/ldk/notification/AbstractNotification.java b/LDK/api-src/org/labkey/api/ldk/notification/AbstractNotification.java index 39587709..cd0ce795 100644 --- a/LDK/api-src/org/labkey/api/ldk/notification/AbstractNotification.java +++ b/LDK/api-src/org/labkey/api/ldk/notification/AbstractNotification.java @@ -19,8 +19,13 @@ import org.jetbrains.annotations.Nullable; import org.labkey.api.data.Container; import org.labkey.api.data.SimpleFilter; +import org.labkey.api.data.TableInfo; +import org.labkey.api.data.TableSelector; import org.labkey.api.module.Module; +import org.labkey.api.query.QueryService; import org.labkey.api.query.QueryUrls; +import org.labkey.api.query.UserSchema; +import org.labkey.api.security.User; import org.labkey.api.settings.LookAndFeelProperties; import org.labkey.api.util.PageFlowUtil; import org.labkey.api.util.logging.LogHelper; @@ -85,4 +90,40 @@ public Module getOwnerModule() { return _owner; } + + protected void genericQueryCheck(Container c, User u, StringBuilder msg, String schemaName, String queryName, String message) + { + genericQueryCheck(c, u, msg, schemaName, queryName, message, null); + } + + protected void genericQueryCheck(Container c, User u, StringBuilder msg, String schemaName, String queryName, String message, @Nullable SimpleFilter filter) + { + TableInfo ti = getTableInfo(u, c, schemaName, queryName); + + TableSelector ts = new TableSelector(ti, filter, null); + long count = ts.getRowCount(); + if (count > 0) + { + msg.append("WARNING: There are ").append(count).append(" ").append(message).append("
\n"); + msg.append("

Click here to view them
\n\n"); + msg.append("


\n\n"); + } + } + + protected TableInfo getTableInfo(User u, Container c, String schemaName, String queryName) + { + UserSchema us = QueryService.get().getUserSchema(u, c, schemaName); + if (us == null) + { + throw new IllegalStateException("Missing user schema: " + schemaName); + } + + TableInfo ti = us.getTable(queryName); + if (ti == null) + { + throw new IllegalStateException("Missing table: " + schemaName + "." + queryName); + } + + return ti; + } }