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

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

References #721: Added platform variants to web gui.

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