source: trunk/www/views/derivedbioassaysets/index.jsp @ 5657

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

References #1153: Handling short read transcript sequence data

Added web pages for editing and viewing derived bioassay sets. They'll probably need to be polished up a bit.

The final link to raw bioassay is still not possible. I think we have to re-design the link somewhat. In BASE 2 we used the array index to link back to the correct (labeled) extracts. We can't use that in BASE 3 since for sequencing experiments there doesn't have to be any relation between extracts in the same lane of the flow cell. The idea was to provide a direct link to the extract, but then we loose one of the parents in 2-channel microarray experiments...

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