source: trunk/www/lims/arrayslides/index.jsp @ 6695

Last change on this file since 6695 was 6695, checked in by Nicklas Nordborg, 8 years ago

References #1908: Batch inheriting multiple annotations

Added to list pages for samples, extracts, physical bioassays, derived bioassays and array lims.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 16.5 KB
Line 
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.PhysicalBioAssay "
32  import="net.sf.basedb.core.ArraySlide"
33  import="net.sf.basedb.core.ArrayBatch"
34  import="net.sf.basedb.core.Protocol"
35  import="net.sf.basedb.core.ItemQuery"
36  import="net.sf.basedb.core.ItemResultIterator"
37  import="net.sf.basedb.core.Permission"
38  import="net.sf.basedb.core.ItemContext"
39  import="net.sf.basedb.core.MultiPermissions"
40  import="net.sf.basedb.core.OwnedItem"
41  import="net.sf.basedb.core.AnnotatedItem"
42  import="net.sf.basedb.core.InvalidDataException"
43  import="net.sf.basedb.core.PermissionDeniedException"
44  import="net.sf.basedb.core.ItemAlreadyExistsException"
45  import="net.sf.basedb.core.HibernateUtil" 
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.core.plugin.GuiContext"
54  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
55  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
56  import="net.sf.basedb.clients.web.extensions.JspContext"
57  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
58  import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer"
59  import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer"
60  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
61  import="java.util.Enumeration"
62  import="java.util.Set"
63  import="java.util.HashSet"
64  import="java.util.TreeSet"
65  import="java.util.List"
66  import="java.util.ArrayList"
67  import="java.util.Collections"
68%>
69<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
70<%!
71  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,arrayDesign,physicalBioAssay,description");
72  private static final Item itemType = Item.ARRAYSLIDE;
73%>
74<%
75final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
76final String ID = sc.getId();
77final String cmd = request.getParameter("cmd");
78final String root = request.getContextPath()+"/";
79final String mode = request.getParameter("mode");
80final String callback = request.getParameter("callback");
81final String itemId = request.getParameter("item_id");
82final String listPage = "list_slides.jsp?ID="+ID
83  +(mode == null ? "" : "&mode="+mode)
84  +(callback == null ? "" : "&callback="+callback)
85  +(itemId == null ? "" : "&item_id="+itemId);
86final String viewPage = "view_slide.jsp?ID="+ID;
87final String editPage = "edit_slide.jsp?ID="+ID;
88final String wizardPage = "create_wizard.jsp?ID="+ID+"&cmd=WizardStep1";
89
90String forward = null;
91String redirect = null;
92String message = null;
93DbControl dc = null;
94
95try
96{
97  if (cmd == null || "List".equals(cmd))
98  {
99    // Display the list page without updatinging the current context
100    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
101    redirect = listPage;
102  }
103  else if ("UpdateContext".equals(cmd))
104  {
105    // Display the list page after updating the current context from the request parameters
106    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
107    redirect = listPage;
108  }
109  else if ("LoadContext".equals(cmd))
110  {
111    // Display the list page after loading a saved context
112    int contextId = Values.getInt(request.getParameter("context"));
113    Base.loadContext(sc, contextId, defaultContext);
114    redirect = listPage;
115  }
116
117  else if ("ViewItem".equals(cmd))
118  {
119    // Display the view page for a single item
120    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
121    forward = viewPage;
122  }
123  else if ("EditItem".equals(cmd))
124  {
125    // Display the edit page for a single item (should be opened in a popup)
126    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
127    redirect = editPage;
128  }
129  else if ("NewItem".equals(cmd))
130  {
131    // Display the edit page for a new item (should be opened in a popup)
132    if (!sc.hasPermission(Permission.CREATE, itemType))
133    {
134      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
135    }
136    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
137    cc.setId(0);
138    forward = editPage;
139  } 
140  else if ("UpdateItem".equals(cmd))
141  {
142    // Update the properties on an item (will close the popup)
143    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
144    final int maxRecent = Base.getMaxRecent(sc);
145    dc = sc.newDbControl();
146    ArraySlide slide = (ArraySlide)cc.getObject("item");
147    if (slide == null)
148    {
149      int batchId = Values.getInt(request.getParameter("arraybatch_id"), -1);
150      ArrayBatch batch = ArrayBatch.getById(dc, batchId);
151      slide = ArraySlide.getNew(dc, batch);
152      message = "Array slide created";
153      dc.saveItem(slide);
154      if (batch != null) cc.setRecent(batch, maxRecent);
155    }
156    else
157    {
158      dc.reattachItem(slide, false);
159      message = "Array slide updated";
160    }
161    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.ARRAYSLIDE), slide);
162    ExtensionsInvoker invoker = EditUtil.useOnSaveExtensions(jspContext);
163    try
164    {
165      slide.setName(Values.getStringOrNull(request.getParameter("name")));
166      String newBarcode = Values.getStringOrNull(request.getParameter("barcode"));
167      if (newBarcode != null && !newBarcode.equals(slide.getBarcode()))
168      {
169        if (ArraySlide.barcodeExists(dc, newBarcode))
170        {
171          throw new ItemAlreadyExistsException("ArraySlide[barcode=" + newBarcode + "]");
172        }
173      }
174      slide.setBarcode(newBarcode);
175      slide.setBatchIndex(Values.getInt(request.getParameter("batch_index")));
176      slide.setDestroyed(Values.getBoolean(request.getParameter("destroyed")));
177      slide.setDescription(Values.getStringOrNull(request.getParameter("description")));
178     
179      // Annotations tab
180      Base.updateAnnotations(dc, slide, slide, request);
181     
182      // OnSave extensions
183      invoker.render(OnSaveRenderer.ON_SAVE);
184      dc.commit();
185      invoker.render(OnSaveRenderer.ON_COMMIT);
186    }
187    catch (Exception ex)
188    {
189      invoker.render(OnSaveRenderer.onRollback(ex));
190      throw ex;
191    }
192    finally
193    {
194      cc.removeObject("item");
195    }
196  }
197  else if ("NewItems".equals(cmd))
198  {
199//    Display the wizard page for new items wizard(should be open in a popup)
200    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
201    cc.setId(0);
202    forward = wizardPage;
203  }
204  else if ("CreateItems".equals(cmd))
205  {
206    //Finish the wizard and create the given quantity of Array slides
207    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
208    final int maxRecent = Base.getMaxRecent(sc);
209    dc = sc.newDbControl();
210    int quantity = Values.getInt(request.getParameter("quantity"));
211    int batchId = Values.getInt(request.getParameter("arraybatch_id"));
212    int startAt = Values.getInt(request.getParameter("start_at"), 1);
213    String description = Values.getStringOrNull(request.getParameter("description"));
214    ArrayBatch batch = ArrayBatch.getById(dc, batchId);
215    if (batch != null) cc.setRecent(batch, maxRecent);
216    boolean caseInsensitive = HibernateUtil.getDbEngine().caseInsensitiveComparison();
217    Set<String> barcodes = caseInsensitive ? 
218      new TreeSet<String>(String.CASE_INSENSITIVE_ORDER) : new HashSet<String>();
219    for (int i = 0; i < quantity; ++i)
220    {
221      ArraySlide slide = ArraySlide.getNew(dc, batch);
222      dc.saveItem(slide);
223      slide.setName(Values.getStringOrNull(request.getParameter("name"+i)));
224      slide.setBatchIndex(startAt + i);
225     
226      String newBarcode = Values.getStringOrNull(request.getParameter("barcode" + i));
227      if (newBarcode != null)
228      {
229        if (barcodes.contains(newBarcode))
230        {
231          throw new InvalidDataException("Trying to create more than one slide with barcode=" + newBarcode);
232        }
233        else if (ArraySlide.barcodeExists(dc, newBarcode))
234        {
235          throw new ItemAlreadyExistsException("ArraySlide[barcode=" + newBarcode + "]");
236        }
237        barcodes.add(newBarcode);
238      }
239      slide.setBarcode(newBarcode);
240      slide.setDescription(description);
241    }
242    dc.commit();
243    message = quantity + " Array slides created";
244  }
245  else if ("DeleteItem".equals(cmd))
246  {
247    // Delete a single item and then return to the view page
248    dc = sc.newDbControl();
249    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
250    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
251    dc.commit();
252    redirect = viewPage;
253  }
254  else if ("DeleteItems".equals(cmd))
255  {
256    // Delete all selected items on the list page
257    dc = sc.newDbControl();
258    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
259    int numTotal = cc.getSelected().size();
260    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
261    dc.commit();
262    if (numTotal != numRemoved)
263    {
264      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
265    }
266    redirect = listPage;
267  }
268  else if ("RestoreItem".equals(cmd))
269  {
270    // Restore a single item and then return to the view page
271    dc = sc.newDbControl();
272    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
273    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
274    dc.commit();
275    redirect = viewPage;
276  }
277  else if ("RestoreItems".equals(cmd))
278  {
279    // Restore all selected items on the list page
280    dc = sc.newDbControl();
281    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
282    int numTotal = cc.getSelected().size();
283    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
284    dc.commit();
285    if (numTotal != numRemoved)
286    {
287      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
288    }
289    redirect = listPage;
290  }
291  else if ("ShareItem".equals(cmd))
292  {
293    // Display a popup window for sharing a single item
294    dc = sc.newDbControl();
295    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
296    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
297    dc.close();
298    cc.setObject("MultiPermissions", permissions);
299    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
300  }
301  else if ("ShareItems".equals(cmd))
302  {
303    // Display a popup window for sharing all selected items on the list page
304    dc = sc.newDbControl();
305    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
306    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
307    dc.close();
308    cc.setObject("MultiPermissions", permissions);
309    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
310  }
311  else if ("SetOwnerOfItem".equals(cmd))
312  {
313    // Change owner of items selected on a list page
314    dc = sc.newDbControl();
315    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
316    OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId());
317    cc.setObject("OwnedItems", Collections.singleton(item));
318    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
319  }
320  else if ("SetOwnerOfItems".equals(cmd))
321  {
322    // Change owner of items selected on a list page
323    dc = sc.newDbControl();
324    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
325    Set<OwnedItem> items = new HashSet<OwnedItem>();
326    for (Integer id : cc.getSelected())
327    {
328      if (id != null) items.add((OwnedItem)itemType.getById(dc, id));
329    }
330    dc.close();
331    cc.setObject("OwnedItems", items);
332    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
333  }
334  else if ("InheritAnnotations".equals(cmd))
335  {
336    // Change owner of items selected on a list page
337    dc = sc.newDbControl();
338    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
339    Set<AnnotatedItem> items = new HashSet<AnnotatedItem>();
340    for (Integer id : cc.getSelected())
341    {
342      if (id != null) items.add((AnnotatedItem)itemType.getById(dc, id));
343    }
344    dc.close();
345    cc.setObject("AnnotatedItems", items);
346    redirect = "../../common/annotations/batch_inherit.jsp?ID="+ID+"&item_type="+itemType.name();
347  }
348  else if ("ExportItems".equals(cmd))
349  {
350    // Run an export plugin in a list context
351    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
352    final ItemQuery<ArraySlide> query = ArraySlide.getQuery();
353    dc = sc.newDbControl();
354    cc.configureQuery(dc, query, true);
355    cc.setQuery(query);
356    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null);
357    ExtensionsInvoker listInvoker = ListColumnUtil.useExtensions(jspContext);
358    listInvoker.render(new ListColumnExportRenderer(cc));
359    dc.close();
360    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+array+slides";
361  }
362  else if ("ExportItem".equals(cmd))
363  {
364    // Run an export plugin in single-item context
365    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
366    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+array+slide";
367  }
368  else if ("ImportItems".equals(cmd))
369  {
370    // Run an import plugin in a list context
371    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
372    final ItemQuery<ArraySlide> query = ArraySlide.getQuery();
373    dc = sc.newDbControl();
374    cc.configureQuery(dc, query, true);
375    dc.close();
376    cc.setQuery(query);
377    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+array+slides";
378  }
379  else if ("ImportItem".equals(cmd))
380  {
381    // Run an import plugin in single-item context
382    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
383    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+array+slide";
384  }
385  else if ("RunListPlugin".equals(cmd))
386  {
387    // Run another plugin in a list context
388    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
389    final ItemQuery<ArraySlide> query = ArraySlide.getQuery();
390    dc = sc.newDbControl();
391    cc.configureQuery(dc, query, true);
392    dc.close();
393    cc.setQuery(query);
394    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
395  }
396  else if ("RunPlugin".equals(cmd))
397  {
398    // Run another plugin in single-item context
399    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
400    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
401  }
402  else
403  {
404    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
405  }
406}
407finally
408{
409  if (dc != null) dc.close();
410}
411
412if (forward != null)
413{
414  sc.setSessionSetting("alert-message", message);
415  pageContext.forward(forward);
416}
417else if (redirect != null)
418{
419  sc.setSessionSetting("alert-message", message);
420  response.sendRedirect(redirect);
421}
422else if (message == null)
423{
424  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
425}
426else
427{
428  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
429}
430%>
431
Note: See TracBrowser for help on using the repository browser.