source: trunk/www/admin/platforms/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: 12.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.PlatformVariant"
41  import="net.sf.basedb.core.ItemAlreadyExistsException"
42  import="net.sf.basedb.core.query.Expressions"
43  import="net.sf.basedb.core.query.Hql"
44  import="net.sf.basedb.core.query.Orders"
45  import="net.sf.basedb.core.query.Restrictions"
46  import="net.sf.basedb.util.RemovableUtil" 
47  import="net.sf.basedb.clients.web.Base"
48  import="net.sf.basedb.clients.web.WebException"
49  import="net.sf.basedb.util.Values"
50  import="net.sf.basedb.clients.web.util.HTML"
51  import="net.sf.basedb.util.formatter.Formatter"
52  import="net.sf.basedb.util.formatter.NameableFormatter"
53  import="net.sf.basedb.clients.web.plugins.ItemQueryLoader"
54  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
55  import="java.util.Date"
56  import="java.util.Set"
57  import="java.util.HashSet"
58  import="java.util.List"
59  import="java.util.ArrayList"
60  import="java.util.Collections"
61%>
62<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
63<%!
64  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,fileOnly,externalId,description");
65  private static final Item itemType = Item.PLATFORM;
66 
67  private static void registerExportUtils(ItemContext cc)
68  {
69    // Register formatters
70    cc.setObject("export.formatter.&variants(name)", new NameableFormatter());
71   
72    // Register dataloaders
73    String platformParameter = "platform";
74    final ItemQuery<PlatformVariant> variantQuery = PlatformVariant.getQuery();
75    variantQuery.include(cc.getInclude());
76    variantQuery.restrict(Restrictions.eq(Hql.property("platform"), Expressions.parameter(platformParameter)));
77    variantQuery.order(Orders.asc(Hql.property("name"))); 
78    cc.setObject("export.dataloader.&variants(name)", new ItemQueryLoader(variantQuery, platformParameter));
79  }
80%>
81<%
82final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
83final String ID = sc.getId();
84final String cmd = request.getParameter("cmd");
85final String root = request.getContextPath()+"/";
86final String mode = request.getParameter("mode");
87final String callback = request.getParameter("callback");
88final String itemId = request.getParameter("item_id");
89final String listPage = "list_platforms.jsp?ID="+ID
90  +(mode == null ? "" : "&mode="+mode)
91  +(callback == null ? "" : "&callback="+callback)
92  +(itemId == null ? "" : "&item_id="+itemId);
93final String viewPage = "view_platform.jsp?ID="+ID;
94final String editPage = "edit_platform.jsp?ID="+ID;
95
96String forward = null;
97String redirect = null;
98String message = null;
99DbControl dc = null;
100
101try
102{
103  if (cmd == null || "List".equals(cmd))
104  {
105    // Display the list page without updatinging the current context
106    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
107    redirect = listPage;
108  }
109  else if ("UpdateContext".equals(cmd))
110  {
111    // Display the list page after updating the current context from the request parameters
112    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
113    redirect = listPage;
114  }
115  else if ("LoadContext".equals(cmd))
116  {
117    // Display the list page after loading a saved context
118    int contextId = Values.getInt(request.getParameter("context"));
119    Base.loadContext(sc, contextId, defaultContext);
120    redirect = listPage;
121  }
122
123  else if ("ViewItem".equals(cmd))
124  {
125    // Display the view page for a single item
126    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
127    forward = viewPage;
128  }
129  else if ("EditItem".equals(cmd))
130  {
131    // Display the edit page for a single item (should be opened in a popup)
132    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
133    forward = editPage;
134  }
135  else if ("NewItem".equals(cmd))
136  {
137    // Display the edit page for a new item (should be opened in a popup)
138    if (!sc.hasPermission(Permission.CREATE, itemType))
139    {
140      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
141    }
142    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
143    cc.setId(0);
144    redirect = editPage;
145  }
146  else if ("UpdateItem".equals(cmd))
147  {
148    // Update the properties on an item (will close the popup)
149    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
150    dc = sc.newDbControl();
151    Platform platform = (Platform)cc.getObject("item");
152    if (platform == null)
153    {
154      boolean fileOnly = Values.getBoolean(request.getParameter("fileOnly"));
155      String externalId = Values.getStringOrNull(request.getParameter("externalId"));
156      if (fileOnly)
157      {
158        platform = Platform.getNew(dc, externalId, Values.getInt(request.getParameter("channels")));
159      }
160      else
161      {
162        RawDataType rdt = RawDataTypes.getRawDataType(request.getParameter("rawdatatype"));
163        platform = Platform.getNew(dc, externalId, rdt);
164      }
165      message = "Platform created";
166      dc.saveItem(platform);
167    }
168    else
169    {
170      dc.reattachItem(platform);
171      message = "Platform updated";
172    }
173    platform.setName(Values.getStringOrNull(request.getParameter("name")));
174    platform.setDescription(Values.getStringOrNull(request.getParameter("description")));
175   
176    // Data file types
177    String[] modifiedFileTypes = Values.getString(request.getParameter("modifiedFileTypes")).split(",");
178    for (int i = 0; i < modifiedFileTypes.length; ++i)
179    {
180      int ftId = Values.getInt(modifiedFileTypes[i], -1);
181      if (ftId != -1) 
182      {
183        DataFileType dft = DataFileType.getById(dc, ftId);
184        boolean required = Values.getBoolean(request.getParameter("F"+ftId));
185        platform.addFileType(dft, required, null);
186      }
187    }
188    String[] removedFileTypes = Values.getString(request.getParameter("removedFileTypes")).split(",");
189    for (int i = 0; i < removedFileTypes.length; ++i)
190    {
191      int ftId = Values.getInt(removedFileTypes[i], -1);
192      if (ftId != -1) 
193      {
194        DataFileType dft = DataFileType.getById(dc, ftId);
195        platform.removeFileType(dft, null);
196      }
197    }
198
199    dc.commit();
200    cc.removeObject("item");
201  }
202  else if ("DeleteItem".equals(cmd))
203  {
204    // Delete a single item and then return to the view page
205    dc = sc.newDbControl();
206    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
207    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
208    dc.commit();
209    redirect = viewPage;
210  }
211  else if ("DeleteItems".equals(cmd))
212  {
213    // Delete all selected items on the list page
214    dc = sc.newDbControl();
215    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
216    int numTotal = cc.getSelected().size();
217    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
218    dc.commit();
219    if (numTotal != numRemoved)
220    {
221      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
222    }
223    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
224  }
225  else if ("RestoreItem".equals(cmd))
226  {
227    // Restore a single item and then return to the view page
228    dc = sc.newDbControl();
229    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
230    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
231    dc.commit();
232    redirect = viewPage;
233  }
234  else if ("RestoreItems".equals(cmd))
235  {
236    // Restore all selected items on the list page
237    dc = sc.newDbControl();
238    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
239    int numTotal = cc.getSelected().size();
240    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
241    dc.commit();
242    if (numTotal != numRemoved)
243    {
244      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
245    }
246    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
247  }
248  else if ("ExportItems".equals(cmd))
249  {
250    // Run an export plugin in a list context
251    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
252    final ItemQuery<Platform> query = Platform.getQuery();
253    cc.configureQuery(query, true);
254    cc.setQuery(query);
255    registerExportUtils(cc);
256    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+platforms";
257  }
258  else if ("ExportItem".equals(cmd))
259  {
260    // Run an export plugin in single-item context
261    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
262    registerExportUtils(cc);
263    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+platform";
264  }
265  else if ("ImportItems".equals(cmd))
266  {
267    // Run an import plugin in a list context
268    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
269    final ItemQuery<Platform> query = Platform.getQuery();
270    cc.configureQuery(query, true);
271    cc.setQuery(query);
272    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+platforms";
273  }
274  else if ("ImportItem".equals(cmd))
275  {
276    // Run an import plugin in single-item context
277    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
278    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+platform";
279  }
280  else if ("RunListPlugin".equals(cmd))
281  {
282    // Run another plugin in a list context
283    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
284    final ItemQuery<Platform> query = Platform.getQuery();
285    cc.configureQuery(query, true);
286    cc.setQuery(query);
287    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
288  }
289  else if ("RunPlugin".equals(cmd))
290  {
291    // Run another plugin in single-item context
292    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
293    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
294  }
295  else
296  {
297    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
298  }
299}
300finally
301{
302  if (dc != null) dc.close();
303}
304
305if (forward != null)
306{
307  pageContext.forward(forward);
308}
309else if (redirect != null)
310{
311  response.sendRedirect(redirect);
312}
313else if (message == null)
314{
315  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
316}
317else
318{
319  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
320}
321%>
322
Note: See TracBrowser for help on using the repository browser.