source: branches/filedb/www/admin/platforms/index.jsp @ 3798

Last change on this file since 3798 was 3798, checked in by Nicklas Nordborg, 15 years ago

References #721: Changed systemId to externalId in JSP as well

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 10.1 KB
Line 
1<%-- $Id: index.jsp 3798 2007-09-28 06:45:09Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2007 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 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.Platform"
33  import="net.sf.basedb.core.RawDataType"
34  import="net.sf.basedb.core.RawDataTypes"
35  import="net.sf.basedb.core.ItemQuery"
36  import="net.sf.basedb.core.Permission"
37  import="net.sf.basedb.core.ItemContext"
38  import="net.sf.basedb.core.MultiPermissions"
39  import="net.sf.basedb.core.PermissionDeniedException"
40  import="net.sf.basedb.core.ItemAlreadyExistsException"
41  import="net.sf.basedb.util.RemovableUtil"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.WebException"
44  import="net.sf.basedb.util.Values"
45  import="net.sf.basedb.clients.web.util.HTML"
46  import="net.sf.basedb.util.formatter.Formatter"
47  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
48  import="java.util.Date"
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,fileOnly,externalId,description");
58  private static final Item itemType = Item.PLATFORM;
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_platforms.jsp?ID="+ID
69  +(mode == null ? "" : "&mode="+mode)
70  +(callback == null ? "" : "&callback="+callback)
71  +(itemId == null ? "" : "&item_id="+itemId);
72final String viewPage = "view_platform.jsp?ID="+ID;
73final String editPage = "edit_platform.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    redirect = editPage;
124  }
125  else if ("UpdateItem".equals(cmd))
126  {
127    // Update the properties on an item (will close the popup)
128    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
129    dc = sc.newDbControl();
130    Platform platform = (Platform)cc.getObject("item");
131    if (platform == null)
132    {
133      boolean fileOnly = Values.getBoolean(request.getParameter("fileOnly"));
134      String externalId = Values.getStringOrNull(request.getParameter("externalId"));
135      if (fileOnly)
136      {
137        platform = Platform.getNew(dc, externalId, Values.getInt(request.getParameter("channels")));
138      }
139      else
140      {
141        RawDataType rdt = RawDataTypes.getRawDataType(request.getParameter("rawdatatype"));
142        platform = Platform.getNew(dc, externalId, rdt);
143      }
144      message = "Platform created";
145      dc.saveItem(platform);
146    }
147    else
148    {
149      dc.reattachItem(platform);
150      message = "Platform updated";
151    }
152    platform.setName(Values.getStringOrNull(request.getParameter("name")));
153    platform.setDescription(Values.getStringOrNull(request.getParameter("description")));
154    dc.commit();
155    cc.removeObject("item");
156  }
157  else if ("DeleteItem".equals(cmd))
158  {
159    // Delete a single item and then return to the view page
160    dc = sc.newDbControl();
161    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
162    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
163    dc.commit();
164    redirect = viewPage;
165  }
166  else if ("DeleteItems".equals(cmd))
167  {
168    // Delete all selected items on the list page
169    dc = sc.newDbControl();
170    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
171    int numTotal = cc.getSelected().size();
172    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
173    dc.commit();
174    if (numTotal != numRemoved)
175    {
176      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
177    }
178    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
179  }
180  else if ("RestoreItem".equals(cmd))
181  {
182    // Restore a single item and then return to the view page
183    dc = sc.newDbControl();
184    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
185    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
186    dc.commit();
187    redirect = viewPage;
188  }
189  else if ("RestoreItems".equals(cmd))
190  {
191    // Restore all selected items on the list page
192    dc = sc.newDbControl();
193    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
194    int numTotal = cc.getSelected().size();
195    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
196    dc.commit();
197    if (numTotal != numRemoved)
198    {
199      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
200    }
201    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
202  }
203  else if ("ExportItems".equals(cmd))
204  {
205    // Run an export plugin in a list context
206    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
207    final ItemQuery<Platform> query = Platform.getQuery();
208    cc.configureQuery(query, true);
209    cc.setQuery(query);
210    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+platforms";
211  }
212  else if ("ExportItem".equals(cmd))
213  {
214    // Run an export plugin in single-item context
215    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
216    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+platform";
217  }
218  else if ("ImportItems".equals(cmd))
219  {
220    // Run an import plugin in a list context
221    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
222    final ItemQuery<Platform> query = Platform.getQuery();
223    cc.configureQuery(query, true);
224    cc.setQuery(query);
225    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+platforms";
226  }
227  else if ("ImportItem".equals(cmd))
228  {
229    // Run an import plugin in single-item context
230    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
231    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+platform";
232  }
233  else if ("RunListPlugin".equals(cmd))
234  {
235    // Run another plugin in a list context
236    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
237    final ItemQuery<Platform> query = Platform.getQuery();
238    cc.configureQuery(query, true);
239    cc.setQuery(query);
240    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
241  }
242  else if ("RunPlugin".equals(cmd))
243  {
244    // Run another plugin in single-item context
245    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
246    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
247  }
248  else
249  {
250    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
251  }
252}
253finally
254{
255  if (dc != null) dc.close();
256}
257
258if (forward != null)
259{
260  pageContext.forward(forward);
261}
262else if (redirect != null)
263{
264  response.sendRedirect(redirect);
265}
266else if (message == null)
267{
268  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
269}
270else
271{
272  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
273}
274%>
275
Note: See TracBrowser for help on using the repository browser.