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

Last change on this file since 5590 was 5590, checked in by Nicklas Nordborg, 12 years ago

References #1589: Delete deprecated classes and methods

Removed deprecated methods and classes from the core API.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 17.3 KB
Line 
1<%-- $Id: index.jsp 5590 2011-03-16 11:48:47Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, 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 pageEncoding="UTF-8" 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.core.SimpleProgressReporter"
47  import="net.sf.basedb.core.snapshot.SnapshotManager"
48  import="net.sf.basedb.util.RemovableUtil"
49  import="net.sf.basedb.util.ShareableUtil"
50  import="net.sf.basedb.util.OwnableUtil"
51  import="net.sf.basedb.clients.web.Base"
52  import="net.sf.basedb.clients.web.WebException"
53  import="net.sf.basedb.util.Values"
54  import="net.sf.basedb.clients.web.util.HTML"
55  import="net.sf.basedb.util.formatter.Formatter"
56  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
57  import="net.sf.basedb.core.plugin.GuiContext"
58  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
59  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
60  import="net.sf.basedb.clients.web.extensions.JspContext"
61  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
62  import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer"
63  import="java.util.Enumeration"
64  import="java.util.Set"
65  import="java.util.HashSet"
66  import="java.util.List"
67  import="java.util.ArrayList"
68  import="java.util.Collections"
69  import="java.util.Date"
70%>
71<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
72<%!
73  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,rawDataType,description,actions");
74  private static final Item itemType = Item.EXPERIMENT;
75%>
76<%
77final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
78final String ID = sc.getId();
79final String cmd = request.getParameter("cmd");
80final String root = request.getContextPath()+"/";
81final String mode = request.getParameter("mode");
82final String callback = request.getParameter("callback");
83final String itemId = request.getParameter("item_id");
84final String listPage = "list_experiments.jsp?ID="+ID
85  +(mode == null ? "" : "&mode="+mode)
86  +(callback == null ? "" : "&callback="+callback)
87  +(itemId == null ? "" : "&item_id="+itemId);
88final String viewPage = "view_experiment.jsp?ID="+ID;
89final String editPage = "edit_experiment.jsp?ID="+ID;
90
91String forward = null;
92String redirect = null;
93String message = null;
94DbControl dc = null;
95try
96{
97  if (cmd == null || "List".equals(cmd))
98  {
99    // Display the list page without updatinging the current context
100    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
101    redirect = listPage;
102  }
103  else if ("UpdateContext".equals(cmd))
104  {
105    // Display the list page after updating the current context from the request parameters
106    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
107    redirect = listPage;
108  }
109  else if ("LoadContext".equals(cmd))
110  {
111    // Display the list page after loading a saved context
112    int contextId = Values.getInt(request.getParameter("context"));
113    Base.loadContext(sc, contextId, defaultContext);
114    redirect = listPage;
115  }
116
117  else if ("ViewItem".equals(cmd))
118  {
119    // Display the view page for a single item
120    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
121    forward = viewPage;
122  }
123  else if ("EditItem".equals(cmd))
124  {
125    // Display the edit page for a single item (should be opened in a popup)
126    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
127    redirect = editPage;
128  }
129  else if ("NewItem".equals(cmd))
130  {
131    // Display the edit page for a new item (should be opened in a popup)
132    if (!sc.hasPermission(Permission.CREATE, itemType))
133    {
134      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
135    }
136    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
137    cc.setId(0);
138    forward = editPage;
139  }
140  else if ("UpdateItem".equals(cmd))
141  {
142    // Update the properties on an item (will close the popup)
143    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
144    final int maxRecent = Base.getMaxRecent(sc);
145    dc = sc.newDbControl();
146   
147    Experiment experiment = (Experiment)cc.getObject("item");
148    if (experiment == null)
149    {
150      RawDataType rdt = RawDataTypes.getRawDataType(Values.getStringOrNull(request.getParameter("rawdatatype")));
151      if (rdt != null) cc.setRecent("RawDataType", rdt.getId(), maxRecent);
152      experiment = Experiment.getNew(dc, rdt);
153      message = "Experiment created";
154      dc.saveItem(experiment);
155    }
156    else
157    {
158      dc.reattachItem(experiment, false);
159      message = "Experiment updated";
160    }
161
162    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.EXPERIMENT), experiment);
163    ExtensionsInvoker invoker = EditUtil.useOnSaveExtensions(jspContext);
164    try
165    {
166      Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
167      experiment.setName(Values.getStringOrNull(request.getParameter("name")));
168      experiment.setTitle(Values.getStringOrNull(request.getParameter("title")));
169      experiment.setAbstract(Values.getStringOrNull(request.getParameter("abstract")));
170      experiment.setAffiliations(Values.getStringOrNull(request.getParameter("affiliations")));
171      experiment.setAuthors(Values.getStringOrNull(request.getParameter("authors")));
172      experiment.setExperimentDesign(Values.getStringOrNull(request.getParameter("experimentDesign")));
173      experiment.setExperimentType(Values.getStringOrNull(request.getParameter("experimentType")));
174      experiment.setPublication(Values.getStringOrNull(request.getParameter("publication")));
175      experiment.setPublicationDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("publicationDate"))));
176      experiment.setPubMedId(Values.getStringOrNull(request.getParameter("pubMedId")));
177      experiment.setDescription(Values.getStringOrNull(request.getParameter("description")));
178 
179      int directoryId = Values.getInt(request.getParameter("directory_id"), -1);
180      if (directoryId >= 0) // < 0 = denied or unchanged
181      {
182        Directory dir = directoryId == 0 ? null : Directory.getById(dc, directoryId);
183        experiment.setDirectory(dir);
184        if (dir != null) cc.setRecent(dir, maxRecent);
185      }
186 
187      String[] removeRawBioAssays = Values.getString(request.getParameter("removedRawBioAssays")).split(",");
188      for (int i = 0; i < removeRawBioAssays.length; ++i)
189      {
190        int rawBioAssayId = Values.getInt(removeRawBioAssays[i], -1);
191        if (rawBioAssayId != -1) experiment.removeRawBioAssay(RawBioAssay.getById(dc, rawBioAssayId));
192      }
193     
194      String[] addRawBioAssays = Values.getString(request.getParameter("addedRawBioAssays")).split(",");
195      for (int i = 0; i < addRawBioAssays.length; ++i)
196      {
197        int rawBioAssayId = Values.getInt(addRawBioAssays[i], -1);
198        if (rawBioAssayId != -1) experiment.addRawBioAssay(RawBioAssay.getById(dc, rawBioAssayId));
199      }
200     
201      String[] removeAnnotationTypes = Values.getString(request.getParameter("removedAnnotationTypes")).split(",");
202      for (int i = 0; i < removeAnnotationTypes.length; ++i)
203      {
204        int annotationTypeId = Values.getInt(removeAnnotationTypes[i], -1);
205        if (annotationTypeId != -1) experiment.removeExperimentalFactor(AnnotationType.getById(dc, annotationTypeId));
206      }
207     
208      String[] addAnnotationTypes = Values.getString(request.getParameter("addedAnnotationTypes")).split(",");
209      for (int i = 0; i < addAnnotationTypes.length; ++i)
210      {
211        int annotationTypeId = Values.getInt(addAnnotationTypes[i], -1);
212        if (annotationTypeId != -1) experiment.addExperimentalFactor(AnnotationType.getById(dc, annotationTypeId));
213      }
214     
215      // OnSave extensions
216      invoker.render(OnSaveRenderer.ON_SAVE);
217      dc.commit();
218      invoker.render(OnSaveRenderer.ON_COMMIT);
219    }
220    catch (Exception ex)
221    {
222      invoker.render(OnSaveRenderer.onRollback(ex));
223      throw ex;
224    }
225    finally
226    {
227      cc.removeObject("item");
228    }
229  }
230  else if ("DeleteItem".equals(cmd))
231  {
232    // Delete a single item and then return to the view page
233    dc = sc.newDbControl();
234    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
235    RemovableUtil.removeRecursively(dc, itemType, Collections.singleton(cc.getId()), true);
236    dc.commit();
237    redirect = viewPage;
238  }
239  else if ("DeleteItems".equals(cmd))
240  {
241    // Delete all selected items on the list page
242    dc = sc.newDbControl();
243    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
244    int numTotal = cc.getSelected().size();
245    int[] numRemoved = RemovableUtil.removeRecursively(dc, itemType, cc.getSelected(), true);
246    numTotal += numRemoved[1];
247    dc.commit();
248    if (numTotal != numRemoved[0])
249    {
250      message = (numRemoved[0] == 0 ? "No" : "Only "+numRemoved[0]+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
251    }
252    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
253  }
254  else if ("RestoreItem".equals(cmd))
255  {
256    // Restore a single item and then return to the view page
257    dc = sc.newDbControl();
258    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
259    RemovableUtil.removeRecursively(dc, itemType, Collections.singleton(cc.getId()), false);
260    dc.commit();
261    redirect = viewPage;
262  }
263  else if ("RestoreItems".equals(cmd))
264  {
265    // Restore all selected items on the list page
266    dc = sc.newDbControl();
267    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
268    int numTotal = cc.getSelected().size();
269    int[] numRemoved = RemovableUtil.removeRecursively(dc, itemType, cc.getSelected(), false);
270    numTotal += numRemoved[1];
271    dc.commit();
272    if (numTotal != numRemoved[0])
273    {
274      message = (numRemoved[0] == 0 ? "No" : "Only "+numRemoved[0]+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
275    }
276    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
277  }
278  else if ("ShareItem".equals(cmd))
279  {
280    // Display a popup window for sharing a single item
281    dc = sc.newDbControl();
282    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
283    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
284    dc.close();
285    cc.setObject("MultiPermissions", permissions);
286    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
287  }
288  else if ("ShareItems".equals(cmd))
289  {
290    // Display a popup window for sharing all selected items on the list page
291    dc = sc.newDbControl();
292    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
293    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
294    dc.close();
295    cc.setObject("MultiPermissions", permissions);
296    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
297  }
298  else if ("SetOwnerOfItem".equals(cmd))
299  {
300    // Change owner of items selected on a list page
301    dc = sc.newDbControl();
302    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
303    OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId());
304    cc.setObject("OwnedItems", Collections.singleton(item));
305    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
306  }
307  else if ("SetOwnerOfItems".equals(cmd))
308  {
309    // Change owner of items selected on a list page
310    dc = sc.newDbControl();
311    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
312    Set<OwnedItem> items = new HashSet<OwnedItem>();
313    for (Integer id : cc.getSelected())
314    {
315      if (id != null) items.add((OwnedItem)itemType.getById(dc, id));
316    }
317    dc.close();
318    cc.setObject("OwnedItems", items);
319    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
320  }
321  else if ("ExportItems".equals(cmd))
322  {
323    // Run an export plugin in a list context
324    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
325    final ItemQuery<Experiment> query = Experiment.getQuery();
326    dc = sc.newDbControl();
327    cc.configureQuery(dc, query, true);
328    dc.close();
329    cc.setQuery(query);
330    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+experiments";
331  }
332  else if ("ExportItem".equals(cmd))
333  {
334    // Run an export plugin in single-item context
335    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
336    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+experiment";
337  }
338  else if ("ImportItems".equals(cmd))
339  {
340    // Run an import plugin in a list context
341    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
342    final ItemQuery<Experiment> query = Experiment.getQuery();
343    dc = sc.newDbControl();
344    cc.configureQuery(dc, query, true);
345    dc.close();
346    cc.setQuery(query);
347    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+experiments";
348  }
349  else if ("ImportItem".equals(cmd))
350  {
351    // Run an import plugin in single-item context
352    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
353    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+experiment";
354  }
355  else if ("RunListPlugin".equals(cmd))
356  {
357    // Run another plugin in a list context
358    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
359    final ItemQuery<Experiment> query = Experiment.getQuery();
360    dc = sc.newDbControl();
361    cc.configureQuery(dc, query, true);
362    dc.close();
363    cc.setQuery(query);
364    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
365  }
366  else if ("RunPlugin".equals(cmd))
367  {
368    // Run another plugin in single-item context
369    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
370    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
371  }
372  else if ("AutoInherit".equals(cmd))
373  {
374    Integer[] annotationTypeIds = Values.getInt(request.getParameterValues("autoinherit"));
375    int numInherited = 0;
376    int numRawBioAssays = 0;
377    if (annotationTypeIds.length > 0)
378    {
379      dc = sc.newDbControl();
380      SimpleProgressReporter progress = new SimpleProgressReporter(null);
381      sc.setSessionSetting("progress.autoinherit", progress);
382      Experiment exp = Experiment.getById(dc, Values.getInt(itemId));
383      List<AnnotationType> annotationTypes = new ArrayList<AnnotationType>(annotationTypeIds.length);
384      for (int atId : annotationTypeIds)
385      {
386        annotationTypes.add(AnnotationType.getById(dc, atId));
387      }
388      ItemQuery<RawBioAssay> query = exp.getRawBioAssays();
389      query.include(Include.ALL);
390      query.setItemPermission(Permission.WRITE);
391      SnapshotManager manager = new SnapshotManager();
392      List<RawBioAssay> all = query.list(dc);
393      int total = all.size();
394      int done = 0;
395      for (RawBioAssay rba : all)
396      {
397        progress.display(10+(90 * done) / total, "Processing <i>" + rba.getName() + "</i>...");
398        ++done;
399        int inherited = rba.getAnnotationSet().autoInherit(dc, annotationTypes, manager, false);
400        numInherited += inherited;
401        if (inherited > 0) numRawBioAssays++;
402      }
403      message = numInherited + " annotation(s) inherited by " + numRawBioAssays + " raw bioassay(s)";
404      progress.display(100, message);
405      dc.commit();
406    }
407    redirect = viewPage;
408  }
409  else
410  {
411    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
412  }
413}
414finally
415{
416  if (dc != null) dc.close();
417}
418
419if (forward != null)
420{
421  pageContext.forward(forward);
422}
423else if (redirect != null)
424{
425  response.sendRedirect(redirect);
426}
427else if (message == null)
428{
429  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
430}
431else
432{
433  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
434}
435%>
436
Note: See TracBrowser for help on using the repository browser.