7601 |
22 Feb 19 |
nicklas |
1 |
<%-- $Id$ |
2929 |
17 Nov 06 |
nicklas |
2 |
------------------------------------------------------------------ |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2006 Nicklas Nordborg |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Johan Enell |
2929 |
17 Nov 06 |
nicklas |
5 |
|
2929 |
17 Nov 06 |
nicklas |
6 |
This file is part of BASE - BioArray Software Environment. |
2929 |
17 Nov 06 |
nicklas |
7 |
Available at http://base.thep.lu.se/ |
2929 |
17 Nov 06 |
nicklas |
8 |
|
2929 |
17 Nov 06 |
nicklas |
9 |
BASE is free software; you can redistribute it and/or |
2929 |
17 Nov 06 |
nicklas |
10 |
modify it under the terms of the GNU General Public License |
4476 |
05 Sep 08 |
jari |
11 |
as published by the Free Software Foundation; either version 3 |
2929 |
17 Nov 06 |
nicklas |
12 |
of the License, or (at your option) any later version. |
2929 |
17 Nov 06 |
nicklas |
13 |
|
2929 |
17 Nov 06 |
nicklas |
14 |
BASE is distributed in the hope that it will be useful, |
2929 |
17 Nov 06 |
nicklas |
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2929 |
17 Nov 06 |
nicklas |
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2929 |
17 Nov 06 |
nicklas |
17 |
GNU General Public License for more details. |
2929 |
17 Nov 06 |
nicklas |
18 |
|
2929 |
17 Nov 06 |
nicklas |
19 |
You should have received a copy of the GNU General Public License |
4510 |
11 Sep 08 |
jari |
20 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
2929 |
17 Nov 06 |
nicklas |
21 |
------------------------------------------------------------------ |
2929 |
17 Nov 06 |
nicklas |
22 |
|
2929 |
17 Nov 06 |
nicklas |
23 |
@author Nicklas |
2929 |
17 Nov 06 |
nicklas |
24 |
@version 2.0 |
2929 |
17 Nov 06 |
nicklas |
25 |
--%> |
5426 |
24 Sep 10 |
nicklas |
26 |
<%@ page pageEncoding="UTF-8" session="false" |
2929 |
17 Nov 06 |
nicklas |
27 |
import="net.sf.basedb.core.SessionControl" |
2929 |
17 Nov 06 |
nicklas |
28 |
import="net.sf.basedb.core.DbControl" |
2929 |
17 Nov 06 |
nicklas |
29 |
import="net.sf.basedb.core.Item" |
3501 |
15 Jun 07 |
enell |
30 |
import="net.sf.basedb.core.BasicItem" |
3501 |
15 Jun 07 |
enell |
31 |
import="net.sf.basedb.core.MultiPermissions" |
3501 |
15 Jun 07 |
enell |
32 |
import="net.sf.basedb.core.Removable" |
3501 |
15 Jun 07 |
enell |
33 |
import="net.sf.basedb.core.SharedItem" |
2929 |
17 Nov 06 |
nicklas |
34 |
import="net.sf.basedb.core.ItemContext" |
2929 |
17 Nov 06 |
nicklas |
35 |
import="net.sf.basedb.clients.web.Base" |
3501 |
15 Jun 07 |
enell |
36 |
import="net.sf.basedb.core.PermissionDeniedException" |
2929 |
17 Nov 06 |
nicklas |
37 |
import="net.sf.basedb.clients.web.WebException" |
2929 |
17 Nov 06 |
nicklas |
38 |
import="net.sf.basedb.clients.web.util.HTML" |
2929 |
17 Nov 06 |
nicklas |
39 |
import="net.sf.basedb.util.Values" |
3501 |
15 Jun 07 |
enell |
40 |
import="net.sf.basedb.util.RemovableUtil" |
3501 |
15 Jun 07 |
enell |
41 |
import="java.util.Enumeration" |
3501 |
15 Jun 07 |
enell |
42 |
import="java.util.HashSet" |
3501 |
15 Jun 07 |
enell |
43 |
import="java.util.Set" |
2929 |
17 Nov 06 |
nicklas |
44 |
%> |
2929 |
17 Nov 06 |
nicklas |
45 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
2929 |
17 Nov 06 |
nicklas |
46 |
<%! |
2929 |
17 Nov 06 |
nicklas |
47 |
private static final String subContext = "diskUsage"; |
2929 |
17 Nov 06 |
nicklas |
48 |
private static final ItemContext defaultContext = |
2929 |
17 Nov 06 |
nicklas |
49 |
Base.createDefaultContext("bytes", "type,name,bytes,location"); |
4701 |
11 Dec 08 |
nicklas |
50 |
static |
4701 |
11 Dec 08 |
nicklas |
51 |
{ |
4701 |
11 Dec 08 |
nicklas |
52 |
defaultContext.setSortDirection(ItemContext.SortDirection.DESC); |
4701 |
11 Dec 08 |
nicklas |
53 |
} |
2929 |
17 Nov 06 |
nicklas |
54 |
%> |
2929 |
17 Nov 06 |
nicklas |
55 |
<% |
2929 |
17 Nov 06 |
nicklas |
56 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
2929 |
17 Nov 06 |
nicklas |
57 |
final String ID = sc.getId(); |
2929 |
17 Nov 06 |
nicklas |
58 |
final String cmd = request.getParameter("cmd"); |
2929 |
17 Nov 06 |
nicklas |
59 |
final String root = request.getContextPath()+"/"; |
2929 |
17 Nov 06 |
nicklas |
60 |
final Item itemType = Item.valueOf(request.getParameter("item_type")); |
2929 |
17 Nov 06 |
nicklas |
61 |
final String viewPage = "view_details.jsp?ID="+ID+"&item_type="+itemType.name(); |
2929 |
17 Nov 06 |
nicklas |
62 |
|
2929 |
17 Nov 06 |
nicklas |
63 |
String forward = null; |
2929 |
17 Nov 06 |
nicklas |
64 |
String redirect = null; |
2929 |
17 Nov 06 |
nicklas |
65 |
String message = null; |
2929 |
17 Nov 06 |
nicklas |
66 |
DbControl dc = null; |
2929 |
17 Nov 06 |
nicklas |
67 |
|
2929 |
17 Nov 06 |
nicklas |
68 |
try |
2929 |
17 Nov 06 |
nicklas |
69 |
{ |
2929 |
17 Nov 06 |
nicklas |
70 |
if ("UpdateContext".equals(cmd)) |
2929 |
17 Nov 06 |
nicklas |
71 |
{ |
2929 |
17 Nov 06 |
nicklas |
72 |
// Display the list page after updating the current context from the request parameters |
2929 |
17 Nov 06 |
nicklas |
73 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
2929 |
17 Nov 06 |
nicklas |
74 |
redirect = viewPage; |
2929 |
17 Nov 06 |
nicklas |
75 |
} |
2929 |
17 Nov 06 |
nicklas |
76 |
else if ("LoadContext".equals(cmd)) |
2929 |
17 Nov 06 |
nicklas |
77 |
{ |
2929 |
17 Nov 06 |
nicklas |
78 |
// Display the list page after loading a saved context |
2929 |
17 Nov 06 |
nicklas |
79 |
int contextId = Values.getInt(request.getParameter("context")); |
2929 |
17 Nov 06 |
nicklas |
80 |
Base.loadContext(sc, contextId, defaultContext); |
2929 |
17 Nov 06 |
nicklas |
81 |
redirect = viewPage; |
2929 |
17 Nov 06 |
nicklas |
82 |
} |
2929 |
17 Nov 06 |
nicklas |
83 |
else if ("ViewItem".equals(cmd)) |
2929 |
17 Nov 06 |
nicklas |
84 |
{ |
2929 |
17 Nov 06 |
nicklas |
85 |
// Display the view page for a single item |
2929 |
17 Nov 06 |
nicklas |
86 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
2929 |
17 Nov 06 |
nicklas |
87 |
forward = viewPage; |
2929 |
17 Nov 06 |
nicklas |
88 |
} |
3501 |
15 Jun 07 |
enell |
89 |
else if ("DeleteItems".equals(cmd)) |
3501 |
15 Jun 07 |
enell |
90 |
{ |
3501 |
15 Jun 07 |
enell |
91 |
// Delete all selected items on the view page |
7954 |
12 May 21 |
nicklas |
92 |
dc = sc.newDbControl("Disk usage: Delete items"); |
3501 |
15 Jun 07 |
enell |
93 |
int numTotal = 0; |
3501 |
15 Jun 07 |
enell |
94 |
int numRemoved = 0; |
3501 |
15 Jun 07 |
enell |
95 |
|
7601 |
22 Feb 19 |
nicklas |
96 |
Enumeration<String> names = request.getParameterNames(); |
3501 |
15 Jun 07 |
enell |
97 |
while (names.hasMoreElements()) |
3501 |
15 Jun 07 |
enell |
98 |
{ |
3501 |
15 Jun 07 |
enell |
99 |
String name = names.nextElement(); |
3501 |
15 Jun 07 |
enell |
100 |
if (name.startsWith("item:")) |
3501 |
15 Jun 07 |
enell |
101 |
{ |
3501 |
15 Jun 07 |
enell |
102 |
Item item = Item.valueOf(name.substring(5)); |
3501 |
15 Jun 07 |
enell |
103 |
Integer[] ids = Values.getInt(request.getParameterValues(name)); |
3501 |
15 Jun 07 |
enell |
104 |
for (int itemId : ids) |
3501 |
15 Jun 07 |
enell |
105 |
{ |
3501 |
15 Jun 07 |
enell |
106 |
numTotal++; |
3501 |
15 Jun 07 |
enell |
107 |
try |
3501 |
15 Jun 07 |
enell |
108 |
{ |
3501 |
15 Jun 07 |
enell |
109 |
BasicItem basicItem = item.getById(dc, itemId); |
3501 |
15 Jun 07 |
enell |
110 |
Removable r = (Removable)basicItem; |
3501 |
15 Jun 07 |
enell |
111 |
r.setRemoved(true); |
3501 |
15 Jun 07 |
enell |
112 |
numRemoved++; |
3501 |
15 Jun 07 |
enell |
113 |
} |
3501 |
15 Jun 07 |
enell |
114 |
catch (PermissionDeniedException ex) |
3501 |
15 Jun 07 |
enell |
115 |
{} |
3501 |
15 Jun 07 |
enell |
116 |
} |
3501 |
15 Jun 07 |
enell |
117 |
} |
3501 |
15 Jun 07 |
enell |
118 |
} |
3501 |
15 Jun 07 |
enell |
119 |
dc.commit(); |
3501 |
15 Jun 07 |
enell |
120 |
if (numTotal != numRemoved) |
3501 |
15 Jun 07 |
enell |
121 |
{ |
3501 |
15 Jun 07 |
enell |
122 |
message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission"; |
3501 |
15 Jun 07 |
enell |
123 |
} |
6192 |
31 Oct 12 |
nicklas |
124 |
redirect = viewPage; |
3501 |
15 Jun 07 |
enell |
125 |
} |
3501 |
15 Jun 07 |
enell |
126 |
else if ("RestoreItems".equals(cmd)) |
3501 |
15 Jun 07 |
enell |
127 |
{ |
3501 |
15 Jun 07 |
enell |
128 |
// Restore all selected items on the view page |
7954 |
12 May 21 |
nicklas |
129 |
dc = sc.newDbControl("Disk usage: Restore items"); |
3501 |
15 Jun 07 |
enell |
130 |
int numTotal = 0; |
3501 |
15 Jun 07 |
enell |
131 |
int numRestored = 0; |
3501 |
15 Jun 07 |
enell |
132 |
|
7601 |
22 Feb 19 |
nicklas |
133 |
Enumeration<String> names = request.getParameterNames(); |
3501 |
15 Jun 07 |
enell |
134 |
while (names.hasMoreElements()) |
3501 |
15 Jun 07 |
enell |
135 |
{ |
3501 |
15 Jun 07 |
enell |
136 |
String name = names.nextElement(); |
3501 |
15 Jun 07 |
enell |
137 |
if (name.startsWith("item:")) |
3501 |
15 Jun 07 |
enell |
138 |
{ |
3501 |
15 Jun 07 |
enell |
139 |
Item item = Item.valueOf(name.substring(5)); |
3501 |
15 Jun 07 |
enell |
140 |
Integer[] ids = Values.getInt(request.getParameterValues(name)); |
3501 |
15 Jun 07 |
enell |
141 |
for (int itemId : ids) |
3501 |
15 Jun 07 |
enell |
142 |
{ |
3501 |
15 Jun 07 |
enell |
143 |
numTotal++; |
3501 |
15 Jun 07 |
enell |
144 |
try |
3501 |
15 Jun 07 |
enell |
145 |
{ |
3501 |
15 Jun 07 |
enell |
146 |
BasicItem basicItem = item.getById(dc, itemId); |
3501 |
15 Jun 07 |
enell |
147 |
Removable r = (Removable)basicItem; |
3501 |
15 Jun 07 |
enell |
148 |
r.setRemoved(false); |
3501 |
15 Jun 07 |
enell |
149 |
numRestored++; |
3501 |
15 Jun 07 |
enell |
150 |
} |
3501 |
15 Jun 07 |
enell |
151 |
catch (PermissionDeniedException ex) |
3501 |
15 Jun 07 |
enell |
152 |
{} |
3501 |
15 Jun 07 |
enell |
153 |
} |
3501 |
15 Jun 07 |
enell |
154 |
} |
3501 |
15 Jun 07 |
enell |
155 |
} |
3501 |
15 Jun 07 |
enell |
156 |
dc.commit(); |
3501 |
15 Jun 07 |
enell |
157 |
if (numTotal != numRestored) |
3501 |
15 Jun 07 |
enell |
158 |
{ |
3501 |
15 Jun 07 |
enell |
159 |
message = (numRestored == 0 ? "No" : "Only "+numRestored+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; |
3501 |
15 Jun 07 |
enell |
160 |
} |
6192 |
31 Oct 12 |
nicklas |
161 |
redirect = viewPage; |
3501 |
15 Jun 07 |
enell |
162 |
} |
3501 |
15 Jun 07 |
enell |
163 |
else if ("ShareItems".equals(cmd)) |
3501 |
15 Jun 07 |
enell |
164 |
{ |
3501 |
15 Jun 07 |
enell |
165 |
// Share all selected items in the view page |
7954 |
12 May 21 |
nicklas |
166 |
dc = sc.newDbControl("Disk usage: Share items"); |
3501 |
15 Jun 07 |
enell |
167 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
3501 |
15 Jun 07 |
enell |
168 |
|
3501 |
15 Jun 07 |
enell |
169 |
Set<SharedItem> ss = new HashSet<SharedItem>(); |
7601 |
22 Feb 19 |
nicklas |
170 |
Enumeration<String> names = request.getParameterNames(); |
3501 |
15 Jun 07 |
enell |
171 |
while (names.hasMoreElements()) |
3501 |
15 Jun 07 |
enell |
172 |
{ |
3501 |
15 Jun 07 |
enell |
173 |
String name = names.nextElement(); |
3501 |
15 Jun 07 |
enell |
174 |
if (name.startsWith("item:")) |
3501 |
15 Jun 07 |
enell |
175 |
{ |
3501 |
15 Jun 07 |
enell |
176 |
Item item = Item.valueOf(name.substring(5)); |
3501 |
15 Jun 07 |
enell |
177 |
if (SharedItem.class.isAssignableFrom(item.getItemClass())) |
3501 |
15 Jun 07 |
enell |
178 |
{ |
3501 |
15 Jun 07 |
enell |
179 |
Integer[] ids = Values.getInt(request.getParameterValues(name)); |
3501 |
15 Jun 07 |
enell |
180 |
for (int itemId : ids) |
3501 |
15 Jun 07 |
enell |
181 |
{ |
3501 |
15 Jun 07 |
enell |
182 |
ss.add((SharedItem)item.getById(dc, itemId)); |
3501 |
15 Jun 07 |
enell |
183 |
} |
3501 |
15 Jun 07 |
enell |
184 |
} |
3501 |
15 Jun 07 |
enell |
185 |
} |
3501 |
15 Jun 07 |
enell |
186 |
} |
3501 |
15 Jun 07 |
enell |
187 |
if (ss.size() == 0) |
3501 |
15 Jun 07 |
enell |
188 |
{ |
3501 |
15 Jun 07 |
enell |
189 |
throw new WebException("popup", "No shareable items selected", |
3501 |
15 Jun 07 |
enell |
190 |
"The items you selected can't be shared."); |
3501 |
15 Jun 07 |
enell |
191 |
} |
3501 |
15 Jun 07 |
enell |
192 |
cc.setObject("MultiPermissions", new MultiPermissions(ss)); |
3501 |
15 Jun 07 |
enell |
193 |
dc.close(); |
3501 |
15 Jun 07 |
enell |
194 |
redirect = "../../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name()+"&subcontext="+subContext; |
3501 |
15 Jun 07 |
enell |
195 |
} |
2929 |
17 Nov 06 |
nicklas |
196 |
else |
2929 |
17 Nov 06 |
nicklas |
197 |
{ |
2929 |
17 Nov 06 |
nicklas |
198 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
2929 |
17 Nov 06 |
nicklas |
199 |
} |
2929 |
17 Nov 06 |
nicklas |
200 |
} |
2929 |
17 Nov 06 |
nicklas |
201 |
finally |
2929 |
17 Nov 06 |
nicklas |
202 |
{ |
2929 |
17 Nov 06 |
nicklas |
203 |
if (dc != null) dc.close(); |
2929 |
17 Nov 06 |
nicklas |
204 |
} |
2929 |
17 Nov 06 |
nicklas |
205 |
|
2929 |
17 Nov 06 |
nicklas |
206 |
if (forward != null) |
2929 |
17 Nov 06 |
nicklas |
207 |
{ |
6192 |
31 Oct 12 |
nicklas |
208 |
sc.setSessionSetting("alert-message", message); |
2929 |
17 Nov 06 |
nicklas |
209 |
pageContext.forward(forward); |
2929 |
17 Nov 06 |
nicklas |
210 |
} |
2929 |
17 Nov 06 |
nicklas |
211 |
else if (redirect != null) |
2929 |
17 Nov 06 |
nicklas |
212 |
{ |
6192 |
31 Oct 12 |
nicklas |
213 |
sc.setSessionSetting("alert-message", message); |
2929 |
17 Nov 06 |
nicklas |
214 |
response.sendRedirect(redirect); |
2929 |
17 Nov 06 |
nicklas |
215 |
} |
2929 |
17 Nov 06 |
nicklas |
216 |
else if (message == null) |
2929 |
17 Nov 06 |
nicklas |
217 |
{ |
2929 |
17 Nov 06 |
nicklas |
218 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
2929 |
17 Nov 06 |
nicklas |
219 |
} |
2929 |
17 Nov 06 |
nicklas |
220 |
else |
2929 |
17 Nov 06 |
nicklas |
221 |
{ |
2929 |
17 Nov 06 |
nicklas |
222 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
2929 |
17 Nov 06 |
nicklas |
223 |
} |
2929 |
17 Nov 06 |
nicklas |
224 |
%> |
2929 |
17 Nov 06 |
nicklas |
225 |
|