source: trunk/www/admin/pluginconfigurations/index.jsp @ 2992

Last change on this file since 2992 was 2992, checked in by Johan Enell, 15 years ago

Merged log:branches/2.1#2846:2990 trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 13.9 KB
Line 
1<%-- $Id: index.jsp 2992 2006-12-01 14:00:14Z enell $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
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 2
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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
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.PluginDefinition"
33  import="net.sf.basedb.core.PluginConfiguration"
34  import="net.sf.basedb.core.ItemQuery"
35  import="net.sf.basedb.core.Permission"
36  import="net.sf.basedb.core.ItemContext"
37  import="net.sf.basedb.core.MultiPermissions"
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.util.JarClassLoader"
44  import="net.sf.basedb.clients.web.Base"
45  import="net.sf.basedb.clients.web.WebException"
46  import="net.sf.basedb.util.Values"
47  import="net.sf.basedb.clients.web.util.HTML"
48  import="java.util.Enumeration"
49  import="java.util.Set"
50  import="java.util.HashSet"
51  import="java.util.List"
52  import="java.util.ArrayList"
53  import="java.util.Collections"
54%>
55<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
56<%!
57  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,pluginType,pluginDefinition,description,actions");
58  private static final Item itemType = Item.PLUGINCONFIGURATION;
59%>
60<%
61final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
62final String ID = sc.getId();
63final String cmd = request.getParameter("cmd");
64final String root = request.getContextPath()+"/";
65final String mode = request.getParameter("mode");
66final String callback = request.getParameter("callback");
67final String itemId = request.getParameter("item_id");
68final String listPage = "list_configurations.jsp?ID="+ID
69  +(mode == null ? "" : "&mode="+mode)
70  +(callback == null ? "" : "&callback="+callback)
71  +(itemId == null ? "" : "&item_id="+itemId);
72final String viewPage = "view_configuration.jsp?ID="+ID;
73final String editPage = "edit_configuration.jsp?ID="+ID;
74
75String forward = null;
76String redirect = null;
77String message = null;
78DbControl dc = null;
79
80try
81{
82  if (cmd == null || "List".equals(cmd))
83  {
84    // Display the list page without updatinging the current context
85    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
86    redirect = listPage;
87  }
88  else if ("UpdateContext".equals(cmd))
89  {
90    // Display the list page after updating the current context from the request parameters
91    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
92    redirect = listPage;
93  }
94  else if ("LoadContext".equals(cmd))
95  {
96    // Display the list page after loading a saved context
97    int contextId = Values.getInt(request.getParameter("context"));
98    Base.loadContext(sc, contextId, defaultContext);
99    redirect = listPage;
100  }
101
102  else if ("ViewItem".equals(cmd))
103  {
104    // Display the view page for a single item
105    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
106    forward = viewPage;
107  }
108  else if ("EditItem".equals(cmd))
109  {
110    // Display the edit page for a single item (should be opened in a popup)
111    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
112    redirect = editPage;
113  }
114  else if ("NewItem".equals(cmd))
115  {
116    // Display the edit page for a new item (should be opened in a popup)
117    if (!sc.hasPermission(Permission.CREATE, itemType))
118    {
119      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
120    }
121    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
122    cc.setId(0);
123    forward = editPage;
124  }
125  else if ("CopyItem".equals(cmd))
126  {
127    // Display the edit page for new item(copied from an existing item)
128    if (!sc.hasPermission(Permission.CREATE, itemType))
129    {
130      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
131    }
132    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
133    redirect = editPage + "&cmd="+ cmd;
134  }
135  else if ("UpdateItem".equals(cmd))
136  {
137    // Update the properties on an item (will close the popup)
138    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
139    final int maxRecent = Base.getMaxRecent(sc);
140    dc = sc.newDbControl();
141    PluginConfiguration configuration = (PluginConfiguration)cc.getObject("item");
142    boolean configure = Values.getBoolean(request.getParameter("configure"));
143    if (configuration == null)
144    {
145      int pluginDefinitionId = Values.getInt(request.getParameter("plugindefinition_id"), -1);
146      PluginDefinition plugin = PluginDefinition.getById(dc, pluginDefinitionId);
147      if (!plugin.supportsConfigurations())
148      {
149        throw new WebException("popup", "Configurations are not supported",
150          "The plugin {1} doesn't support configurations.", HTML.encodeTags(plugin.getName()));
151      }
152      if (plugin != null) cc.setRecent(plugin, maxRecent);
153      configuration = PluginConfiguration.getNew(dc, plugin);
154      int copyFromId = Values.getInt(request.getParameter("copyfrom"), 0);
155      if (copyFromId > 0)
156      {
157        PluginConfiguration copyFrom = PluginConfiguration.getById(dc, copyFromId);
158        configuration.copyParametersFrom(copyFrom);
159      }
160      message = "Configuration created";
161      dc.saveItem(configuration);
162    }
163    else
164    {
165      dc.reattachItem(configuration);
166      message = "Configuration updated";
167    }
168    configuration.setName(Values.getStringOrNull(request.getParameter("name")));
169    configuration.setDescription(Values.getStringOrNull(request.getParameter("description")));
170    dc.commit();
171    cc.removeObject("item");
172    if (configure)
173    {
174      redirect = "../../common/plugin/index.jsp?ID=" + ID + 
175        "&cmd=ConfigurePlugin&pluginconfiguration_id=" + configuration.getId();
176    }
177  }
178  else if ("DeleteItem".equals(cmd))
179  {
180    // Delete a single item and then return to the view page
181    dc = sc.newDbControl();
182    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
183    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
184    dc.commit();
185    redirect = viewPage;
186  }
187  else if ("DeleteItems".equals(cmd))
188  {
189    // Delete all selected items on the list page
190    dc = sc.newDbControl();
191    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
192    int numTotal = cc.getSelected().size();
193    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
194    dc.commit();
195    if (numTotal != numRemoved)
196    {
197      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
198    }
199    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
200  }
201  else if ("RestoreItem".equals(cmd))
202  {
203    // Restore a single item and then return to the view page
204    dc = sc.newDbControl();
205    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
206    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
207    dc.commit();
208    redirect = viewPage;
209  }
210  else if ("RestoreItems".equals(cmd))
211  {
212    // Restore all selected items on the list page
213    dc = sc.newDbControl();
214    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
215    int numTotal = cc.getSelected().size();
216    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
217    dc.commit();
218    if (numTotal != numRemoved)
219    {
220      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
221    }
222    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
223  }
224  else if ("ShareItem".equals(cmd))
225  {
226    // Display a popup window for sharing a single item
227    dc = sc.newDbControl();
228    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
229    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
230    dc.close();
231    cc.setObject("MultiPermissions", permissions);
232    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
233  }
234  else if ("ShareItems".equals(cmd))
235  {
236    // Display a popup window for sharing all selected items on the list page
237    dc = sc.newDbControl();
238    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
239    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
240    dc.close();
241    cc.setObject("MultiPermissions", permissions);
242    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
243  }
244  else if ("TakeOwnershipOfItem".equals(cmd))
245  {
246    // Take ownership a single item and then return to the view page
247    dc = sc.newDbControl();
248    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
249    OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null);
250    dc.commit();
251    redirect = viewPage;
252  }
253  else if ("TakeOwnershipOfItems".equals(cmd))
254  {
255    // Take ownership all selected items on the list page
256    dc = sc.newDbControl();
257    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
258    int numTotal = cc.getSelected().size();
259    int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null);
260    dc.commit();
261    if (numTotal != numOwned)
262    {
263      message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission";
264    }
265    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
266  }
267  else if ("ExportItems".equals(cmd))
268  {
269    // Run an export plugin in a list context
270    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
271    final ItemQuery<PluginConfiguration> query = PluginConfiguration.getQuery();
272    cc.configureQuery(query, true);
273    cc.setQuery(query);
274    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+plugin+configurations";
275  }
276  else if ("ExportItem".equals(cmd))
277  {
278    // Run an export plugin in single-item context
279    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
280    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+plugin+configuration";
281  }
282  else if ("ImportItems".equals(cmd))
283  {
284    // Run an import plugin in a list context
285    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
286    final ItemQuery<PluginConfiguration> query = PluginConfiguration.getQuery();
287    cc.configureQuery(query, true);
288    cc.setQuery(query);
289    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+plugin+configurations";
290  }
291  else if ("ImportItem".equals(cmd))
292  {
293    // Run an import plugin in single-item context
294    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
295    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+plugin+configuration";
296  }
297  else if ("RunListPlugin".equals(cmd))
298  {
299    // Run another plugin in a list context
300    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
301    final ItemQuery<PluginConfiguration> query = PluginConfiguration.getQuery();
302    cc.configureQuery(query, true);
303    cc.setQuery(query);
304    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
305  }
306  else if ("RunPlugin".equals(cmd))
307  {
308    // Run another plugin in single-item context
309    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
310    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
311  }
312  else if ("UnloadItems".equals(cmd))
313  {
314    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
315    dc = sc.newDbControl();
316    for (int id : cc.getSelected())
317    {
318      PluginDefinition pd = PluginDefinition.getById(dc, id);
319      if (pd.getJarPath() != null)
320      {
321        JarClassLoader.unload(pd.getJarPath());
322      }
323    }
324    dc.close();
325    redirect = listPage;
326  }
327  else if ("UnloadItem".equals(cmd))
328  {
329    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
330    dc = sc.newDbControl();
331    PluginDefinition pd = PluginDefinition.getById(dc, cc.getId());
332    if (pd.getJarPath() != null)
333    {
334      JarClassLoader.unload(pd.getJarPath());
335    }
336    dc.close();
337    redirect = viewPage;
338  }
339  else
340  {
341    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
342  }
343}
344finally
345{
346  if (dc != null) dc.close();
347}
348
349if (forward != null)
350{
351  pageContext.forward(forward);
352}
353else if (redirect != null)
354{
355  response.sendRedirect(redirect);
356}
357else if (message == null)
358{
359  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
360}
361else
362{
363  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
364}
365%>
366
Note: See TracBrowser for help on using the repository browser.