source: trunk/www/admin/plugintypes/index.jsp @ 4889

Last change on this file since 4889 was 4889, checked in by Nicklas Nordborg, 13 years ago

References #1290: Change source files to UTF-8

Changed 'Hakkinen' to 'Häkkinen'.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 9.9 KB
Line 
1<%-- $Id: index.jsp 4889 2009-04-06 12:52:39Z 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 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.PluginType"
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.MultiPermissions"
36  import="net.sf.basedb.core.PermissionDeniedException"
37  import="net.sf.basedb.core.ItemAlreadyExistsException"
38  import="net.sf.basedb.util.RemovableUtil"
39  import="net.sf.basedb.clients.web.Base"
40  import="net.sf.basedb.clients.web.WebException"
41  import="net.sf.basedb.util.Values"
42  import="net.sf.basedb.clients.web.util.HTML"
43  import="java.util.Enumeration"
44  import="java.util.Set"
45  import="java.util.HashSet"
46  import="java.util.List"
47  import="java.util.ArrayList"
48  import="java.util.Collections"
49%>
50<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
51<%!
52  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,interfaceName,description");
53  private static final Item itemType = Item.PLUGINTYPE;
54%>
55<%
56final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
57final String ID = sc.getId();
58final String cmd = request.getParameter("cmd");
59final String root = request.getContextPath()+"/";
60final String mode = request.getParameter("mode");
61final String callback = request.getParameter("callback");
62final String itemId = request.getParameter("item_id");
63final String listPage = "list_plugintypes.jsp?ID="+ID
64  +(mode == null ? "" : "&mode="+mode)
65  +(callback == null ? "" : "&callback="+callback)
66  +(itemId == null ? "" : "&item_id="+itemId);
67final String viewPage = "view_plugintype.jsp?ID="+ID;
68final String editPage = "edit_plugintype.jsp?ID="+ID;
69
70String forward = null;
71String redirect = null;
72String message = null;
73DbControl dc = null;
74
75try
76{
77  if (cmd == null || "List".equals(cmd))
78  {
79    // Display the list page without updatinging the current context
80    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
81    redirect = listPage;
82  }
83  else if ("UpdateContext".equals(cmd))
84  {
85    // Display the list page after updating the current context from the request parameters
86    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
87    redirect = listPage;
88  }
89  else if ("LoadContext".equals(cmd))
90  {
91    // Display the list page after loading a saved context
92    int contextId = Values.getInt(request.getParameter("context"));
93    Base.loadContext(sc, contextId, defaultContext);
94    redirect = listPage;
95  }
96
97  else if ("ViewItem".equals(cmd))
98  {
99    // Display the view page for a single item
100    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
101    forward = viewPage;
102  }
103  else if ("EditItem".equals(cmd))
104  {
105    // Display the edit page for a single item (should be opened in a popup)
106    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
107    redirect = editPage;
108  }
109  else if ("NewItem".equals(cmd))
110  {
111    // Display the edit page for a new item (should be opened in a popup)
112    if (!sc.hasPermission(Permission.CREATE, itemType))
113    {
114      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
115    }
116    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
117    cc.setId(0);
118    redirect = editPage;
119  }
120  else if ("UpdateItem".equals(cmd))
121  {
122    // Update the properties on an item (will close the popup)
123    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
124    dc = sc.newDbControl();
125    PluginType pluginType = (PluginType)cc.getObject("item");
126    String interfaceName = Values.getStringOrNull(request.getParameter("interfaceName"));
127    String jarPath = Values.getStringOrNull(request.getParameter("jarPath"));
128    if (pluginType == null)
129    {
130      pluginType = PluginType.getNew(dc, interfaceName, jarPath);
131      message = "Plugin type created";
132      dc.saveItem(pluginType);
133    }
134    else
135    {
136      dc.reattachItem(pluginType);
137      pluginType.loadInterfaceInformation(jarPath, interfaceName);
138      message = "Plugin type updated";
139    }
140    pluginType.setName(Values.getStringOrNull(request.getParameter("name")));
141    pluginType.setDescription(Values.getStringOrNull(request.getParameter("description")));
142    dc.commit();
143    cc.removeObject("item");
144  }
145  else if ("DeleteItem".equals(cmd))
146  {
147    // Delete a single item and then return to the view page
148    dc = sc.newDbControl();
149    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
150    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
151    dc.commit();
152    redirect = viewPage;
153  }
154  else if ("DeleteItems".equals(cmd))
155  {
156    // Delete all selected items on the list page
157    dc = sc.newDbControl();
158    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
159    int numTotal = cc.getSelected().size();
160    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
161    dc.commit();
162    if (numTotal != numRemoved)
163    {
164      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
165    }
166    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
167  }
168  else if ("RestoreItem".equals(cmd))
169  {
170    // Restore a single item and then return to the view page
171    dc = sc.newDbControl();
172    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
173    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
174    dc.commit();
175    redirect = viewPage;
176  }
177  else if ("RestoreItems".equals(cmd))
178  {
179    // Restore all selected items on the list page
180    dc = sc.newDbControl();
181    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
182    int numTotal = cc.getSelected().size();
183    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
184    dc.commit();
185    if (numTotal != numRemoved)
186    {
187      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
188    }
189    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
190  }
191  else if ("ExportItems".equals(cmd))
192  {
193    // Run an export plugin in a list context
194    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
195    final ItemQuery<PluginType> query = PluginType.getQuery();
196    cc.configureQuery(query, true);
197    cc.setQuery(query);
198    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+plugin+types";
199  }
200  else if ("ExportItem".equals(cmd))
201  {
202    // Run an export plugin in single-item context
203    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
204    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+plugin+type";
205  }
206  else if ("ImportItems".equals(cmd))
207  {
208    // Run an import plugin in a list context
209    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
210    final ItemQuery<PluginType> query = PluginType.getQuery();
211    cc.configureQuery(query, true);
212    cc.setQuery(query);
213    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+plugin+types";
214  }
215  else if ("ImportItem".equals(cmd))
216  {
217    // Run an import plugin in single-item context
218    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
219    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+plugin+type";
220  }
221  else if ("RunListPlugin".equals(cmd))
222  {
223    // Run another plugin in a list context
224    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
225    final ItemQuery<PluginType> query = PluginType.getQuery();
226    cc.configureQuery(query, true);
227    cc.setQuery(query);
228    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
229  }
230  else if ("RunPlugin".equals(cmd))
231  {
232    // Run another plugin in single-item context
233    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
234    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
235  }
236  else
237  {
238    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
239  }
240}
241finally
242{
243  if (dc != null) dc.close();
244}
245
246if (forward != null)
247{
248  pageContext.forward(forward);
249}
250else if (redirect != null)
251{
252  response.sendRedirect(redirect);
253}
254else if (message == null)
255{
256  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
257}
258else
259{
260  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
261}
262%>
263
Note: See TracBrowser for help on using the repository browser.