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