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