source: trunk/www/admin/platforms/index.jsp @ 4510

Last change on this file since 4510 was 4510, checked in by Jari Häkkinen, 13 years ago

Addresses #1106. Missed to change reference wherefrom retrive GPLv3 license text. And some other changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 11.0 KB
Line 
1<%@page import="net.sf.basedb.core.PlatformFileType"%>
2<%-- $Id:index.jsp 3820 2007-10-12 10:03:18Z nicklas $
3  ------------------------------------------------------------------
4  Copyright (C) 2007 Nicklas Nordborg
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.Platform"
32  import="net.sf.basedb.core.DataFileType"
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    forward = 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   
155    // Data file types
156    String[] modifiedFileTypes = Values.getString(request.getParameter("modifiedFileTypes")).split(",");
157    for (int i = 0; i < modifiedFileTypes.length; ++i)
158    {
159      int ftId = Values.getInt(modifiedFileTypes[i], -1);
160      if (ftId != -1) 
161      {
162        DataFileType dft = DataFileType.getById(dc, ftId);
163        boolean required = Values.getBoolean(request.getParameter("F"+ftId));
164        platform.addFileType(dft, required, null);
165      }
166    }
167    String[] removedFileTypes = Values.getString(request.getParameter("removedFileTypes")).split(",");
168    for (int i = 0; i < removedFileTypes.length; ++i)
169    {
170      int ftId = Values.getInt(removedFileTypes[i], -1);
171      if (ftId != -1) 
172      {
173        DataFileType dft = DataFileType.getById(dc, ftId);
174        platform.removeFileType(dft, null);
175      }
176    }
177
178    dc.commit();
179    cc.removeObject("item");
180  }
181  else if ("DeleteItem".equals(cmd))
182  {
183    // Delete a single item and then return to the view page
184    dc = sc.newDbControl();
185    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
186    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
187    dc.commit();
188    redirect = viewPage;
189  }
190  else if ("DeleteItems".equals(cmd))
191  {
192    // Delete all selected items on the list page
193    dc = sc.newDbControl();
194    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
195    int numTotal = cc.getSelected().size();
196    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
197    dc.commit();
198    if (numTotal != numRemoved)
199    {
200      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
201    }
202    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
203  }
204  else if ("RestoreItem".equals(cmd))
205  {
206    // Restore a single item and then return to the view page
207    dc = sc.newDbControl();
208    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
209    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
210    dc.commit();
211    redirect = viewPage;
212  }
213  else if ("RestoreItems".equals(cmd))
214  {
215    // Restore all selected items on the list page
216    dc = sc.newDbControl();
217    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
218    int numTotal = cc.getSelected().size();
219    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
220    dc.commit();
221    if (numTotal != numRemoved)
222    {
223      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
224    }
225    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
226  }
227  else if ("ExportItems".equals(cmd))
228  {
229    // Run an export plugin in a list context
230    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
231    final ItemQuery<Platform> query = Platform.getQuery();
232    cc.configureQuery(query, true);
233    cc.setQuery(query);
234    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+platforms";
235  }
236  else if ("ExportItem".equals(cmd))
237  {
238    // Run an export plugin in single-item context
239    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
240    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+platform";
241  }
242  else if ("ImportItems".equals(cmd))
243  {
244    // Run an import plugin in a list context
245    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
246    final ItemQuery<Platform> query = Platform.getQuery();
247    cc.configureQuery(query, true);
248    cc.setQuery(query);
249    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+platforms";
250  }
251  else if ("ImportItem".equals(cmd))
252  {
253    // Run an import plugin in single-item context
254    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
255    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+platform";
256  }
257  else if ("RunListPlugin".equals(cmd))
258  {
259    // Run another plugin in a list context
260    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
261    final ItemQuery<Platform> query = Platform.getQuery();
262    cc.configureQuery(query, true);
263    cc.setQuery(query);
264    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
265  }
266  else if ("RunPlugin".equals(cmd))
267  {
268    // Run another plugin in single-item context
269    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
270    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
271  }
272  else
273  {
274    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
275  }
276}
277finally
278{
279  if (dc != null) dc.close();
280}
281
282if (forward != null)
283{
284  pageContext.forward(forward);
285}
286else if (redirect != null)
287{
288  response.sendRedirect(redirect);
289}
290else if (message == null)
291{
292  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
293}
294else
295{
296  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
297}
298%>
299
Note: See TracBrowser for help on using the repository browser.