source: trunk/www/views/experiments/bioassaysets/index.jsp @ 2993

Last change on this file since 2993 was 2993, checked in by Nicklas Nordborg, 17 years ago

Fixes #215: Incorrect use of DynamicSpotQuery? in table view, plot function, filter function, etc.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 14.2 KB
Line 
1<%-- $Id: index.jsp 2993 2006-12-01 14:34:35Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Nicklas Nordborg
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  This file is part of BASE.
9
10  BASE is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 2
13  of the License, or (at your option) any later version.
14
15  BASE is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330,
23  Boston, MA  02111-1307, USA.
24  ------------------------------------------------------------------
25
26  @author Nicklas
27  @version 2.0
28--%>
29<%@ page session="false"
30  import="net.sf.basedb.core.SessionControl"
31  import="net.sf.basedb.core.DbControl"
32  import="net.sf.basedb.core.Item"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.Experiment"
35  import="net.sf.basedb.core.BioAssaySet"
36  import="net.sf.basedb.core.Job"
37  import="net.sf.basedb.core.RawBioAssay"
38  import="net.sf.basedb.core.StringParameterType"
39  import="net.sf.basedb.core.IntegerParameterType"
40  import="net.sf.basedb.core.ItemParameterType"
41  import="net.sf.basedb.core.User"
42  import="net.sf.basedb.core.Path"
43  import="net.sf.basedb.core.ItemQuery"
44  import="net.sf.basedb.core.ItemResultIterator"
45  import="net.sf.basedb.core.Permission"
46  import="net.sf.basedb.core.PluginDefinition"
47  import="net.sf.basedb.core.ItemContext"
48  import="net.sf.basedb.core.MultiPermissions"
49  import="net.sf.basedb.core.PermissionDeniedException"
50  import="net.sf.basedb.core.ItemAlreadyExistsException"
51  import="net.sf.basedb.core.query.Restriction"
52  import="net.sf.basedb.util.RemovableUtil"
53  import="net.sf.basedb.util.ShareableUtil"
54  import="net.sf.basedb.util.BioAssaySetUtil"
55  import="net.sf.basedb.util.DynamicFilter"
56  import="net.sf.basedb.util.IncludeExcludeFilter"
57  import="net.sf.basedb.clients.web.Base"
58  import="net.sf.basedb.clients.web.WebException"
59  import="net.sf.basedb.util.Values"
60  import="net.sf.basedb.clients.web.util.HTML"
61  import="java.util.Enumeration"
62  import="java.util.Set"
63  import="java.util.HashSet"
64  import="java.util.List"
65  import="java.util.LinkedList"
66  import="java.util.Collections"
67  import="java.util.Arrays"
68%>
69<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
70<%!
71  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,spots,reporters,date,tools");
72  private static final Item itemType = Item.BIOASSAYSET;
73 
74 
75  private void setClosed(HttpServletRequest request, ItemContext cc)
76  {
77    String closed = request.getParameter("closed");
78    if (closed != null)
79    {
80      cc.setObject("closed", new HashSet<String>(Arrays.asList(closed.split(","))));
81    }
82  }
83%>
84<%
85final int experimentId = Values.getInt(request.getParameter("experiment_id"));
86final String transformationId = request.getParameter("transformation_id");
87final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
88final String ID = sc.getId();
89final String cmd = request.getParameter("cmd");
90final String root = request.getContextPath()+"/";
91final String mode = request.getParameter("mode");
92final String callback = request.getParameter("callback");
93final String itemId = request.getParameter("item_id");
94final String listPage = "list_bioassaysets.jsp?ID="+ID+"&experiment_id="+experimentId
95  +(mode == null ? "" : "&mode="+mode)
96  +(callback == null ? "" : "&callback="+callback)
97  +(itemId == null ? "" : "&item_id="+itemId);
98final String viewPage = "view_bioassayset.jsp?ID="+ID+"&experiment_id="+experimentId;
99final String editPage = "edit_bioassayset.jsp?ID="+ID+"&experiment_id="+experimentId;
100final String viewTransformationPage = "../transformations/view_transformation.jsp?ID="+ID+
101  "&experiment_id="+experimentId;
102final String newPage = "../../../common/plugin/index.jsp?ID="+ID
103  +"&cmd=SelectPlugin&main_type=INTENSITY&item_type=BIOASSAYSET&context_type=LIST&title=Create+root+bioassay+set";
104
105if (experimentId != 0) sc.getCurrentContext(Item.EXPERIMENT).setId(experimentId);
106
107String forward = null;
108String redirect = null;
109String message = null;
110DbControl dc = null;
111
112try
113{
114  if (cmd == null || "List".equals(cmd))
115  {
116    // Display the list page without updatinging the current context
117    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
118    if (transformationId != null)
119    {
120      forward = viewTransformationPage;
121    }
122    else if (itemId != null)
123    {
124      forward = viewPage;
125    }
126    else
127    {
128      redirect = listPage;
129    }
130  }
131  else if ("UpdateContext".equals(cmd))
132  {
133    // Display the list page after updating the current context from the request parameters
134    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
135    setClosed(request, cc);
136    if (transformationId != null)
137    {
138      forward = viewTransformationPage;
139    }
140    else if (itemId != null)
141    {
142      forward = viewPage;
143    }
144    else
145    {
146      redirect = listPage;
147    }
148  }
149  else if ("LoadContext".equals(cmd))
150  {
151    // Display the list page after loading a saved context
152    int contextId = Values.getInt(request.getParameter("context"));
153    Base.loadContext(sc, contextId, defaultContext);
154    if (transformationId != null)
155    {
156      forward = viewTransformationPage;
157    }
158    else if (itemId != null)
159    {
160      forward = viewPage;
161    }
162    else
163    {
164      redirect = listPage;
165    }
166  }
167
168  else if ("ViewItem".equals(cmd))
169  {
170    // Display the view page for a single item
171    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
172    forward = viewPage;
173  }
174  else if ("EditItem".equals(cmd))
175  {
176    // Display the edit page for a single item (should be opened in a popup)
177    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
178    redirect = editPage;
179  }
180  else if ("NewItem".equals(cmd))
181  {
182    // Display the edit page for a new item (should be opened in a popup)
183    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
184    cc.setId(0);
185    redirect = newPage;
186  }
187  else if ("UpdateItem".equals(cmd))
188  {
189    // Update the properties on an item (will close the popup)
190    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
191    dc = sc.newDbControl();
192   
193    BioAssaySet bas = (BioAssaySet)cc.getObject("item");
194    if (bas != null)
195    {
196      dc.reattachItem(bas);
197      message = "Bioassay set updated";
198      bas.setName(Values.getStringOrNull(request.getParameter("name")));
199      bas.setDescription(Values.getStringOrNull(request.getParameter("description")));
200
201      // Annotations tab
202      Base.updateAnnotations(dc, bas, bas, request);
203    }
204    dc.commit();
205    cc.removeObject("item");
206  }
207  else if ("DeleteItem".equals(cmd))
208  {
209    // Delete a single item and then return to the view page
210    dc = sc.newDbControl();
211    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
212    RemovableUtil.removeRecursively(dc, itemType, Collections.singleton(cc.getId()), true);
213    dc.commit();
214    redirect = viewPage;
215  }
216  else if ("DeleteItems".equals(cmd))
217  {
218    // Delete all selected items on the list page
219    dc = sc.newDbControl();
220    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
221    ItemContext tc = sc.getCurrentContext(Item.TRANSFORMATION);
222    ItemContext xc = sc.getCurrentContext(Item.EXTRAVALUE);
223    setClosed(request, cc);
224
225    int numTotal = cc.getSelected().size()+tc.getSelected().size();
226    int numRemoved = 0;
227    int[] numTransformationRemoved = RemovableUtil.removeRecursively(dc, Item.TRANSFORMATION, tc.getSelected(), true);
228    int[] numBioAssaySetRemoved = RemovableUtil.removeRecursively(dc, itemType, cc.getSelected(), true);
229    int numXV = RemovableUtil.delete(dc, Item.EXTRAVALUE, xc.getSelected());
230    numTotal += numTransformationRemoved[1] + numBioAssaySetRemoved[1];
231    numRemoved += numTransformationRemoved[0] + numBioAssaySetRemoved[0];
232
233    dc.commit();
234    if (numTotal != numRemoved)
235    {
236      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
237    }
238    if (transformationId != null)
239    {
240      forward = viewTransformationPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
241    }
242    else if (itemId != null)
243    {
244      forward = viewPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
245    }
246    else
247    {
248      redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
249    }
250  }
251  else if ("RestoreItem".equals(cmd))
252  {
253    // Restore a single item and then return to the view page
254    dc = sc.newDbControl();
255    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
256    RemovableUtil.removeRecursively(dc, itemType, Collections.singleton(cc.getId()), false);
257    dc.commit();
258    redirect = viewPage;
259  }
260  else if ("RestoreItems".equals(cmd))
261  {
262    // Restore all selected items on the list page
263    dc = sc.newDbControl();
264    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
265    ItemContext tc = sc.getCurrentContext(Item.TRANSFORMATION);
266    setClosed(request, cc);
267
268    int numTotal = cc.getSelected().size()+tc.getSelected().size();
269    int numRemoved = 0;
270    int[] numTransformationRemoved = RemovableUtil.removeRecursively(dc, Item.TRANSFORMATION, tc.getSelected(), false);
271    int[] numBioAssaySetRemoved = RemovableUtil.removeRecursively(dc, itemType, cc.getSelected(), false);
272    numTotal += numTransformationRemoved[1] + numBioAssaySetRemoved[1];
273    numRemoved += numTransformationRemoved[0] + numBioAssaySetRemoved[0];
274   
275    dc.commit();
276    if (numTotal != numRemoved)
277    {
278      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
279    }
280    if (transformationId != null)
281    {
282      forward = viewTransformationPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
283    }
284    else if (itemId != null)
285    {
286      forward = viewPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
287    }
288    else
289    {
290      redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
291    }
292  }
293  else if ("ExportItems".equals(cmd))
294  {
295    // Run an export plugin in a list context
296    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
297    setClosed(request, cc);
298    dc = sc.newDbControl();
299    final Experiment experiment = Experiment.getById(dc, experimentId);
300    dc.close();
301    final ItemQuery<BioAssaySet> query = experiment.getBioAssaySets();
302    cc.configureQuery(query, true);
303    cc.setQuery(query);
304    redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+bioassay+sets";
305  }
306  else if ("ExportItem".equals(cmd))
307  {
308    // Run an export plugin in single-item context
309    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
310    redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+bioassay+set";
311  }
312  else if ("ImportItems".equals(cmd))
313  {
314    // Run an import plugin in a list context
315    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
316    setClosed(request, cc);
317    dc = sc.newDbControl();
318    final Experiment experiment = Experiment.getById(dc, experimentId);
319    dc.close();
320    final ItemQuery<BioAssaySet> query = experiment.getBioAssaySets();
321    cc.configureQuery(query, true);
322    cc.setQuery(query);
323    redirect = "../../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+bioassay+sets";
324  }
325  else if ("ImportItem".equals(cmd))
326  {
327    // Run an import plugin in single-item context
328    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
329    redirect = "../../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+bioassay+set";
330  }
331  else if ("RunListPlugin".equals(cmd))
332  {
333    // Run another plugin in a list context
334    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
335    setClosed(request, cc);
336    dc = sc.newDbControl();
337    final Experiment experiment = Experiment.getById(dc, experimentId);
338    dc.close();
339    final ItemQuery<BioAssaySet> query = experiment.getBioAssaySets();
340    cc.configureQuery(query, true);
341    cc.setQuery(query);
342    redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
343  }
344  else if ("RunPlugin".equals(cmd))
345  {
346    // Run a plugin in single-item context
347    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
348    redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
349  }
350  else if ("RunAnalysisPlugin".equals(cmd))
351  {
352    // Run an analysis plugin in single-item context
353    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
354    redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=ANALYZE&title=Run+analysis+plugin";
355  }
356  else if ("NewFilteredBioAssaySet".equals(cmd))
357  {
358    // Display the edit page for for filtering a bioassay set (should be opened in a popup)
359    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
360    redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=NewJob&item_type="+itemType.name()+"&context_type=ITEM&main_type=ANALYZE&title=Filter+bioassay+set&plugin_class=net.sf.basedb.plugins.FormulaFilter";
361  }
362  else
363  {
364    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
365  }
366}
367finally
368{
369  if (dc != null) dc.close();
370}
371
372if (forward != null)
373{
374  pageContext.forward(forward);
375}
376else if (redirect != null)
377{
378  response.sendRedirect(redirect);
379}
380else if (message == null)
381{
382  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
383}
384else
385{
386  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
387}
388%>
389
Note: See TracBrowser for help on using the repository browser.