5048 |
17 Aug 09 |
nicklas |
1 |
<%-- $Id$ |
5048 |
17 Aug 09 |
nicklas |
2 |
------------------------------------------------------------------ |
5048 |
17 Aug 09 |
nicklas |
Copyright (C) 2005 Nicklas Nordborg |
5425 |
23 Sep 10 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
5048 |
17 Aug 09 |
nicklas |
5 |
|
5048 |
17 Aug 09 |
nicklas |
6 |
This file is part of BASE - BioArray Software Environment. |
5048 |
17 Aug 09 |
nicklas |
7 |
Available at http://base.thep.lu.se/ |
5048 |
17 Aug 09 |
nicklas |
8 |
|
5048 |
17 Aug 09 |
nicklas |
9 |
BASE is free software; you can redistribute it and/or |
5048 |
17 Aug 09 |
nicklas |
10 |
modify it under the terms of the GNU General Public License |
5048 |
17 Aug 09 |
nicklas |
11 |
as published by the Free Software Foundation; either version 3 |
5048 |
17 Aug 09 |
nicklas |
12 |
of the License, or (at your option) any later version. |
5048 |
17 Aug 09 |
nicklas |
13 |
|
5048 |
17 Aug 09 |
nicklas |
14 |
BASE is distributed in the hope that it will be useful, |
5048 |
17 Aug 09 |
nicklas |
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5048 |
17 Aug 09 |
nicklas |
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5048 |
17 Aug 09 |
nicklas |
17 |
GNU General Public License for more details. |
5048 |
17 Aug 09 |
nicklas |
18 |
|
5048 |
17 Aug 09 |
nicklas |
19 |
You should have received a copy of the GNU General Public License |
5048 |
17 Aug 09 |
nicklas |
20 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5048 |
17 Aug 09 |
nicklas |
21 |
------------------------------------------------------------------ |
5048 |
17 Aug 09 |
nicklas |
22 |
|
5048 |
17 Aug 09 |
nicklas |
23 |
@author Nicklas |
5048 |
17 Aug 09 |
nicklas |
24 |
@version 2.0 |
5048 |
17 Aug 09 |
nicklas |
25 |
--%> |
5426 |
24 Sep 10 |
nicklas |
26 |
<%@ page pageEncoding="UTF-8" session="false" |
5048 |
17 Aug 09 |
nicklas |
27 |
import="net.sf.basedb.core.SessionControl" |
5048 |
17 Aug 09 |
nicklas |
28 |
import="net.sf.basedb.core.DbControl" |
5048 |
17 Aug 09 |
nicklas |
29 |
import="net.sf.basedb.core.Item" |
5048 |
17 Aug 09 |
nicklas |
30 |
import="net.sf.basedb.core.Include" |
5048 |
17 Aug 09 |
nicklas |
31 |
import="net.sf.basedb.core.BasicItem" |
5048 |
17 Aug 09 |
nicklas |
32 |
import="net.sf.basedb.core.ChangeHistory" |
7952 |
12 May 21 |
nicklas |
33 |
import="net.sf.basedb.core.Session" |
5048 |
17 Aug 09 |
nicklas |
34 |
import="net.sf.basedb.core.ItemQuery" |
5048 |
17 Aug 09 |
nicklas |
35 |
import="net.sf.basedb.core.ItemResultIterator" |
5048 |
17 Aug 09 |
nicklas |
36 |
import="net.sf.basedb.core.Permission" |
5048 |
17 Aug 09 |
nicklas |
37 |
import="net.sf.basedb.core.ItemContext" |
5048 |
17 Aug 09 |
nicklas |
38 |
import="net.sf.basedb.core.MultiPermissions" |
5048 |
17 Aug 09 |
nicklas |
39 |
import="net.sf.basedb.core.OwnedItem" |
5048 |
17 Aug 09 |
nicklas |
40 |
import="net.sf.basedb.core.PermissionDeniedException" |
5048 |
17 Aug 09 |
nicklas |
41 |
import="net.sf.basedb.core.ItemAlreadyExistsException" |
5048 |
17 Aug 09 |
nicklas |
42 |
import="net.sf.basedb.core.Sample" |
5048 |
17 Aug 09 |
nicklas |
43 |
import="net.sf.basedb.core.query.Hql" |
5048 |
17 Aug 09 |
nicklas |
44 |
import="net.sf.basedb.core.query.Orders" |
5048 |
17 Aug 09 |
nicklas |
45 |
import="net.sf.basedb.core.query.Restrictions" |
5048 |
17 Aug 09 |
nicklas |
46 |
import="net.sf.basedb.core.query.Expressions" |
7952 |
12 May 21 |
nicklas |
47 |
import="net.sf.basedb.core.log.ChangeTypeFormatter" |
5048 |
17 Aug 09 |
nicklas |
48 |
import="net.sf.basedb.util.RemovableUtil" |
5048 |
17 Aug 09 |
nicklas |
49 |
import="net.sf.basedb.util.ShareableUtil" |
5048 |
17 Aug 09 |
nicklas |
50 |
import="net.sf.basedb.util.OwnableUtil" |
5048 |
17 Aug 09 |
nicklas |
51 |
import="net.sf.basedb.util.formatter.NameableFormatter" |
7952 |
12 May 21 |
nicklas |
52 |
import="net.sf.basedb.util.formatter.ItemTypeFormatter" |
5048 |
17 Aug 09 |
nicklas |
53 |
import="net.sf.basedb.clients.web.Base" |
5048 |
17 Aug 09 |
nicklas |
54 |
import="net.sf.basedb.clients.web.WebException" |
5048 |
17 Aug 09 |
nicklas |
55 |
import="net.sf.basedb.util.Values" |
5048 |
17 Aug 09 |
nicklas |
56 |
import="net.sf.basedb.clients.web.plugins.ItemQueryLoader" |
5048 |
17 Aug 09 |
nicklas |
57 |
import="net.sf.basedb.clients.web.util.HTML" |
6040 |
30 Mar 12 |
nicklas |
58 |
import="net.sf.basedb.core.plugin.GuiContext" |
6040 |
30 Mar 12 |
nicklas |
59 |
import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
6355 |
26 Nov 13 |
nicklas |
60 |
import="net.sf.basedb.clients.web.plugins.ChangeHistoryDetailLoader" |
7952 |
12 May 21 |
nicklas |
61 |
import="net.sf.basedb.clients.web.plugins.ChangeHistoryItemLoader" |
6040 |
30 Mar 12 |
nicklas |
62 |
import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
6040 |
30 Mar 12 |
nicklas |
63 |
import="net.sf.basedb.clients.web.extensions.JspContext" |
6040 |
30 Mar 12 |
nicklas |
64 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer" |
7604 |
25 Feb 19 |
nicklas |
65 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnAction" |
6040 |
30 Mar 12 |
nicklas |
66 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil" |
7952 |
12 May 21 |
nicklas |
67 |
import="net.sf.basedb.clients.web.formatter.AutoItemExportFormatter" |
5048 |
17 Aug 09 |
nicklas |
68 |
import="java.util.Enumeration" |
5048 |
17 Aug 09 |
nicklas |
69 |
import="java.util.Set" |
5048 |
17 Aug 09 |
nicklas |
70 |
import="java.util.HashSet" |
5048 |
17 Aug 09 |
nicklas |
71 |
import="java.util.List" |
5048 |
17 Aug 09 |
nicklas |
72 |
import="java.util.ArrayList" |
5048 |
17 Aug 09 |
nicklas |
73 |
import="java.util.Collections" |
5048 |
17 Aug 09 |
nicklas |
74 |
%> |
5048 |
17 Aug 09 |
nicklas |
75 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
5048 |
17 Aug 09 |
nicklas |
76 |
<%! |
5048 |
17 Aug 09 |
nicklas |
77 |
private static final ItemContext defaultContext = |
7982 |
14 Jun 21 |
nicklas |
78 |
Base.createDefaultContext("-$hst.time", "time,changeType,changeInfo,transaction,user", "time"); |
5048 |
17 Aug 09 |
nicklas |
79 |
private static final Item itemType = Item.CHANGEHISTORY; |
6355 |
26 Nov 13 |
nicklas |
80 |
|
6355 |
26 Nov 13 |
nicklas |
81 |
private static void registerExportUtils(ItemContext cc) |
6355 |
26 Nov 13 |
nicklas |
82 |
{ |
6355 |
26 Nov 13 |
nicklas |
83 |
// Register dataloaders for old and new values |
6355 |
26 Nov 13 |
nicklas |
84 |
cc.setObject("export.dataloader.oldValue", new ChangeHistoryDetailLoader(true)); |
6355 |
26 Nov 13 |
nicklas |
85 |
cc.setObject("export.dataloader.newValue", new ChangeHistoryDetailLoader(false)); |
7952 |
12 May 21 |
nicklas |
86 |
cc.setObject("export.dataloader.item", new ChangeHistoryItemLoader()); |
7952 |
12 May 21 |
nicklas |
87 |
cc.setObject("export.formatter.item", new AutoItemExportFormatter()); |
7952 |
12 May 21 |
nicklas |
88 |
cc.setObject("export.formatter.changeType", new ChangeTypeFormatter()); |
7952 |
12 May 21 |
nicklas |
89 |
cc.setObject("export.formatter.itemType", new ItemTypeFormatter()); |
6355 |
26 Nov 13 |
nicklas |
90 |
} |
5048 |
17 Aug 09 |
nicklas |
91 |
%> |
5048 |
17 Aug 09 |
nicklas |
92 |
<% |
5048 |
17 Aug 09 |
nicklas |
93 |
final int sourceId = Values.getInt(request.getParameter("source_id")); |
6244 |
25 Feb 13 |
nicklas |
94 |
final Item sourceType = request.getParameter("source_type") != null ? |
6244 |
25 Feb 13 |
nicklas |
95 |
Item.valueOf(request.getParameter("source_type")) : null; |
7952 |
12 May 21 |
nicklas |
96 |
final boolean isSessionLog = sourceType == Item.SESSION; |
7952 |
12 May 21 |
nicklas |
97 |
final String subContext = isSessionLog ? "session-log":""; |
5048 |
17 Aug 09 |
nicklas |
98 |
|
5048 |
17 Aug 09 |
nicklas |
99 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
5048 |
17 Aug 09 |
nicklas |
100 |
final String ID = sc.getId(); |
5048 |
17 Aug 09 |
nicklas |
101 |
final String cmd = request.getParameter("cmd"); |
5048 |
17 Aug 09 |
nicklas |
102 |
final String root = request.getContextPath()+"/"; |
5048 |
17 Aug 09 |
nicklas |
103 |
final String mode = request.getParameter("mode"); |
5048 |
17 Aug 09 |
nicklas |
104 |
final String callback = request.getParameter("callback"); |
5048 |
17 Aug 09 |
nicklas |
105 |
final String itemId = request.getParameter("item_id"); |
7952 |
12 May 21 |
nicklas |
106 |
final int transactId = Values.getInt(request.getParameter("transact_id")); |
5048 |
17 Aug 09 |
nicklas |
107 |
final String listPage = "list_history.jsp?ID="+ID |
5048 |
17 Aug 09 |
nicklas |
108 |
+"&source_id="+sourceId |
6244 |
25 Feb 13 |
nicklas |
109 |
+(sourceType == null ? "" : "&source_type="+sourceType.name()) |
5048 |
17 Aug 09 |
nicklas |
110 |
+(mode == null ? "" : "&mode="+mode) |
5048 |
17 Aug 09 |
nicklas |
111 |
+(callback == null ? "" : "&callback="+callback) |
7952 |
12 May 21 |
nicklas |
112 |
+(itemId == null ? "" : "&item_id="+itemId) |
7952 |
12 May 21 |
nicklas |
113 |
+(transactId == 0 ? "" : "&transact_id="+transactId); |
5048 |
17 Aug 09 |
nicklas |
114 |
final String viewPage = "view_history.jsp?ID="+ID; |
5048 |
17 Aug 09 |
nicklas |
115 |
|
5048 |
17 Aug 09 |
nicklas |
116 |
String forward = null; |
5048 |
17 Aug 09 |
nicklas |
117 |
String redirect = null; |
5048 |
17 Aug 09 |
nicklas |
118 |
String message = null; |
5048 |
17 Aug 09 |
nicklas |
119 |
DbControl dc = null; |
5048 |
17 Aug 09 |
nicklas |
120 |
|
5048 |
17 Aug 09 |
nicklas |
121 |
try |
5048 |
17 Aug 09 |
nicklas |
122 |
{ |
5048 |
17 Aug 09 |
nicklas |
123 |
if (cmd == null || "List".equals(cmd)) |
5048 |
17 Aug 09 |
nicklas |
124 |
{ |
5048 |
17 Aug 09 |
nicklas |
125 |
// Display the list page without updatinging the current context |
7952 |
12 May 21 |
nicklas |
126 |
Base.getAndSetCurrentContext(sc, itemType, subContext, (PageContext)null, defaultContext, true); |
5048 |
17 Aug 09 |
nicklas |
127 |
redirect = listPage; |
5048 |
17 Aug 09 |
nicklas |
128 |
} |
5048 |
17 Aug 09 |
nicklas |
129 |
else if ("UpdateContext".equals(cmd)) |
5048 |
17 Aug 09 |
nicklas |
130 |
{ |
5048 |
17 Aug 09 |
nicklas |
131 |
// Display the list page after updating the current context from the request parameters |
7952 |
12 May 21 |
nicklas |
132 |
Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
5048 |
17 Aug 09 |
nicklas |
133 |
redirect = listPage; |
5048 |
17 Aug 09 |
nicklas |
134 |
} |
5048 |
17 Aug 09 |
nicklas |
135 |
else if ("LoadContext".equals(cmd)) |
5048 |
17 Aug 09 |
nicklas |
136 |
{ |
5048 |
17 Aug 09 |
nicklas |
137 |
// Display the list page after loading a saved context |
5048 |
17 Aug 09 |
nicklas |
138 |
int contextId = Values.getInt(request.getParameter("context")); |
5048 |
17 Aug 09 |
nicklas |
139 |
Base.loadContext(sc, contextId, defaultContext); |
5048 |
17 Aug 09 |
nicklas |
140 |
redirect = listPage; |
5048 |
17 Aug 09 |
nicklas |
141 |
} |
5048 |
17 Aug 09 |
nicklas |
142 |
|
5048 |
17 Aug 09 |
nicklas |
143 |
else if ("ViewItem".equals(cmd)) |
5048 |
17 Aug 09 |
nicklas |
144 |
{ |
5048 |
17 Aug 09 |
nicklas |
145 |
// Display the view page for a single item |
7952 |
12 May 21 |
nicklas |
146 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
5048 |
17 Aug 09 |
nicklas |
147 |
forward = viewPage; |
5048 |
17 Aug 09 |
nicklas |
148 |
} |
5048 |
17 Aug 09 |
nicklas |
149 |
else if ("ExportItems".equals(cmd)) |
5048 |
17 Aug 09 |
nicklas |
150 |
{ |
5048 |
17 Aug 09 |
nicklas |
151 |
// Run an export plugin in a list context |
7952 |
12 May 21 |
nicklas |
152 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
7954 |
12 May 21 |
nicklas |
153 |
dc = sc.newDbControl(":Export "+itemType); |
5048 |
17 Aug 09 |
nicklas |
154 |
BasicItem source = sourceType.getById(dc, sourceId); |
7952 |
12 May 21 |
nicklas |
155 |
final ItemQuery<ChangeHistory> query = isSessionLog ? ChangeHistory.getChangesIn((Session)source) : ChangeHistory.getHistoryOf(source); |
7914 |
23 Feb 21 |
nicklas |
156 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
157 |
cc.configureQuery(dc, query, jspContext, true); |
7952 |
12 May 21 |
nicklas |
158 |
if (transactId > 0) |
7952 |
12 May 21 |
nicklas |
159 |
{ |
7952 |
12 May 21 |
nicklas |
160 |
query.restrict(Restrictions.eq(Hql.property("hst", "id"), Expressions.integer(transactId))); |
7952 |
12 May 21 |
nicklas |
161 |
} |
6355 |
26 Nov 13 |
nicklas |
162 |
registerExportUtils(cc); |
6040 |
30 Mar 12 |
nicklas |
163 |
cc.setQuery(query); |
7604 |
25 Feb 19 |
nicklas |
164 |
ExtensionsInvoker<ListColumnAction<ChangeHistory,?>> listInvoker = ListColumnUtil.useExtensions(jspContext); |
7604 |
25 Feb 19 |
nicklas |
165 |
listInvoker.render(new ListColumnExportRenderer<ChangeHistory>(cc)); |
5590 |
16 Mar 11 |
nicklas |
166 |
dc.close(); |
7952 |
12 May 21 |
nicklas |
167 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&subcontext="+subContext+"&title=Export+change+history"; |
5048 |
17 Aug 09 |
nicklas |
168 |
} |
5048 |
17 Aug 09 |
nicklas |
169 |
else if ("ExportItem".equals(cmd)) |
5048 |
17 Aug 09 |
nicklas |
170 |
{ |
5048 |
17 Aug 09 |
nicklas |
171 |
// Run an export plugin in single-item context |
5048 |
17 Aug 09 |
nicklas |
172 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
7952 |
12 May 21 |
nicklas |
173 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&subcontext="+subContext+"&title=Export+change+history"; |
5048 |
17 Aug 09 |
nicklas |
174 |
} |
5048 |
17 Aug 09 |
nicklas |
175 |
else |
5048 |
17 Aug 09 |
nicklas |
176 |
{ |
5048 |
17 Aug 09 |
nicklas |
177 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
5048 |
17 Aug 09 |
nicklas |
178 |
} |
5048 |
17 Aug 09 |
nicklas |
179 |
} |
5048 |
17 Aug 09 |
nicklas |
180 |
finally |
5048 |
17 Aug 09 |
nicklas |
181 |
{ |
5048 |
17 Aug 09 |
nicklas |
182 |
if (dc != null) dc.close(); |
5048 |
17 Aug 09 |
nicklas |
183 |
} |
5048 |
17 Aug 09 |
nicklas |
184 |
|
5048 |
17 Aug 09 |
nicklas |
185 |
if (forward != null) |
5048 |
17 Aug 09 |
nicklas |
186 |
{ |
6192 |
31 Oct 12 |
nicklas |
187 |
sc.setSessionSetting("alert-message", message); |
5048 |
17 Aug 09 |
nicklas |
188 |
pageContext.forward(forward); |
5048 |
17 Aug 09 |
nicklas |
189 |
} |
5048 |
17 Aug 09 |
nicklas |
190 |
else if (redirect != null) |
5048 |
17 Aug 09 |
nicklas |
191 |
{ |
6192 |
31 Oct 12 |
nicklas |
192 |
sc.setSessionSetting("alert-message", message); |
5048 |
17 Aug 09 |
nicklas |
193 |
response.sendRedirect(redirect); |
5048 |
17 Aug 09 |
nicklas |
194 |
} |
5048 |
17 Aug 09 |
nicklas |
195 |
else if (message == null) |
5048 |
17 Aug 09 |
nicklas |
196 |
{ |
5048 |
17 Aug 09 |
nicklas |
197 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
5048 |
17 Aug 09 |
nicklas |
198 |
} |
5048 |
17 Aug 09 |
nicklas |
199 |
else |
5048 |
17 Aug 09 |
nicklas |
200 |
{ |
5048 |
17 Aug 09 |
nicklas |
201 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
5048 |
17 Aug 09 |
nicklas |
202 |
} |
5048 |
17 Aug 09 |
nicklas |
203 |
%> |
5048 |
17 Aug 09 |
nicklas |
204 |
|