source: trunk/www/views/derivedbioassays/index.jsp @ 5685

Last change on this file since 5685 was 5685, checked in by Nicklas Nordborg, 11 years ago

References #1153: Handling short read transcript sequence data

Simplified the design by only keeping DerivedBioAssay between PhysicalBioAssay and RawBioAssay. This should make batch importer, validation, etc. easier to implement and also provides the better backwards compatibility with array experiments. The web gui is usable but may need improvements in some cases.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 16.9 KB
Line 
1<%-- $Id $
2  ------------------------------------------------------------------
3  Copyright (C) 2011 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 3
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 BASE. If not, see <http://www.gnu.org/licenses/>.
22  ------------------------------------------------------------------
23
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.DerivedBioAssay"
29  import="net.sf.basedb.core.PhysicalBioAssay"
30  import="net.sf.basedb.core.RawBioAssay"
31  import="net.sf.basedb.core.ItemSubtype"
32  import="net.sf.basedb.core.Extract"
33  import="net.sf.basedb.core.Protocol"
34  import="net.sf.basedb.core.Software"
35  import="net.sf.basedb.core.Hardware"
36  import="net.sf.basedb.core.Item"
37  import="net.sf.basedb.core.Include"
38  import="net.sf.basedb.core.User"
39  import="net.sf.basedb.core.OwnedItem"
40  import="net.sf.basedb.core.ItemQuery"
41  import="net.sf.basedb.core.ItemResultIterator"
42  import="net.sf.basedb.core.Permission"
43  import="net.sf.basedb.core.PluginDefinition"
44  import="net.sf.basedb.core.ItemContext"
45  import="net.sf.basedb.core.MultiPermissions"
46  import="net.sf.basedb.core.PermissionDeniedException"
47  import="net.sf.basedb.core.ItemAlreadyExistsException"
48  import="net.sf.basedb.core.query.Hql"
49  import="net.sf.basedb.core.query.Orders"
50  import="net.sf.basedb.core.query.Restrictions"
51  import="net.sf.basedb.core.query.Expressions"
52  import="net.sf.basedb.util.RemovableUtil"
53  import="net.sf.basedb.util.ShareableUtil"
54  import="net.sf.basedb.util.IncludeExcludeFilter"
55  import="net.sf.basedb.clients.web.Base"
56  import="net.sf.basedb.clients.web.WebException"
57  import="net.sf.basedb.util.Values"
58  import="net.sf.basedb.clients.web.util.HTML"
59  import="net.sf.basedb.core.plugin.GuiContext"
60  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
61  import="net.sf.basedb.util.formatter.NameableFormatter"
62  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
63  import="net.sf.basedb.clients.web.extensions.JspContext"
64  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
65  import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer"
66  import="net.sf.basedb.clients.web.plugins.ItemQueryLoader"
67  import="java.util.Enumeration"
68  import="java.util.Set"
69  import="java.util.HashSet"
70  import="java.util.List"
71  import="java.util.LinkedList"
72  import="java.util.Collections"
73  import="java.util.Arrays"
74%>
75<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
76<%!
77  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,itemSubtype,physicalBioAssay,extract,parent,description");
78  private static final Item itemType = Item.DERIVEDBIOASSAY;
79 
80  private static void registerExportUtils(ItemContext cc)
81  {
82    // Register formatters
83    cc.setObject("export.formatter.&children(name)", new NameableFormatter());
84    cc.setObject("export.formatter.&rawBioAssays(name)", new NameableFormatter());
85   
86    // Register dataloaders
87    String bioassayParameter = "bioassay";
88    // Child bioassays
89    ItemQuery<DerivedBioAssay> dbasQuery = DerivedBioAssay.getQuery();
90    dbasQuery.include(cc.getInclude());
91    dbasQuery.restrict(Restrictions.eq(Hql.property("parent"), Expressions.parameter(bioassayParameter)));
92    dbasQuery.order(Orders.asc(Hql.property("name")));
93    cc.setObject("export.dataloader.&children(name)", new ItemQueryLoader(dbasQuery, bioassayParameter));
94   
95    // Child raw bioassays
96    ItemQuery<RawBioAssay> rawQuery = RawBioAssay.getQuery();
97    rawQuery.include(cc.getInclude());
98    rawQuery.restrict(Restrictions.eq(Hql.property("parentBioAssay"), Expressions.parameter(bioassayParameter)));
99    rawQuery.order(Orders.asc(Hql.property("name")));
100    cc.setObject("export.dataloader.&rawBioAssays(name)", new ItemQueryLoader(rawQuery, bioassayParameter));
101
102  }
103
104%>
105<%
106final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
107final String ID = sc.getId();
108final String cmd = request.getParameter("cmd");
109final String root = request.getContextPath()+"/";
110final String mode = request.getParameter("mode");
111final String callback = request.getParameter("callback");
112final String itemId = request.getParameter("item_id");
113final String listPage = "list_bioassays.jsp?ID="+ID+"&item_id="+itemId
114  +(mode == null ? "" : "&mode="+mode)
115  +(callback == null ? "" : "&callback="+callback)
116  +(itemId == null ? "" : "&item_id="+itemId);
117final String viewPage = "view_bioassay.jsp?ID="+ID;
118final String editPage = "edit_bioassay.jsp?ID="+ID;
119
120String forward = null;
121String redirect = null;
122String message = null;
123DbControl dc = null;
124
125try
126{
127  if (cmd == null || "List".equals(cmd))
128  {
129    // Display the list page without updatinging the current context
130    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
131    redirect = listPage;
132  }
133  else if ("UpdateContext".equals(cmd))
134  {
135    // Display the list page after updating the current context from the request parameters
136    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
137    redirect = listPage;
138  }
139  else if ("LoadContext".equals(cmd))
140  {
141    // Display the list page after loading a saved context
142    int contextId = Values.getInt(request.getParameter("context"));
143    Base.loadContext(sc, contextId, defaultContext);
144    redirect = listPage;
145  }
146  else if ("ViewItem".equals(cmd))
147  {
148    // Display the view page for a single item
149    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
150    forward = viewPage;
151  }
152  else if ("EditItem".equals(cmd))
153  {
154    // Display the edit page for a single item (should be opened in a popup)
155    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
156    redirect = editPage;
157  }
158  else if ("NewItem".equals(cmd))
159  {
160    // Display the edit page for a new item (should be opened in a popup)
161    if (!sc.hasPermission(Permission.CREATE, itemType))
162    {
163      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
164    }
165    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
166    cc.setId(0);
167    forward = editPage;
168  }
169  else if ("UpdateItem".equals(cmd))
170  {
171    // Update the properties on an item (will close the popup)
172    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
173    final int maxRecent = Base.getMaxRecent(sc);
174    dc = sc.newDbControl();
175   
176    DerivedBioAssay bas = (DerivedBioAssay)cc.getObject("item");
177    if (bas == null)
178    {
179      int parentId = Values.getInt(request.getParameter("parent_id"));
180      int physicalBioAssayId = Values.getInt(request.getParameter("physicalbioassay_id"));
181      if (parentId == 0)
182      {
183        PhysicalBioAssay bioAssay = PhysicalBioAssay.getById(dc, physicalBioAssayId);
184        bas = DerivedBioAssay.getNew(dc, bioAssay);
185        cc.setRecent(bioAssay, maxRecent);
186      }
187      else
188      {
189        DerivedBioAssay parent = DerivedBioAssay.getById(dc, parentId);
190        bas = DerivedBioAssay.getNew(dc, parent);
191        cc.setRecent(parent, maxRecent);
192      }
193      dc.saveItem(bas);
194      message = "Derived bioassay created";
195    }
196    else
197    {
198      dc.reattachItem(bas, false);
199      message = "Derived bioassay updated";
200    }
201
202    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), bas);
203    ExtensionsInvoker invoker = EditUtil.useOnSaveExtensions(jspContext);
204    try
205    {
206      bas.setName(Values.getStringOrNull(request.getParameter("name")));
207      bas.setDescription(Values.getStringOrNull(request.getParameter("description")));
208 
209      int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1);
210      if (subtypeId >= 0) // < 0 = denied or unchanged
211      {
212        ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);
213        bas.setItemSubtype(subtype);
214        if (subtype != null) cc.setRecent(subtype, maxRecent);
215      }
216     
217      int extractId = Values.getInt(request.getParameter("extract_id"), -1);
218      if (extractId >= 0) // < 0 = denied or unchanged
219      {
220        Extract extract = extractId == 0 ? null : Extract.getById(dc, extractId);
221        bas.setExtract(extract);
222      }
223
224      int protocolId = Values.getInt(request.getParameter("protocol_id"), -1);
225      if (protocolId >= 0) // < 0 = denied or unchanged
226      {
227        Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId);
228        bas.setProtocol(pt);
229        if (pt != null) cc.setRecent(pt, maxRecent);
230      }
231     
232      int hardwareId = Values.getInt(request.getParameter("hardware_id"), -1);
233      if (hardwareId >= 0) // < 0 denied or unchanged
234      {
235        Hardware hw = hardwareId == 0 ? null : Hardware.getById(dc, hardwareId);
236        bas.setHardware(hw);
237        if (hw != null) cc.setRecent(hw, maxRecent);
238      }
239
240      int softwareId = Values.getInt(request.getParameter("software_id"), -1);
241      if (softwareId >= 0) // < 0 denied or unchanged
242      {
243        Software sw = softwareId == 0 ? null : Software.getById(dc, softwareId);
244        bas.setSoftware(sw);
245        if (sw != null) cc.setRecent(sw, maxRecent);
246      }
247     
248      // Data files tab
249      boolean validate = Values.getBoolean(request.getParameter("datafiles.validate"));
250      Base.updateFiles(dc, bas, request, validate, cc, maxRecent);
251     
252      // Annotations tab
253      Base.updateAnnotations(dc, bas, bas, request);
254       
255      // OnSave extensions
256      invoker.render(OnSaveRenderer.ON_SAVE);
257      dc.commit();
258      invoker.render(OnSaveRenderer.ON_COMMIT);
259    }
260    catch (Exception ex)
261    {
262      invoker.render(OnSaveRenderer.onRollback(ex));
263      throw ex;
264    }
265    finally
266    {
267      cc.removeObject("item");
268    }
269  }
270  else if ("DeleteItem".equals(cmd))
271  {
272    // Delete a single item and then return to the view page
273    dc = sc.newDbControl();
274    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
275    RemovableUtil.removeRecursively(dc, itemType, Collections.singleton(cc.getId()), true);
276    dc.commit();
277    redirect = viewPage;
278  }
279  else if ("DeleteItems".equals(cmd))
280  {
281    // Delete all selected items on the list page
282    dc = sc.newDbControl();
283    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
284    int numTotal = cc.getSelected().size();
285    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
286    dc.commit();
287    if (numTotal != numRemoved)
288    {
289      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
290    }
291    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
292  }
293  else if ("RestoreItem".equals(cmd))
294  {
295    // Restore a single item and then return to the view page
296    dc = sc.newDbControl();
297    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
298    RemovableUtil.removeRecursively(dc, itemType, Collections.singleton(cc.getId()), false);
299    dc.commit();
300    redirect = viewPage;
301  }
302  else if ("RestoreItems".equals(cmd))
303  {
304    // Restore all selected items on the list page
305    dc = sc.newDbControl();
306    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
307    int numTotal = cc.getSelected().size();
308    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
309    dc.commit();
310    if (numTotal != numRemoved)
311    {
312      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
313    }
314    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
315  }
316  else if ("ShareItem".equals(cmd))
317  {
318    // Display a popup window for sharing a single item
319    dc = sc.newDbControl();
320    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
321    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
322    dc.close();
323    cc.setObject("MultiPermissions", permissions);
324    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
325  }
326  else if ("ShareItems".equals(cmd))
327  {
328    // Display a popup window for sharing all selected items on the list page
329    dc = sc.newDbControl();
330    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
331    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
332    dc.close();
333    cc.setObject("MultiPermissions", permissions);
334    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
335  }
336  else if ("SetOwnerOfItem".equals(cmd))
337  {
338    // Change owner of items selected on a list page
339    dc = sc.newDbControl();
340    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
341    OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId());
342    cc.setObject("OwnedItems", Collections.singleton(item));
343    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
344  }
345  else if ("SetOwnerOfItems".equals(cmd))
346  {
347    // Change owner of items selected on a list page
348    dc = sc.newDbControl();
349    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
350    Set<OwnedItem> items = new HashSet<OwnedItem>();
351    for (Integer id : cc.getSelected())
352    {
353      if (id != null) items.add((OwnedItem)itemType.getById(dc, id));
354    }
355    dc.close();
356    cc.setObject("OwnedItems", items);
357    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
358  }
359  else if ("ExportItems".equals(cmd))
360  {
361    // Run an export plugin in a list context
362    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
363    final ItemQuery<DerivedBioAssay> query = DerivedBioAssay.getQuery();
364    registerExportUtils(cc);
365    dc = sc.newDbControl();
366    cc.configureQuery(dc, query, true);
367    dc.close();
368    cc.setQuery(query);
369    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+bioassay+sets";
370  }
371  else if ("ExportItem".equals(cmd))
372  {
373    // Run an export plugin in single-item context
374    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
375    registerExportUtils(cc);
376    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+bioassay+set";
377  }
378  else if ("ImportItems".equals(cmd))
379  {
380    // Run an import plugin in a list context
381    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
382    final ItemQuery<DerivedBioAssay> query = DerivedBioAssay.getQuery();
383    dc = sc.newDbControl();
384    cc.configureQuery(dc, query, true);
385    dc.close();
386    cc.setQuery(query);
387    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+bioassay+sets";
388  }
389  else if ("ImportItem".equals(cmd))
390  {
391    // Run an import plugin in single-item context
392    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
393    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+bioassay+set";
394  }
395  else if ("RunListPlugin".equals(cmd))
396  {
397    // Run another plugin in a list context
398    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
399    final ItemQuery<DerivedBioAssay> query = DerivedBioAssay.getQuery();
400    dc = sc.newDbControl();
401    cc.configureQuery(dc, query, true);
402    dc.close();
403    cc.setQuery(query);
404    redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
405  }
406  else if ("RunPlugin".equals(cmd))
407  {
408    // Run a plugin in single-item context
409    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
410    redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
411  }
412  else if ("RunAnalysisPlugin".equals(cmd))
413  {
414    // Run an analysis plugin in single-item context
415    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
416    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=ANALYZE&title=Run+analysis+plugin";
417  }
418  else
419  {
420    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
421  }
422}
423finally
424{
425  if (dc != null) dc.close();
426}
427
428if (forward != null)
429{
430  pageContext.forward(forward);
431}
432else if (redirect != null)
433{
434  response.sendRedirect(redirect);
435}
436else if (message == null)
437{
438  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
439}
440else
441{
442  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
443}
444%>
445
Note: See TracBrowser for help on using the repository browser.