forked from bimberlabinternal/LabDevKitModules
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAbstractNotification.java
More file actions
88 lines (74 loc) · 3.05 KB
/
Copy pathAbstractNotification.java
File metadata and controls
88 lines (74 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Copyright (c) 2015-2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey.api.ldk.notification;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.data.Container;
import org.labkey.api.data.SimpleFilter;
import org.labkey.api.module.Module;
import org.labkey.api.query.QueryUrls;
import org.labkey.api.settings.LookAndFeelProperties;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.util.logging.LogHelper;
import org.labkey.api.view.ActionURL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
abstract public class AbstractNotification implements Notification
{
private final Module _owner;
protected final static Logger log = LogHelper.getLogger(AbstractNotification.class, "LDK notification errors");
protected final static SimpleDateFormat _timeFormat = new SimpleDateFormat("kk:mm");
protected final static QueryUrls _queryUrls = PageFlowUtil.urlProvider(QueryUrls.class);
public AbstractNotification(Module owner)
{
_owner = owner;
}
@Override
public boolean isAvailable(Container c)
{
return c.getActiveModules().contains(_owner);
}
protected String getExecuteQueryUrl(Container c, String schemaName, String queryName, @Nullable String viewName)
{
return getExecuteQueryUrl(c, schemaName, queryName, viewName, null);
}
/**
* Returned URL always contains a couple parameters and therefore always has a "?". It should return an ActionURL,
* but there is a lot of legacy URL string manipulation migrated into java, and it's not worth changing all of it
* at this point.
*/
protected String getExecuteQueryUrl(Container c, String schemaName, String queryName, @Nullable String viewName, @Nullable SimpleFilter filter)
{
ActionURL url = _queryUrls.urlExecuteQuery(c, schemaName, queryName);
if (viewName != null)
url.addParameter("query.viewName", viewName);
if (filter != null)
filter.applyToURL(url, "query");
return url.getURIString(); // Return an absolute URL since links are sent via email
}
public DateFormat getDateFormat(Container c)
{
return new SimpleDateFormat(LookAndFeelProperties.getInstance(c).getDefaultDateFormat());
}
public DateFormat getDateTimeFormat(Container c)
{
return new SimpleDateFormat(LookAndFeelProperties.getInstance(c).getDefaultDateTimeFormat());
}
public Module getOwnerModule()
{
return _owner;
}
}