source: trunk/www/views/itemlists/members/index.jsp @ 7604

Last change on this file since 7604 was 7604, checked in by Nicklas Nordborg, 3 years ago

References #2151: Pre-compile all JSP pages before releases

Getting rid of rawtypes warnings. Most of them are relatively simple by adding a type parameter.

Utility functions that are used with generics are typically a bit harder.

File size: 10.2 KB
Line 
1<%-- $Id: index.jsp 6278 2013-05-24 10:41:55Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2008 Nicklas Nordborg
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 3
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Nicklas
23  @version 2.10
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.Item"
29  import="net.sf.basedb.core.ItemContext"
30  import="net.sf.basedb.core.Type"
31  import="net.sf.basedb.core.ItemQuery"
32  import="net.sf.basedb.core.ItemList"
33  import="net.sf.basedb.core.BasicItem"
34  import="net.sf.basedb.core.Listable"
35  import="net.sf.basedb.core.OwnedItem"
36  import="net.sf.basedb.core.query.Restrictions"
37  import="net.sf.basedb.core.query.Expressions"
38  import="net.sf.basedb.core.query.Hql"
39  import="net.sf.basedb.core.query.Orders"
40  import="net.sf.basedb.core.MultiPermissions"
41  import="net.sf.basedb.core.Permission"
42  import="net.sf.basedb.core.PermissionDeniedException"
43  import="net.sf.basedb.clients.web.Base"
44  import="net.sf.basedb.clients.web.WebException"
45  import="net.sf.basedb.util.ShareableUtil"
46  import="net.sf.basedb.util.RemovableUtil"
47  import="net.sf.basedb.util.Values"
48  import="net.sf.basedb.clients.web.util.HTML"
49  import="net.sf.basedb.core.plugin.GuiContext"
50  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
51  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
52  import="net.sf.basedb.clients.web.extensions.JspContext"
53  import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer"
54  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
55  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
56  import="java.util.Arrays"
57  import="java.util.Collections"
58  import="java.util.Set"
59  import="java.util.HashSet"
60%>
61<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
62<%!
63  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,itemSubtype,description");
64
65  private static void registerExportUtils(ItemContext cc)
66  {
67    Item memberType = cc.getItemType();
68  }
69%>
70<%
71final int listId = Values.getInt(request.getParameter("list_id"));
72final String subContext = "listmembers."+listId;
73
74final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
75final String ID = sc.getId();
76final String cmd = request.getParameter("cmd");
77final String root = request.getContextPath()+"/";
78final String mode = request.getParameter("mode");
79final String callback = request.getParameter("callback");
80final String listPage = "list_members.jsp?ID="+ID
81  +"&list_id="+listId
82  +(mode == null ? "" : "&mode="+mode)
83  +(callback == null ? "" : "&callback="+callback);
84
85String forward = null;
86String redirect = null;
87String message = null;
88DbControl dc = null;
89try
90{
91  dc = sc.newDbControl();
92  final ItemList list = ItemList.getById(dc, listId);
93  final Item itemType = list.getMemberType();
94 
95  if (cmd == null || "List".equals(cmd))
96  {
97    // Display the list page without updatinging the current context
98    Base.getAndSetCurrentContext(sc, itemType, subContext, (PageContext)null, defaultContext, true);
99    redirect = listPage;
100  }
101  else if ("UpdateContext".equals(cmd))
102  {
103    // Display the list page after updating the current context from the request parameters
104    Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
105    redirect = listPage;
106  }
107  else if ("LoadContext".equals(cmd))
108  {
109    // Display the list page after loading a saved context
110    int contextId = Values.getInt(request.getParameter("context"));
111    Base.loadContext(sc, contextId, defaultContext);
112    redirect = listPage;
113  }
114  else if ("DeleteItems".equals(cmd))
115  {
116    // Delete all selected items on the list page
117    dc = sc.newDbControl();
118    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
119    int numTotal = cc.getSelected().size();
120    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
121    dc.commit();
122    if (numTotal != numRemoved)
123    {
124      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
125    }
126    redirect = listPage;
127  }
128  else if ("RestoreItems".equals(cmd))
129  {
130    // Restore all selected items on the list page
131    dc = sc.newDbControl();
132    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
133    int numTotal = cc.getSelected().size();
134    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
135    dc.commit();
136    if (numTotal != numRemoved)
137    {
138      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
139    }
140    redirect = listPage;
141  }
142  else if ("ShareItems".equals(cmd))
143  {
144    // Display a popup window for sharing all selected items on the list page
145    dc = sc.newDbControl();
146    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
147    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
148    dc.close();
149    cc.setObject("MultiPermissions", permissions);
150    redirect = "../../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name()+"&subcontext="+subContext;
151  }
152  else if ("SetOwnerOfItems".equals(cmd))
153  {
154    // Change owner of items selected on a list page
155    dc = sc.newDbControl();
156    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
157    Set<OwnedItem> items = new HashSet<OwnedItem>();
158    for (Integer id : cc.getSelected())
159    {
160      if (id != null) items.add((OwnedItem)itemType.getById(dc, id));
161    }
162    dc.close();
163    cc.setObject("OwnedItems", items);
164    redirect = "../../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name()+"&subcontext="+subContext;
165  }
166  else if ("ExportItems".equals(cmd))
167  {
168    // Run an export plugin in a list context
169    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
170    registerExportUtils(cc);
171    final ItemQuery<? extends Listable> query = list.getMembers();
172    dc = sc.newDbControl();
173    cc.configureQuery(dc, query, true);
174    cc.setQuery(query);
175    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null);
176    ExtensionsInvoker<ListColumnAction<Listable,?>> listInvoker = ListColumnUtil.useExtensions(jspContext);
177    listInvoker.render(new ListColumnExportRenderer<Listable>(cc));
178    dc.close();
179    redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&subcontext="+subContext+"&title=Export+list+members";
180  }
181  else if ("ImportItems".equals(cmd))
182  {
183    // Run an import plugin in a list context
184    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
185    final ItemQuery<? extends Listable> query = list.getMembers();
186    cc.configureQuery(dc, query, true);
187    cc.setQuery(query);
188    dc.close();
189    redirect = "../../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&subcontext="+subContext+"&title=Import+list+members";
190  }
191  else if ("RunListPlugin".equals(cmd))
192  {
193    // Run another plugin in a list context
194    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
195    final ItemQuery<? extends BasicItem> query = list.getMembers();
196    cc.configureQuery(dc, query, true);
197    cc.setQuery(query);
198    dc.close();
199    redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&subcontext="+subContext+"&main_type=OTHER&title=Run+plugin";
200  }
201  else if ("AddMembers".equals(cmd))
202  {
203    ItemContext memberContext = sc.getCurrentContext(itemType);
204    final ItemQuery<? extends Listable> query = list.getAllItems();
205    memberContext.configureQuery(dc, query, true);
206    String which = request.getParameter("which");
207    if ("selected".equals(which))
208    {
209      query.setFirstResult(0);
210      query.setMaxResults(-1);
211      Integer[] itemIds = Values.getInt(request.getParameter("items").split(","));
212      query.restrict(
213        Restrictions.in(
214          Hql.property("id"),
215          Expressions.parameter("selectedItems")
216        )
217      );
218      query.setParameter("selectedItems", Arrays.asList(itemIds), Type.INT);     
219    }
220    else if ("all".equals(which))
221    {
222      query.setFirstResult(0);
223      query.setMaxResults(-1);
224    }
225    int count = list.add(query.iterate(dc));
226    dc.commit();
227    message = count + " members added to list";
228  }
229  else if ("RemoveMembers".equals(cmd))
230  {
231    // Delete all selected items on the list page
232    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
233    for (int itemId : cc.getSelected())
234    {
235      list.removeItem((Listable)itemType.getById(dc, itemId));
236    }
237    dc.commit();
238    redirect = listPage;
239  }
240
241  else
242  {
243    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
244  }
245}
246finally
247{
248  if (dc != null) dc.close();
249}
250
251if (forward != null)
252{
253  sc.setSessionSetting("alert-message", message);
254  pageContext.forward(forward);
255}
256else if (redirect != null)
257{
258  sc.setSessionSetting("alert-message", message);
259  response.sendRedirect(redirect);
260}
261else if (message == null)
262{
263  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
264}
265else
266{
267  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
268}
269%>
270
Note: See TracBrowser for help on using the repository browser.