1 | <%-- $Id: index.jsp 4133 2008-02-08 10:54:05Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg, Gregory Vincic |
---|
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.SessionControl" |
---|
30 | import="net.sf.basedb.core.DbControl" |
---|
31 | import="net.sf.basedb.core.Item" |
---|
32 | import="net.sf.basedb.core.Include" |
---|
33 | import="net.sf.basedb.core.Hybridization" |
---|
34 | import="net.sf.basedb.core.ArraySlide" |
---|
35 | import="net.sf.basedb.core.BioMaterialEvent" |
---|
36 | import="net.sf.basedb.core.LabeledExtract" |
---|
37 | import="net.sf.basedb.core.Protocol" |
---|
38 | import="net.sf.basedb.core.Hardware" |
---|
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,labeledExtracts,arraySlide,scans,description"); |
---|
66 | private static final Item itemType = Item.HYBRIDIZATION; |
---|
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_hybridizations.jsp?ID="+ID |
---|
77 | +(mode == null ? "" : "&mode="+mode) |
---|
78 | +(callback == null ? "" : "&callback="+callback) |
---|
79 | +(itemId == null ? "" : "&item_id="+itemId); |
---|
80 | final String viewPage = "view_hybridization.jsp?ID="+ID; |
---|
81 | final String editPage = "edit_hybridization.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 | Hybridization hyb = (Hybridization)cc.getObject("item"); |
---|
140 | BioMaterialEvent creationEvent = null; |
---|
141 | if (hyb == null) |
---|
142 | { |
---|
143 | hyb = Hybridization.getNew(dc); |
---|
144 | creationEvent = hyb.getCreationEvent(); |
---|
145 | message = "Hybridization created"; |
---|
146 | dc.saveItem(hyb); |
---|
147 | } |
---|
148 | else |
---|
149 | { |
---|
150 | creationEvent = hyb.getCreationEvent(); |
---|
151 | dc.reattachItem(hyb); |
---|
152 | dc.reattachItem(creationEvent); |
---|
153 | message = "Hybridization updated"; |
---|
154 | } |
---|
155 | hyb.setName(Values.getStringOrNull(request.getParameter("name"))); |
---|
156 | hyb.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
---|
157 | hyb.setNumArrays(Values.getInt(request.getParameter("numArrays"), 1)); |
---|
158 | |
---|
159 | int arraySlideId = Values.getInt(request.getParameter("arrayslide_id"), -1); |
---|
160 | if (arraySlideId >= 0) // < 0 = denied or unchanged |
---|
161 | { |
---|
162 | ArraySlide slide = arraySlideId == 0 ? null : ArraySlide.getById(dc, arraySlideId); |
---|
163 | hyb.setArraySlide(slide); |
---|
164 | } |
---|
165 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
166 | creationEvent.setEventDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("event_date")))); |
---|
167 | int protocolId = Values.getInt(request.getParameter("protocol_id"), -1); |
---|
168 | if (protocolId >= 0) // < 0 = denied or unchanged |
---|
169 | { |
---|
170 | Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId); |
---|
171 | creationEvent.setProtocol(pt); |
---|
172 | if (pt != null) cc.setRecent(pt, maxRecent); |
---|
173 | } |
---|
174 | |
---|
175 | //Hybridization station |
---|
176 | int hybStationId = Values.getInt(request.getParameter("hardware_id"), -1); |
---|
177 | if (hybStationId >= 0) // < 0 denied or unchanged |
---|
178 | { |
---|
179 | Hardware hw = hybStationId == 0 ? null : Hardware.getById(dc, hybStationId); |
---|
180 | creationEvent.setHardware(hw); |
---|
181 | if (hw != null) cc.setRecent(hw, maxRecent); |
---|
182 | } |
---|
183 | |
---|
184 | // Labeled extracts |
---|
185 | String[] modifiedLabeledExtracts = Values.getString(request.getParameter("modifiedLabeledExtracts")).split(","); |
---|
186 | for (int i = 0; i < modifiedLabeledExtracts.length; ++i) |
---|
187 | { |
---|
188 | int leId = Values.getInt(modifiedLabeledExtracts[i], -1); |
---|
189 | if (leId != -1) |
---|
190 | { |
---|
191 | LabeledExtract le = LabeledExtract.getById(dc, leId); |
---|
192 | String[] extra = request.getParameter("L"+leId).split(":"); |
---|
193 | Float usedQuantity = Values.getFloat(extra[0], null); |
---|
194 | int arrayIndex = extra.length > 1 ? Values.getInt(extra[1], 1) : 1; |
---|
195 | creationEvent.addSource(le, usedQuantity); |
---|
196 | creationEvent.setSourceGroup(le, arrayIndex); |
---|
197 | } |
---|
198 | } |
---|
199 | String[] removedLabeledExtracts = Values.getString(request.getParameter("removedLabeledExtracts")).split(","); |
---|
200 | for (int i = 0; i < removedLabeledExtracts.length; ++i) |
---|
201 | { |
---|
202 | int leId = Values.getInt(removedLabeledExtracts[i], -1); |
---|
203 | if (leId != -1) creationEvent.removeSource(LabeledExtract.getById(dc, leId)); |
---|
204 | } |
---|
205 | |
---|
206 | // Annotations tab |
---|
207 | Base.updateAnnotations(dc, hyb, hyb, request); |
---|
208 | dc.commit(); |
---|
209 | cc.removeObject("item"); |
---|
210 | } |
---|
211 | else if ("DeleteItem".equals(cmd)) |
---|
212 | { |
---|
213 | // Delete a single item and then return to the view page |
---|
214 | dc = sc.newDbControl(); |
---|
215 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
216 | RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true); |
---|
217 | dc.commit(); |
---|
218 | redirect = viewPage; |
---|
219 | } |
---|
220 | else if ("DeleteItems".equals(cmd)) |
---|
221 | { |
---|
222 | // Delete all selected items on the list page |
---|
223 | dc = sc.newDbControl(); |
---|
224 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
225 | int numTotal = cc.getSelected().size(); |
---|
226 | int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true); |
---|
227 | dc.commit(); |
---|
228 | if (numTotal != numRemoved) |
---|
229 | { |
---|
230 | message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission"; |
---|
231 | } |
---|
232 | redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : ""); |
---|
233 | } |
---|
234 | else if ("RestoreItem".equals(cmd)) |
---|
235 | { |
---|
236 | // Restore a single item and then return to the view page |
---|
237 | dc = sc.newDbControl(); |
---|
238 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
239 | RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false); |
---|
240 | dc.commit(); |
---|
241 | redirect = viewPage; |
---|
242 | } |
---|
243 | else if ("RestoreItems".equals(cmd)) |
---|
244 | { |
---|
245 | // Restore all selected items on the list page |
---|
246 | dc = sc.newDbControl(); |
---|
247 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
248 | int numTotal = cc.getSelected().size(); |
---|
249 | int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false); |
---|
250 | dc.commit(); |
---|
251 | if (numTotal != numRemoved) |
---|
252 | { |
---|
253 | message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; |
---|
254 | } |
---|
255 | redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : ""); |
---|
256 | } |
---|
257 | else if ("ShareItem".equals(cmd)) |
---|
258 | { |
---|
259 | // Display a popup window for sharing a single item |
---|
260 | dc = sc.newDbControl(); |
---|
261 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
262 | MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId())); |
---|
263 | dc.close(); |
---|
264 | cc.setObject("MultiPermissions", permissions); |
---|
265 | redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
---|
266 | } |
---|
267 | else if ("ShareItems".equals(cmd)) |
---|
268 | { |
---|
269 | // Display a popup window for sharing all selected items on the list page |
---|
270 | dc = sc.newDbControl(); |
---|
271 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
272 | MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected()); |
---|
273 | dc.close(); |
---|
274 | cc.setObject("MultiPermissions", permissions); |
---|
275 | redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
---|
276 | } |
---|
277 | else if ("TakeOwnershipOfItem".equals(cmd)) |
---|
278 | { |
---|
279 | // Take ownership a single item and then return to the view page |
---|
280 | dc = sc.newDbControl(); |
---|
281 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
282 | OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null); |
---|
283 | dc.commit(); |
---|
284 | redirect = viewPage; |
---|
285 | } |
---|
286 | else if ("TakeOwnershipOfItems".equals(cmd)) |
---|
287 | { |
---|
288 | // Take ownership all selected items on the list page |
---|
289 | dc = sc.newDbControl(); |
---|
290 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
291 | int numTotal = cc.getSelected().size(); |
---|
292 | int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null); |
---|
293 | dc.commit(); |
---|
294 | if (numTotal != numOwned) |
---|
295 | { |
---|
296 | message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission"; |
---|
297 | } |
---|
298 | redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : ""); |
---|
299 | } |
---|
300 | else if ("ExportItems".equals(cmd)) |
---|
301 | { |
---|
302 | // Run an export plugin in a list context |
---|
303 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
304 | final ItemQuery<Hybridization> query = Hybridization.getQuery(); |
---|
305 | cc.configureQuery(query, true); |
---|
306 | cc.setQuery(query); |
---|
307 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+hybridizations"; |
---|
308 | } |
---|
309 | else if ("ExportItem".equals(cmd)) |
---|
310 | { |
---|
311 | // Run an export plugin in single-item context |
---|
312 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
313 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+hybridization"; |
---|
314 | } |
---|
315 | else if ("ImportItems".equals(cmd)) |
---|
316 | { |
---|
317 | // Run an import plugin in a list context |
---|
318 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
319 | final ItemQuery<Hybridization> query = Hybridization.getQuery(); |
---|
320 | cc.configureQuery(query, true); |
---|
321 | cc.setQuery(query); |
---|
322 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+hybrydizations"; |
---|
323 | } |
---|
324 | else if ("ImportItem".equals(cmd)) |
---|
325 | { |
---|
326 | // Run an import plugin in single-item context |
---|
327 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
328 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+hybridization"; |
---|
329 | } |
---|
330 | else if ("RunListPlugin".equals(cmd)) |
---|
331 | { |
---|
332 | // Run another plugin in a list context |
---|
333 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
334 | final ItemQuery<Hybridization> query = Hybridization.getQuery(); |
---|
335 | cc.configureQuery(query, true); |
---|
336 | cc.setQuery(query); |
---|
337 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
---|
338 | } |
---|
339 | else if ("RunPlugin".equals(cmd)) |
---|
340 | { |
---|
341 | // Run another plugin in single-item context |
---|
342 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
343 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; |
---|
344 | } |
---|
345 | else |
---|
346 | { |
---|
347 | throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
---|
348 | } |
---|
349 | } |
---|
350 | finally |
---|
351 | { |
---|
352 | if (dc != null) dc.close(); |
---|
353 | } |
---|
354 | |
---|
355 | if (forward != null) |
---|
356 | { |
---|
357 | pageContext.forward(forward); |
---|
358 | } |
---|
359 | else if (redirect != null) |
---|
360 | { |
---|
361 | response.sendRedirect(redirect); |
---|
362 | } |
---|
363 | else if (message == null) |
---|
364 | { |
---|
365 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
---|
366 | } |
---|
367 | else |
---|
368 | { |
---|
369 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
---|
370 | } |
---|
371 | %> |
---|
372 | |
---|