source: trunk/www/views/experiments/index.jsp @ 4619

Last change on this file since 4619 was 4619, checked in by Nicklas Nordborg, 13 years ago

References #1129: Filtering of child/parent items in table listing

Remove debug code belonging to #1145 (Raw data batch import) that was checked in by accident in [4613].

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 14.9 KB
Line 
1<%-- $Id: index.jsp 4619 2008-10-30 13:35:53Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Hakkinen, Nicklas Nordborg, Martin Svensson
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.Experiment"
32  import="net.sf.basedb.core.RawBioAssay"
33  import="net.sf.basedb.core.AnnotationType"
34  import="net.sf.basedb.core.RawDataType"
35  import="net.sf.basedb.core.RawDataTypes"
36  import="net.sf.basedb.core.User"
37  import="net.sf.basedb.core.Directory"
38  import="net.sf.basedb.core.ItemQuery"
39  import="net.sf.basedb.core.ItemResultIterator"
40  import="net.sf.basedb.core.Permission"
41  import="net.sf.basedb.core.ItemContext"
42  import="net.sf.basedb.core.MultiPermissions"
43  import="net.sf.basedb.core.OwnedItem"
44  import="net.sf.basedb.core.PermissionDeniedException"
45  import="net.sf.basedb.core.ItemAlreadyExistsException"
46  import="net.sf.basedb.util.RemovableUtil"
47  import="net.sf.basedb.util.ShareableUtil"
48  import="net.sf.basedb.util.OwnableUtil"
49  import="net.sf.basedb.clients.web.Base"
50  import="net.sf.basedb.clients.web.WebException"
51  import="net.sf.basedb.util.Values"
52  import="net.sf.basedb.clients.web.util.HTML"
53  import="net.sf.basedb.util.formatter.Formatter"
54  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
55  import="java.util.Enumeration"
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  import="java.util.Date"
62%>
63<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
64<%!
65  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,rawDataType,description,actions");
66  private static final Item itemType = Item.EXPERIMENT;
67%>
68<%
69final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
70final String ID = sc.getId();
71final String cmd = request.getParameter("cmd");
72final String root = request.getContextPath()+"/";
73final String mode = request.getParameter("mode");
74final String callback = request.getParameter("callback");
75final String itemId = request.getParameter("item_id");
76final String listPage = "list_experiments.jsp?ID="+ID
77  +(mode == null ? "" : "&mode="+mode)
78  +(callback == null ? "" : "&callback="+callback)
79  +(itemId == null ? "" : "&item_id="+itemId);
80final String viewPage = "view_experiment.jsp?ID="+ID;
81final String editPage = "edit_experiment.jsp?ID="+ID;
82
83String forward = null;
84String redirect = null;
85String message = null;
86DbControl dc = null;
87
88try
89{
90  if (cmd == null || "List".equals(cmd))
91  {
92    // Display the list page without updatinging the current context
93    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
94    redirect = listPage;
95  }
96  else if ("UpdateContext".equals(cmd))
97  {
98    // Display the list page after updating the current context from the request parameters
99    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
100    redirect = listPage;
101  }
102  else if ("LoadContext".equals(cmd))
103  {
104    // Display the list page after loading a saved context
105    int contextId = Values.getInt(request.getParameter("context"));
106    Base.loadContext(sc, contextId, defaultContext);
107    redirect = listPage;
108  }
109
110  else if ("ViewItem".equals(cmd))
111  {
112    // Display the view page for a single item
113    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
114    forward = viewPage;
115  }
116  else if ("EditItem".equals(cmd))
117  {
118    // Display the edit page for a single item (should be opened in a popup)
119    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
120    redirect = editPage;
121  }
122  else if ("NewItem".equals(cmd))
123  {
124    // Display the edit page for a new item (should be opened in a popup)
125    if (!sc.hasPermission(Permission.CREATE, itemType))
126    {
127      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
128    }
129    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
130    cc.setId(0);
131    forward = editPage;
132  }
133  else if ("UpdateItem".equals(cmd))
134  {
135    // Update the properties on an item (will close the popup)
136    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
137    final int maxRecent = Base.getMaxRecent(sc);
138    dc = sc.newDbControl();
139   
140    Experiment experiment = (Experiment)cc.getObject("item");
141    if (experiment == null)
142    {
143      RawDataType rdt = RawDataTypes.getRawDataType(Values.getStringOrNull(request.getParameter("rawdatatype")));
144      if (rdt != null) cc.setRecent("RawDataType", rdt.getId(), maxRecent);
145      experiment = Experiment.getNew(dc, rdt);
146      message = "Experiment created";
147      dc.saveItem(experiment);
148    }
149    else
150    {
151      dc.reattachItem(experiment);
152      message = "Experiment updated";
153    }
154
155    Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
156    experiment.setName(Values.getStringOrNull(request.getParameter("name")));
157    experiment.setTitle(Values.getStringOrNull(request.getParameter("title")));
158    experiment.setAbstract(Values.getStringOrNull(request.getParameter("abstract")));
159    experiment.setAffiliations(Values.getStringOrNull(request.getParameter("affiliations")));
160    experiment.setAuthors(Values.getStringOrNull(request.getParameter("authors")));
161    experiment.setExperimentDesign(Values.getStringOrNull(request.getParameter("experimentDesign")));
162    experiment.setExperimentType(Values.getStringOrNull(request.getParameter("experimentType")));
163    experiment.setPublication(Values.getStringOrNull(request.getParameter("publication")));
164    experiment.setPublicationDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("publicationDate"))));
165    experiment.setPubMedId(Values.getStringOrNull(request.getParameter("pubMedId")));
166    experiment.setDescription(Values.getStringOrNull(request.getParameter("description")));
167
168    int directoryId = Values.getInt(request.getParameter("directory_id"), -1);
169    if (directoryId >= 0) // < 0 = denied or unchanged
170    {
171      Directory dir = directoryId == 0 ? null : Directory.getById(dc, directoryId);
172      experiment.setDirectory(dir);
173      if (dir != null) cc.setRecent(dir, maxRecent);
174    }
175
176    String[] removeRawBioAssays = Values.getString(request.getParameter("removedRawBioAssays")).split(",");
177    for (int i = 0; i < removeRawBioAssays.length; ++i)
178    {
179      int rawBioAssayId = Values.getInt(removeRawBioAssays[i], -1);
180      if (rawBioAssayId != -1) experiment.removeRawBioAssay(RawBioAssay.getById(dc, rawBioAssayId));
181    }
182   
183    String[] addRawBioAssays = Values.getString(request.getParameter("addedRawBioAssays")).split(",");
184    for (int i = 0; i < addRawBioAssays.length; ++i)
185    {
186      int rawBioAssayId = Values.getInt(addRawBioAssays[i], -1);
187      if (rawBioAssayId != -1) experiment.addRawBioAssay(RawBioAssay.getById(dc, rawBioAssayId));
188    }
189   
190    String[] removeAnnotationTypes = Values.getString(request.getParameter("removedAnnotationTypes")).split(",");
191    for (int i = 0; i < removeAnnotationTypes.length; ++i)
192    {
193      int annotationTypeId = Values.getInt(removeAnnotationTypes[i], -1);
194      if (annotationTypeId != -1) experiment.removeExperimentalFactor(AnnotationType.getById(dc, annotationTypeId));
195    }
196   
197    String[] addAnnotationTypes = Values.getString(request.getParameter("addedAnnotationTypes")).split(",");
198    for (int i = 0; i < addAnnotationTypes.length; ++i)
199    {
200      int annotationTypeId = Values.getInt(addAnnotationTypes[i], -1);
201      if (annotationTypeId != -1) experiment.addExperimentalFactor(AnnotationType.getById(dc, annotationTypeId));
202    }
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    int numTotal = cc.getSelected().size();
222    int[] numRemoved = RemovableUtil.removeRecursively(dc, itemType, cc.getSelected(), true);
223    numTotal += numRemoved[1];
224    dc.commit();
225    if (numTotal != numRemoved[0])
226    {
227      message = (numRemoved[0] == 0 ? "No" : "Only "+numRemoved[0]+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
228    }
229    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
230  }
231  else if ("RestoreItem".equals(cmd))
232  {
233    // Restore a single item and then return to the view page
234    dc = sc.newDbControl();
235    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
236    RemovableUtil.removeRecursively(dc, itemType, Collections.singleton(cc.getId()), false);
237    dc.commit();
238    redirect = viewPage;
239  }
240  else if ("RestoreItems".equals(cmd))
241  {
242    // Restore all selected items on the list page
243    dc = sc.newDbControl();
244    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
245    int numTotal = cc.getSelected().size();
246    int[] numRemoved = RemovableUtil.removeRecursively(dc, itemType, cc.getSelected(), false);
247    numTotal += numRemoved[1];
248    dc.commit();
249    if (numTotal != numRemoved[0])
250    {
251      message = (numRemoved[0] == 0 ? "No" : "Only "+numRemoved[0]+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
252    }
253    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
254  }
255  else if ("ShareItem".equals(cmd))
256  {
257    // Display a popup window for sharing a single item
258    dc = sc.newDbControl();
259    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
260    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
261    dc.close();
262    cc.setObject("MultiPermissions", permissions);
263    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
264  }
265  else if ("ShareItems".equals(cmd))
266  {
267    // Display a popup window for sharing all selected items on the list page
268    dc = sc.newDbControl();
269    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
270    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
271    dc.close();
272    cc.setObject("MultiPermissions", permissions);
273    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
274  }
275  else if ("SetOwnerOfItem".equals(cmd))
276  {
277    // Change owner of items selected on a list page
278    dc = sc.newDbControl();
279    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
280    OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId());
281    cc.setObject("OwnedItems", Collections.singleton(item));
282    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
283  }
284  else if ("SetOwnerOfItems".equals(cmd))
285  {
286    // Change owner of items selected on a list page
287    dc = sc.newDbControl();
288    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
289    Set<OwnedItem> items = new HashSet<OwnedItem>();
290    for (Integer id : cc.getSelected())
291    {
292      if (id != null) items.add((OwnedItem)itemType.getById(dc, id));
293    }
294    dc.close();
295    cc.setObject("OwnedItems", items);
296    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
297  }
298  else if ("ExportItems".equals(cmd))
299  {
300    // Run an export plugin in a list context
301    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
302    final ItemQuery<Experiment> query = Experiment.getQuery();
303    cc.configureQuery(query, true);
304    cc.setQuery(query);
305    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+raw+bioassays";
306  }
307  else if ("ExportItem".equals(cmd))
308  {
309    // Run an export plugin in single-item context
310    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
311    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+raw+bioassay";
312  }
313  else if ("ImportItems".equals(cmd))
314  {
315    // Run an import plugin in a list context
316    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
317    final ItemQuery<Experiment> query = Experiment.getQuery();
318    cc.configureQuery(query, true);
319    cc.setQuery(query);
320    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+raw+bioassays";
321  }
322  else if ("ImportItem".equals(cmd))
323  {
324    // Run an import plugin in single-item context
325    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
326    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+raw+bioassay";
327  }
328  else if ("RunListPlugin".equals(cmd))
329  {
330    // Run another plugin in a list context
331    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
332    final ItemQuery<Experiment> query = Experiment.getQuery();
333    cc.configureQuery(query, true);
334    cc.setQuery(query);
335    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
336  }
337  else if ("RunPlugin".equals(cmd))
338  {
339    // Run another plugin in single-item context
340    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
341    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
342  }
343  else
344  {
345    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
346  }
347}
348finally
349{
350  if (dc != null) dc.close();
351}
352
353if (forward != null)
354{
355  pageContext.forward(forward);
356}
357else if (redirect != null)
358{
359  response.sendRedirect(redirect);
360}
361else if (message == null)
362{
363  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
364}
365else
366{
367  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
368}
369%>
370
Note: See TracBrowser for help on using the repository browser.