source: branches/2.10-stable/www/views/scans/index.jsp @ 4831

Last change on this file since 4831 was 4831, checked in by Nicklas Nordborg, 14 years ago

Fixes #1260: Incorrect title on import dialog when opened from array slide and array batch pages

And an identical problem for scans and experiments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.6 KB
Line 
1<%-- $Id: index.jsp 4831 2009-03-24 07:28:38Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Gregory Vincic
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.Scan"
32  import="net.sf.basedb.core.Hybridization"
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,hybridization,rawBioAssays,description");
60  private static final Item itemType = Item.SCAN;
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_scans.jsp?ID="+ID
71  +(mode == null ? "" : "&mode="+mode)
72  +(callback == null ? "" : "&callback="+callback)
73  +(itemId == null ? "" : "&item_id="+itemId);
74final String viewPage = "view_scan.jsp?ID="+ID;
75final String editPage = "edit_scan.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    Scan scan = (Scan)cc.getObject("item");
134    int hybridizationId = Values.getInt(request.getParameter("hybridization_id"), -1);
135    if (scan == null)
136    {
137      scan = Scan.getNew(dc, Hybridization.getById(dc, hybridizationId));
138      message = "Scan created";
139      dc.saveItem(scan);
140    }
141    else
142    {
143      dc.reattachItem(scan);
144      message = "Scan updated";
145    }
146    scan.setName(Values.getStringOrNull(request.getParameter("name")));
147    scan.setDescription(Values.getStringOrNull(request.getParameter("description")));
148    int protocolId = Values.getInt(request.getParameter("protocol_id"), -1);
149    if (protocolId >= 0) // < 0 = denied or unchanged
150    {
151      Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId);
152      scan.setProtocol(pt);
153      if (pt != null) cc.setRecent(pt, maxRecent);
154    }
155    int scannerId = Values.getInt(request.getParameter("scanner_id"), -1);
156    if (scannerId >= 0) // < 0 = denied or unchanged
157    {
158      Hardware hw = scannerId == 0 ? null : Hardware.getById(dc, scannerId);
159      scan.setScanner(hw);
160      if (hw != null) cc.setRecent(hw, maxRecent);
161    }
162    if (hybridizationId >= 0) // < 0 = denied or unchanged
163    {
164      Hybridization hyb = hybridizationId == 0 ? null : Hybridization.getById(dc, hybridizationId);
165      scan.setHybridization(hyb);
166      if (hyb != null) cc.setRecent(hyb, maxRecent);
167    }
168   
169    // Annotations tab
170    Base.updateAnnotations(dc, scan, scan, request);
171    dc.commit();
172    cc.removeObject("item");
173  }
174  else if ("DeleteItem".equals(cmd))
175  {
176    // Delete a single item and then return to the view page
177    dc = sc.newDbControl();
178    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
179    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
180    dc.commit();
181    redirect = viewPage;
182  }
183  else if ("DeleteItems".equals(cmd))
184  {
185    // Delete all selected items on the list page
186    dc = sc.newDbControl();
187    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
188    int numTotal = cc.getSelected().size();
189    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
190    dc.commit();
191    if (numTotal != numRemoved)
192    {
193      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
194    }
195    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
196  }
197  else if ("RestoreItem".equals(cmd))
198  {
199    // Restore a single item and then return to the view page
200    dc = sc.newDbControl();
201    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
202    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
203    dc.commit();
204    redirect = viewPage;
205  }
206  else if ("RestoreItems".equals(cmd))
207  {
208    // Restore all selected items on the list page
209    dc = sc.newDbControl();
210    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
211    int numTotal = cc.getSelected().size();
212    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
213    dc.commit();
214    if (numTotal != numRemoved)
215    {
216      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
217    }
218    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
219  }
220  else if ("ShareItem".equals(cmd))
221  {
222    // Display a popup window for sharing a single item
223    dc = sc.newDbControl();
224    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
225    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
226    dc.close();
227    cc.setObject("MultiPermissions", permissions);
228    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
229  }
230  else if ("ShareItems".equals(cmd))
231  {
232    // Display a popup window for sharing all selected items on the list page
233    dc = sc.newDbControl();
234    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
235    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
236    dc.close();
237    cc.setObject("MultiPermissions", permissions);
238    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
239  }
240  else if ("SetOwnerOfItem".equals(cmd))
241  {
242    // Change owner of items selected on a list page
243    dc = sc.newDbControl();
244    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
245    OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId());
246    cc.setObject("OwnedItems", Collections.singleton(item));
247    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
248  }
249  else if ("SetOwnerOfItems".equals(cmd))
250  {
251    // Change owner of items selected on a list page
252    dc = sc.newDbControl();
253    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
254    Set<OwnedItem> items = new HashSet<OwnedItem>();
255    for (Integer id : cc.getSelected())
256    {
257      if (id != null) items.add((OwnedItem)itemType.getById(dc, id));
258    }
259    dc.close();
260    cc.setObject("OwnedItems", items);
261    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
262  }
263  else if ("ExportItems".equals(cmd))
264  {
265    // Run an export plugin in a list context
266    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
267    final ItemQuery<Scan> query = Scan.getQuery();
268    cc.configureQuery(query, true);
269    cc.setQuery(query);
270    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+scans";
271  }
272  else if ("ExportItem".equals(cmd))
273  {
274    // Run an export plugin in single-item context
275    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
276    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+scan";
277  }
278  else if ("ImportItems".equals(cmd))
279  {
280    // Run an import plugin in a list context
281    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
282    final ItemQuery<Scan> query = Scan.getQuery();
283    cc.configureQuery(query, true);
284    cc.setQuery(query);
285    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+scans";
286  }
287  else if ("ImportItem".equals(cmd))
288  {
289    // Run an import plugin in single-item context
290    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
291    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+scan";
292  }
293  else if ("RunListPlugin".equals(cmd))
294  {
295    // Run another plugin in a list context
296    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
297    final ItemQuery<Scan> query = Scan.getQuery();
298    cc.configureQuery(query, true);
299    cc.setQuery(query);
300    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
301  }
302  else if ("RunPlugin".equals(cmd))
303  {
304    // Run another plugin in single-item context
305    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
306    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
307  }
308  else
309  {
310    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
311  }
312}
313finally
314{
315  if (dc != null) dc.close();
316}
317
318if (forward != null)
319{
320  pageContext.forward(forward);
321}
322else if (redirect != null)
323{
324  response.sendRedirect(redirect);
325}
326else if (message == null)
327{
328  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
329}
330else
331{
332  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
333}
334%>
335
Note: See TracBrowser for help on using the repository browser.