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

Last change on this file since 4906 was 4906, checked in by Martin Svensson, 13 years ago

References #1128 More item-pages updated

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