source: branches/3.16-stable/www/biomaterials/extracts/index.jsp @ 7804

Last change on this file since 7804 was 7804, checked in by Nicklas Nordborg, 2 years ago

References #2209: Add items to existing item list from list page

Fixed on the list pages for extracts, physical, derived and raw bioassays.

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