5599 |
31 Mar 11 |
nicklas |
1 |
<%-- $Id $ |
5361 |
14 Jun 10 |
nicklas |
2 |
------------------------------------------------------------------ |
5361 |
14 Jun 10 |
nicklas |
Copyright (C) 2010 Nicklas Nordborg |
5361 |
14 Jun 10 |
nicklas |
4 |
|
5361 |
14 Jun 10 |
nicklas |
5 |
This file is part of BASE - BioArray Software Environment. |
5361 |
14 Jun 10 |
nicklas |
6 |
Available at http://base.thep.lu.se/ |
5361 |
14 Jun 10 |
nicklas |
7 |
|
5361 |
14 Jun 10 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or |
5361 |
14 Jun 10 |
nicklas |
9 |
modify it under the terms of the GNU General Public License |
5361 |
14 Jun 10 |
nicklas |
10 |
as published by the Free Software Foundation; either version 3 |
5361 |
14 Jun 10 |
nicklas |
11 |
of the License, or (at your option) any later version. |
5361 |
14 Jun 10 |
nicklas |
12 |
|
5361 |
14 Jun 10 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, |
5361 |
14 Jun 10 |
nicklas |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5361 |
14 Jun 10 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5361 |
14 Jun 10 |
nicklas |
16 |
GNU General Public License for more details. |
5361 |
14 Jun 10 |
nicklas |
17 |
|
5361 |
14 Jun 10 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
5361 |
14 Jun 10 |
nicklas |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5361 |
14 Jun 10 |
nicklas |
20 |
------------------------------------------------------------------ |
5361 |
14 Jun 10 |
nicklas |
21 |
|
5361 |
14 Jun 10 |
nicklas |
22 |
--%> |
5426 |
24 Sep 10 |
nicklas |
23 |
<%@ page pageEncoding="UTF-8" session="false" |
5361 |
14 Jun 10 |
nicklas |
24 |
import="net.sf.basedb.core.SessionControl" |
5361 |
14 Jun 10 |
nicklas |
25 |
import="net.sf.basedb.core.DbControl" |
5361 |
14 Jun 10 |
nicklas |
26 |
import="net.sf.basedb.core.Item" |
5361 |
14 Jun 10 |
nicklas |
27 |
import="net.sf.basedb.core.Include" |
5361 |
14 Jun 10 |
nicklas |
28 |
import="net.sf.basedb.core.FileServer" |
5361 |
14 Jun 10 |
nicklas |
29 |
import="net.sf.basedb.core.ItemQuery" |
5361 |
14 Jun 10 |
nicklas |
30 |
import="net.sf.basedb.core.Permission" |
5361 |
14 Jun 10 |
nicklas |
31 |
import="net.sf.basedb.core.ItemContext" |
5361 |
14 Jun 10 |
nicklas |
32 |
import="net.sf.basedb.core.ItemQuery" |
5361 |
14 Jun 10 |
nicklas |
33 |
import="net.sf.basedb.core.MultiPermissions" |
5361 |
14 Jun 10 |
nicklas |
34 |
import="net.sf.basedb.core.OwnedItem" |
5361 |
14 Jun 10 |
nicklas |
35 |
import="net.sf.basedb.core.PermissionDeniedException" |
5361 |
14 Jun 10 |
nicklas |
36 |
import="net.sf.basedb.core.ItemAlreadyExistsException" |
5361 |
14 Jun 10 |
nicklas |
37 |
import="net.sf.basedb.util.RemovableUtil" |
5361 |
14 Jun 10 |
nicklas |
38 |
import="net.sf.basedb.util.ShareableUtil" |
5361 |
14 Jun 10 |
nicklas |
39 |
import="net.sf.basedb.util.OwnableUtil" |
5361 |
14 Jun 10 |
nicklas |
40 |
import="net.sf.basedb.clients.web.Base" |
5361 |
14 Jun 10 |
nicklas |
41 |
import="net.sf.basedb.clients.web.WebException" |
5361 |
14 Jun 10 |
nicklas |
42 |
import="net.sf.basedb.util.Values" |
5361 |
14 Jun 10 |
nicklas |
43 |
import="net.sf.basedb.clients.web.util.HTML" |
5362 |
16 Jun 10 |
nicklas |
44 |
import="net.sf.basedb.clients.web.fileupload.FileUpload" |
5362 |
16 Jun 10 |
nicklas |
45 |
import="net.sf.basedb.clients.web.fileupload.UploadedFile" |
5501 |
18 Nov 10 |
nicklas |
46 |
import="net.sf.basedb.core.plugin.GuiContext" |
5501 |
18 Nov 10 |
nicklas |
47 |
import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
5501 |
18 Nov 10 |
nicklas |
48 |
import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
5501 |
18 Nov 10 |
nicklas |
49 |
import="net.sf.basedb.clients.web.extensions.JspContext" |
5501 |
18 Nov 10 |
nicklas |
50 |
import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
7604 |
25 Feb 19 |
nicklas |
51 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveAction" |
5501 |
18 Nov 10 |
nicklas |
52 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer" |
6040 |
30 Mar 12 |
nicklas |
53 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer" |
7604 |
25 Feb 19 |
nicklas |
54 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnAction" |
6040 |
30 Mar 12 |
nicklas |
55 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil" |
5599 |
31 Mar 11 |
nicklas |
56 |
import="java.io.ByteArrayOutputStream" |
5361 |
14 Jun 10 |
nicklas |
57 |
import="java.util.Enumeration" |
5361 |
14 Jun 10 |
nicklas |
58 |
import="java.util.Set" |
5361 |
14 Jun 10 |
nicklas |
59 |
import="java.util.HashSet" |
5361 |
14 Jun 10 |
nicklas |
60 |
import="java.util.List" |
5361 |
14 Jun 10 |
nicklas |
61 |
import="java.util.ArrayList" |
5361 |
14 Jun 10 |
nicklas |
62 |
import="java.util.Collections" |
5361 |
14 Jun 10 |
nicklas |
63 |
%> |
5361 |
14 Jun 10 |
nicklas |
64 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
5361 |
14 Jun 10 |
nicklas |
65 |
<%! |
5618 |
28 Apr 11 |
nicklas |
66 |
private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,host,username,description"); |
5361 |
14 Jun 10 |
nicklas |
67 |
private static final Item itemType = Item.FILESERVER; |
5361 |
14 Jun 10 |
nicklas |
68 |
%> |
5361 |
14 Jun 10 |
nicklas |
69 |
<% |
5361 |
14 Jun 10 |
nicklas |
70 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
5361 |
14 Jun 10 |
nicklas |
71 |
final String ID = sc.getId(); |
5361 |
14 Jun 10 |
nicklas |
72 |
final String cmd = request.getParameter("cmd"); |
5361 |
14 Jun 10 |
nicklas |
73 |
final String root = request.getContextPath()+"/"; |
5361 |
14 Jun 10 |
nicklas |
74 |
final String mode = request.getParameter("mode"); |
5361 |
14 Jun 10 |
nicklas |
75 |
final String callback = request.getParameter("callback"); |
5361 |
14 Jun 10 |
nicklas |
76 |
final String itemId = request.getParameter("item_id"); |
5361 |
14 Jun 10 |
nicklas |
77 |
final String listPage = "list_fileservers.jsp?ID="+ID |
5361 |
14 Jun 10 |
nicklas |
78 |
+(mode == null ? "" : "&mode="+mode) |
5361 |
14 Jun 10 |
nicklas |
79 |
+(callback == null ? "" : "&callback="+callback) |
5361 |
14 Jun 10 |
nicklas |
80 |
+(itemId == null ? "" : "&item_id="+itemId); |
5361 |
14 Jun 10 |
nicklas |
81 |
final String viewPage = "view_fileserver.jsp?ID="+ID; |
5361 |
14 Jun 10 |
nicklas |
82 |
final String editPage = "edit_fileserver.jsp?ID="+ID; |
5361 |
14 Jun 10 |
nicklas |
83 |
|
5361 |
14 Jun 10 |
nicklas |
84 |
String forward = null; |
5361 |
14 Jun 10 |
nicklas |
85 |
String redirect = null; |
5361 |
14 Jun 10 |
nicklas |
86 |
String message = null; |
5361 |
14 Jun 10 |
nicklas |
87 |
DbControl dc = null; |
5361 |
14 Jun 10 |
nicklas |
88 |
|
5361 |
14 Jun 10 |
nicklas |
89 |
try |
5361 |
14 Jun 10 |
nicklas |
90 |
{ |
5361 |
14 Jun 10 |
nicklas |
91 |
if (cmd == null || "List".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
92 |
{ |
5361 |
14 Jun 10 |
nicklas |
93 |
// Display the list page without updatinging the current context |
5361 |
14 Jun 10 |
nicklas |
94 |
Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true); |
5361 |
14 Jun 10 |
nicklas |
95 |
redirect = listPage; |
5361 |
14 Jun 10 |
nicklas |
96 |
} |
5361 |
14 Jun 10 |
nicklas |
97 |
else if ("UpdateContext".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
98 |
{ |
5361 |
14 Jun 10 |
nicklas |
99 |
// Display the list page after updating the current context from the request parameters |
5361 |
14 Jun 10 |
nicklas |
100 |
Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
101 |
redirect = listPage; |
5361 |
14 Jun 10 |
nicklas |
102 |
} |
5361 |
14 Jun 10 |
nicklas |
103 |
else if ("LoadContext".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
104 |
{ |
5361 |
14 Jun 10 |
nicklas |
105 |
// Display the list page after loading a saved context |
5361 |
14 Jun 10 |
nicklas |
106 |
int contextId = Values.getInt(request.getParameter("context")); |
5361 |
14 Jun 10 |
nicklas |
107 |
Base.loadContext(sc, contextId, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
108 |
redirect = listPage; |
5361 |
14 Jun 10 |
nicklas |
109 |
} |
5361 |
14 Jun 10 |
nicklas |
110 |
|
5361 |
14 Jun 10 |
nicklas |
111 |
else if ("ViewItem".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
112 |
{ |
5361 |
14 Jun 10 |
nicklas |
113 |
// Display the view page for a single item |
5361 |
14 Jun 10 |
nicklas |
114 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
115 |
forward = viewPage; |
5361 |
14 Jun 10 |
nicklas |
116 |
} |
5361 |
14 Jun 10 |
nicklas |
117 |
else if ("EditItem".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
118 |
{ |
5361 |
14 Jun 10 |
nicklas |
119 |
// Display the edit page for a single item (should be opened in a popup) |
5361 |
14 Jun 10 |
nicklas |
120 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
121 |
redirect = editPage; |
5361 |
14 Jun 10 |
nicklas |
122 |
} |
5361 |
14 Jun 10 |
nicklas |
123 |
else if ("NewItem".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
124 |
{ |
5361 |
14 Jun 10 |
nicklas |
125 |
// Display the edit page for a new item (should be opened in a popup) |
5361 |
14 Jun 10 |
nicklas |
126 |
if (!sc.hasPermission(Permission.CREATE, itemType)) |
5361 |
14 Jun 10 |
nicklas |
127 |
{ |
5361 |
14 Jun 10 |
nicklas |
128 |
throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
5361 |
14 Jun 10 |
nicklas |
129 |
} |
5361 |
14 Jun 10 |
nicklas |
130 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
131 |
cc.setId(0); |
5361 |
14 Jun 10 |
nicklas |
132 |
redirect = editPage; |
5361 |
14 Jun 10 |
nicklas |
133 |
} |
5361 |
14 Jun 10 |
nicklas |
134 |
else if ("UpdateItem".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
135 |
{ |
5361 |
14 Jun 10 |
nicklas |
136 |
// Update the properties on an item (will close the popup) |
5361 |
14 Jun 10 |
nicklas |
137 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
7954 |
12 May 21 |
nicklas |
138 |
dc = sc.newDbControl(":Edit "+itemType); |
7605 |
26 Feb 19 |
nicklas |
139 |
FileServer server = cc.getObject("item"); |
5361 |
14 Jun 10 |
nicklas |
140 |
if (server == null) |
5361 |
14 Jun 10 |
nicklas |
141 |
{ |
5361 |
14 Jun 10 |
nicklas |
142 |
server = FileServer.getNew(dc); |
5361 |
14 Jun 10 |
nicklas |
143 |
message = "File server created"; |
5361 |
14 Jun 10 |
nicklas |
144 |
dc.saveItem(server); |
5361 |
14 Jun 10 |
nicklas |
145 |
} |
5361 |
14 Jun 10 |
nicklas |
146 |
else |
5361 |
14 Jun 10 |
nicklas |
147 |
{ |
5361 |
14 Jun 10 |
nicklas |
148 |
dc.reattachItem(server, false); |
5361 |
14 Jun 10 |
nicklas |
149 |
message = "File server updated"; |
5361 |
14 Jun 10 |
nicklas |
150 |
} |
5501 |
18 Nov 10 |
nicklas |
151 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.FILESERVER), server); |
7604 |
25 Feb 19 |
nicklas |
152 |
ExtensionsInvoker<OnSaveAction> invoker = EditUtil.useOnSaveExtensions(jspContext); |
5501 |
18 Nov 10 |
nicklas |
153 |
try |
5362 |
16 Jun 10 |
nicklas |
154 |
{ |
5501 |
18 Nov 10 |
nicklas |
155 |
FileUpload upload = new FileUpload(request); |
5501 |
18 Nov 10 |
nicklas |
156 |
// Parse the form to the beginning of the first file entry |
5501 |
18 Nov 10 |
nicklas |
157 |
UploadedFile uploadedFile = upload.next(); |
5501 |
18 Nov 10 |
nicklas |
158 |
|
5501 |
18 Nov 10 |
nicklas |
159 |
byte[] serverCertificate = null; |
5501 |
18 Nov 10 |
nicklas |
160 |
byte[] clientCertificate = null; |
7472 |
10 Apr 18 |
nicklas |
161 |
byte[] sshPrivateKey = null; |
5501 |
18 Nov 10 |
nicklas |
162 |
while (uploadedFile != null) |
5362 |
16 Jun 10 |
nicklas |
163 |
{ |
5501 |
18 Nov 10 |
nicklas |
164 |
String formName = uploadedFile.getFormName(); |
5501 |
18 Nov 10 |
nicklas |
165 |
ByteArrayOutputStream fileData = new ByteArrayOutputStream(1000); |
5501 |
18 Nov 10 |
nicklas |
166 |
uploadedFile.writeTo(fileData); |
5501 |
18 Nov 10 |
nicklas |
167 |
if ("server_certificate".equals(formName)) |
5501 |
18 Nov 10 |
nicklas |
168 |
{ |
5501 |
18 Nov 10 |
nicklas |
169 |
serverCertificate = fileData.toByteArray(); |
5501 |
18 Nov 10 |
nicklas |
170 |
} |
5501 |
18 Nov 10 |
nicklas |
171 |
else if ("client_certificate".equals(formName)) |
5501 |
18 Nov 10 |
nicklas |
172 |
{ |
5501 |
18 Nov 10 |
nicklas |
173 |
clientCertificate = fileData.toByteArray(); |
5501 |
18 Nov 10 |
nicklas |
174 |
} |
7472 |
10 Apr 18 |
nicklas |
175 |
else if ("ssh_private_key".equals(formName)) |
7472 |
10 Apr 18 |
nicklas |
176 |
{ |
7472 |
10 Apr 18 |
nicklas |
177 |
sshPrivateKey = fileData.toByteArray(); |
7472 |
10 Apr 18 |
nicklas |
178 |
} |
5501 |
18 Nov 10 |
nicklas |
179 |
uploadedFile = upload.next(); |
5362 |
16 Jun 10 |
nicklas |
180 |
} |
5501 |
18 Nov 10 |
nicklas |
181 |
|
5501 |
18 Nov 10 |
nicklas |
182 |
server.setName(Values.getStringOrNull(upload.getParameter("name"))); |
5501 |
18 Nov 10 |
nicklas |
183 |
server.setDescription(Values.getStringOrNull(upload.getParameter("description"))); |
5599 |
31 Mar 11 |
nicklas |
184 |
server.setConnectionManagerFactoryId(Values.getStringOrNull(upload.getParameter("connectionManager"))); |
5618 |
28 Apr 11 |
nicklas |
185 |
server.setHost(Values.getStringOrNull(upload.getParameter("host"))); |
5501 |
18 Nov 10 |
nicklas |
186 |
server.setUsername(Values.getStringOrNull(upload.getParameter("username"))); |
5501 |
18 Nov 10 |
nicklas |
187 |
String password = Values.getStringOrNull(upload.getParameter("password")); |
5501 |
18 Nov 10 |
nicklas |
188 |
if (password != null) server.setPassword(password); |
6497 |
26 Jun 14 |
nicklas |
189 |
server.setRootPath(Values.getStringOrNull(upload.getParameter("rootPath"))); |
6497 |
26 Jun 14 |
nicklas |
190 |
server.setSshFingerprint(Values.getStringOrNull(upload.getParameter("sshFingerprint"))); |
7472 |
10 Apr 18 |
nicklas |
191 |
server.setSshPrivateKeyFormat(Values.getStringOrNull(upload.getParameter("ssh_private_key_format"))); |
5501 |
18 Nov 10 |
nicklas |
192 |
String certPassword = Values.getStringOrNull(upload.getParameter("client_certificate_password")); |
5501 |
18 Nov 10 |
nicklas |
193 |
if (certPassword != null) server.setClientCertificatePassword(certPassword); |
7472 |
10 Apr 18 |
nicklas |
194 |
String sshPrivateKeyPassword = Values.getStringOrNull(upload.getParameter("ssh_private_key_password")); |
7472 |
10 Apr 18 |
nicklas |
195 |
if (sshPrivateKeyPassword != null) server.setSshPrivateKeyPassword(sshPrivateKeyPassword); |
5501 |
18 Nov 10 |
nicklas |
196 |
if (Values.getBoolean(upload.getParameter("remove_server_certificate"))) |
5362 |
16 Jun 10 |
nicklas |
197 |
{ |
5501 |
18 Nov 10 |
nicklas |
198 |
server.setServerCertificate(null); |
5362 |
16 Jun 10 |
nicklas |
199 |
} |
5501 |
18 Nov 10 |
nicklas |
200 |
else if (serverCertificate != null && serverCertificate.length > 0) |
5501 |
18 Nov 10 |
nicklas |
201 |
{ |
5501 |
18 Nov 10 |
nicklas |
202 |
server.setServerCertificate(serverCertificate); |
5501 |
18 Nov 10 |
nicklas |
203 |
} |
5501 |
18 Nov 10 |
nicklas |
204 |
if (Values.getBoolean(upload.getParameter("remove_client_certificate"))) |
5501 |
18 Nov 10 |
nicklas |
205 |
{ |
5501 |
18 Nov 10 |
nicklas |
206 |
server.setClientCertificate(null); |
5501 |
18 Nov 10 |
nicklas |
207 |
server.setClientCertificatePassword(null); |
5501 |
18 Nov 10 |
nicklas |
208 |
} |
5501 |
18 Nov 10 |
nicklas |
209 |
else if (clientCertificate != null && clientCertificate.length > 0) |
5501 |
18 Nov 10 |
nicklas |
210 |
{ |
5501 |
18 Nov 10 |
nicklas |
211 |
server.setClientCertificate(clientCertificate); |
5501 |
18 Nov 10 |
nicklas |
212 |
} |
7472 |
10 Apr 18 |
nicklas |
213 |
if (Values.getBoolean(upload.getParameter("remove_ssh_private_key"))) |
7472 |
10 Apr 18 |
nicklas |
214 |
{ |
7472 |
10 Apr 18 |
nicklas |
215 |
server.setSshPrivateKey(null); |
7472 |
10 Apr 18 |
nicklas |
216 |
server.setSshPrivateKeyPassword(null); |
7472 |
10 Apr 18 |
nicklas |
217 |
} |
7472 |
10 Apr 18 |
nicklas |
218 |
else if (sshPrivateKey != null && sshPrivateKey.length > 0) |
7472 |
10 Apr 18 |
nicklas |
219 |
{ |
7472 |
10 Apr 18 |
nicklas |
220 |
server.setSshPrivateKey(sshPrivateKey); |
7472 |
10 Apr 18 |
nicklas |
221 |
} |
8160 |
07 Jun 23 |
nicklas |
222 |
// Annotations tab -- need wrapper to FileUpload since this form is submitted as multipart/form-data |
8160 |
07 Jun 23 |
nicklas |
223 |
Base.updateAnnotations(dc, server, server, |
8160 |
07 Jun 23 |
nicklas |
224 |
new HttpServletRequestWrapper(request) |
8160 |
07 Jun 23 |
nicklas |
225 |
{ |
8160 |
07 Jun 23 |
nicklas |
226 |
// This is the only method that is called in Base.updateAnnotations |
8160 |
07 Jun 23 |
nicklas |
227 |
public String getParameter(String name) |
8160 |
07 Jun 23 |
nicklas |
228 |
{ |
8160 |
07 Jun 23 |
nicklas |
229 |
return upload.getParameter(name); |
8160 |
07 Jun 23 |
nicklas |
230 |
} |
8160 |
07 Jun 23 |
nicklas |
231 |
}); |
5501 |
18 Nov 10 |
nicklas |
232 |
|
5501 |
18 Nov 10 |
nicklas |
233 |
// OnSave extensions |
5501 |
18 Nov 10 |
nicklas |
234 |
invoker.render(OnSaveRenderer.ON_SAVE); |
5501 |
18 Nov 10 |
nicklas |
235 |
dc.commit(); |
5501 |
18 Nov 10 |
nicklas |
236 |
invoker.render(OnSaveRenderer.ON_COMMIT); |
5362 |
16 Jun 10 |
nicklas |
237 |
} |
5501 |
18 Nov 10 |
nicklas |
238 |
catch (Exception ex) |
5362 |
16 Jun 10 |
nicklas |
239 |
{ |
5501 |
18 Nov 10 |
nicklas |
240 |
invoker.render(OnSaveRenderer.onRollback(ex)); |
5501 |
18 Nov 10 |
nicklas |
241 |
throw ex; |
5362 |
16 Jun 10 |
nicklas |
242 |
} |
5501 |
18 Nov 10 |
nicklas |
243 |
finally |
5362 |
16 Jun 10 |
nicklas |
244 |
{ |
5501 |
18 Nov 10 |
nicklas |
245 |
cc.removeObject("item"); |
5362 |
16 Jun 10 |
nicklas |
246 |
} |
5361 |
14 Jun 10 |
nicklas |
247 |
} |
5361 |
14 Jun 10 |
nicklas |
248 |
else if ("DeleteItem".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
249 |
{ |
5361 |
14 Jun 10 |
nicklas |
250 |
// Delete a single item and then return to the view page |
7954 |
12 May 21 |
nicklas |
251 |
dc = sc.newDbControl(":Delete "+itemType); |
5361 |
14 Jun 10 |
nicklas |
252 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
253 |
RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true); |
5361 |
14 Jun 10 |
nicklas |
254 |
dc.commit(); |
5361 |
14 Jun 10 |
nicklas |
255 |
redirect = viewPage; |
5361 |
14 Jun 10 |
nicklas |
256 |
} |
5361 |
14 Jun 10 |
nicklas |
257 |
else if ("DeleteItems".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
258 |
{ |
5361 |
14 Jun 10 |
nicklas |
259 |
// Delete all selected items on the list page |
7954 |
12 May 21 |
nicklas |
260 |
dc = sc.newDbControl(":Delete "+itemType); |
5361 |
14 Jun 10 |
nicklas |
261 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
262 |
int numTotal = cc.getSelected().size(); |
5361 |
14 Jun 10 |
nicklas |
263 |
int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true); |
5361 |
14 Jun 10 |
nicklas |
264 |
dc.commit(); |
5361 |
14 Jun 10 |
nicklas |
265 |
if (numTotal != numRemoved) |
5361 |
14 Jun 10 |
nicklas |
266 |
{ |
5361 |
14 Jun 10 |
nicklas |
267 |
message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission"; |
5361 |
14 Jun 10 |
nicklas |
268 |
} |
6192 |
31 Oct 12 |
nicklas |
269 |
redirect = listPage; |
5361 |
14 Jun 10 |
nicklas |
270 |
} |
5361 |
14 Jun 10 |
nicklas |
271 |
else if ("RestoreItem".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
272 |
{ |
5361 |
14 Jun 10 |
nicklas |
273 |
// Restore a single item and then return to the view page |
7954 |
12 May 21 |
nicklas |
274 |
dc = sc.newDbControl(":Restore "+itemType); |
5361 |
14 Jun 10 |
nicklas |
275 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
276 |
RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false); |
5361 |
14 Jun 10 |
nicklas |
277 |
dc.commit(); |
5361 |
14 Jun 10 |
nicklas |
278 |
redirect = viewPage; |
5361 |
14 Jun 10 |
nicklas |
279 |
} |
5361 |
14 Jun 10 |
nicklas |
280 |
else if ("RestoreItems".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
281 |
{ |
5361 |
14 Jun 10 |
nicklas |
282 |
// Restore all selected items on the list page |
7954 |
12 May 21 |
nicklas |
283 |
dc = sc.newDbControl(":Restore "+itemType); |
5361 |
14 Jun 10 |
nicklas |
284 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
285 |
int numTotal = cc.getSelected().size(); |
5361 |
14 Jun 10 |
nicklas |
286 |
int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false); |
5361 |
14 Jun 10 |
nicklas |
287 |
dc.commit(); |
5361 |
14 Jun 10 |
nicklas |
288 |
if (numTotal != numRemoved) |
5361 |
14 Jun 10 |
nicklas |
289 |
{ |
5361 |
14 Jun 10 |
nicklas |
290 |
message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; |
5361 |
14 Jun 10 |
nicklas |
291 |
} |
6192 |
31 Oct 12 |
nicklas |
292 |
redirect = listPage; |
5361 |
14 Jun 10 |
nicklas |
293 |
} |
5361 |
14 Jun 10 |
nicklas |
294 |
else if ("ShareItem".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
295 |
{ |
5361 |
14 Jun 10 |
nicklas |
296 |
// Display a popup window for sharing a single item |
7954 |
12 May 21 |
nicklas |
297 |
dc = sc.newDbControl(":Share "+itemType); |
5361 |
14 Jun 10 |
nicklas |
298 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
299 |
MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId())); |
5361 |
14 Jun 10 |
nicklas |
300 |
dc.close(); |
5361 |
14 Jun 10 |
nicklas |
301 |
cc.setObject("MultiPermissions", permissions); |
5361 |
14 Jun 10 |
nicklas |
302 |
redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
5361 |
14 Jun 10 |
nicklas |
303 |
} |
5361 |
14 Jun 10 |
nicklas |
304 |
else if ("ShareItems".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
305 |
{ |
5361 |
14 Jun 10 |
nicklas |
306 |
// Display a popup window for sharing all selected items on the list page |
7954 |
12 May 21 |
nicklas |
307 |
dc = sc.newDbControl(":Share "+itemType); |
5361 |
14 Jun 10 |
nicklas |
308 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
309 |
MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected()); |
5361 |
14 Jun 10 |
nicklas |
310 |
dc.close(); |
5361 |
14 Jun 10 |
nicklas |
311 |
cc.setObject("MultiPermissions", permissions); |
5361 |
14 Jun 10 |
nicklas |
312 |
redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
5361 |
14 Jun 10 |
nicklas |
313 |
} |
5361 |
14 Jun 10 |
nicklas |
314 |
else if ("SetOwnerOfItem".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
315 |
{ |
5361 |
14 Jun 10 |
nicklas |
316 |
// Change owner of items selected on a list page |
7954 |
12 May 21 |
nicklas |
317 |
dc = sc.newDbControl(":Set owner of "+itemType); |
5361 |
14 Jun 10 |
nicklas |
318 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
319 |
OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId()); |
5361 |
14 Jun 10 |
nicklas |
320 |
cc.setObject("OwnedItems", Collections.singleton(item)); |
5361 |
14 Jun 10 |
nicklas |
321 |
redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name(); |
5361 |
14 Jun 10 |
nicklas |
322 |
} |
5361 |
14 Jun 10 |
nicklas |
323 |
else if ("SetOwnerOfItems".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
324 |
{ |
5361 |
14 Jun 10 |
nicklas |
325 |
// Change owner of items selected on a list page |
7954 |
12 May 21 |
nicklas |
326 |
dc = sc.newDbControl(":Set owner of "+itemType); |
5361 |
14 Jun 10 |
nicklas |
327 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
328 |
Set<OwnedItem> items = new HashSet<OwnedItem>(); |
5361 |
14 Jun 10 |
nicklas |
329 |
for (Integer id : cc.getSelected()) |
5361 |
14 Jun 10 |
nicklas |
330 |
{ |
5361 |
14 Jun 10 |
nicklas |
331 |
if (id != null) items.add((OwnedItem)itemType.getById(dc, id)); |
5361 |
14 Jun 10 |
nicklas |
332 |
} |
5361 |
14 Jun 10 |
nicklas |
333 |
dc.close(); |
5361 |
14 Jun 10 |
nicklas |
334 |
cc.setObject("OwnedItems", items); |
5361 |
14 Jun 10 |
nicklas |
335 |
redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name(); |
5361 |
14 Jun 10 |
nicklas |
336 |
} |
5361 |
14 Jun 10 |
nicklas |
337 |
else if ("ExportItems".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
338 |
{ |
5361 |
14 Jun 10 |
nicklas |
339 |
// Run an export plugin in a list context |
5361 |
14 Jun 10 |
nicklas |
340 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
341 |
final ItemQuery<FileServer> query = FileServer.getQuery(); |
7954 |
12 May 21 |
nicklas |
342 |
dc = sc.newDbControl(":Export "+itemType); |
7914 |
23 Feb 21 |
nicklas |
343 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
344 |
cc.configureQuery(dc, query, jspContext, true); |
6040 |
30 Mar 12 |
nicklas |
345 |
cc.setQuery(query); |
7604 |
25 Feb 19 |
nicklas |
346 |
ExtensionsInvoker<ListColumnAction<FileServer,?>> listInvoker = ListColumnUtil.useExtensions(jspContext); |
7604 |
25 Feb 19 |
nicklas |
347 |
listInvoker.render(new ListColumnExportRenderer<FileServer>(cc)); |
5590 |
16 Mar 11 |
nicklas |
348 |
dc.close(); |
5361 |
14 Jun 10 |
nicklas |
349 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+file+servers"; |
5361 |
14 Jun 10 |
nicklas |
350 |
} |
5361 |
14 Jun 10 |
nicklas |
351 |
else if ("ExportItem".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
352 |
{ |
5361 |
14 Jun 10 |
nicklas |
353 |
// Run an export plugin in single-item context |
5361 |
14 Jun 10 |
nicklas |
354 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
355 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+file+server"; |
5361 |
14 Jun 10 |
nicklas |
356 |
} |
5361 |
14 Jun 10 |
nicklas |
357 |
else if ("ImportItems".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
358 |
{ |
5361 |
14 Jun 10 |
nicklas |
359 |
// Run an import plugin in a list context |
5361 |
14 Jun 10 |
nicklas |
360 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
361 |
final ItemQuery<FileServer> query = FileServer.getQuery(); |
7954 |
12 May 21 |
nicklas |
362 |
dc = sc.newDbControl(":Import "+itemType); |
7914 |
23 Feb 21 |
nicklas |
363 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
364 |
cc.configureQuery(dc, query, jspContext, true); |
5590 |
16 Mar 11 |
nicklas |
365 |
dc.close(); |
5361 |
14 Jun 10 |
nicklas |
366 |
cc.setQuery(query); |
5361 |
14 Jun 10 |
nicklas |
367 |
redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+file+servers"; |
5361 |
14 Jun 10 |
nicklas |
368 |
} |
5361 |
14 Jun 10 |
nicklas |
369 |
else if ("ImportItem".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
370 |
{ |
5361 |
14 Jun 10 |
nicklas |
371 |
// Run an import plugin in single-item context |
5361 |
14 Jun 10 |
nicklas |
372 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
373 |
redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+file+server"; |
5361 |
14 Jun 10 |
nicklas |
374 |
} |
5361 |
14 Jun 10 |
nicklas |
375 |
else if ("RunListPlugin".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
376 |
{ |
5361 |
14 Jun 10 |
nicklas |
377 |
// Run another plugin in a list context |
5361 |
14 Jun 10 |
nicklas |
378 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
379 |
final ItemQuery<FileServer> query = FileServer.getQuery(); |
7954 |
12 May 21 |
nicklas |
380 |
dc = sc.newDbControl(":Run plugin "+itemType); |
7914 |
23 Feb 21 |
nicklas |
381 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
382 |
cc.configureQuery(dc, query, jspContext, true); |
5590 |
16 Mar 11 |
nicklas |
383 |
dc.close(); |
5361 |
14 Jun 10 |
nicklas |
384 |
cc.setQuery(query); |
5361 |
14 Jun 10 |
nicklas |
385 |
redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
5361 |
14 Jun 10 |
nicklas |
386 |
} |
5361 |
14 Jun 10 |
nicklas |
387 |
else if ("RunPlugin".equals(cmd)) |
5361 |
14 Jun 10 |
nicklas |
388 |
{ |
5361 |
14 Jun 10 |
nicklas |
389 |
// Run another plugin in single-item context |
5361 |
14 Jun 10 |
nicklas |
390 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
5361 |
14 Jun 10 |
nicklas |
391 |
redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; |
5361 |
14 Jun 10 |
nicklas |
392 |
} |
5361 |
14 Jun 10 |
nicklas |
393 |
else |
5361 |
14 Jun 10 |
nicklas |
394 |
{ |
5361 |
14 Jun 10 |
nicklas |
395 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
5361 |
14 Jun 10 |
nicklas |
396 |
} |
5361 |
14 Jun 10 |
nicklas |
397 |
} |
5361 |
14 Jun 10 |
nicklas |
398 |
finally |
5361 |
14 Jun 10 |
nicklas |
399 |
{ |
5361 |
14 Jun 10 |
nicklas |
400 |
if (dc != null) dc.close(); |
5361 |
14 Jun 10 |
nicklas |
401 |
} |
5361 |
14 Jun 10 |
nicklas |
402 |
|
5361 |
14 Jun 10 |
nicklas |
403 |
if (forward != null) |
5361 |
14 Jun 10 |
nicklas |
404 |
{ |
6192 |
31 Oct 12 |
nicklas |
405 |
sc.setSessionSetting("alert-message", message); |
5361 |
14 Jun 10 |
nicklas |
406 |
pageContext.forward(forward); |
5361 |
14 Jun 10 |
nicklas |
407 |
} |
5361 |
14 Jun 10 |
nicklas |
408 |
else if (redirect != null) |
5361 |
14 Jun 10 |
nicklas |
409 |
{ |
6192 |
31 Oct 12 |
nicklas |
410 |
sc.setSessionSetting("alert-message", message); |
5361 |
14 Jun 10 |
nicklas |
411 |
response.sendRedirect(redirect); |
5361 |
14 Jun 10 |
nicklas |
412 |
} |
5361 |
14 Jun 10 |
nicklas |
413 |
else if (message == null) |
5361 |
14 Jun 10 |
nicklas |
414 |
{ |
5361 |
14 Jun 10 |
nicklas |
415 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
5361 |
14 Jun 10 |
nicklas |
416 |
} |
5361 |
14 Jun 10 |
nicklas |
417 |
else |
5361 |
14 Jun 10 |
nicklas |
418 |
{ |
5361 |
14 Jun 10 |
nicklas |
419 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
5361 |
14 Jun 10 |
nicklas |
420 |
} |
5361 |
14 Jun 10 |
nicklas |
421 |
%> |
5361 |
14 Jun 10 |
nicklas |
422 |
|