1 | <%-- $Id: index.jsp 5722 2011-09-07 09:26:07Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Jari Häkkinen, 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 3 |
---|
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 BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
21 | ------------------------------------------------------------------ |
---|
22 | |
---|
23 | @author Nicklas |
---|
24 | @version 2.0 |
---|
25 | --%> |
---|
26 | <%@ page pageEncoding="UTF-8" session="false" |
---|
27 | import="net.sf.basedb.core.SessionControl" |
---|
28 | import="net.sf.basedb.core.DbControl" |
---|
29 | import="net.sf.basedb.core.Item" |
---|
30 | import="net.sf.basedb.core.ItemContext" |
---|
31 | import="net.sf.basedb.core.BioMaterialEvent" |
---|
32 | import="net.sf.basedb.core.MeasuredBioMaterial" |
---|
33 | import="net.sf.basedb.core.Protocol" |
---|
34 | import="net.sf.basedb.core.ItemQuery" |
---|
35 | import="net.sf.basedb.core.Permission" |
---|
36 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
37 | import="net.sf.basedb.util.RemovableUtil" |
---|
38 | import="net.sf.basedb.clients.web.Base" |
---|
39 | import="net.sf.basedb.clients.web.WebException" |
---|
40 | import="net.sf.basedb.clients.web.util.HTML" |
---|
41 | import="net.sf.basedb.util.Values" |
---|
42 | import="net.sf.basedb.util.formatter.Formatter" |
---|
43 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
44 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
45 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
46 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
47 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
48 | import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
---|
49 | import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer" |
---|
50 | import="java.util.Date" |
---|
51 | import="java.util.List" |
---|
52 | import="java.util.Collections" |
---|
53 | %> |
---|
54 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
55 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
56 | <%! |
---|
57 | private static final ItemContext defaultContext = Base.createDefaultContext("entryDate", "type,bioPlateEvent,entryDate,eventDate,quantity,protocol,comment"); |
---|
58 | private static final Item itemType = Item.BIOMATERIALEVENT; |
---|
59 | %> |
---|
60 | <% |
---|
61 | final int bioMaterialId = Values.getInt(request.getParameter("biomaterial_id")); |
---|
62 | final Item bioMaterialType = Item.valueOf(request.getParameter("biomaterial_type")); |
---|
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_events.jsp?ID="+ID |
---|
72 | +"&biomaterial_id="+bioMaterialId |
---|
73 | +"&biomaterial_type="+bioMaterialType.name() |
---|
74 | +(mode == null ? "" : "&mode="+mode) |
---|
75 | +(callback == null ? "" : "&callback="+callback) |
---|
76 | +(itemId == null ? "" : "&item_id="+itemId); |
---|
77 | final String viewPage = "view_event.jsp?ID="+ID+"&biomaterial_id="+bioMaterialId+"&biomaterial_type="+bioMaterialType.name(); |
---|
78 | final String editPage = "edit_event.jsp?ID="+ID+"&biomaterial_id="+bioMaterialId+"&biomaterial_type="+bioMaterialType.name(); |
---|
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 | else if ("ViewItem".equals(cmd)) |
---|
107 | { |
---|
108 | // Display the view page for a single item |
---|
109 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
110 | forward = viewPage; |
---|
111 | } |
---|
112 | else if ("EditItem".equals(cmd)) |
---|
113 | { |
---|
114 | // Display the edit page for a single item (should be opened in a popup) |
---|
115 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
116 | redirect = editPage; |
---|
117 | } |
---|
118 | else if ("NewItem".equals(cmd)) |
---|
119 | { |
---|
120 | // Display the edit page for a new item (should be opened in a popup) |
---|
121 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
122 | cc.setId(0); |
---|
123 | redirect = editPage; |
---|
124 | } |
---|
125 | else if ("UpdateItem".equals(cmd)) |
---|
126 | { |
---|
127 | // Update the properties on an item (will close the popup) |
---|
128 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
---|
129 | final int maxRecent = Base.getMaxRecent(sc); |
---|
130 | dc = sc.newDbControl(); |
---|
131 | BioMaterialEvent event = (BioMaterialEvent)cc.getObject("item"); |
---|
132 | if (event == null) |
---|
133 | { |
---|
134 | MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId); |
---|
135 | event = BioMaterialEvent.getNew(dc, bioMaterial); |
---|
136 | message = "Event created"; |
---|
137 | dc.saveItem(event); |
---|
138 | } |
---|
139 | else |
---|
140 | { |
---|
141 | dc.reattachItem(event, false); |
---|
142 | message = "Event updated"; |
---|
143 | } |
---|
144 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.BIOMATERIALEVENT), event); |
---|
145 | ExtensionsInvoker invoker = EditUtil.useOnSaveExtensions(jspContext); |
---|
146 | try |
---|
147 | { |
---|
148 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
149 | event.setComment(Values.getStringOrNull(request.getParameter("comment"))); |
---|
150 | event.setEventDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("event_date")))); |
---|
151 | event.setUsedQuantity(Values.getFloat(request.getParameter("used_quantity"), null)); |
---|
152 | int protocolId = Values.getInt(request.getParameter("protocol_id"), -1); |
---|
153 | if (protocolId >= 0) // < 0 = denied or unchanged |
---|
154 | { |
---|
155 | Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId); |
---|
156 | event.setProtocol(pt); |
---|
157 | if (pt != null) cc.setRecent(pt, maxRecent); |
---|
158 | } |
---|
159 | |
---|
160 | // OnSave extensions |
---|
161 | invoker.render(OnSaveRenderer.ON_SAVE); |
---|
162 | dc.commit(); |
---|
163 | invoker.render(OnSaveRenderer.ON_COMMIT); |
---|
164 | } |
---|
165 | catch (Exception ex) |
---|
166 | { |
---|
167 | invoker.render(OnSaveRenderer.onRollback(ex)); |
---|
168 | throw ex; |
---|
169 | } |
---|
170 | finally |
---|
171 | { |
---|
172 | cc.removeObject("item"); |
---|
173 | } |
---|
174 | } |
---|
175 | else if ("DeleteItem".equals(cmd)) |
---|
176 | { |
---|
177 | // Delete a single item and then return to the view page |
---|
178 | dc = sc.newDbControl(); |
---|
179 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
180 | RemovableUtil.delete(dc, itemType, Collections.singleton(cc.getId())); |
---|
181 | dc.commit(); |
---|
182 | redirect = listPage; |
---|
183 | } |
---|
184 | else if ("DeleteItems".equals(cmd)) |
---|
185 | { |
---|
186 | // Delete all selected items on the list page |
---|
187 | dc = sc.newDbControl(); |
---|
188 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
189 | int numTotal = cc.getSelected().size(); |
---|
190 | int numDeleted = RemovableUtil.delete(dc, itemType, cc.getSelected()); |
---|
191 | dc.commit(); |
---|
192 | if (numTotal != numDeleted) |
---|
193 | { |
---|
194 | message = (numDeleted == 0 ? "No" : "Only "+numDeleted+" of "+numTotal) + " items could be deleted, because you have no DELETE permission"; |
---|
195 | } |
---|
196 | redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : ""); |
---|
197 | } |
---|
198 | else if ("ExportItems".equals(cmd)) |
---|
199 | { |
---|
200 | // Run an export plugin in a list context |
---|
201 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
202 | dc = sc.newDbControl(); |
---|
203 | MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId); |
---|
204 | final ItemQuery<BioMaterialEvent> query = BioMaterialEvent.getQuery(bioMaterial); |
---|
205 | cc.configureQuery(dc, query, true); |
---|
206 | dc.close(); |
---|
207 | cc.setQuery(query); |
---|
208 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+events"; |
---|
209 | } |
---|
210 | else if ("ExportItem".equals(cmd)) |
---|
211 | { |
---|
212 | // Run an export plugin in single-item context |
---|
213 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
214 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+event"; |
---|
215 | } |
---|
216 | else if ("ImportItems".equals(cmd)) |
---|
217 | { |
---|
218 | // Run an import plugin in a list context |
---|
219 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
220 | dc = sc.newDbControl(); |
---|
221 | MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId); |
---|
222 | final ItemQuery<BioMaterialEvent> query = BioMaterialEvent.getQuery(bioMaterial); |
---|
223 | cc.configureQuery(dc, query, true); |
---|
224 | dc.close(); |
---|
225 | cc.setQuery(query); |
---|
226 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+events"; |
---|
227 | } |
---|
228 | else if ("ImportItem".equals(cmd)) |
---|
229 | { |
---|
230 | // Run an import plugin in single-item context |
---|
231 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
232 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+event"; |
---|
233 | } |
---|
234 | else if ("RunListPlugin".equals(cmd)) |
---|
235 | { |
---|
236 | // Run another plugin in a list context |
---|
237 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
238 | dc = sc.newDbControl(); |
---|
239 | MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId); |
---|
240 | final ItemQuery<BioMaterialEvent> query = BioMaterialEvent.getQuery(bioMaterial); |
---|
241 | cc.configureQuery(dc, query, true); |
---|
242 | dc.close(); |
---|
243 | cc.setQuery(query); |
---|
244 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
---|
245 | } |
---|
246 | else if ("RunPlugin".equals(cmd)) |
---|
247 | { |
---|
248 | // Run another plugin in single-item context |
---|
249 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
250 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; |
---|
251 | } |
---|
252 | else |
---|
253 | { |
---|
254 | throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
---|
255 | } |
---|
256 | |
---|
257 | } |
---|
258 | finally |
---|
259 | { |
---|
260 | if (dc != null) dc.close(); |
---|
261 | } |
---|
262 | if (forward != null) |
---|
263 | { |
---|
264 | pageContext.forward(forward); |
---|
265 | } |
---|
266 | else if (redirect != null) |
---|
267 | { |
---|
268 | response.sendRedirect(redirect); |
---|
269 | } |
---|
270 | else if (message == null) |
---|
271 | { |
---|
272 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
---|
273 | } |
---|
274 | else |
---|
275 | { |
---|
276 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
---|
277 | } |
---|
278 | |
---|
279 | %> |
---|