1 | <%-- $Id: index.jsp 6695 2015-01-28 06:59:57Z 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.Include" |
---|
31 | import="net.sf.basedb.core.Sample" |
---|
32 | import="net.sf.basedb.core.BioSource" |
---|
33 | import="net.sf.basedb.core.BioMaterialEvent" |
---|
34 | import="net.sf.basedb.core.BioPlateEventType" |
---|
35 | import="net.sf.basedb.core.BioWell" |
---|
36 | import="net.sf.basedb.core.ItemSubtype" |
---|
37 | import="net.sf.basedb.core.Extract" |
---|
38 | import="net.sf.basedb.core.Protocol" |
---|
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.OwnedItem" |
---|
45 | import="net.sf.basedb.core.AnnotatedItem" |
---|
46 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
47 | import="net.sf.basedb.core.ItemAlreadyExistsException" |
---|
48 | import="net.sf.basedb.core.query.Hql" |
---|
49 | import="net.sf.basedb.core.query.Orders" |
---|
50 | import="net.sf.basedb.core.query.Restrictions" |
---|
51 | import="net.sf.basedb.core.query.Expressions" |
---|
52 | import="net.sf.basedb.util.RemovableUtil" |
---|
53 | import="net.sf.basedb.util.ShareableUtil" |
---|
54 | import="net.sf.basedb.util.OwnableUtil" |
---|
55 | import="net.sf.basedb.clients.web.Base" |
---|
56 | import="net.sf.basedb.clients.web.WebException" |
---|
57 | import="net.sf.basedb.util.Values" |
---|
58 | import="net.sf.basedb.clients.web.plugins.ParentBioMaterialLoader" |
---|
59 | import="net.sf.basedb.clients.web.plugins.BioMaterialEventSourceFormatter" |
---|
60 | import="net.sf.basedb.clients.web.plugins.ParentBioMaterialEventSourceLoader" |
---|
61 | import="net.sf.basedb.clients.web.plugins.ItemQueryLoader" |
---|
62 | import="net.sf.basedb.clients.web.util.HTML" |
---|
63 | import="net.sf.basedb.util.formatter.Formatter" |
---|
64 | import="net.sf.basedb.util.formatter.WellCoordinateFormatter" |
---|
65 | import="net.sf.basedb.util.formatter.NameableFormatter" |
---|
66 | import="net.sf.basedb.util.formatter.ItemTypeFormatter" |
---|
67 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
68 | |
---|
69 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
70 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
71 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
72 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
73 | import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
---|
74 | import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer" |
---|
75 | import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer" |
---|
76 | import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil" |
---|
77 | import="java.util.Enumeration" |
---|
78 | import="java.util.Set" |
---|
79 | import="java.util.HashSet" |
---|
80 | import="java.util.List" |
---|
81 | import="java.util.ArrayList" |
---|
82 | import="java.util.Collections" |
---|
83 | import="java.util.Date" |
---|
84 | %> |
---|
85 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
86 | <%! |
---|
87 | private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,itemSubtype,originalQuantity,remainingQuantity,extracts,description"); |
---|
88 | private static final Item itemType = Item.SAMPLE; |
---|
89 | |
---|
90 | private static void registerExportUtils(ItemContext cc) |
---|
91 | { |
---|
92 | // Register formatters |
---|
93 | cc.setObject("export.formatter.bioWell.row", new WellCoordinateFormatter(true)); |
---|
94 | cc.setObject("export.formatter.bioWell.column", new WellCoordinateFormatter(false)); |
---|
95 | cc.setObject("export.formatter.&creationEvent.sources(bioMaterial.name)", new BioMaterialEventSourceFormatter()); |
---|
96 | cc.setObject("export.formatter.&childCreationEvents(event.bioMaterial.name)", new NameableFormatter()); |
---|
97 | cc.setObject("export.formatter.&children(name)", new NameableFormatter()); |
---|
98 | cc.setObject("export.formatter.parentType", new ItemTypeFormatter()); |
---|
99 | |
---|
100 | // Register dataloaders |
---|
101 | String sampleParameter = "sample"; |
---|
102 | |
---|
103 | // Child extracts |
---|
104 | ItemQuery<Extract> extractQuery = Extract.getQuery(); |
---|
105 | extractQuery.include(cc.getInclude()); |
---|
106 | extractQuery.restrict(Restrictions.eq(Hql.property("parent"), Expressions.parameter(sampleParameter))); |
---|
107 | extractQuery.order(Orders.asc(Hql.property("name"))); |
---|
108 | cc.setObject("export.dataloader.&children(name)", new ItemQueryLoader(extractQuery, sampleParameter)); |
---|
109 | |
---|
110 | // Child samples |
---|
111 | ItemQuery<Sample> childSamplesQuery = Sample.getQuery(); |
---|
112 | childSamplesQuery.join(Hql.innerJoin("creationEvent", "ce")); |
---|
113 | childSamplesQuery.join(Hql.innerJoin("ce", "sources", "src")); |
---|
114 | childSamplesQuery.restrict(Restrictions.eq(Hql.property("src", "bioMaterial"), Expressions.parameter(sampleParameter))); |
---|
115 | childSamplesQuery.order(Orders.asc(Hql.property("name"))); |
---|
116 | childSamplesQuery.include(cc.getInclude()); |
---|
117 | cc.setObject("export.dataloader.&childCreationEvents(event.bioMaterial.name)", new ItemQueryLoader(childSamplesQuery, sampleParameter)); |
---|
118 | |
---|
119 | // Parent samples |
---|
120 | cc.setObject("export.dataloader.&creationEvent.sources(bioMaterial.name)", new ParentBioMaterialEventSourceLoader()); |
---|
121 | } |
---|
122 | %> |
---|
123 | <% |
---|
124 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
125 | final String ID = sc.getId(); |
---|
126 | final String cmd = request.getParameter("cmd"); |
---|
127 | final String root = request.getContextPath()+"/"; |
---|
128 | final String mode = request.getParameter("mode"); |
---|
129 | final String callback = request.getParameter("callback"); |
---|
130 | final String itemId = request.getParameter("item_id"); |
---|
131 | final String listPage = "list_samples.jsp?ID="+ID |
---|
132 | +(mode == null ? "" : "&mode="+mode) |
---|
133 | +(callback == null ? "" : "&callback="+callback) |
---|
134 | +(itemId == null ? "" : "&item_id="+itemId); |
---|
135 | final String viewPage = "view_sample.jsp?ID="+ID; |
---|
136 | final String editPage = "edit_sample.jsp?ID="+ID; |
---|
137 | |
---|
138 | String forward = null; |
---|
139 | String redirect = null; |
---|
140 | String message = null; |
---|
141 | DbControl dc = null; |
---|
142 | |
---|
143 | try |
---|
144 | { |
---|
145 | if (cmd == null || "List".equals(cmd)) |
---|
146 | { |
---|
147 | // Display the list page without updatinging the current context |
---|
148 | Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true); |
---|
149 | redirect = listPage; |
---|
150 | } |
---|
151 | else if ("UpdateContext".equals(cmd)) |
---|
152 | { |
---|
153 | // Display the list page after updating the current context from the request parameters |
---|
154 | Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
155 | redirect = listPage; |
---|
156 | } |
---|
157 | else if ("LoadContext".equals(cmd)) |
---|
158 | { |
---|
159 | // Display the list page after loading a saved context |
---|
160 | int contextId = Values.getInt(request.getParameter("context")); |
---|
161 | Base.loadContext(sc, contextId, defaultContext); |
---|
162 | redirect = listPage; |
---|
163 | } |
---|
164 | |
---|
165 | else if ("ViewItem".equals(cmd)) |
---|
166 | { |
---|
167 | // Display the view page for a single item |
---|
168 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
169 | forward = viewPage; |
---|
170 | } |
---|
171 | else if ("EditItem".equals(cmd)) |
---|
172 | { |
---|
173 | // Display the edit page for a single item (should be opened in a popup) |
---|
174 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
175 | redirect = editPage; |
---|
176 | } |
---|
177 | else if ("NewItem".equals(cmd)) |
---|
178 | { |
---|
179 | // Display the edit page for a new item (should be opened in a popup) |
---|
180 | if (!sc.hasPermission(Permission.CREATE, itemType)) |
---|
181 | { |
---|
182 | throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
---|
183 | } |
---|
184 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
185 | cc.setId(0); |
---|
186 | forward = editPage; |
---|
187 | } |
---|
188 | else if ("NewPooledItem".equals(cmd)) |
---|
189 | { |
---|
190 | // Display the edit page for a new pooled item (should be opened in a popup) |
---|
191 | if (!sc.hasPermission(Permission.CREATE, itemType)) |
---|
192 | { |
---|
193 | throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
---|
194 | } |
---|
195 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
196 | cc.setId(0); |
---|
197 | forward = editPage+"&pooled="+true; |
---|
198 | } |
---|
199 | else if ("UpdateItem".equals(cmd)) |
---|
200 | { |
---|
201 | // Update the properties on an item (will close the popup) |
---|
202 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
---|
203 | final int maxRecent = Base.getMaxRecent(sc); |
---|
204 | dc = sc.newDbControl(); |
---|
205 | Sample sample = (Sample)cc.getObject("item"); |
---|
206 | if (sample == null) |
---|
207 | { |
---|
208 | sample = Sample.getNew(dc); |
---|
209 | message = "Sample created"; |
---|
210 | dc.saveItem(sample); |
---|
211 | } |
---|
212 | else |
---|
213 | { |
---|
214 | dc.reattachItem(sample, false); |
---|
215 | dc.reattachItem(sample.getCreationEvent(), false); |
---|
216 | message = "Sample updated"; |
---|
217 | } |
---|
218 | |
---|
219 | // Create extension context |
---|
220 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.SAMPLE), sample); |
---|
221 | ExtensionsInvoker invoker = EditUtil.useOnSaveExtensions(jspContext); |
---|
222 | try |
---|
223 | { |
---|
224 | sample.setName(Values.getStringOrNull(request.getParameter("name"))); |
---|
225 | sample.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
---|
226 | sample.setExternalId(Values.getStringOrNull(request.getParameter("external_id"))); |
---|
227 | sample.setOriginalQuantity(Values.getFloat(request.getParameter("original_quantity"), null)); |
---|
228 | |
---|
229 | int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1); |
---|
230 | ItemSubtype subtype = null; |
---|
231 | if (subtypeId >= 0) // < 0 = denied or unchanged |
---|
232 | { |
---|
233 | if (subtypeId > 0) subtype = ItemSubtype.getById(dc, subtypeId); |
---|
234 | sample.setItemSubtype(subtype); |
---|
235 | if (subtype != null) cc.setRecent(subtype, maxRecent); |
---|
236 | } |
---|
237 | |
---|
238 | BioMaterialEvent creationEvent = sample.getCreationEvent(); |
---|
239 | if (creationEvent.hasPermission(Permission.WRITE)) |
---|
240 | { |
---|
241 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
242 | creationEvent.setEventDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("event_date")))); |
---|
243 | int protocolId = Values.getInt(request.getParameter("protocol_id"), -1); |
---|
244 | if (protocolId >= 0) // < 0 = denied or unchanged |
---|
245 | { |
---|
246 | Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId); |
---|
247 | creationEvent.setProtocol(pt); |
---|
248 | if (pt != null) cc.setRecent(pt, subtype, maxRecent); |
---|
249 | } |
---|
250 | } |
---|
251 | |
---|
252 | int biowellId = Values.getInt(request.getParameter("biowell_id"), -1); |
---|
253 | if (biowellId >= 0) // < 0 = denied or unchanged |
---|
254 | { |
---|
255 | BioWell bw = biowellId == 0 ? null : BioWell.getById(dc, biowellId); |
---|
256 | if (bw != null && bw.getBioMaterial() != null) |
---|
257 | { |
---|
258 | throw new WebException("popup", "Biowell can not be used", |
---|
259 | "The biowell [{1}] on bioplate {2} is already connected to another biomaterial", |
---|
260 | HTML.encodeTags(bw.getRow()+"," + bw.getColumn()), HTML.encodeTags(bw.getPlate().getName())); |
---|
261 | } |
---|
262 | sample.setBioWell(bw); |
---|
263 | if (bw != null) cc.setRecent(bw.getPlate(), subtype, maxRecent); |
---|
264 | } |
---|
265 | |
---|
266 | // Parents tab |
---|
267 | Item parentType = Item.valueOf(request.getParameter("parentType")); |
---|
268 | if (parentType == Item.BIOSOURCE) |
---|
269 | { |
---|
270 | int bioSourceId = Values.getInt(request.getParameter("biosource_id"), -1); |
---|
271 | if (bioSourceId >= 0) // < 0 = denied or unchanged |
---|
272 | { |
---|
273 | BioSource bs = bioSourceId == 0 ? null : BioSource.getById(dc, bioSourceId); |
---|
274 | creationEvent.setSource(bs); |
---|
275 | if (bs != null) cc.setRecent(bs, maxRecent); |
---|
276 | } |
---|
277 | } |
---|
278 | else |
---|
279 | { |
---|
280 | if (sample.getParentType() != Item.SAMPLE) |
---|
281 | { |
---|
282 | creationEvent.clearSources(); |
---|
283 | } |
---|
284 | String[] modifiedSamples = Values.getString(request.getParameter("+SAMPLE")).split(","); |
---|
285 | for (int i = 0; i < modifiedSamples.length; ++i) |
---|
286 | { |
---|
287 | int sId = Values.getInt(modifiedSamples[i], -1); |
---|
288 | if (sId != -1) |
---|
289 | { |
---|
290 | Sample s = Sample.getById(dc, sId); |
---|
291 | creationEvent.addSource(s).setUsedQuantity(Values.getFloat(request.getParameter("SAMPLE."+sId), null)); |
---|
292 | } |
---|
293 | } |
---|
294 | String[] removedSamples = Values.getString(request.getParameter("-SAMPLE")).split(","); |
---|
295 | for (int i = 0; i < removedSamples.length; ++i) |
---|
296 | { |
---|
297 | int sId = Values.getInt(removedSamples[i], -1); |
---|
298 | if (sId != -1) creationEvent.removeSource(Sample.getById(dc, sId)); |
---|
299 | } |
---|
300 | } |
---|
301 | |
---|
302 | // Annotations tab |
---|
303 | Base.updateAnnotations(dc, sample, sample, request); |
---|
304 | |
---|
305 | // OnSave extensions |
---|
306 | invoker.render(OnSaveRenderer.ON_SAVE); |
---|
307 | dc.commit(); |
---|
308 | invoker.render(OnSaveRenderer.ON_COMMIT); |
---|
309 | } |
---|
310 | catch (Exception ex) |
---|
311 | { |
---|
312 | invoker.render(OnSaveRenderer.onRollback(ex)); |
---|
313 | throw ex; |
---|
314 | } |
---|
315 | finally |
---|
316 | { |
---|
317 | cc.removeObject("item"); |
---|
318 | } |
---|
319 | } |
---|
320 | else if ("DeleteItem".equals(cmd)) |
---|
321 | { |
---|
322 | // Delete a single item and then return to the view page |
---|
323 | dc = sc.newDbControl(); |
---|
324 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
325 | RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true); |
---|
326 | dc.commit(); |
---|
327 | redirect = viewPage; |
---|
328 | } |
---|
329 | else if ("DeleteItems".equals(cmd)) |
---|
330 | { |
---|
331 | // Delete all selected items on the list page |
---|
332 | dc = sc.newDbControl(); |
---|
333 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
334 | int numTotal = cc.getSelected().size(); |
---|
335 | int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true); |
---|
336 | dc.commit(); |
---|
337 | if (numTotal != numRemoved) |
---|
338 | { |
---|
339 | message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission"; |
---|
340 | } |
---|
341 | redirect = listPage; |
---|
342 | } |
---|
343 | else if ("RestoreItem".equals(cmd)) |
---|
344 | { |
---|
345 | // Restore a single item and then return to the view page |
---|
346 | dc = sc.newDbControl(); |
---|
347 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
348 | RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false); |
---|
349 | dc.commit(); |
---|
350 | redirect = viewPage; |
---|
351 | } |
---|
352 | else if ("RestoreItems".equals(cmd)) |
---|
353 | { |
---|
354 | // Restore all selected items on the list page |
---|
355 | dc = sc.newDbControl(); |
---|
356 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
357 | int numTotal = cc.getSelected().size(); |
---|
358 | int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false); |
---|
359 | dc.commit(); |
---|
360 | if (numTotal != numRemoved) |
---|
361 | { |
---|
362 | message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; |
---|
363 | } |
---|
364 | redirect = listPage; |
---|
365 | } |
---|
366 | else if ("ShareItem".equals(cmd)) |
---|
367 | { |
---|
368 | // Display a popup window for sharing a single item |
---|
369 | dc = sc.newDbControl(); |
---|
370 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
371 | MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId())); |
---|
372 | dc.close(); |
---|
373 | cc.setObject("MultiPermissions", permissions); |
---|
374 | redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
---|
375 | } |
---|
376 | else if ("ShareItems".equals(cmd)) |
---|
377 | { |
---|
378 | // Display a popup window for sharing all selected items on the list page |
---|
379 | dc = sc.newDbControl(); |
---|
380 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
381 | MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected()); |
---|
382 | dc.close(); |
---|
383 | cc.setObject("MultiPermissions", permissions); |
---|
384 | redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
---|
385 | } |
---|
386 | else if ("SetOwnerOfItem".equals(cmd)) |
---|
387 | { |
---|
388 | // Change owner of items selected on a list page |
---|
389 | dc = sc.newDbControl(); |
---|
390 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
391 | OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId()); |
---|
392 | cc.setObject("OwnedItems", Collections.singleton(item)); |
---|
393 | redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name(); |
---|
394 | } |
---|
395 | else if ("SetOwnerOfItems".equals(cmd)) |
---|
396 | { |
---|
397 | // Change owner of items selected on a list page |
---|
398 | dc = sc.newDbControl(); |
---|
399 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
400 | Set<OwnedItem> items = new HashSet<OwnedItem>(); |
---|
401 | for (Integer id : cc.getSelected()) |
---|
402 | { |
---|
403 | if (id != null) items.add((OwnedItem)itemType.getById(dc, id)); |
---|
404 | } |
---|
405 | dc.close(); |
---|
406 | cc.setObject("OwnedItems", items); |
---|
407 | redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name(); |
---|
408 | } |
---|
409 | else if ("InheritAnnotations".equals(cmd)) |
---|
410 | { |
---|
411 | // Change owner of items selected on a list page |
---|
412 | dc = sc.newDbControl(); |
---|
413 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
414 | Set<AnnotatedItem> items = new HashSet<AnnotatedItem>(); |
---|
415 | for (Integer id : cc.getSelected()) |
---|
416 | { |
---|
417 | if (id != null) items.add((AnnotatedItem)itemType.getById(dc, id)); |
---|
418 | } |
---|
419 | dc.close(); |
---|
420 | cc.setObject("AnnotatedItems", items); |
---|
421 | redirect = "../../common/annotations/batch_inherit.jsp?ID="+ID+"&item_type="+itemType.name(); |
---|
422 | } |
---|
423 | else if ("ExportItems".equals(cmd)) |
---|
424 | { |
---|
425 | // Run an export plugin in a list context |
---|
426 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
427 | final ItemQuery<Sample> query = Sample.getQuery(); |
---|
428 | dc = sc.newDbControl(); |
---|
429 | cc.configureQuery(dc, query, true); |
---|
430 | registerExportUtils(cc); |
---|
431 | cc.setQuery(query); |
---|
432 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
---|
433 | ExtensionsInvoker listInvoker = ListColumnUtil.useExtensions(jspContext); |
---|
434 | listInvoker.render(new ListColumnExportRenderer(cc)); |
---|
435 | dc.close(); |
---|
436 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+samples"; |
---|
437 | } |
---|
438 | else if ("ExportItem".equals(cmd)) |
---|
439 | { |
---|
440 | // Run an export plugin in single-item context |
---|
441 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
442 | registerExportUtils(cc); |
---|
443 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+sample"; |
---|
444 | } |
---|
445 | else if ("ImportItems".equals(cmd)) |
---|
446 | { |
---|
447 | // Run an import plugin in a list context |
---|
448 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
449 | final ItemQuery<Sample> query = Sample.getQuery(); |
---|
450 | dc = sc.newDbControl(); |
---|
451 | cc.configureQuery(dc, query, true); |
---|
452 | dc.close(); |
---|
453 | cc.setQuery(query); |
---|
454 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+sample"; |
---|
455 | } |
---|
456 | else if ("ImportItem".equals(cmd)) |
---|
457 | { |
---|
458 | // Run an import plugin in single-item context |
---|
459 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
460 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+sample"; |
---|
461 | } |
---|
462 | else if ("RunListPlugin".equals(cmd)) |
---|
463 | { |
---|
464 | // Run another plugin in a list context |
---|
465 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
466 | final ItemQuery<Sample> query = Sample.getQuery(); |
---|
467 | dc = sc.newDbControl(); |
---|
468 | cc.configureQuery(dc, query, true); |
---|
469 | dc.close(); |
---|
470 | cc.setQuery(query); |
---|
471 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
---|
472 | } |
---|
473 | else if ("RunPlugin".equals(cmd)) |
---|
474 | { |
---|
475 | // Run another plugin in single-item context |
---|
476 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
477 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; |
---|
478 | } |
---|
479 | else if ("CreateBioMaterialList".equals(cmd)) |
---|
480 | { |
---|
481 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
482 | final ItemQuery<Sample> query = Sample.getQuery(); |
---|
483 | dc = sc.newDbControl(); |
---|
484 | cc.configureQuery(dc, query, true); |
---|
485 | dc.close(); |
---|
486 | cc.setQuery(query); |
---|
487 | redirect = "../lists/index.jsp?ID="+ID+"&cmd=NewItem&addBioMaterials=1&formId=samples&fromContext=SAMPLE"; |
---|
488 | } |
---|
489 | else if ("PlaceOnPlate".equals(cmd)) |
---|
490 | { |
---|
491 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
492 | final ItemQuery<Sample> query = Sample.getQuery(); |
---|
493 | dc = sc.newDbControl(); |
---|
494 | cc.configureQuery(dc, query, true); |
---|
495 | dc.close(); |
---|
496 | cc.filterOnSelectedItems(query); |
---|
497 | sc.getCurrentContext(Item.BIOPLATEEVENT, BioPlateEventType.PLACE_ON_PLATE).setQuery(query); |
---|
498 | redirect = "../wizards/place_on_plate.jsp?ID="+ID+"&itemType=SAMPLE"; |
---|
499 | } |
---|
500 | else |
---|
501 | { |
---|
502 | throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
---|
503 | } |
---|
504 | } |
---|
505 | finally |
---|
506 | { |
---|
507 | if (dc != null) dc.close(); |
---|
508 | } |
---|
509 | |
---|
510 | if (forward != null) |
---|
511 | { |
---|
512 | sc.setSessionSetting("alert-message", message); |
---|
513 | pageContext.forward(forward); |
---|
514 | } |
---|
515 | else if (redirect != null) |
---|
516 | { |
---|
517 | sc.setSessionSetting("alert-message", message); |
---|
518 | response.sendRedirect(redirect); |
---|
519 | } |
---|
520 | else if (message == null) |
---|
521 | { |
---|
522 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
---|
523 | } |
---|
524 | else |
---|
525 | { |
---|
526 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
---|
527 | } |
---|
528 | %> |
---|
529 | |
---|