source: trunk/www/biomaterials/labels/index.jsp @ 5590

Last change on this file since 5590 was 5590, checked in by Nicklas Nordborg, 11 years ago

References #1589: Delete deprecated classes and methods

Removed deprecated methods and classes from the core API.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.4 KB
Line 
1<%-- $Id: index.jsp 5590 2011-03-16 11:48:47Z 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.Label"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.ItemContext"
35  import="net.sf.basedb.core.ItemQuery"
36  import="net.sf.basedb.core.MultiPermissions"
37  import="net.sf.basedb.core.OwnedItem"
38  import="net.sf.basedb.core.PermissionDeniedException"
39  import="net.sf.basedb.core.ItemAlreadyExistsException"
40  import="net.sf.basedb.util.RemovableUtil"
41  import="net.sf.basedb.util.ShareableUtil"
42  import="net.sf.basedb.util.OwnableUtil"
43  import="net.sf.basedb.clients.web.Base"
44  import="net.sf.basedb.clients.web.WebException"
45  import="net.sf.basedb.util.Values"
46  import="net.sf.basedb.clients.web.util.HTML"
47  import="net.sf.basedb.core.plugin.GuiContext"
48  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
49  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
50  import="net.sf.basedb.clients.web.extensions.JspContext"
51  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
52  import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer"
53  import="java.util.Enumeration"
54  import="java.util.Set"
55  import="java.util.HashSet"
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,description");
63  private static final Item itemType = Item.LABEL;
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_labels.jsp?ID="+ID
74  +(mode == null ? "" : "&mode="+mode)
75  +(callback == null ? "" : "&callback="+callback)
76  +(itemId == null ? "" : "&item_id="+itemId);
77final String viewPage = "view_label.jsp?ID="+ID;
78final String editPage = "edit_label.jsp?ID="+ID;
79
80String forward = null;
81String redirect = null;
82String message = null;
83DbControl dc = null;
84
85try
86{
87  if (cmd == null || "List".equals(cmd))
88  {
89    // Display the list page without updatinging the current context
90    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
91    redirect = listPage;
92  }
93  else if ("UpdateContext".equals(cmd))
94  {
95    // Display the list page after updating the current context from the request parameters
96    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
97    redirect = listPage;
98  }
99  else if ("LoadContext".equals(cmd))
100  {
101    // Display the list page after loading a saved context
102    int contextId = Values.getInt(request.getParameter("context"));
103    Base.loadContext(sc, contextId, defaultContext);
104    redirect = listPage;
105  }
106
107  else if ("ViewItem".equals(cmd))
108  {
109    // Display the view page for a single item
110    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
111    forward = viewPage;
112  }
113  else if ("EditItem".equals(cmd))
114  {
115    // Display the edit page for a single item (should be opened in a popup)
116    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
117    redirect = editPage;
118  }
119  else if ("NewItem".equals(cmd))
120  {
121    // Display the edit page for a new item (should be opened in a popup)
122    if (!sc.hasPermission(Permission.CREATE, itemType))
123    {
124      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
125    }
126    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
127    cc.setId(0);
128    redirect = editPage;
129  }
130  else if ("UpdateItem".equals(cmd))
131  {
132    // Update the properties on an item (will close the popup)
133    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
134    dc = sc.newDbControl();
135    Label label = (Label)cc.getObject("item");
136    if (label == null)
137    {
138      label = Label.getNew(dc);
139      message = "Label created";
140      dc.saveItem(label);
141    }
142    else
143    {
144      dc.reattachItem(label, false);
145      message = "Label updated";
146    }
147    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.LABEL), label);
148    ExtensionsInvoker invoker = EditUtil.useOnSaveExtensions(jspContext);
149    try
150    {
151      label.setName(Values.getStringOrNull(request.getParameter("name")));
152      label.setDescription(Values.getStringOrNull(request.getParameter("description")));
153
154      // OnSave extensions
155      invoker.render(OnSaveRenderer.ON_SAVE);
156      dc.commit();
157      invoker.render(OnSaveRenderer.ON_COMMIT);
158    }
159    catch (Exception ex)
160    {
161      invoker.render(OnSaveRenderer.onRollback(ex));
162      throw ex;
163    }
164    finally
165    {
166      cc.removeObject("item");
167    }
168  }
169  else if ("DeleteItem".equals(cmd))
170  {
171    // Delete a single item and then return to the view page
172    dc = sc.newDbControl();
173    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
174    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
175    dc.commit();
176    redirect = viewPage;
177  }
178  else if ("DeleteItems".equals(cmd))
179  {
180    // Delete all selected items on the list page
181    dc = sc.newDbControl();
182    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
183    int numTotal = cc.getSelected().size();
184    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
185    dc.commit();
186    if (numTotal != numRemoved)
187    {
188      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
189    }
190    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
191  }
192  else if ("RestoreItem".equals(cmd))
193  {
194    // Restore a single item and then return to the view page
195    dc = sc.newDbControl();
196    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
197    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
198    dc.commit();
199    redirect = viewPage;
200  }
201  else if ("RestoreItems".equals(cmd))
202  {
203    // Restore all selected items on the list page
204    dc = sc.newDbControl();
205    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
206    int numTotal = cc.getSelected().size();
207    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
208    dc.commit();
209    if (numTotal != numRemoved)
210    {
211      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
212    }
213    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
214  }
215  else if ("ShareItem".equals(cmd))
216  {
217    // Display a popup window for sharing a single item
218    dc = sc.newDbControl();
219    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
220    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
221    dc.close();
222    cc.setObject("MultiPermissions", permissions);
223    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
224  }
225  else if ("ShareItems".equals(cmd))
226  {
227    // Display a popup window for sharing all selected items on the list page
228    dc = sc.newDbControl();
229    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
230    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
231    dc.close();
232    cc.setObject("MultiPermissions", permissions);
233    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
234  }
235  else if ("SetOwnerOfItem".equals(cmd))
236  {
237    // Change owner of items selected on a list page
238    dc = sc.newDbControl();
239    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
240    OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId());
241    cc.setObject("OwnedItems", Collections.singleton(item));
242    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
243  }
244  else if ("SetOwnerOfItems".equals(cmd))
245  {
246    // Change owner of items selected on a list page
247    dc = sc.newDbControl();
248    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
249    Set<OwnedItem> items = new HashSet<OwnedItem>();
250    for (Integer id : cc.getSelected())
251    {
252      if (id != null) items.add((OwnedItem)itemType.getById(dc, id));
253    }
254    dc.close();
255    cc.setObject("OwnedItems", items);
256    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
257  }
258  else if ("ExportItems".equals(cmd))
259  {
260    // Run an export plugin in a list context
261    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
262    final ItemQuery<Label> query = Label.getQuery();
263    dc = sc.newDbControl();
264    cc.configureQuery(dc, query, true);
265    dc.close();
266    cc.setQuery(query);
267    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+labels";
268  }
269  else if ("ExportItem".equals(cmd))
270  {
271    // Run an export plugin in single-item context
272    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
273    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+label";
274  }
275  else if ("ImportItems".equals(cmd))
276  {
277    // Run an import plugin in a list context
278    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
279    final ItemQuery<Label> query = Label.getQuery();
280    dc = sc.newDbControl();
281    cc.configureQuery(dc, query, true);
282    dc.close();
283    cc.setQuery(query);
284    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+labels";
285  }
286  else if ("ImportItem".equals(cmd))
287  {
288    // Run an import plugin in single-item context
289    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
290    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+label";
291  }
292  else if ("RunListPlugin".equals(cmd))
293  {
294    // Run another plugin in a list context
295    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
296    final ItemQuery<Label> query = Label.getQuery();
297    dc = sc.newDbControl();
298    cc.configureQuery(dc, query, true);
299    dc.close();
300    cc.setQuery(query);
301    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
302  }
303  else if ("RunPlugin".equals(cmd))
304  {
305    // Run another plugin in single-item context
306    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
307    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
308  }
309  else
310  {
311    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
312  }
313}
314finally
315{
316  if (dc != null) dc.close();
317}
318
319if (forward != null)
320{
321  pageContext.forward(forward);
322}
323else if (redirect != null)
324{
325  response.sendRedirect(redirect);
326}
327else if (message == null)
328{
329  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
330}
331else
332{
333  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
334}
335%>
336
Note: See TracBrowser for help on using the repository browser.