1 | <%-- $Id: index.jsp 2917 2006-11-15 10:28:36Z nicklas $ |
---|
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 |
---|
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.LabeledExtract" |
---|
33 | import="net.sf.basedb.core.Extract" |
---|
34 | import="net.sf.basedb.core.Label" |
---|
35 | import="net.sf.basedb.core.BioMaterialEvent" |
---|
36 | import="net.sf.basedb.core.Protocol" |
---|
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.util.RemovableUtil" |
---|
45 | import="net.sf.basedb.util.ShareableUtil" |
---|
46 | import="net.sf.basedb.util.OwnableUtil" |
---|
47 | import="net.sf.basedb.clients.web.Base" |
---|
48 | import="net.sf.basedb.clients.web.WebException" |
---|
49 | import="net.sf.basedb.util.Values" |
---|
50 | import="net.sf.basedb.clients.web.util.HTML" |
---|
51 | import="java.util.Enumeration" |
---|
52 | import="java.util.Set" |
---|
53 | import="java.util.HashSet" |
---|
54 | import="java.util.List" |
---|
55 | import="java.util.ArrayList" |
---|
56 | import="java.util.Collections" |
---|
57 | %> |
---|
58 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
59 | <%! |
---|
60 | private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,label,originalQuantity,remainingQuantity,hybridizations,description"); |
---|
61 | private static final Item itemType = Item.LABELEDEXTRACT; |
---|
62 | %> |
---|
63 | <% |
---|
64 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
65 | final String ID = sc.getId(); |
---|
66 | final String cmd = request.getParameter("cmd"); |
---|
67 | final String root = request.getContextPath()+"/"; |
---|
68 | final String mode = request.getParameter("mode"); |
---|
69 | final String callback = request.getParameter("callback"); |
---|
70 | final String itemId = request.getParameter("item_id"); |
---|
71 | final String listPage = "list_labeledextracts.jsp?ID="+ID |
---|
72 | +(mode == null ? "" : "&mode="+mode) |
---|
73 | +(callback == null ? "" : "&callback="+callback) |
---|
74 | +(itemId == null ? "" : "&item_id="+itemId); |
---|
75 | final String viewPage = "view_labeledextract.jsp?ID="+ID; |
---|
76 | final String editPage = "edit_labeledextract.jsp?ID="+ID; |
---|
77 | |
---|
78 | String forward = null; |
---|
79 | String redirect = null; |
---|
80 | String message = null; |
---|
81 | DbControl dc = null; |
---|
82 | |
---|
83 | try |
---|
84 | { |
---|
85 | if (cmd == null || "List".equals(cmd)) |
---|
86 | { |
---|
87 | // Display the list page without updatinging the current context |
---|
88 | Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true); |
---|
89 | redirect = listPage; |
---|
90 | } |
---|
91 | else if ("UpdateContext".equals(cmd)) |
---|
92 | { |
---|
93 | // Display the list page after updating the current context from the request parameters |
---|
94 | Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
95 | redirect = listPage; |
---|
96 | } |
---|
97 | else if ("LoadContext".equals(cmd)) |
---|
98 | { |
---|
99 | // Display the list page after loading a saved context |
---|
100 | int contextId = Values.getInt(request.getParameter("context")); |
---|
101 | Base.loadContext(sc, contextId, defaultContext); |
---|
102 | redirect = listPage; |
---|
103 | } |
---|
104 | |
---|
105 | else if ("ViewItem".equals(cmd)) |
---|
106 | { |
---|
107 | // Display the view page for a single item |
---|
108 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
109 | forward = viewPage; |
---|
110 | } |
---|
111 | else if ("EditItem".equals(cmd)) |
---|
112 | { |
---|
113 | // Display the edit page for a single item (should be opened in a popup) |
---|
114 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
115 | redirect = editPage; |
---|
116 | } |
---|
117 | else if ("NewItem".equals(cmd)) |
---|
118 | { |
---|
119 | // Display the edit page for a new item (should be opened in a popup) |
---|
120 | if (!sc.hasPermission(Permission.CREATE, itemType)) |
---|
121 | { |
---|
122 | throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
---|
123 | } |
---|
124 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
125 | cc.setId(0); |
---|
126 | forward = editPage; |
---|
127 | } |
---|
128 | else if ("NewPooledItem".equals(cmd)) |
---|
129 | { |
---|
130 | //Display the edit page for a new pooled item (should be opened in a popup) |
---|
131 | if (!sc.hasPermission(Permission.CREATE, itemType)) |
---|
132 | { |
---|
133 | throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
---|
134 | } |
---|
135 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
136 | cc.setId(0); |
---|
137 | forward = editPage+"&pooled=true"; |
---|
138 | } |
---|
139 | else if ("NewHybridization".equals(cmd)) |
---|
140 | { |
---|
141 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
142 | redirect = "../../views/hybridizations/index.jsp?ID="+ID+"&cmd=NewItem&useParents=true"; |
---|
143 | } |
---|
144 | else if ("UpdateItem".equals(cmd)) |
---|
145 | { |
---|
146 | // Update the properties on an item (will close the popup) |
---|
147 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
---|
148 | final int maxRecent = Base.getMaxRecent(sc); |
---|
149 | dc = sc.newDbControl(); |
---|
150 | LabeledExtract extract = (LabeledExtract)cc.getObject("item"); |
---|
151 | int labelId = Values.getInt(request.getParameter("label_id"), -1); |
---|
152 | if (extract == null) |
---|
153 | { |
---|
154 | extract = LabeledExtract.getNew(dc, Label.getById(dc, labelId)); |
---|
155 | message = "Labeled extract created"; |
---|
156 | dc.saveItem(extract); |
---|
157 | cc.setRecent(extract.getLabel(), maxRecent); |
---|
158 | } |
---|
159 | else |
---|
160 | { |
---|
161 | dc.reattachItem(extract); |
---|
162 | dc.reattachItem(extract.getCreationEvent()); |
---|
163 | message = "Labeled extract updated"; |
---|
164 | if (labelId >= 0) // < 0 = denied or unchanged |
---|
165 | { |
---|
166 | Label l = labelId == 0 ? null : Label.getById(dc, labelId); |
---|
167 | extract.setLabel(l); |
---|
168 | if (l != null) cc.setRecent(l, maxRecent); |
---|
169 | } |
---|
170 | } |
---|
171 | extract.setName(Values.getStringOrNull(request.getParameter("name"))); |
---|
172 | extract.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
---|
173 | extract.setExternalId(Values.getStringOrNull(request.getParameter("external_id"))); |
---|
174 | extract.setOriginalQuantity(Values.getFloat(request.getParameter("original_quantity"), null)); |
---|
175 | |
---|
176 | BioMaterialEvent creationEvent = extract.getCreationEvent(); |
---|
177 | creationEvent.setEventDate(Values.getDate(request.getParameter("event_date"))); |
---|
178 | int protocolId = Values.getInt(request.getParameter("protocol_id"), -1); |
---|
179 | if (protocolId >= 0) // < 0 = denied or unchanged |
---|
180 | { |
---|
181 | Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId); |
---|
182 | creationEvent.setProtocol(pt); |
---|
183 | if (pt != null) cc.setRecent(pt, maxRecent); |
---|
184 | } |
---|
185 | |
---|
186 | // Parents tab |
---|
187 | extract.setPooled(Values.getBoolean(request.getParameter("pooled"))); |
---|
188 | if (!extract.isPooled()) |
---|
189 | { |
---|
190 | int extractId = Values.getInt(request.getParameter("extract_id"), -1); |
---|
191 | if (extractId >= 0) // < 0 = denied or unchanged |
---|
192 | { |
---|
193 | Extract e = extractId == 0 ? null : Extract.getById(dc, extractId); |
---|
194 | extract.setExtract(e, e == null ? null : Values.getFloat(request.getParameter("used_from_extract"), null)); |
---|
195 | if (e != null) cc.setRecent(e, maxRecent); |
---|
196 | } |
---|
197 | } |
---|
198 | else |
---|
199 | { |
---|
200 | String[] modifiedExtracts = Values.getString(request.getParameter("modifiedLabeledExtracts")).split(","); |
---|
201 | for (int i = 0; i < modifiedExtracts.length; ++i) |
---|
202 | { |
---|
203 | int eId = Values.getInt(modifiedExtracts[i], -1); |
---|
204 | if (eId != -1) |
---|
205 | { |
---|
206 | LabeledExtract e = LabeledExtract.getById(dc, eId); |
---|
207 | creationEvent.addSource(e, Values.getFloat(request.getParameter("E"+eId), null)); |
---|
208 | } |
---|
209 | } |
---|
210 | String[] removedExtracts = Values.getString(request.getParameter("removedLabeledExtracts")).split(","); |
---|
211 | for (int i = 0; i < removedExtracts.length; ++i) |
---|
212 | { |
---|
213 | int eId = Values.getInt(removedExtracts[i], -1); |
---|
214 | if (eId != -1) creationEvent.removeSource(LabeledExtract.getById(dc, eId)); |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|
218 | // Annotations tab |
---|
219 | Base.updateAnnotations(dc, extract, extract, request); |
---|
220 | dc.commit(); |
---|
221 | cc.removeObject("item"); |
---|
222 | } |
---|
223 | else if ("DeleteItem".equals(cmd)) |
---|
224 | { |
---|
225 | // Delete 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()), true); |
---|
229 | dc.commit(); |
---|
230 | redirect = viewPage; |
---|
231 | } |
---|
232 | else if ("DeleteItems".equals(cmd)) |
---|
233 | { |
---|
234 | // Delete 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(), true); |
---|
239 | dc.commit(); |
---|
240 | if (numTotal != numRemoved) |
---|
241 | { |
---|
242 | message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission"; |
---|
243 | } |
---|
244 | redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : ""); |
---|
245 | } |
---|
246 | else if ("RestoreItem".equals(cmd)) |
---|
247 | { |
---|
248 | // Restore a single item and then return to the view page |
---|
249 | dc = sc.newDbControl(); |
---|
250 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
251 | RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false); |
---|
252 | dc.commit(); |
---|
253 | redirect = viewPage; |
---|
254 | } |
---|
255 | else if ("RestoreItems".equals(cmd)) |
---|
256 | { |
---|
257 | // Restore 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 numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false); |
---|
262 | dc.commit(); |
---|
263 | if (numTotal != numRemoved) |
---|
264 | { |
---|
265 | message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; |
---|
266 | } |
---|
267 | redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : ""); |
---|
268 | } |
---|
269 | else if ("ShareItem".equals(cmd)) |
---|
270 | { |
---|
271 | // Display a popup window for sharing a single item |
---|
272 | dc = sc.newDbControl(); |
---|
273 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
274 | MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId())); |
---|
275 | dc.close(); |
---|
276 | cc.setObject("MultiPermissions", permissions); |
---|
277 | redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
---|
278 | } |
---|
279 | else if ("ShareItems".equals(cmd)) |
---|
280 | { |
---|
281 | // Display a popup window for sharing all selected items on the list page |
---|
282 | dc = sc.newDbControl(); |
---|
283 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
284 | MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected()); |
---|
285 | dc.close(); |
---|
286 | cc.setObject("MultiPermissions", permissions); |
---|
287 | redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
---|
288 | } |
---|
289 | else if ("TakeOwnershipOfItem".equals(cmd)) |
---|
290 | { |
---|
291 | // Take ownership a single item and then return to the view page |
---|
292 | dc = sc.newDbControl(); |
---|
293 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
294 | OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null); |
---|
295 | dc.commit(); |
---|
296 | redirect = viewPage; |
---|
297 | } |
---|
298 | else if ("TakeOwnershipOfItems".equals(cmd)) |
---|
299 | { |
---|
300 | // Take ownership all selected items on the list page |
---|
301 | dc = sc.newDbControl(); |
---|
302 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
303 | int numTotal = cc.getSelected().size(); |
---|
304 | int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null); |
---|
305 | dc.commit(); |
---|
306 | if (numTotal != numOwned) |
---|
307 | { |
---|
308 | message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission"; |
---|
309 | } |
---|
310 | redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : ""); |
---|
311 | } |
---|
312 | else if ("ExportItems".equals(cmd)) |
---|
313 | { |
---|
314 | // Run an export plugin in a list context |
---|
315 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
316 | final ItemQuery<LabeledExtract> query = LabeledExtract.getQuery(); |
---|
317 | cc.configureQuery(query, true); |
---|
318 | cc.setQuery(query); |
---|
319 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+labeled+extracts"; |
---|
320 | } |
---|
321 | else if ("ExportItem".equals(cmd)) |
---|
322 | { |
---|
323 | // Run an export plugin in single-item context |
---|
324 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
325 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+labeled+extract"; |
---|
326 | } |
---|
327 | else if ("ImportItems".equals(cmd)) |
---|
328 | { |
---|
329 | // Run an import plugin in a list context |
---|
330 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
331 | final ItemQuery<LabeledExtract> query = LabeledExtract.getQuery(); |
---|
332 | cc.configureQuery(query, true); |
---|
333 | cc.setQuery(query); |
---|
334 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+labeled+extracts"; |
---|
335 | } |
---|
336 | else if ("ImportItem".equals(cmd)) |
---|
337 | { |
---|
338 | // Run an import plugin in single-item context |
---|
339 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
340 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+labeled+extract"; |
---|
341 | } |
---|
342 | else if ("RunListPlugin".equals(cmd)) |
---|
343 | { |
---|
344 | // Run another plugin in a list context |
---|
345 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
346 | final ItemQuery<LabeledExtract> query = LabeledExtract.getQuery(); |
---|
347 | cc.configureQuery(query, true); |
---|
348 | cc.setQuery(query); |
---|
349 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
---|
350 | } |
---|
351 | else if ("RunPlugin".equals(cmd)) |
---|
352 | { |
---|
353 | // Run another plugin in single-item context |
---|
354 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
355 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; |
---|
356 | } |
---|
357 | else |
---|
358 | { |
---|
359 | throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
---|
360 | } |
---|
361 | } |
---|
362 | finally |
---|
363 | { |
---|
364 | if (dc != null) dc.close(); |
---|
365 | } |
---|
366 | |
---|
367 | if (forward != null) |
---|
368 | { |
---|
369 | pageContext.forward(forward); |
---|
370 | } |
---|
371 | else if (redirect != null) |
---|
372 | { |
---|
373 | response.sendRedirect(redirect); |
---|
374 | } |
---|
375 | else if (message == null) |
---|
376 | { |
---|
377 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
---|
378 | } |
---|
379 | else |
---|
380 | { |
---|
381 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
---|
382 | } |
---|
383 | %> |
---|
384 | |
---|