1794 |
19 Jan 06 |
nicklas |
1 |
<%-- $Id$ |
1794 |
19 Jan 06 |
nicklas |
2 |
------------------------------------------------------------------ |
5425 |
23 Sep 10 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
1794 |
19 Jan 06 |
nicklas |
4 |
|
2304 |
22 May 06 |
jari |
5 |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
6 |
Available at http://base.thep.lu.se/ |
1794 |
19 Jan 06 |
nicklas |
7 |
|
1794 |
19 Jan 06 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or |
1794 |
19 Jan 06 |
nicklas |
9 |
modify it under the terms of the GNU General Public License |
4476 |
05 Sep 08 |
jari |
10 |
as published by the Free Software Foundation; either version 3 |
1794 |
19 Jan 06 |
nicklas |
11 |
of the License, or (at your option) any later version. |
1794 |
19 Jan 06 |
nicklas |
12 |
|
1794 |
19 Jan 06 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, |
1794 |
19 Jan 06 |
nicklas |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1794 |
19 Jan 06 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1794 |
19 Jan 06 |
nicklas |
16 |
GNU General Public License for more details. |
1794 |
19 Jan 06 |
nicklas |
17 |
|
1794 |
19 Jan 06 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
4510 |
11 Sep 08 |
jari |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
1794 |
19 Jan 06 |
nicklas |
20 |
------------------------------------------------------------------ |
1794 |
19 Jan 06 |
nicklas |
21 |
|
1794 |
19 Jan 06 |
nicklas |
22 |
@author Nicklas |
1794 |
19 Jan 06 |
nicklas |
23 |
@version 2.0 |
1794 |
19 Jan 06 |
nicklas |
24 |
--%> |
5426 |
24 Sep 10 |
nicklas |
25 |
<%@ page pageEncoding="UTF-8" session="false" |
1794 |
19 Jan 06 |
nicklas |
26 |
import="net.sf.basedb.core.SessionControl" |
1794 |
19 Jan 06 |
nicklas |
27 |
import="net.sf.basedb.core.DbControl" |
1794 |
19 Jan 06 |
nicklas |
28 |
import="net.sf.basedb.core.Item" |
1794 |
19 Jan 06 |
nicklas |
29 |
import="net.sf.basedb.core.Include" |
1794 |
19 Jan 06 |
nicklas |
30 |
import="net.sf.basedb.core.Directory" |
1794 |
19 Jan 06 |
nicklas |
31 |
import="net.sf.basedb.core.ItemQuery" |
1794 |
19 Jan 06 |
nicklas |
32 |
import="net.sf.basedb.core.Permission" |
1794 |
19 Jan 06 |
nicklas |
33 |
import="net.sf.basedb.core.ItemContext" |
1794 |
19 Jan 06 |
nicklas |
34 |
import="net.sf.basedb.core.MultiPermissions" |
1794 |
19 Jan 06 |
nicklas |
35 |
import="net.sf.basedb.core.PermissionDeniedException" |
1794 |
19 Jan 06 |
nicklas |
36 |
import="net.sf.basedb.core.ItemAlreadyExistsException" |
5010 |
23 Jun 09 |
nicklas |
37 |
import="net.sf.basedb.core.query.Expressions" |
5010 |
23 Jun 09 |
nicklas |
38 |
import="net.sf.basedb.core.query.Restrictions" |
5010 |
23 Jun 09 |
nicklas |
39 |
import="net.sf.basedb.core.query.Hql" |
1794 |
19 Jan 06 |
nicklas |
40 |
import="net.sf.basedb.util.RemovableUtil" |
1794 |
19 Jan 06 |
nicklas |
41 |
import="net.sf.basedb.util.ShareableUtil" |
2918 |
15 Nov 06 |
nicklas |
42 |
import="net.sf.basedb.util.OwnableUtil" |
1794 |
19 Jan 06 |
nicklas |
43 |
import="net.sf.basedb.clients.web.Base" |
1794 |
19 Jan 06 |
nicklas |
44 |
import="net.sf.basedb.clients.web.WebException" |
2753 |
20 Oct 06 |
nicklas |
45 |
import="net.sf.basedb.util.Values" |
1794 |
19 Jan 06 |
nicklas |
46 |
import="net.sf.basedb.clients.web.util.HTML" |
5501 |
18 Nov 10 |
nicklas |
47 |
import="net.sf.basedb.core.plugin.GuiContext" |
5501 |
18 Nov 10 |
nicklas |
48 |
import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
5501 |
18 Nov 10 |
nicklas |
49 |
import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
5501 |
18 Nov 10 |
nicklas |
50 |
import="net.sf.basedb.clients.web.extensions.JspContext" |
5501 |
18 Nov 10 |
nicklas |
51 |
import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
7604 |
25 Feb 19 |
nicklas |
52 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveAction" |
5501 |
18 Nov 10 |
nicklas |
53 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer" |
1794 |
19 Jan 06 |
nicklas |
54 |
import="java.util.Enumeration" |
1794 |
19 Jan 06 |
nicklas |
55 |
import="java.util.Set" |
1794 |
19 Jan 06 |
nicklas |
56 |
import="java.util.HashSet" |
1794 |
19 Jan 06 |
nicklas |
57 |
import="java.util.List" |
1794 |
19 Jan 06 |
nicklas |
58 |
import="java.util.ArrayList" |
1794 |
19 Jan 06 |
nicklas |
59 |
import="java.util.Collections" |
1794 |
19 Jan 06 |
nicklas |
60 |
%> |
1794 |
19 Jan 06 |
nicklas |
61 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
1794 |
19 Jan 06 |
nicklas |
62 |
<%! |
1794 |
19 Jan 06 |
nicklas |
63 |
private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,description"); |
1794 |
19 Jan 06 |
nicklas |
64 |
private static final Item itemType = Item.DIRECTORY; |
1794 |
19 Jan 06 |
nicklas |
65 |
%> |
1794 |
19 Jan 06 |
nicklas |
66 |
<% |
1794 |
19 Jan 06 |
nicklas |
67 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
1794 |
19 Jan 06 |
nicklas |
68 |
final String ID = sc.getId(); |
1794 |
19 Jan 06 |
nicklas |
69 |
final String cmd = request.getParameter("cmd"); |
1794 |
19 Jan 06 |
nicklas |
70 |
final String root = request.getContextPath()+"/"; |
1794 |
19 Jan 06 |
nicklas |
71 |
final String mode = request.getParameter("mode"); |
1794 |
19 Jan 06 |
nicklas |
72 |
final String callback = request.getParameter("callback"); |
1794 |
19 Jan 06 |
nicklas |
73 |
final String itemId = request.getParameter("item_id"); |
1794 |
19 Jan 06 |
nicklas |
74 |
final int parentId = Values.getInt(request.getParameter("parent_id")); |
1794 |
19 Jan 06 |
nicklas |
75 |
final String listPage = "list_directories.jsp?ID="+ID+"&parent_id="+parentId |
1794 |
19 Jan 06 |
nicklas |
76 |
+(mode == null ? "" : "&mode="+mode) |
1794 |
19 Jan 06 |
nicklas |
77 |
+(callback == null ? "" : "&callback="+callback) |
1794 |
19 Jan 06 |
nicklas |
78 |
+(itemId == null ? "" : "&item_id="+itemId); |
1794 |
19 Jan 06 |
nicklas |
79 |
final String editPage = "edit_directory.jsp?ID="+ID+"&parent_id="+parentId; |
2694 |
03 Oct 06 |
nicklas |
80 |
final String viewPage = "../index.jsp?ID="+ID+"&cmd=List"; |
1794 |
19 Jan 06 |
nicklas |
81 |
String forward = null; |
1794 |
19 Jan 06 |
nicklas |
82 |
String redirect = null; |
1794 |
19 Jan 06 |
nicklas |
83 |
String message = null; |
1794 |
19 Jan 06 |
nicklas |
84 |
DbControl dc = null; |
1794 |
19 Jan 06 |
nicklas |
85 |
|
1794 |
19 Jan 06 |
nicklas |
86 |
try |
1794 |
19 Jan 06 |
nicklas |
87 |
{ |
1794 |
19 Jan 06 |
nicklas |
88 |
if (cmd == null || "List".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
89 |
{ |
1794 |
19 Jan 06 |
nicklas |
90 |
// Display the list page without updating the current context |
2811 |
26 Oct 06 |
nicklas |
91 |
Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true); |
1794 |
19 Jan 06 |
nicklas |
92 |
redirect = listPage; |
1794 |
19 Jan 06 |
nicklas |
93 |
} |
2694 |
03 Oct 06 |
nicklas |
94 |
else if ("ViewItem".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
95 |
{ |
2694 |
03 Oct 06 |
nicklas |
96 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2694 |
03 Oct 06 |
nicklas |
97 |
redirect = viewPage; |
2694 |
03 Oct 06 |
nicklas |
98 |
} |
2694 |
03 Oct 06 |
nicklas |
99 |
else if ("EditItem".equals(cmd)) |
2694 |
03 Oct 06 |
nicklas |
100 |
{ |
1794 |
19 Jan 06 |
nicklas |
101 |
// Display the edit page for a single item (should be opened in a popup) |
1794 |
19 Jan 06 |
nicklas |
102 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1794 |
19 Jan 06 |
nicklas |
103 |
redirect = editPage; |
1794 |
19 Jan 06 |
nicklas |
104 |
} |
1794 |
19 Jan 06 |
nicklas |
105 |
else if ("NewItem".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
106 |
{ |
1794 |
19 Jan 06 |
nicklas |
107 |
// Display the edit page for a new item (should be opened in a popup) |
1794 |
19 Jan 06 |
nicklas |
108 |
if (!sc.hasPermission(Permission.CREATE, itemType)) |
1794 |
19 Jan 06 |
nicklas |
109 |
{ |
1794 |
19 Jan 06 |
nicklas |
110 |
throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
1794 |
19 Jan 06 |
nicklas |
111 |
} |
1794 |
19 Jan 06 |
nicklas |
112 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1794 |
19 Jan 06 |
nicklas |
113 |
cc.setId(0); |
1794 |
19 Jan 06 |
nicklas |
114 |
redirect = editPage; |
1794 |
19 Jan 06 |
nicklas |
115 |
} |
2388 |
16 Jun 06 |
nicklas |
116 |
else if ("ShareItem".equals(cmd)) |
2388 |
16 Jun 06 |
nicklas |
117 |
{ |
2388 |
16 Jun 06 |
nicklas |
118 |
// Display a popup window for sharing a single item |
7954 |
12 May 21 |
nicklas |
119 |
dc = sc.newDbControl(":Share "+itemType); |
2388 |
16 Jun 06 |
nicklas |
120 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2388 |
16 Jun 06 |
nicklas |
121 |
MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId())); |
2388 |
16 Jun 06 |
nicklas |
122 |
dc.close(); |
2388 |
16 Jun 06 |
nicklas |
123 |
cc.setObject("MultiPermissions", permissions); |
2388 |
16 Jun 06 |
nicklas |
124 |
redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
2388 |
16 Jun 06 |
nicklas |
125 |
} |
4578 |
13 Oct 08 |
martin |
126 |
else if ("SetOwnerOfItem".equals(cmd)) |
2918 |
15 Nov 06 |
nicklas |
127 |
{ |
4578 |
13 Oct 08 |
martin |
128 |
// Change owner of items selected on a list page |
2918 |
15 Nov 06 |
nicklas |
129 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
4578 |
13 Oct 08 |
martin |
130 |
cc.setObject("OwnedItems", Collections.singleton(cc.getId())); |
4578 |
13 Oct 08 |
martin |
131 |
redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name(); |
2918 |
15 Nov 06 |
nicklas |
132 |
} |
1794 |
19 Jan 06 |
nicklas |
133 |
else if ("UpdateItem".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
134 |
{ |
1794 |
19 Jan 06 |
nicklas |
135 |
// Update the properties on an item (will close the popup) |
1794 |
19 Jan 06 |
nicklas |
136 |
|
1794 |
19 Jan 06 |
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 |
Directory directory = cc.getObject("item"); |
1794 |
19 Jan 06 |
nicklas |
140 |
if (directory == null) |
1794 |
19 Jan 06 |
nicklas |
141 |
{ |
1794 |
19 Jan 06 |
nicklas |
142 |
directory = Directory.getNew(dc, Directory.getById(dc, parentId)); |
1794 |
19 Jan 06 |
nicklas |
143 |
message = "Directory created"; |
1794 |
19 Jan 06 |
nicklas |
144 |
dc.saveItem(directory); |
1794 |
19 Jan 06 |
nicklas |
145 |
} |
1794 |
19 Jan 06 |
nicklas |
146 |
else |
1794 |
19 Jan 06 |
nicklas |
147 |
{ |
5060 |
19 Aug 09 |
nicklas |
148 |
dc.reattachItem(directory, false); |
1794 |
19 Jan 06 |
nicklas |
149 |
message = "Directory updated"; |
1794 |
19 Jan 06 |
nicklas |
150 |
} |
5501 |
18 Nov 10 |
nicklas |
151 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.DIRECTORY), directory); |
7604 |
25 Feb 19 |
nicklas |
152 |
ExtensionsInvoker<OnSaveAction> invoker = EditUtil.useOnSaveExtensions(jspContext); |
5501 |
18 Nov 10 |
nicklas |
153 |
try |
5010 |
23 Jun 09 |
nicklas |
154 |
{ |
5501 |
18 Nov 10 |
nicklas |
155 |
directory.setName(Values.getStringOrNull(request.getParameter("name"))); |
5501 |
18 Nov 10 |
nicklas |
156 |
final boolean autoCompress = Values.getBoolean(request.getParameter("autoCompress")); |
5501 |
18 Nov 10 |
nicklas |
157 |
final boolean autoShare = Values.getBoolean(request.getParameter("autoShare")); |
5501 |
18 Nov 10 |
nicklas |
158 |
directory.setAutoCompress(autoCompress); |
5501 |
18 Nov 10 |
nicklas |
159 |
directory.setAutoShare(autoShare); |
5501 |
18 Nov 10 |
nicklas |
160 |
directory.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
5501 |
18 Nov 10 |
nicklas |
161 |
|
5501 |
18 Nov 10 |
nicklas |
162 |
final boolean autoCompressRecursive = Values.getBoolean(request.getParameter("autoCompressRecursive")); |
5501 |
18 Nov 10 |
nicklas |
163 |
final boolean autoShareRecursive = Values.getBoolean(request.getParameter("autoShareRecursive")); |
5501 |
18 Nov 10 |
nicklas |
164 |
if (autoCompressRecursive || autoShareRecursive) |
5501 |
18 Nov 10 |
nicklas |
165 |
{ |
5501 |
18 Nov 10 |
nicklas |
166 |
net.sf.basedb.util.FileUtil.doRecursively(dc, directory, |
5501 |
18 Nov 10 |
nicklas |
167 |
new net.sf.basedb.util.filter.Filter<Directory>() |
5010 |
23 Jun 09 |
nicklas |
168 |
{ |
5501 |
18 Nov 10 |
nicklas |
169 |
public boolean evaluate(Directory dir) |
5501 |
18 Nov 10 |
nicklas |
170 |
{ |
5501 |
18 Nov 10 |
nicklas |
171 |
if (autoShareRecursive) dir.setAutoShare(autoShare); |
5501 |
18 Nov 10 |
nicklas |
172 |
if (autoCompressRecursive) dir.setAutoCompress(autoCompress); |
5501 |
18 Nov 10 |
nicklas |
173 |
return true; |
5501 |
18 Nov 10 |
nicklas |
174 |
} |
5501 |
18 Nov 10 |
nicklas |
175 |
}, null); |
5501 |
18 Nov 10 |
nicklas |
176 |
} |
5501 |
18 Nov 10 |
nicklas |
177 |
|
5501 |
18 Nov 10 |
nicklas |
178 |
// OnSave extensions |
5501 |
18 Nov 10 |
nicklas |
179 |
invoker.render(OnSaveRenderer.ON_SAVE); |
5501 |
18 Nov 10 |
nicklas |
180 |
dc.commit(); |
5501 |
18 Nov 10 |
nicklas |
181 |
invoker.render(OnSaveRenderer.ON_COMMIT); |
5010 |
23 Jun 09 |
nicklas |
182 |
} |
5501 |
18 Nov 10 |
nicklas |
183 |
catch (Exception ex) |
5501 |
18 Nov 10 |
nicklas |
184 |
{ |
5501 |
18 Nov 10 |
nicklas |
185 |
invoker.render(OnSaveRenderer.onRollback(ex)); |
5501 |
18 Nov 10 |
nicklas |
186 |
throw ex; |
5501 |
18 Nov 10 |
nicklas |
187 |
} |
5501 |
18 Nov 10 |
nicklas |
188 |
finally |
5501 |
18 Nov 10 |
nicklas |
189 |
{ |
5501 |
18 Nov 10 |
nicklas |
190 |
cc.removeObject("item"); |
5501 |
18 Nov 10 |
nicklas |
191 |
} |
1794 |
19 Jan 06 |
nicklas |
192 |
} |
1794 |
19 Jan 06 |
nicklas |
193 |
else |
1794 |
19 Jan 06 |
nicklas |
194 |
{ |
1794 |
19 Jan 06 |
nicklas |
195 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
1794 |
19 Jan 06 |
nicklas |
196 |
} |
1794 |
19 Jan 06 |
nicklas |
197 |
} |
1794 |
19 Jan 06 |
nicklas |
198 |
finally |
1794 |
19 Jan 06 |
nicklas |
199 |
{ |
1794 |
19 Jan 06 |
nicklas |
200 |
if (dc != null) dc.close(); |
1794 |
19 Jan 06 |
nicklas |
201 |
} |
1794 |
19 Jan 06 |
nicklas |
202 |
|
1794 |
19 Jan 06 |
nicklas |
203 |
if (forward != null) |
1794 |
19 Jan 06 |
nicklas |
204 |
{ |
6192 |
31 Oct 12 |
nicklas |
205 |
sc.setSessionSetting("alert-message", message); |
1794 |
19 Jan 06 |
nicklas |
206 |
pageContext.forward(forward); |
1794 |
19 Jan 06 |
nicklas |
207 |
} |
1794 |
19 Jan 06 |
nicklas |
208 |
else if (redirect != null) |
1794 |
19 Jan 06 |
nicklas |
209 |
{ |
6192 |
31 Oct 12 |
nicklas |
210 |
sc.setSessionSetting("alert-message", message); |
1794 |
19 Jan 06 |
nicklas |
211 |
response.sendRedirect(redirect); |
1794 |
19 Jan 06 |
nicklas |
212 |
} |
1794 |
19 Jan 06 |
nicklas |
213 |
else if (message == null) |
1794 |
19 Jan 06 |
nicklas |
214 |
{ |
1794 |
19 Jan 06 |
nicklas |
215 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
1794 |
19 Jan 06 |
nicklas |
216 |
} |
1794 |
19 Jan 06 |
nicklas |
217 |
else |
1794 |
19 Jan 06 |
nicklas |
218 |
{ |
1794 |
19 Jan 06 |
nicklas |
219 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
1794 |
19 Jan 06 |
nicklas |
220 |
} |
1794 |
19 Jan 06 |
nicklas |
221 |
%> |
1794 |
19 Jan 06 |
nicklas |
222 |
|