source: trunk/www/lims/arraybatches/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: 12.6 KB
Line 
1<%-- $Id: index.jsp 4587 2008-10-15 14:40:47Z martin $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Hakkinen, 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 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.ArrayBatch"
32  import="net.sf.basedb.core.ArrayDesign"
33  import="net.sf.basedb.core.Protocol"
34  import="net.sf.basedb.core.Hardware"
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.PermissionDeniedException"
42  import="net.sf.basedb.core.ItemAlreadyExistsException"
43  import="net.sf.basedb.util.RemovableUtil"
44  import="net.sf.basedb.util.ShareableUtil"
45  import="net.sf.basedb.util.OwnableUtil"
46  import="net.sf.basedb.clients.web.Base"
47  import="net.sf.basedb.clients.web.WebException"
48  import="net.sf.basedb.util.Values"
49  import="net.sf.basedb.clients.web.util.HTML"
50  import="java.util.Enumeration"
51  import="java.util.Set"
52  import="java.util.HashSet"
53  import="java.util.List"
54  import="java.util.ArrayList"
55  import="java.util.Collections"
56%>
57<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
58<%!
59  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,arrayDesign,slides,description");
60  private static final Item itemType = Item.ARRAYBATCH;
61%>
62<%
63final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
64final String ID = sc.getId();
65final String cmd = request.getParameter("cmd");
66final String root = request.getContextPath()+"/";
67final String mode = request.getParameter("mode");
68final String callback = request.getParameter("callback");
69final String itemId = request.getParameter("item_id");
70final String listPage = "list_batches.jsp?ID="+ID
71  +(mode == null ? "" : "&mode="+mode)
72  +(callback == null ? "" : "&callback="+callback)
73  +(itemId == null ? "" : "&item_id="+itemId);
74final String viewPage = "view_batch.jsp?ID="+ID;
75final String editPage = "edit_batch.jsp?ID="+ID;
76
77String forward = null;
78String redirect = null;
79String message = null;
80DbControl dc = null;
81
82try
83{
84  if (cmd == null || "List".equals(cmd))
85  {
86    // Display the list page without updatinging the current context
87    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
88    redirect = listPage;
89  }
90  else if ("UpdateContext".equals(cmd))
91  {
92    // Display the list page after updating the current context from the request parameters
93    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
94    redirect = listPage;
95  }
96  else if ("LoadContext".equals(cmd))
97  {
98    // Display the list page after loading a saved context
99    int contextId = Values.getInt(request.getParameter("context"));
100    Base.loadContext(sc, contextId, defaultContext);
101    redirect = listPage;
102  }
103
104  else if ("ViewItem".equals(cmd))
105  {
106    // Display the view page for a single item
107    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
108    forward = viewPage;
109  }
110  else if ("EditItem".equals(cmd))
111  {
112    // Display the edit page for a single item (should be opened in a popup)
113    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
114    redirect = editPage;
115  }
116  else if ("NewItem".equals(cmd))
117  {
118    // Display the edit page for a new item (should be opened in a popup)
119    if (!sc.hasPermission(Permission.CREATE, itemType))
120    {
121      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
122    }
123    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
124    cc.setId(0);
125    forward = editPage;
126  }
127  else if ("UpdateItem".equals(cmd))
128  {
129    // Update the properties on an item (will close the popup)
130    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
131    final int maxRecent = Base.getMaxRecent(sc);
132    dc = sc.newDbControl();
133    ArrayBatch batch = (ArrayBatch)cc.getObject("item");
134    if (batch == null)
135    {
136      int designId = Values.getInt(request.getParameter("arraydesign_id"), -1);
137      ArrayDesign design = ArrayDesign.getById(dc, designId);
138      batch = ArrayBatch.getNew(dc, design);
139      message = "Array batch created";
140      dc.saveItem(batch);
141      if (design != null) cc.setRecent(design, maxRecent);
142    }
143    else
144    {
145      dc.reattachItem(batch);
146      message = "Array batch updated";
147    }
148    batch.setName(Values.getStringOrNull(request.getParameter("name")));
149    batch.setDescription(Values.getStringOrNull(request.getParameter("description")));
150    int protocolId = Values.getInt(request.getParameter("protocol_id"), -1);
151    if (protocolId >= 0) // < 0 = denied or unchanged
152    {
153      Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId);
154      batch.setProtocol(pt);
155      if (pt != null) cc.setRecent(pt, maxRecent);
156    }
157    int robotId = Values.getInt(request.getParameter("printrobot_id"), -1);
158    if (robotId >= 0) // < 0 = denied or unchanged
159    {
160      Hardware hw = robotId == 0 ? null : Hardware.getById(dc, robotId);
161      batch.setPrintRobot(hw);
162      if (hw != null) cc.setRecent(hw, maxRecent);
163    }
164
165    // Annotations tab
166    Base.updateAnnotations(dc, batch, batch, request);
167    dc.commit();
168    cc.removeObject("item");
169  }
170  else if ("DeleteItem".equals(cmd))
171  {
172    // Delete a single item and then return to the view page
173    dc = sc.newDbControl();
174    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
175    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
176    dc.commit();
177    redirect = viewPage;
178  }
179  else if ("DeleteItems".equals(cmd))
180  {
181    // Delete all selected items on the list page
182    dc = sc.newDbControl();
183    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
184    int numTotal = cc.getSelected().size();
185    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
186    dc.commit();
187    if (numTotal != numRemoved)
188    {
189      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
190    }
191    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
192  }
193  else if ("RestoreItem".equals(cmd))
194  {
195    // Restore a single item and then return to the view page
196    dc = sc.newDbControl();
197    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
198    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
199    dc.commit();
200    redirect = viewPage;
201  }
202  else if ("RestoreItems".equals(cmd))
203  {
204    // Restore all selected items on the list page
205    dc = sc.newDbControl();
206    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
207    int numTotal = cc.getSelected().size();
208    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
209    dc.commit();
210    if (numTotal != numRemoved)
211    {
212      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
213    }
214    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
215  }
216  else if ("ShareItem".equals(cmd))
217  {
218    // Display a popup window for sharing a single item
219    dc = sc.newDbControl();
220    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
221    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
222    dc.close();
223    cc.setObject("MultiPermissions", permissions);
224    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
225  }
226  else if ("ShareItems".equals(cmd))
227  {
228    // Display a popup window for sharing all selected items on the list page
229    dc = sc.newDbControl();
230    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
231    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
232    dc.close();
233    cc.setObject("MultiPermissions", permissions);
234    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
235  }
236  else if ("SetOwnerOfItem".equals(cmd))
237  {
238    // Change owner of items selected on a list page
239    dc = sc.newDbControl();
240    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
241    OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId());
242    cc.setObject("OwnedItems", Collections.singleton(item));
243    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
244  }
245  else if ("SetOwnerOfItems".equals(cmd))
246  {
247    // Change owner of items selected on a list page
248    dc = sc.newDbControl();
249    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
250    Set<OwnedItem> items = new HashSet<OwnedItem>();
251    for (Integer id : cc.getSelected())
252    {
253      if (id != null) items.add((OwnedItem)itemType.getById(dc, id));
254    }
255    dc.close();
256    cc.setObject("OwnedItems", items);
257    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
258  }
259  else if ("ExportItems".equals(cmd))
260  {
261    // Run an export plugin in a list context
262    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
263    final ItemQuery<ArrayBatch> query = ArrayBatch.getQuery();
264    cc.configureQuery(query, true);
265    cc.setQuery(query);
266    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+hybridizations";
267  }
268  else if ("ExportItem".equals(cmd))
269  {
270    // Run an export plugin in single-item context
271    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
272    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+hybridization";
273  }
274  else if ("ImportItems".equals(cmd))
275  {
276    // Run an import plugin in a list context
277    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
278    final ItemQuery<ArrayBatch> query = ArrayBatch.getQuery();
279    cc.configureQuery(query, true);
280    cc.setQuery(query);
281    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+hybrydizations";
282  }
283  else if ("ImportItem".equals(cmd))
284  {
285    // Run an import plugin in single-item context
286    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
287    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+hybridization";
288  }
289  else if ("RunListPlugin".equals(cmd))
290  {
291    // Run another plugin in a list context
292    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
293    final ItemQuery<ArrayBatch> query = ArrayBatch.getQuery();
294    cc.configureQuery(query, true);
295    cc.setQuery(query);
296    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
297  }
298  else if ("RunPlugin".equals(cmd))
299  {
300    // Run another plugin in single-item context
301    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
302    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
303  }
304  else
305  {
306    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
307  }
308}
309finally
310{
311  if (dc != null) dc.close();
312}
313
314if (forward != null)
315{
316  pageContext.forward(forward);
317}
318else if (redirect != null)
319{
320  response.sendRedirect(redirect);
321}
322else if (message == null)
323{
324  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
325}
326else
327{
328  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
329}
330%>
331
Note: See TracBrowser for help on using the repository browser.