Skip to content

Commit 3a571fd

Browse files
authored
Migrate some String URL handling to ActionURL (#138)
1 parent 455baec commit 3a571fd

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

LDK/api-src/org/labkey/api/ldk/notification/AbstractNotification.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
*/
1616
package org.labkey.api.ldk.notification;
1717

18-
import org.apache.logging.log4j.LogManager;
1918
import org.apache.logging.log4j.Logger;
2019
import org.jetbrains.annotations.Nullable;
2120
import org.labkey.api.data.Container;
2221
import org.labkey.api.data.SimpleFilter;
2322
import org.labkey.api.module.Module;
24-
import org.labkey.api.query.DetailsURL;
25-
import org.labkey.api.settings.AppProps;
23+
import org.labkey.api.query.QueryUrls;
2624
import org.labkey.api.settings.LookAndFeelProperties;
25+
import org.labkey.api.util.PageFlowUtil;
26+
import org.labkey.api.util.logging.LogHelper;
27+
import org.labkey.api.view.ActionURL;
2728

2829
import java.text.DateFormat;
2930
import java.text.SimpleDateFormat;
@@ -35,14 +36,19 @@
3536
*/
3637
abstract public class AbstractNotification implements Notification
3738
{
38-
private Module _owner;
39+
private final Module _owner;
3940

40-
protected final static Logger log = LogManager.getLogger(AbstractNotification.class);
41+
protected final static Logger log = LogHelper.getLogger(AbstractNotification.class, "LDK notification errors");
4142
protected final static SimpleDateFormat _timeFormat = new SimpleDateFormat("kk:mm");
43+
protected final static QueryUrls _queryUrls = PageFlowUtil.urlProvider(QueryUrls.class);
4244

4345
public AbstractNotification(Module owner)
4446
{
4547
_owner = owner;
48+
49+
// AbstractNotifications must be constructed after QueryUrls has been registered, typically in startup() or
50+
// doStartupAfterSpringConfig()
51+
assert _queryUrls != null;
4652
}
4753

4854
@Override
@@ -57,21 +63,21 @@ protected String getExecuteQueryUrl(Container c, String schemaName, String query
5763
}
5864

5965
/**
60-
* This should really be using URLHelpers better, but there is a lot of legacy URL strings
61-
* migrated into java and its not worth changing all of it at this point
66+
* Returned URL always contains a couple parameters and therefore always has a "?". It should return an ActionURL,
67+
* but there is a lot of legacy URL string manipulation migrated into java, and it's not worth changing all of it
68+
* at this point.
6269
*/
6370
protected String getExecuteQueryUrl(Container c, String schemaName, String queryName, @Nullable String viewName, @Nullable SimpleFilter filter)
6471
{
65-
DetailsURL url = DetailsURL.fromString("/query/executeQuery.view", c);
66-
String ret = AppProps.getInstance().getBaseServerUrl() + url.getActionURL().toString();
67-
ret += "schemaName=" + schemaName + "&query.queryName=" + queryName;
72+
ActionURL url = _queryUrls.urlExecuteQuery(c, schemaName, queryName);
73+
6874
if (viewName != null)
69-
ret += "&query.viewName=" + viewName;
75+
url.addParameter("query.viewName", viewName);
7076

71-
if (filter != null)
72-
ret += "&" + filter.toQueryString("query");
77+
if (filter != null)
78+
filter.applyToURL(url, "query");
7379

74-
return ret;
80+
return url.getURIString(); // Return an absolute URL since links are sent via email
7581
}
7682

7783
public DateFormat getDateFormat(Container c)

LDK/api-src/org/labkey/api/ldk/notification/NotificationService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ static public void setInstance(NotificationService instance)
4444
_instance = instance;
4545
}
4646

47+
/**
48+
* Note: Register all notifications in startup() or doStartupAfterSpringConfig() (not init())
49+
*/
4750
abstract public void registerNotification(Notification notification);
4851

4952
abstract public Set<Notification> getNotifications(Container c, boolean includeAll);

0 commit comments

Comments
 (0)