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

Last change on this file since 4587 was 4587, checked in by Martin Svensson, 14 years ago

References #1136 Change to fit all jsp-pages, including files, and project items. Begin to update the documentation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 14.5 KB
Line 
1<%@page import="net.sf.basedb.core.InvalidDataException"%>
2<%-- $Id: index.jsp 4587 2008-10-15 14:40:47Z martin $
3  ------------------------------------------------------------------
4  Copyright (C) 2005 Nicklas Nordborg
5  Copyright (C) 2006 Jari Hakkinen, Nicklas Nordborg, Martin Svensson
6
7  This file is part of BASE - BioArray Software Environment.
8  Available at http://base.thep.lu.se/
9
10  BASE is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 3
13  of the License, or (at your option) any later version.
14
15  BASE is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with BASE. If not, see <http://www.gnu.org/licenses/>.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.Include"
32  import="net.sf.basedb.core.Hybridization"
33  import="net.sf.basedb.core.ArraySlide"
34  import="net.sf.basedb.core.ArrayBatch"
35  import="net.sf.basedb.core.Protocol"
36  import="net.sf.basedb.core.ItemQuery"
37  import="net.sf.basedb.core.ItemResultIterator"
38  import="net.sf.basedb.core.Permission"
39  import="net.sf.basedb.core.ItemContext"
40  import="net.sf.basedb.core.MultiPermissions"
41  import="net.sf.basedb.core.OwnedItem"
42  import="net.sf.basedb.core.PermissionDeniedException"
43  import="net.sf.basedb.core.ItemAlreadyExistsException"
44  import="net.sf.basedb.core.HibernateUtil" 
45  import="net.sf.basedb.util.RemovableUtil"
46  import="net.sf.basedb.util.ShareableUtil"
47  import="net.sf.basedb.util.OwnableUtil"
48  import="net.sf.basedb.clients.web.Base"
49  import="net.sf.basedb.clients.web.WebException"
50  import="net.sf.basedb.util.Values"
51  import="net.sf.basedb.clients.web.util.HTML"
52  import="java.util.Enumeration"
53  import="java.util.Set"
54  import="java.util.HashSet"
55  import="java.util.TreeSet"
56  import="java.util.List"
57  import="java.util.ArrayList"
58  import="java.util.Collections"
59%>
60<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
61<%!
62  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,arrayDesign,hybridization,description");
63  private static final Item itemType = Item.ARRAYSLIDE;
64%>
65<%
66final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
67final String ID = sc.getId();
68final String cmd = request.getParameter("cmd");
69final String root = request.getContextPath()+"/";
70final String mode = request.getParameter("mode");
71final String callback = request.getParameter("callback");
72final String itemId = request.getParameter("item_id");
73final String listPage = "list_slides.jsp?ID="+ID
74  +(mode == null ? "" : "&mode="+mode)
75  +(callback == null ? "" : "&callback="+callback)
76  +(itemId == null ? "" : "&item_id="+itemId);
77final String viewPage = "view_slide.jsp?ID="+ID;
78final String editPage = "edit_slide.jsp?ID="+ID;
79final String wizardPage = "create_wizard.jsp?ID="+ID+"&cmd=WizardStep1";
80
81String forward = null;
82String redirect = null;
83String message = null;
84DbControl dc = null;
85
86try
87{
88  if (cmd == null || "List".equals(cmd))
89  {
90    // Display the list page without updatinging the current context
91    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
92    redirect = listPage;
93  }
94  else if ("UpdateContext".equals(cmd))
95  {
96    // Display the list page after updating the current context from the request parameters
97    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
98    redirect = listPage;
99  }
100  else if ("LoadContext".equals(cmd))
101  {
102    // Display the list page after loading a saved context
103    int contextId = Values.getInt(request.getParameter("context"));
104    Base.loadContext(sc, contextId, defaultContext);
105    redirect = listPage;
106  }
107
108  else if ("ViewItem".equals(cmd))
109  {
110    // Display the view page for a single item
111    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
112    forward = viewPage;
113  }
114  else if ("EditItem".equals(cmd))
115  {
116    // Display the edit page for a single item (should be opened in a popup)
117    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
118    redirect = editPage;
119  }
120  else if ("NewItem".equals(cmd))
121  {
122    // Display the edit page for a new item (should be opened in a popup)
123    if (!sc.hasPermission(Permission.CREATE, itemType))
124    {
125      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
126    }
127    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
128    cc.setId(0);
129    forward = editPage;
130  } 
131  else if ("UpdateItem".equals(cmd))
132  {
133    // Update the properties on an item (will close the popup)
134    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
135    final int maxRecent = Base.getMaxRecent(sc);
136    dc = sc.newDbControl();
137    ArraySlide slide = (ArraySlide)cc.getObject("item");
138    if (slide == null)
139    {
140      int batchId = Values.getInt(request.getParameter("arraybatch_id"), -1);
141      ArrayBatch batch = ArrayBatch.getById(dc, batchId);
142      slide = ArraySlide.getNew(dc, batch);
143      message = "Array slide created";
144      dc.saveItem(slide);
145      if (batch != null) cc.setRecent(batch, maxRecent);
146    }
147    else
148    {
149      dc.reattachItem(slide);
150      message = "Array slide updated";
151    }
152    slide.setName(Values.getStringOrNull(request.getParameter("name")));
153    String newBarcode = Values.getStringOrNull(request.getParameter("barcode"));
154    if (newBarcode != null && !newBarcode.equals(slide.getBarcode()))
155    {
156      if (ArraySlide.barcodeExists(dc, newBarcode))
157      {
158        throw new ItemAlreadyExistsException("ArraySlide[barcode=" + newBarcode + "]");
159      }
160    }
161    slide.setBarcode(newBarcode);
162    slide.setBatchIndex(Values.getInt(request.getParameter("batch_index")));
163    slide.setDestroyed(Values.getBoolean(request.getParameter("destroyed")));
164    slide.setDescription(Values.getStringOrNull(request.getParameter("description")));
165   
166    // Annotations tab
167    Base.updateAnnotations(dc, slide, slide, request);
168    dc.commit();
169    cc.removeObject("item");
170  }
171  else if ("NewItems".equals(cmd))
172  {
173//    Display the wizard page for new items wizard(should be open in a popup)
174    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
175    cc.setId(0);
176    forward = wizardPage;
177  }
178  else if ("CreateItems".equals(cmd))
179  {
180    //Finish the wizard and create the given quantity of Array slides
181    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
182    final int maxRecent = Base.getMaxRecent(sc);
183    dc = sc.newDbControl();
184    int quantity = Values.getInt(request.getParameter("quantity"));
185    int batchId = Values.getInt(request.getParameter("arraybatch_id"));   
186    String description = Values.getStringOrNull(request.getParameter("description"));
187    ArrayBatch batch = ArrayBatch.getById(dc, batchId);
188    if (batch != null) cc.setRecent(batch, maxRecent);
189    boolean caseInsensitive = HibernateUtil.getDbEngine().caseInsensitiveComparison();
190    Set<String> barcodes = caseInsensitive ? 
191      new TreeSet<String>(String.CASE_INSENSITIVE_ORDER) : new HashSet<String>();
192    for (int i = 0; i < quantity; ++i)
193    {
194      ArraySlide slide = ArraySlide.getNew(dc, batch);
195      dc.saveItem(slide);
196      slide.setName(Values.getStringOrNull(request.getParameter("name"+i)));
197      slide.setBatchIndex(batchId);
198     
199      String newBarcode = Values.getStringOrNull(request.getParameter("barcode" + i));
200      if (newBarcode != null)
201      {
202        if (barcodes.contains(newBarcode))
203        {
204          throw new InvalidDataException("Trying to create more than one slide with barcode=" + newBarcode);
205        }
206        else if (ArraySlide.barcodeExists(dc, newBarcode))
207        {
208          throw new ItemAlreadyExistsException("ArraySlide[barcode=" + newBarcode + "]");
209        }
210        barcodes.add(newBarcode);
211      }
212      slide.setBarcode(newBarcode);
213      slide.setDescription(description);
214    }
215    dc.commit();
216    message = quantity + " Array slides created";
217  }
218  else if ("DeleteItem".equals(cmd))
219  {
220    // Delete a single item and then return to the view page
221    dc = sc.newDbControl();
222    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
223    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
224    dc.commit();
225    redirect = viewPage;
226  }
227  else if ("DeleteItems".equals(cmd))
228  {
229    // Delete all selected items on the list page
230    dc = sc.newDbControl();
231    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
232    int numTotal = cc.getSelected().size();
233    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
234    dc.commit();
235    if (numTotal != numRemoved)
236    {
237      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
238    }
239    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
240  }
241  else if ("RestoreItem".equals(cmd))
242  {
243    // Restore a single item and then return to the view page
244    dc = sc.newDbControl();
245    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
246    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
247    dc.commit();
248    redirect = viewPage;
249  }
250  else if ("RestoreItems".equals(cmd))
251  {
252    // Restore all selected items on the list page
253    dc = sc.newDbControl();
254    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
255    int numTotal = cc.getSelected().size();
256    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
257    dc.commit();
258    if (numTotal != numRemoved)
259    {
260      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
261    }
262    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
263  }
264  else if ("ShareItem".equals(cmd))
265  {
266    // Display a popup window for sharing a single item
267    dc = sc.newDbControl();
268    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
269    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
270    dc.close();
271    cc.setObject("MultiPermissions", permissions);
272    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
273  }
274  else if ("ShareItems".equals(cmd))
275  {
276    // Display a popup window for sharing all selected items on the list page
277    dc = sc.newDbControl();
278    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
279    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
280    dc.close();
281    cc.setObject("MultiPermissions", permissions);
282    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
283  }
284  else if ("SetOwnerOfItem".equals(cmd))
285  {
286    // Change owner of items selected on a list page
287    dc = sc.newDbControl();
288    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
289    OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId());
290    cc.setObject("OwnedItems", Collections.singleton(item));
291    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
292  }
293  else if ("SetOwnerOfItems".equals(cmd))
294  {
295    // Change owner of items selected on a list page
296    dc = sc.newDbControl();
297    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
298    Set<OwnedItem> items = new HashSet<OwnedItem>();
299    for (Integer id : cc.getSelected())
300    {
301      if (id != null) items.add((OwnedItem)itemType.getById(dc, id));
302    }
303    dc.close();
304    cc.setObject("OwnedItems", items);
305    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
306  }
307  else if ("ExportItems".equals(cmd))
308  {
309    // Run an export plugin in a list context
310    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
311    final ItemQuery<ArraySlide> query = ArraySlide.getQuery();
312    cc.configureQuery(query, true);
313    cc.setQuery(query);
314    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+hybridizations";
315  }
316  else if ("ExportItem".equals(cmd))
317  {
318    // Run an export plugin in single-item context
319    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
320    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+hybridization";
321  }
322  else if ("ImportItems".equals(cmd))
323  {
324    // Run an import plugin in a list context
325    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
326    final ItemQuery<ArraySlide> query = ArraySlide.getQuery();
327    cc.configureQuery(query, true);
328    cc.setQuery(query);
329    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+hybrydizations";
330  }
331  else if ("ImportItem".equals(cmd))
332  {
333    // Run an import plugin in single-item context
334    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
335    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+hybridization";
336  }
337  else if ("RunListPlugin".equals(cmd))
338  {
339    // Run another plugin in a list context
340    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
341    final ItemQuery<ArraySlide> query = ArraySlide.getQuery();
342    cc.configureQuery(query, true);
343    cc.setQuery(query);
344    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
345  }
346  else if ("RunPlugin".equals(cmd))
347  {
348    // Run another plugin in single-item context
349    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
350    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
351  }
352  else
353  {
354    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
355  }
356}
357finally
358{
359  if (dc != null) dc.close();
360}
361
362if (forward != null)
363{
364  pageContext.forward(forward);
365}
366else if (redirect != null)
367{
368  response.sendRedirect(redirect);
369}
370else if (message == null)
371{
372  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
373}
374else
375{
376  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
377}
378%>
379
Note: See TracBrowser for help on using the repository browser.