source: trunk/www/views/rawbioassays/index.jsp @ 2978

Last change on this file since 2978 was 2978, checked in by Nicklas Nordborg, 17 years ago

Added session="false" to all jsp pages so we no longer generate unneeded cookies

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 18.8 KB
Line 
1<%-- $Id: index.jsp 2978 2006-11-30 07:27:42Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 2
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.Include"
32  import="net.sf.basedb.core.RawBioAssay"
33  import="net.sf.basedb.core.Affymetrix"
34  import="net.sf.basedb.core.Scan"
35  import="net.sf.basedb.core.Protocol"
36  import="net.sf.basedb.core.Software"
37  import="net.sf.basedb.core.ArrayDesign"
38  import="net.sf.basedb.core.File"
39  import="net.sf.basedb.core.FileType"
40  import="net.sf.basedb.core.RawDataType"
41  import="net.sf.basedb.core.RawDataTypes"
42  import="net.sf.basedb.core.User"
43  import="net.sf.basedb.core.Path"
44  import="net.sf.basedb.core.ItemQuery"
45  import="net.sf.basedb.core.ItemResultIterator"
46  import="net.sf.basedb.core.Permission"
47  import="net.sf.basedb.core.ItemContext"
48  import="net.sf.basedb.core.MultiPermissions"
49  import="net.sf.basedb.core.PermissionDeniedException"
50  import="net.sf.basedb.core.ItemAlreadyExistsException"
51  import="net.sf.basedb.core.PluginDefinition"
52  import="net.sf.basedb.core.Job"
53  import="net.sf.basedb.core.IntegerParameterType"
54  import="net.sf.basedb.core.FloatParameterType"
55  import="net.sf.basedb.core.StringParameterType"
56  import="net.sf.basedb.core.FileParameterType"
57  import="net.sf.basedb.core.ItemParameterType"
58  import="net.sf.basedb.core.BooleanParameterType"
59  import="net.sf.basedb.util.RemovableUtil"
60  import="net.sf.basedb.util.ShareableUtil"
61  import="net.sf.basedb.util.OwnableUtil"
62  import="net.sf.basedb.clients.web.Base"
63  import="net.sf.basedb.clients.web.WebException"
64  import="net.sf.basedb.util.Values"
65  import="net.sf.basedb.clients.web.util.HTML"
66  import="java.util.Enumeration"
67  import="java.util.Set"
68  import="java.util.HashSet"
69  import="java.util.List"
70  import="java.util.ArrayList"
71  import="java.util.Collections"
72%>
73<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
74<%!
75  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,rawDataType,spots,description");
76  private static final Item itemType = Item.RAWBIOASSAY;
77%>
78<%
79final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
80final String ID = sc.getId();
81final String cmd = request.getParameter("cmd");
82final String root = request.getContextPath()+"/";
83final String mode = request.getParameter("mode");
84final String callback = request.getParameter("callback");
85final String itemId = request.getParameter("item_id");
86final String listPage = "list_rawbioassays.jsp?ID="+ID
87  +(mode == null ? "" : "&mode="+mode)
88  +(callback == null ? "" : "&callback="+callback)
89  +(itemId == null ? "" : "&item_id="+itemId);
90final String viewPage = "view_rawbioassay.jsp?ID="+ID;
91final String editPage = "edit_rawbioassay.jsp?ID="+ID;
92
93String forward = null;
94String redirect = null;
95String message = null;
96DbControl dc = null;
97
98try
99{
100  if (cmd == null || "List".equals(cmd))
101  {
102    // Display the list page without updatinging the current context
103    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
104    redirect = listPage;
105  }
106  else if ("UpdateContext".equals(cmd))
107  {
108    // Display the list page after updating the current context from the request parameters
109    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
110    redirect = listPage;
111  }
112  else if ("LoadContext".equals(cmd))
113  {
114    // Display the list page after loading a saved context
115    int contextId = Values.getInt(request.getParameter("context"));
116    Base.loadContext(sc, contextId, defaultContext);
117    redirect = listPage;
118  }
119
120  else if ("ViewItem".equals(cmd))
121  {
122    // Display the view page for a single item
123    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
124    forward = viewPage;
125  }
126  else if ("EditItem".equals(cmd))
127  {
128    // Display the edit page for a single item (should be opened in a popup)
129    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
130    redirect = editPage;
131  }
132  else if ("EditSpotImages".equals(cmd))
133  {
134    // Display the spot images edit page for a single item (should be opened in a popup)
135    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
136    redirect = "edit_spotimages.jsp?ID="+ID;
137  }
138  else if ("NewItem".equals(cmd))
139  {
140    // Display the edit page for a new item (should be opened in a popup)
141    if (!sc.hasPermission(Permission.CREATE, itemType))
142    {
143      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
144    }
145    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
146    cc.setId(0);
147    forward = editPage;
148  }
149  else if ("UpdateItem".equals(cmd))
150  {
151    // Update the properties on an item (will close the popup)
152    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
153    final int maxRecent = Base.getMaxRecent(sc);
154    dc = sc.newDbControl();
155    RawBioAssay rba = (RawBioAssay)cc.getObject("item");
156    RawDataType rdt = RawDataTypes.getRawDataType(Values.getStringOrNull(request.getParameter("rawdatatype")));
157    if (rdt != null) cc.setRecent("RawDataType", rdt.getId(), maxRecent);
158
159    if (rba == null)
160    {
161      rba = RawBioAssay.getNew(dc, rdt);
162      message = "Raw bioassay created";
163      dc.saveItem(rba);
164    }
165    else
166    {
167      if (rdt != null) rba.setRawDataType(rdt);
168      dc.reattachItem(rba);
169      message = "Raw bioassay updated";
170    }
171    rba.setName(Values.getStringOrNull(request.getParameter("name")));
172    rba.setDescription(Values.getStringOrNull(request.getParameter("description")));
173    int protocolId = Values.getInt(request.getParameter("protocol_id"), -1);
174    if (protocolId >= 0)  // < 0 = denied or unchanged
175    {
176      Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId);
177      rba.setProtocol(pt);
178      if (pt != null) cc.setRecent(pt, maxRecent);
179    }
180    int softwareId = Values.getInt(request.getParameter("software_id"), -1);
181    if (softwareId >= 0) // < 0 = denied or unchanged
182    {
183      Software sw = softwareId == 0 ? null : Software.getById(dc, softwareId);
184      rba.setSoftware(sw);
185      if (sw != null) cc.setRecent(sw, maxRecent);
186    }
187    int scanId = Values.getInt(request.getParameter("scan_id"), -1);
188    if (scanId >= 0) // < 0 = denied or unchanged
189    {
190      Scan scan = scanId == 0 ? null : Scan.getById(dc, scanId);
191      rba.setScan(scan);
192      if (scan != null) cc.setRecent(scan, maxRecent);
193    }
194    int arrayDesignId = Values.getInt(request.getParameter("arraydesign_id"), -1);
195    if (arrayDesignId >= 0) // < 0 = denied or unchanged
196    {
197      ArrayDesign ad = arrayDesignId == 0 ? null : ArrayDesign.getById(dc, arrayDesignId);
198      rba.setArrayDesign(ad);
199      if (ad != null) cc.setRecent(ad, maxRecent);
200    }
201    rdt = rba.getRawDataType();
202    if (rdt.isAffymetrix())
203    {
204      int celFileId = Values.getInt(request.getParameter("celfile_id"), -1);
205      if (celFileId >= 0) // < 0 = denied or unchanged
206      {
207        File celFile = celFileId == 0 ? null : File.getById(dc, celFileId);
208        Affymetrix.setCelFile(rba, celFile);
209      }
210    }
211
212    // Annotations tab
213    Base.updateAnnotations(dc, rba, rba, request);
214    dc.commit();
215    cc.removeObject("item");
216  }
217  else if ("DeleteItem".equals(cmd))
218  {
219    // Delete a single item and then return to the view page
220    dc = sc.newDbControl();
221    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
222    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
223    dc.commit();
224    redirect = viewPage;
225  }
226  else if ("DeleteItems".equals(cmd))
227  {
228    // Delete all selected items on the list page
229    dc = sc.newDbControl();
230    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
231    int numTotal = cc.getSelected().size();
232    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
233    dc.commit();
234    if (numTotal != numRemoved)
235    {
236      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
237    }
238    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
239  }
240  else if ("RestoreItem".equals(cmd))
241  {
242    // Restore a single item and then return to the view page
243    dc = sc.newDbControl();
244    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
245    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
246    dc.commit();
247    redirect = viewPage;
248  }
249  else if ("RestoreItems".equals(cmd))
250  {
251    // Restore all selected items on the list page
252    dc = sc.newDbControl();
253    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
254    int numTotal = cc.getSelected().size();
255    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
256    dc.commit();
257    if (numTotal != numRemoved)
258    {
259      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
260    }
261    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
262  }
263  else if ("ShareItem".equals(cmd))
264  {
265    // Display a popup window for sharing a single item
266    dc = sc.newDbControl();
267    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
268    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
269    dc.close();
270    cc.setObject("MultiPermissions", permissions);
271    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
272  }
273  else if ("ShareItems".equals(cmd))
274  {
275    // Display a popup window for sharing all selected items on the list page
276    dc = sc.newDbControl();
277    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
278    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
279    dc.close();
280    cc.setObject("MultiPermissions", permissions);
281    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
282  }
283  else if ("TakeOwnershipOfItem".equals(cmd))
284  {
285    // Take ownership a single item and then return to the view page
286    dc = sc.newDbControl();
287    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
288    OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null);
289    dc.commit();
290    redirect = viewPage;
291  }
292  else if ("TakeOwnershipOfItems".equals(cmd))
293  {
294    // Take ownership all selected items on the list page
295    dc = sc.newDbControl();
296    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
297    int numTotal = cc.getSelected().size();
298    int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null);
299    dc.commit();
300    if (numTotal != numOwned)
301    {
302      message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission";
303    }
304    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
305  }
306  else if ("ExportItems".equals(cmd))
307  {
308    // Run an export plugin in a list context
309    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
310    final ItemQuery<RawBioAssay> query = RawBioAssay.getQuery();
311    cc.configureQuery(query, true);
312    cc.setQuery(query);
313    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+raw+bioassays";
314  }
315  else if ("ExportItem".equals(cmd))
316  {
317    // Run an export plugin in single-item context
318    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
319    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+raw+bioassay";
320  }
321  else if ("ImportItems".equals(cmd))
322  {
323    // Run an import plugin in a list context
324    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
325    final ItemQuery<RawBioAssay> query = RawBioAssay.getQuery();
326    cc.configureQuery(query, true);
327    cc.setQuery(query);
328    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+raw+bioassays";
329  }
330  else if ("ImportItem".equals(cmd))
331  {
332    // Run an import plugin in single-item context
333    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
334    // Set file type filter
335    ItemContext fileContext = sc.getCurrentContext(Item.FILE);
336    fileContext.setPropertyFilter(FileType.getPropertyFilter(FileType.RAW_DATA));
337    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+raw+bioassay";
338  }
339  else if ("RunListPlugin".equals(cmd))
340  {
341    // Run another plugin in a list context
342    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
343    final ItemQuery<RawBioAssay> query = RawBioAssay.getQuery();
344    cc.configureQuery(query, true);
345    cc.setQuery(query);
346    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
347  }
348  else if ("RunPlugin".equals(cmd))
349  {
350    // Run another plugin in single-item context
351    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
352    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
353  }
354  else if ("CreateSpotImages".equals(cmd))
355  {
356    dc = sc.newDbControl();
357    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
358    RawBioAssay rba = RawBioAssay.getById(dc, cc.getId());
359   
360    int redFileId = Values.getInt(request.getParameter("redfile_id"));
361    File red = redFileId == 0 ? null : File.getById(dc, redFileId);
362    int greenFileId = Values.getInt(request.getParameter("greenfile_id"));
363    File green = greenFileId == 0 ? null : File.getById(dc, greenFileId);
364    int blueFileId = Values.getInt(request.getParameter("bluefile_id"));
365    File blue = blueFileId == 0 ? null : File.getById(dc, blueFileId);
366
367    String path = Values.getStringOrNull(request.getParameter("path"));
368    if (path.startsWith("~/"))
369    {
370      User user = User.getById(dc, sc.getLoggedInUserId());
371      path = "~"+user.getLogin()+path.substring(1);
372    }
373    Path p = new Path(path, Path.Type.FILE);
374    File saveAs = File.getByPath(dc, p, true);
375    if (saveAs.isInDatabase() && !Values.getBoolean(request.getParameter("overwrite")))
376    {
377      throw new ItemAlreadyExistsException("File[path="+path+"]");
378    }
379   
380    IntegerParameterType integerParameter = new IntegerParameterType();
381    FloatParameterType floatParameter = new FloatParameterType();
382    FileParameterType fileParameter = new FileParameterType();
383    ItemParameterType<RawBioAssay> itemParameter = new ItemParameterType(RawBioAssay.class, null);
384    StringParameterType stringParameter = new StringParameterType();
385    BooleanParameterType booleanParameter = new BooleanParameterType();
386   
387    PluginDefinition plugin = PluginDefinition.getByClassName(dc, "net.sf.basedb.plugins.SpotImageCreator");
388    Job job = Job.getNew(dc, plugin, null);
389    job.setName("Create spot images for raw bioassay: " + rba.getName());
390    job.setParameterValue("rawBioAssay", "Raw bioassay", 
391      "The raw bioassay to create spot images for", itemParameter, rba);
392    job.setParameterValue("xScale", "X scale factor", 
393      "The raw data X value will be divided by this value to get the pixel coordinate", 
394      integerParameter, Values.getInt(request.getParameter("x_scale")));
395    job.setParameterValue("yScale", "Y scale factor", 
396      "The raw data Y value will be divided by this value to get the pixel coordinate", 
397      integerParameter, Values.getInt(request.getParameter("y_scale")));
398    job.setParameterValue("xOffset", "X offset value",
399      "The offset is subtracted from the raw data X value",
400      integerParameter, Values.getInt(request.getParameter("x_offset")));
401    job.setParameterValue("yOffset", "Y offset value",
402      "The offset is subtracted from the raw data Y value",
403      integerParameter, Values.getInt(request.getParameter("y_offset")));
404    job.setParameterValue("spotsize", "Spot size", "The size of each spot in pixels",
405      integerParameter, Values.getInt(request.getParameter("spotsize")));
406    job.setParameterValue("gamma", "Gamma", "Gamma correction for display",
407      floatParameter, Values.getFloat(request.getParameter("gamma")));
408    job.setParameterValue("quality", "Quality", 
409      "The quality is a number between 0.0 and 1.0, with 1.0 indicating highest quality.", 
410      floatParameter, Values.getFloat(request.getParameter("quality")));
411    job.setParameterValue("redFile", "Red image", 
412      "The file containing the image to use for the red part", fileParameter, red);
413    job.setParameterValue("greenFile", "Green image", 
414      "The file containing the image to use for the green part", fileParameter, green);
415    job.setParameterValue("blueFile", "Blue image",
416      "The file containing the image to use for the red part", fileParameter, blue);
417    job.setParameterValue("path", "Save as", 
418      "The file name where the spot images should be saved", stringParameter, path);
419    job.setParameterValue("overwrite", "Overwrite", 
420      "If an existing file should be overwritten or not", booleanParameter, Values.getBoolean(request.getParameter("overwrite")));
421   
422    dc.saveItem(job);
423    dc.commit();
424
425    redirect = "../jobs/index.jsp?ID="+ID+"&cmd=ViewItem&item_id="+job.getId();
426  }
427  else
428  {
429    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
430  }
431
432
433  /*
434  else if ("ImportRawData".equals(cmd))
435  {
436    RawBioAssay rba = (RawBioAssay)sc.getSessionSetting(itemType.name()+".item");
437    ItemContext context = sc.getCurrentContext(itemType);
438    context.setId(rba.getId());
439    redirect = "../../common/import/configure.jsp?ID="+ID+"&item_type="+itemType.name()+"&context_type=ITEM&title=Import+raw+data+for+"+HTML.urlEncode(rba.getName());
440
441  }
442  */
443}
444finally
445{
446  if (dc != null) dc.close();
447}
448
449if (forward != null)
450{
451  pageContext.forward(forward);
452}
453else if (redirect != null)
454{
455  response.sendRedirect(redirect);
456}
457else if (message == null)
458{
459  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
460}
461else
462{
463  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
464}
465%>
466
Note: See TracBrowser for help on using the repository browser.