1 | <%-- $Id: index.jsp 3679 2007-08-17 07:18:29Z jari $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Jari Hakkinen, Nicklas Nordborg, Martin Svensson |
---|
5 | |
---|
6 | This file is part of BASE - BioArray Software Environment. |
---|
7 | Available at http://base.thep.lu.se/ |
---|
8 | |
---|
9 | BASE is free software; you can redistribute it and/or |
---|
10 | modify it under the terms of the GNU General Public License |
---|
11 | as published by the Free Software Foundation; either version 2 |
---|
12 | of the License, or (at your option) any later version. |
---|
13 | |
---|
14 | BASE is distributed in the hope that it will be useful, |
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | GNU General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with this program; if not, write to the Free Software |
---|
21 | Foundation, Inc., 59 Temple Place - Suite 330, |
---|
22 | Boston, MA 02111-1307, USA. |
---|
23 | ------------------------------------------------------------------ |
---|
24 | |
---|
25 | @author Nicklas |
---|
26 | @version 2.0 |
---|
27 | --%> |
---|
28 | <%@ page session="false" |
---|
29 | import="net.sf.basedb.core.BasicItem" |
---|
30 | import="net.sf.basedb.core.SessionControl" |
---|
31 | import="net.sf.basedb.core.DbControl" |
---|
32 | import="net.sf.basedb.core.Item" |
---|
33 | import="net.sf.basedb.core.Include" |
---|
34 | import="net.sf.basedb.core.Project" |
---|
35 | import="net.sf.basedb.core.User" |
---|
36 | import="net.sf.basedb.core.Group" |
---|
37 | import="net.sf.basedb.core.ItemQuery" |
---|
38 | import="net.sf.basedb.core.ItemResultIterator" |
---|
39 | import="net.sf.basedb.core.Permission" |
---|
40 | import="net.sf.basedb.core.ItemContext" |
---|
41 | import="net.sf.basedb.core.MultiPermissions" |
---|
42 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
43 | import="net.sf.basedb.core.ItemAlreadyExistsException" |
---|
44 | import="net.sf.basedb.core.RawDataType" |
---|
45 | import="net.sf.basedb.core.RawDataTypes" |
---|
46 | import="net.sf.basedb.util.RemovableUtil" |
---|
47 | import="net.sf.basedb.util.OwnableUtil" |
---|
48 | import="net.sf.basedb.clients.web.Base" |
---|
49 | import="net.sf.basedb.clients.web.PermissionUtil" |
---|
50 | import="net.sf.basedb.clients.web.WebException" |
---|
51 | import="net.sf.basedb.util.Values" |
---|
52 | import="net.sf.basedb.clients.web.util.HTML" |
---|
53 | import="java.util.Enumeration" |
---|
54 | import="java.util.Set" |
---|
55 | import="java.util.HashSet" |
---|
56 | import="java.util.List" |
---|
57 | import="java.util.ArrayList" |
---|
58 | import="java.util.Collections" |
---|
59 | %> |
---|
60 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
61 | <%! |
---|
62 | private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,description,actions"); |
---|
63 | private static final Item itemType = Item.PROJECT; |
---|
64 | %> |
---|
65 | <% |
---|
66 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
67 | final String ID = sc.getId(); |
---|
68 | final String cmd = request.getParameter("cmd"); |
---|
69 | final String root = request.getContextPath()+"/"; |
---|
70 | final String mode = request.getParameter("mode"); |
---|
71 | final String callback = request.getParameter("callback"); |
---|
72 | final String itemId = request.getParameter("item_id"); |
---|
73 | final String listPage = "list_projects.jsp?ID="+ID |
---|
74 | +(mode == null ? "" : "&mode="+mode) |
---|
75 | +(callback == null ? "" : "&callback="+callback) |
---|
76 | +(itemId == null ? "" : "&item_id="+itemId); |
---|
77 | final String viewPage = "view_project.jsp?ID="+ID; |
---|
78 | final String editPage = "edit_project.jsp?ID="+ID; |
---|
79 | |
---|
80 | String forward = null; |
---|
81 | String redirect = null; |
---|
82 | String message = null; |
---|
83 | DbControl dc = null; |
---|
84 | |
---|
85 | try |
---|
86 | { |
---|
87 | if (cmd == null || "List".equals(cmd)) |
---|
88 | { |
---|
89 | // Display the list page without updatinging the current context |
---|
90 | Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true); |
---|
91 | redirect = listPage; |
---|
92 | } |
---|
93 | else if ("UpdateContext".equals(cmd)) |
---|
94 | { |
---|
95 | // Display the list page after updating the current context from the request parameters |
---|
96 | Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
97 | redirect = listPage; |
---|
98 | } |
---|
99 | else if ("LoadContext".equals(cmd)) |
---|
100 | { |
---|
101 | // Display the list page after loading a saved context |
---|
102 | int contextId = Values.getInt(request.getParameter("context")); |
---|
103 | Base.loadContext(sc, contextId, defaultContext); |
---|
104 | redirect = listPage; |
---|
105 | } |
---|
106 | |
---|
107 | else if ("ViewItem".equals(cmd)) |
---|
108 | { |
---|
109 | // Display the view page for a single item |
---|
110 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
111 | forward = viewPage; |
---|
112 | } |
---|
113 | else if ("EditItem".equals(cmd)) |
---|
114 | { |
---|
115 | // Display the edit page for a single item (should be opened in a popup) |
---|
116 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
117 | redirect = editPage; |
---|
118 | } |
---|
119 | else if ("NewItem".equals(cmd)) |
---|
120 | { |
---|
121 | // Display the edit page for a new item (should be opened in a popup) |
---|
122 | if (!sc.hasPermission(Permission.CREATE, itemType)) |
---|
123 | { |
---|
124 | throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
---|
125 | } |
---|
126 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
127 | cc.setId(0); |
---|
128 | redirect = editPage; |
---|
129 | } |
---|
130 | else if ("UpdateItem".equals(cmd)) |
---|
131 | { |
---|
132 | // Update the properties on an item (will close the popup) |
---|
133 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
---|
134 | dc = sc.newDbControl(); |
---|
135 | Project project = (Project)cc.getObject("item"); |
---|
136 | if (project == null) |
---|
137 | { |
---|
138 | project = Project.getNew(dc); |
---|
139 | message = "Project created"; |
---|
140 | dc.saveItem(project); |
---|
141 | } |
---|
142 | else |
---|
143 | { |
---|
144 | dc.reattachItem(project); |
---|
145 | message = "Project updated"; |
---|
146 | } |
---|
147 | project.setName(Values.getStringOrNull(request.getParameter("name"))); |
---|
148 | project.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
---|
149 | |
---|
150 | // Members tab |
---|
151 | String[] modifiedUsers = Values.getString(request.getParameter("modifiedUsers")).split(","); |
---|
152 | for (int i = 0; i < modifiedUsers.length; ++i) |
---|
153 | { |
---|
154 | int userId = Values.getInt(modifiedUsers[i], -1); |
---|
155 | if (userId != -1) |
---|
156 | { |
---|
157 | Set<Permission> permissions = PermissionUtil.getPermissions(Values.getInt(request.getParameter("U"+userId), 0)); |
---|
158 | project.setPermissions(User.getById(dc, userId), permissions); |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | String[] modifiedGroups = Values.getString(request.getParameter("modifiedGroups")).split(","); |
---|
163 | for (int i = 0; i < modifiedGroups.length; ++i) |
---|
164 | { |
---|
165 | int groupId = Values.getInt(modifiedGroups[i], -1); |
---|
166 | if (groupId != -1) |
---|
167 | { |
---|
168 | Set<Permission> permissions = PermissionUtil.getPermissions(Values.getInt(request.getParameter("G"+groupId), 0)); |
---|
169 | project.setPermissions(Group.getById(dc, groupId), permissions); |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | // Default tab |
---|
174 | for (Project.Default d : Project.Default.values()) |
---|
175 | { |
---|
176 | String selectDefault = "value_"+d.getName(); |
---|
177 | if (d.getItemType() != null) |
---|
178 | { |
---|
179 | int selectId = Values.getInt(request.getParameter(selectDefault), -1); |
---|
180 | if (selectId >= 0) |
---|
181 | { |
---|
182 | BasicItem item = selectId == 0 ? null : d.getItemType().getById(dc, selectId); |
---|
183 | project.setDefaultItem(dc, item, d); |
---|
184 | } |
---|
185 | } |
---|
186 | else if (d == Project.Default.RAW_DATA_TYPE) |
---|
187 | { |
---|
188 | String selectId = request.getParameter(selectDefault); |
---|
189 | if (selectId != null && selectId.length() > 0) |
---|
190 | { |
---|
191 | RawDataType rdt = selectId.equals("0") ? null :RawDataTypes.getRawDataType(selectId); |
---|
192 | project.setDefaultRawDataType(rdt); |
---|
193 | } |
---|
194 | } |
---|
195 | } |
---|
196 | |
---|
197 | dc.commit(); |
---|
198 | cc.removeObject("item"); |
---|
199 | } |
---|
200 | else if ("DeleteItem".equals(cmd)) |
---|
201 | { |
---|
202 | // Delete a single item and then return to the view page |
---|
203 | dc = sc.newDbControl(); |
---|
204 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
205 | RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true); |
---|
206 | dc.commit(); |
---|
207 | redirect = viewPage; |
---|
208 | } |
---|
209 | else if ("DeleteItems".equals(cmd)) |
---|
210 | { |
---|
211 | // Delete all selected items on the list page |
---|
212 | dc = sc.newDbControl(); |
---|
213 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
214 | int numTotal = cc.getSelected().size(); |
---|
215 | int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true); |
---|
216 | dc.commit(); |
---|
217 | if (numTotal != numRemoved) |
---|
218 | { |
---|
219 | message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission"; |
---|
220 | } |
---|
221 | redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : ""); |
---|
222 | } |
---|
223 | else if ("RestoreItem".equals(cmd)) |
---|
224 | { |
---|
225 | // Restore a single item and then return to the view page |
---|
226 | dc = sc.newDbControl(); |
---|
227 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
228 | RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false); |
---|
229 | dc.commit(); |
---|
230 | redirect = viewPage; |
---|
231 | } |
---|
232 | else if ("RestoreItems".equals(cmd)) |
---|
233 | { |
---|
234 | // Restore all selected items on the list page |
---|
235 | dc = sc.newDbControl(); |
---|
236 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
237 | int numTotal = cc.getSelected().size(); |
---|
238 | int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false); |
---|
239 | dc.commit(); |
---|
240 | if (numTotal != numRemoved) |
---|
241 | { |
---|
242 | message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; |
---|
243 | } |
---|
244 | redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : ""); |
---|
245 | } |
---|
246 | else if ("TakeOwnershipOfItem".equals(cmd)) |
---|
247 | { |
---|
248 | // Take ownership a single item and then return to the view page |
---|
249 | dc = sc.newDbControl(); |
---|
250 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
251 | OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null); |
---|
252 | dc.commit(); |
---|
253 | redirect = viewPage; |
---|
254 | } |
---|
255 | else if ("TakeOwnershipOfItems".equals(cmd)) |
---|
256 | { |
---|
257 | // Take ownership all selected items on the list page |
---|
258 | dc = sc.newDbControl(); |
---|
259 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
260 | int numTotal = cc.getSelected().size(); |
---|
261 | int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null); |
---|
262 | dc.commit(); |
---|
263 | if (numTotal != numOwned) |
---|
264 | { |
---|
265 | message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission"; |
---|
266 | } |
---|
267 | redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : ""); |
---|
268 | } |
---|
269 | else if ("ExportItems".equals(cmd)) |
---|
270 | { |
---|
271 | // Run an export plugin in a list context |
---|
272 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
273 | final ItemQuery<Project> query = Project.getQuery(); |
---|
274 | cc.configureQuery(query, true); |
---|
275 | cc.setQuery(query); |
---|
276 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+projects"; |
---|
277 | } |
---|
278 | else if ("ExportItem".equals(cmd)) |
---|
279 | { |
---|
280 | // Run an export plugin in single-item context |
---|
281 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
282 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+project"; |
---|
283 | } |
---|
284 | else if ("ImportItems".equals(cmd)) |
---|
285 | { |
---|
286 | // Run an import plugin in a list context |
---|
287 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
288 | final ItemQuery<Project> query = Project.getQuery(); |
---|
289 | cc.configureQuery(query, true); |
---|
290 | cc.setQuery(query); |
---|
291 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+projects"; |
---|
292 | } |
---|
293 | else if ("ImportItem".equals(cmd)) |
---|
294 | { |
---|
295 | // Run an import plugin in single-item context |
---|
296 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
297 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+project"; |
---|
298 | } |
---|
299 | else if ("RunListPlugin".equals(cmd)) |
---|
300 | { |
---|
301 | // Run another plugin in a list context |
---|
302 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
303 | final ItemQuery<Project> query = Project.getQuery(); |
---|
304 | cc.configureQuery(query, true); |
---|
305 | cc.setQuery(query); |
---|
306 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
---|
307 | } |
---|
308 | else if ("RunPlugin".equals(cmd)) |
---|
309 | { |
---|
310 | // Run another plugin in single-item context |
---|
311 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
312 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; |
---|
313 | } |
---|
314 | else |
---|
315 | { |
---|
316 | throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
---|
317 | } |
---|
318 | } |
---|
319 | finally |
---|
320 | { |
---|
321 | if (dc != null) dc.close(); |
---|
322 | } |
---|
323 | |
---|
324 | if (forward != null) |
---|
325 | { |
---|
326 | pageContext.forward(forward); |
---|
327 | } |
---|
328 | else if (redirect != null) |
---|
329 | { |
---|
330 | response.sendRedirect(redirect); |
---|
331 | } |
---|
332 | else if (message == null) |
---|
333 | { |
---|
334 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
---|
335 | } |
---|
336 | else |
---|
337 | { |
---|
338 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
---|
339 | } |
---|
340 | %> |
---|
341 | |
---|