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

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

Fixes #1620: Implement a 'Manual derived bioassay creator' plug-in

The plug-in can be used and it is possible to put restrictions on the parent bioassay subtype. There are no parameters for setting protocol, hardware or software... This might be needed, but I don't know if it should be on the configuration or in the job wizard. This could be an enhancement for a later BASE version.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 17.0 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    forward = 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, null);
185        cc.setRecent(bioAssay, maxRecent);
186      }
187      else
188      {
189        DerivedBioAssay parent = DerivedBioAssay.getById(dc, parentId);
190        bas = DerivedBioAssay.getNew(dc, parent, null);
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      ItemSubtype subtype = null;
211      if (subtypeId >= 0) // < 0 = denied or unchanged
212      {
213        subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);
214        bas.setItemSubtype(subtype);
215        if (subtype != null) cc.setRecent(subtype, maxRecent);
216      }
217     
218      int extractId = Values.getInt(request.getParameter("extract_id"), -1);
219      if (extractId >= 0) // < 0 = denied or unchanged
220      {
221        Extract extract = extractId == 0 ? null : Extract.getById(dc, extractId);
222        bas.setExtract(extract);
223      }
224
225      int protocolId = Values.getInt(request.getParameter("protocol_id"), -1);
226      if (protocolId >= 0) // < 0 = denied or unchanged
227      {
228        Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId);
229        bas.setProtocol(pt);
230        if (pt != null) cc.setRecent(pt, subtype, maxRecent);
231      }
232     
233      int hardwareId = Values.getInt(request.getParameter("hardware_id"), -1);
234      if (hardwareId >= 0) // < 0 denied or unchanged
235      {
236        Hardware hw = hardwareId == 0 ? null : Hardware.getById(dc, hardwareId);
237        bas.setHardware(hw);
238        if (hw != null) cc.setRecent(hw, subtype, maxRecent);
239      }
240
241      int softwareId = Values.getInt(request.getParameter("software_id"), -1);
242      if (softwareId >= 0) // < 0 denied or unchanged
243      {
244        Software sw = softwareId == 0 ? null : Software.getById(dc, softwareId);
245        bas.setSoftware(sw);
246        if (sw != null) cc.setRecent(sw, subtype, maxRecent);
247      }
248     
249      // Data files tab
250      boolean validate = Values.getBoolean(request.getParameter("datafiles.validate"));
251      Base.updateFiles(dc, bas, request, validate, cc, maxRecent);
252     
253      // Annotations tab
254      Base.updateAnnotations(dc, bas, bas, request);
255       
256      // OnSave extensions
257      invoker.render(OnSaveRenderer.ON_SAVE);
258      dc.commit();
259      invoker.render(OnSaveRenderer.ON_COMMIT);
260    }
261    catch (Exception ex)
262    {
263      invoker.render(OnSaveRenderer.onRollback(ex));
264      throw ex;
265    }
266    finally
267    {
268      cc.removeObject("item");
269    }
270  }
271  else if ("DeleteItem".equals(cmd))
272  {
273    // Delete a single item and then return to the view page
274    dc = sc.newDbControl();
275    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
276    RemovableUtil.removeRecursively(dc, itemType, Collections.singleton(cc.getId()), true);
277    dc.commit();
278    redirect = viewPage;
279  }
280  else if ("DeleteItems".equals(cmd))
281  {
282    // Delete all selected items on the list page
283    dc = sc.newDbControl();
284    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
285    int numTotal = cc.getSelected().size();
286    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
287    dc.commit();
288    if (numTotal != numRemoved)
289    {
290      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
291    }
292    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
293  }
294  else if ("RestoreItem".equals(cmd))
295  {
296    // Restore a single item and then return to the view page
297    dc = sc.newDbControl();
298    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
299    RemovableUtil.removeRecursively(dc, itemType, Collections.singleton(cc.getId()), false);
300    dc.commit();
301    redirect = viewPage;
302  }
303  else if ("RestoreItems".equals(cmd))
304  {
305    // Restore all selected items on the list page
306    dc = sc.newDbControl();
307    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
308    int numTotal = cc.getSelected().size();
309    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
310    dc.commit();
311    if (numTotal != numRemoved)
312    {
313      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
314    }
315    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
316  }
317  else if ("ShareItem".equals(cmd))
318  {
319    // Display a popup window for sharing a single item
320    dc = sc.newDbControl();
321    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
322    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
323    dc.close();
324    cc.setObject("MultiPermissions", permissions);
325    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
326  }
327  else if ("ShareItems".equals(cmd))
328  {
329    // Display a popup window for sharing all selected items on the list page
330    dc = sc.newDbControl();
331    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
332    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
333    dc.close();
334    cc.setObject("MultiPermissions", permissions);
335    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
336  }
337  else if ("SetOwnerOfItem".equals(cmd))
338  {
339    // Change owner of items selected on a list page
340    dc = sc.newDbControl();
341    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
342    OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId());
343    cc.setObject("OwnedItems", Collections.singleton(item));
344    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
345  }
346  else if ("SetOwnerOfItems".equals(cmd))
347  {
348    // Change owner of items selected on a list page
349    dc = sc.newDbControl();
350    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
351    Set<OwnedItem> items = new HashSet<OwnedItem>();
352    for (Integer id : cc.getSelected())
353    {
354      if (id != null) items.add((OwnedItem)itemType.getById(dc, id));
355    }
356    dc.close();
357    cc.setObject("OwnedItems", items);
358    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
359  }
360  else if ("ExportItems".equals(cmd))
361  {
362    // Run an export plugin in a list context
363    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
364    final ItemQuery<DerivedBioAssay> query = DerivedBioAssay.getQuery();
365    registerExportUtils(cc);
366    dc = sc.newDbControl();
367    cc.configureQuery(dc, query, true);
368    dc.close();
369    cc.setQuery(query);
370    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+bioassay+sets";
371  }
372  else if ("ExportItem".equals(cmd))
373  {
374    // Run an export plugin in single-item context
375    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
376    registerExportUtils(cc);
377    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+bioassay+set";
378  }
379  else if ("ImportItems".equals(cmd))
380  {
381    // Run an import plugin in a list context
382    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
383    final ItemQuery<DerivedBioAssay> query = DerivedBioAssay.getQuery();
384    dc = sc.newDbControl();
385    cc.configureQuery(dc, query, true);
386    dc.close();
387    cc.setQuery(query);
388    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+bioassay+sets";
389  }
390  else if ("ImportItem".equals(cmd))
391  {
392    // Run an import plugin in single-item context
393    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
394    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+bioassay+set";
395  }
396  else if ("RunListPlugin".equals(cmd))
397  {
398    // Run another plugin in a list context
399    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
400    final ItemQuery<DerivedBioAssay> query = DerivedBioAssay.getQuery();
401    dc = sc.newDbControl();
402    cc.configureQuery(dc, query, true);
403    dc.close();
404    cc.setQuery(query);
405    redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
406  }
407  else if ("RunPlugin".equals(cmd))
408  {
409    // Run a plugin in single-item context
410    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
411    redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
412  }
413  else if ("RunAnalysisPlugin".equals(cmd))
414  {
415    // Run an analysis plugin in single-item context
416    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
417    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=ANALYZE&title=Run+analysis+plugin";
418  }
419  else
420  {
421    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
422  }
423}
424finally
425{
426  if (dc != null) dc.close();
427}
428
429if (forward != null)
430{
431  pageContext.forward(forward);
432}
433else if (redirect != null)
434{
435  response.sendRedirect(redirect);
436}
437else if (message == null)
438{
439  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
440}
441else
442{
443  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
444}
445%>
446
Note: See TracBrowser for help on using the repository browser.