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

Last change on this file since 6600 was 6600, checked in by Nicklas Nordborg, 8 years ago

Merge BASE 3.3.3 to the trunk.

There is a test failure in "TestFile?" for the https file. I guess this due to updates to the Http client library in #1809 and that it existed already in BASE 3.3.2 when the urls changed due to server move.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 25.6 KB
Line 
1<%-- $Id: index.jsp 6600 2014-11-17 07:41:18Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
5  Copyright (C) 2007 Nicklas Nordborg
6
7  This file is part of BASE - BioArray Software Environment.
8  Available at http://base.thep.lu.se/
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  @author Nicklas
25  @version 2.0
26--%>
27<%@ page pageEncoding="UTF-8" session="false"
28  import="net.sf.basedb.core.Application"
29  import="net.sf.basedb.core.SessionControl"
30  import="net.sf.basedb.core.DbControl"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.Include"
33  import="net.sf.basedb.core.RawBioAssay"
34  import="net.sf.basedb.core.FeatureIdentificationMethod"
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.Extract"
39  import="net.sf.basedb.core.DerivedBioAssay"
40  import="net.sf.basedb.core.Experiment"
41  import="net.sf.basedb.core.File"
42  import="net.sf.basedb.core.RawDataType"
43  import="net.sf.basedb.core.RawDataTypes"
44  import="net.sf.basedb.core.Platform"
45  import="net.sf.basedb.core.PlatformVariant"
46  import="net.sf.basedb.core.User"
47  import="net.sf.basedb.core.Path"
48  import="net.sf.basedb.core.ItemQuery"
49  import="net.sf.basedb.core.ItemResultIterator"
50  import="net.sf.basedb.core.OwnedItem"
51  import="net.sf.basedb.core.Permission"
52  import="net.sf.basedb.core.ItemContext"
53  import="net.sf.basedb.core.MultiPermissions"
54  import="net.sf.basedb.core.PermissionDeniedException"
55  import="net.sf.basedb.core.ItemAlreadyExistsException"
56  import="net.sf.basedb.core.PluginDefinition"
57  import="net.sf.basedb.core.Job"
58  import="net.sf.basedb.core.ProgressReporter"
59  import="net.sf.basedb.core.IntegerParameterType"
60  import="net.sf.basedb.core.FloatParameterType"
61  import="net.sf.basedb.core.StringParameterType"
62  import="net.sf.basedb.core.FileParameterType"
63  import="net.sf.basedb.core.ItemParameterType"
64  import="net.sf.basedb.core.BooleanParameterType"
65  import="net.sf.basedb.core.query.Hql"
66  import="net.sf.basedb.core.query.Orders"
67  import="net.sf.basedb.core.query.Restrictions"
68  import="net.sf.basedb.core.query.Expressions"
69  import="net.sf.basedb.util.RemovableUtil"
70  import="net.sf.basedb.util.ShareableUtil"
71  import="net.sf.basedb.util.OwnableUtil"
72  import="net.sf.basedb.clients.web.Base"
73  import="net.sf.basedb.clients.web.WebException"
74  import="net.sf.basedb.util.Values"
75  import="net.sf.basedb.util.formatter.NameableFormatter"
76  import="net.sf.basedb.util.formatter.FilePathFormatter"
77  import="net.sf.basedb.clients.web.plugins.ItemQueryLoader"
78  import="net.sf.basedb.clients.web.plugins.FileSetMemberLoader"
79  import="net.sf.basedb.clients.web.util.HTML" 
80  import="net.sf.basedb.core.plugin.GuiContext"
81  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
82  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
83  import="net.sf.basedb.clients.web.extensions.JspContext"
84  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
85  import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer"
86  import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer"
87  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
88  import="java.util.Enumeration"
89  import="java.util.Set"
90  import="java.util.HashSet"
91  import="java.util.List"
92  import="java.util.ArrayList"
93  import="java.util.Arrays"
94  import="java.util.Collections"
95%>
96<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
97<%!
98  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,platform,variant,hasData,description");
99  private static final Item itemType = Item.RAWBIOASSAY;
100 
101  private static void registerExportUtils(ItemContext cc)
102  {
103    // Register formatters
104    cc.setObject("export.formatter.&experiments(name)", new NameableFormatter());
105    cc.setObject("export.formatter.&fileSet.members(file.name)", new FilePathFormatter());
106   
107    // Register dataloaders
108    String rawParameter = "rawBioAssay";
109    final ItemQuery<Experiment> experimentQuery = Experiment.getQuery();
110    experimentQuery.include(cc.getInclude());
111    experimentQuery.join(Hql.innerJoin("rawBioAssays", "rba"));
112    experimentQuery.restrict(Restrictions.eq(Hql.alias("rba"), Expressions.parameter(rawParameter)));
113    experimentQuery.order(Orders.asc(Hql.property("name"))); 
114    cc.setObject("export.dataloader.&experiments(name)", new ItemQueryLoader(experimentQuery, rawParameter));
115    cc.setObject("export.dataloader.&fileSet.members(file.name)", new FileSetMemberLoader());
116  }
117 
118  private static class UpdateArrayDesign
119    implements Runnable
120  {
121    private final int jobId;
122    private final int rawBioAssayId;
123    private final int arrayDesignId;
124    private final SessionControl sc;
125    private final FeatureIdentificationMethod fiMethod;
126   
127    private UpdateArrayDesign(Job job, RawBioAssay rba, ArrayDesign design, FeatureIdentificationMethod fiMethod)
128    {
129      this.jobId = job.getId();
130      this.rawBioAssayId = rba.getId();
131      this.arrayDesignId = design.getId();
132      this.sc = job.getSessionControl();
133      this.fiMethod = fiMethod;
134    }
135   
136    public void run()
137    {
138      DbControl dc = sc.newDbControl();
139      try
140      {
141        Job j = Job.getById(dc, jobId);
142        j.start("Initialising...", Application.getHostName(), null);
143        ProgressReporter progress = j.getProgressReporter(null);
144        dc.commit();
145        dc = sc.newDbControl();
146        RawBioAssay rba = RawBioAssay.getById(dc, rawBioAssayId);
147        ArrayDesign design = ArrayDesign.getById(dc, arrayDesignId);
148        try
149        {
150          rba.updateArrayDesign(design, fiMethod, progress);
151          progress.display(99, "Committing changes to database...");
152          dc.commit();
153          dc = sc.newDbControl();
154          j = Job.getById(dc, jobId);
155          j.doneOk("Array design updated successfully");
156          j.setRemoved(true);
157          dc.commit();
158        }
159        catch (Throwable t)
160        {
161          if (dc != null) dc.close();
162          dc = sc.newDbControl();
163          j = Job.getById(dc, jobId);
164          j.doneError(t.getMessage(), Arrays.asList(t));
165          j.setRemoved(true);
166          dc.commit();
167        }
168      }
169      finally
170      {
171        if (dc != null) dc.close();
172      }
173    }
174  }
175%>
176<%
177final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
178final String ID = sc.getId();
179final String cmd = request.getParameter("cmd");
180final String root = request.getContextPath()+"/";
181final String mode = request.getParameter("mode");
182final String callback = request.getParameter("callback");
183final String itemId = request.getParameter("item_id");
184final String listPage = "list_rawbioassays.jsp?ID="+ID
185  +(mode == null ? "" : "&mode="+mode)
186  +(callback == null ? "" : "&callback="+callback)
187  +(itemId == null ? "" : "&item_id="+itemId);
188final String viewPage = "view_rawbioassay.jsp?ID="+ID;
189final String editPage = "edit_rawbioassay.jsp?ID="+ID;
190
191String forward = null;
192String redirect = null;
193String message = null;
194DbControl dc = null;
195
196try
197{
198  if (cmd == null || "List".equals(cmd))
199  {
200    // Display the list page without updatinging the current context
201    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
202    redirect = listPage;
203  }
204  else if ("UpdateContext".equals(cmd))
205  {
206    // Display the list page after updating the current context from the request parameters
207    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
208    redirect = listPage;
209  }
210  else if ("LoadContext".equals(cmd))
211  {
212    // Display the list page after loading a saved context
213    int contextId = Values.getInt(request.getParameter("context"));
214    Base.loadContext(sc, contextId, defaultContext);
215    redirect = listPage;
216  }
217
218  else if ("ViewItem".equals(cmd))
219  {
220    // Display the view page for a single item
221    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
222    forward = viewPage;
223  }
224  else if ("EditItem".equals(cmd))
225  {
226    // Display the edit page for a single item (should be opened in a popup)
227    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
228    forward = editPage;
229  }
230  else if ("EditSpotImages".equals(cmd))
231  {
232    // Display the spot images edit page for a single item (should be opened in a popup)
233    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
234    redirect = "edit_spotimages.jsp?ID="+ID;
235  }
236  else if ("NewItem".equals(cmd))
237  {
238    // Display the edit page for a new item (should be opened in a popup)
239    if (!sc.hasPermission(Permission.CREATE, itemType))
240    {
241      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
242    }
243    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
244    cc.setId(0);
245    forward = editPage;
246  }
247  else if ("UpdateItem".equals(cmd))
248  {
249    // Update the properties on an item (will close the popup)
250    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
251    final int maxRecent = Base.getMaxRecent(sc);
252    dc = sc.newDbControl();
253    RawBioAssay rba = (RawBioAssay)cc.getObject("item");
254   
255    Platform platform = null;
256    PlatformVariant variant = null;
257    String pf = request.getParameter("platform");
258
259    if (pf != null)
260    {
261      if (pf.startsWith("PLATFORM:"))
262      {
263        int platformId = Values.getInt(pf.substring(9), -1);
264        if (platformId > 0) platform =  Platform.getById(dc, platformId);
265      }
266      else if (pf.startsWith("VARIANT:"))
267      {
268        int variantId = Values.getInt(pf.substring(8), -1);
269        if (variantId > 0) 
270        {
271          variant = PlatformVariant.getById(dc, variantId);
272          platform = variant.getPlatform();
273        }
274      }
275    }
276    RawDataType rdt = RawDataTypes.getRawDataType(Values.getStringOrNull(request.getParameter("rawdatatype")));
277    if (platform != null) cc.setRecent(platform, maxRecent);
278    if (variant != null) cc.setRecent(variant, maxRecent);
279    if (rdt != null) cc.setRecent("RawDataType", rdt.getId(), maxRecent);
280
281    if (rba == null)
282    {
283      if (variant != null)
284      {
285        rba = RawBioAssay.getNew(dc, variant, rdt);
286      }
287      else
288      {
289        rba = RawBioAssay.getNew(dc, platform, rdt);
290      }
291      message = "Raw bioassay created";
292      dc.saveItem(rba);
293    }
294    else
295    {
296      dc.reattachItem(rba, false);
297      if (variant != null)
298      {
299        rba.setVariant(variant, rdt);
300      }
301      else if (platform != null)
302      {
303        rba.setPlatform(platform, rdt);
304      }
305      message = "Raw bioassay updated";
306    }
307    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.RAWBIOASSAY), rba);
308    ExtensionsInvoker invoker = EditUtil.useOnSaveExtensions(jspContext);
309    try
310    {
311      rba.setName(Values.getStringOrNull(request.getParameter("name")));
312      rba.setDescription(Values.getStringOrNull(request.getParameter("description")));
313      int protocolId = Values.getInt(request.getParameter("protocol_id"), -1);
314      if (protocolId >= 0)  // < 0 = denied or unchanged
315      {
316        Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId);
317        rba.setProtocol(pt);
318        if (pt != null) cc.setRecent(pt, maxRecent);
319      }
320      int softwareId = Values.getInt(request.getParameter("software_id"), -1);
321      if (softwareId >= 0) // < 0 = denied or unchanged
322      {
323        Software sw = softwareId == 0 ? null : Software.getById(dc, softwareId);
324        rba.setSoftware(sw);
325        if (sw != null) cc.setRecent(sw, maxRecent);
326      }
327      int bioAssayId = Values.getInt(request.getParameter("bioassay_id"), -1);
328      if (bioAssayId >= 0) // < 0 = denied or unchanged
329      {
330        DerivedBioAssay bioAssay = bioAssayId == 0 ? null : DerivedBioAssay.getById(dc, bioAssayId);
331        rba.setParentBioAssay(bioAssay);
332        if (bioAssay != null) cc.setRecent(bioAssay, maxRecent);
333      }
334      int extractId = Values.getInt(request.getParameter("extract_id"), -1);
335      if (extractId >= 0) // < 0 = denied or unchanged
336      {
337        Extract extract = extractId == 0 ? null : Extract.getById(dc, extractId);
338        rba.setParentExtract(extract);
339        if (extract != null) cc.setRecent(extract, maxRecent);
340      }
341
342      Job job = null;
343      ArrayDesign ad = null;
344      FeatureIdentificationMethod fiMethod = null;
345      int arrayDesignId = Values.getInt(request.getParameter("arraydesign_id"), -1);
346      if (arrayDesignId >= 0) // < 0 = denied or unchanged
347      {
348        ad = arrayDesignId == 0 ? null : ArrayDesign.getById(dc, arrayDesignId);
349        if (!rba.isSameArrayDesign(ad) || !rba.isInDatabase())
350        {
351          if (rba.hasData())
352          {
353            try
354            {
355              fiMethod = FeatureIdentificationMethod.valueOf(request.getParameter("fiMethod"));
356            }
357            catch (Exception ex)
358            {}
359            if (rba.getRawDataType().isStoredInDb() && ad != null && ad.hasFeatures())
360            {
361              // Create job and assign it to another thread
362              job = Job.getNew(dc, null, null, null);
363              job.setName("Validating array design on " + rba.getName());
364              job.setPrepared(Application.getHostName(), null);
365              job.setSendMessage(Values.getBoolean(sc.getUserClientSetting("plugins.sendmessage"), false));
366              dc.saveItem(job);
367            }
368            else
369            {
370              rba.updateArrayDesign(ad, fiMethod, null);
371            }
372          }
373          else
374          {
375            rba.setArrayDesign(ad);
376          }
377        }
378        if (ad != null) cc.setRecent(ad, maxRecent);
379      }
380 
381      // Data files tab
382      boolean validate = Values.getBoolean(request.getParameter("datafiles.validate"));
383      Base.updateFiles(dc, rba, request, validate, cc, maxRecent);
384     
385      // Annotations tab
386      Base.updateAnnotations(dc, rba, rba, request);
387     
388      // OnSave extensions
389      invoker.render(OnSaveRenderer.ON_SAVE);
390      dc.commit();
391      invoker.render(OnSaveRenderer.ON_COMMIT);
392      if (job != null) 
393      {
394        redirect = "../jobs/index.jsp?ID="+ID+"&cmd=ViewItem&item_id="+job.getId();
395        Thread updateThread = new Thread(new UpdateArrayDesign(job, rba, ad, fiMethod));
396        updateThread.setPriority(Thread.currentThread().getPriority() - 1);
397        updateThread.start();
398      }
399    }
400    catch (Exception ex)
401    {
402      invoker.render(OnSaveRenderer.onRollback(ex));
403      throw ex;
404    }
405    finally
406    {
407      cc.removeObject("item");
408    }
409  }
410  else if ("DeleteItem".equals(cmd))
411  {
412    // Delete a single item and then return to the view page
413    dc = sc.newDbControl();
414    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
415    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
416    dc.commit();
417    redirect = viewPage;
418  }
419  else if ("DeleteItems".equals(cmd))
420  {
421    // Delete all selected items on the list page
422    dc = sc.newDbControl();
423    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
424    int numTotal = cc.getSelected().size();
425    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
426    dc.commit();
427    if (numTotal != numRemoved)
428    {
429      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
430    }
431    redirect = listPage;
432  }
433  else if ("RestoreItem".equals(cmd))
434  {
435    // Restore a single item and then return to the view page
436    dc = sc.newDbControl();
437    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
438    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
439    dc.commit();
440    redirect = viewPage;
441  }
442  else if ("RestoreItems".equals(cmd))
443  {
444    // Restore all selected items on the list page
445    dc = sc.newDbControl();
446    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
447    int numTotal = cc.getSelected().size();
448    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
449    dc.commit();
450    if (numTotal != numRemoved)
451    {
452      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
453    }
454    redirect = listPage;
455  }
456  else if ("ShareItem".equals(cmd))
457  {
458    // Display a popup window for sharing a single item
459    dc = sc.newDbControl();
460    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
461    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
462    dc.close();
463    cc.setObject("MultiPermissions", permissions);
464    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
465  }
466  else if ("ShareItems".equals(cmd))
467  {
468    // Display a popup window for sharing all selected items on the list page
469    dc = sc.newDbControl();
470    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
471    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
472    dc.close();
473    cc.setObject("MultiPermissions", permissions);
474    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
475  }
476  else if ("SetOwnerOfItem".equals(cmd))
477  {
478    // Change owner of items selected on a list page
479    dc = sc.newDbControl();
480    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
481    OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId());
482    cc.setObject("OwnedItems", Collections.singleton(item));
483    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
484  }
485  else if ("SetOwnerOfItems".equals(cmd))
486  {
487    // Change owner of items selected on a list page
488    dc = sc.newDbControl();
489    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
490    Set<OwnedItem> items = new HashSet<OwnedItem>();
491    for (Integer id : cc.getSelected())
492    {
493      if (id != null) items.add((OwnedItem)itemType.getById(dc, id));
494    }
495    dc.close();
496    cc.setObject("OwnedItems", items);
497    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
498  }
499  else if ("ExportItems".equals(cmd))
500  {
501    // Run an export plugin in a list context
502    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
503    final ItemQuery<RawBioAssay> query = RawBioAssay.getQuery();
504    dc = sc.newDbControl();
505    cc.setQuery(query);
506    cc.configureQuery(dc, query, true);
507    registerExportUtils(cc);
508    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null);
509    ExtensionsInvoker listInvoker = ListColumnUtil.useExtensions(jspContext);
510    listInvoker.render(new ListColumnExportRenderer(cc));
511    dc.close();
512    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+raw+bioassays";
513  }
514  else if ("ExportItem".equals(cmd))
515  {
516    // Run an export plugin in single-item context
517    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
518    registerExportUtils(cc);
519    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+raw+bioassay";
520  }
521  else if ("ImportItems".equals(cmd))
522  {
523    // Run an import plugin in a list context
524    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
525    final ItemQuery<RawBioAssay> query = RawBioAssay.getQuery();
526    dc = sc.newDbControl();
527    cc.configureQuery(dc, query, true);
528    dc.close();
529    cc.setQuery(query);
530    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+raw+bioassays";
531  }
532  else if ("ImportItem".equals(cmd))
533  {
534    // Run an import plugin in single-item context
535    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
536    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+raw+bioassay";
537  }
538  else if ("RunListPlugin".equals(cmd))
539  {
540    // Run another plugin in a list context
541    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
542    final ItemQuery<RawBioAssay> query = RawBioAssay.getQuery();
543    dc = sc.newDbControl();
544    cc.configureQuery(dc, query, true);
545    dc.close();
546    cc.setQuery(query);
547    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
548  }
549  else if ("RunPlugin".equals(cmd))
550  {
551    // Run another plugin in single-item context
552    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
553    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
554  }
555  else if ("NewExperiment".equals(cmd))
556  {
557    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
558    redirect = "../experiments/index.jsp?ID="+ID+"&cmd=NewItem&rawbioassays=1";
559  }
560  else if ("CreateSpotImages".equals(cmd))
561  {
562    dc = sc.newDbControl();
563    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
564    RawBioAssay rba = RawBioAssay.getById(dc, cc.getId());
565   
566    int redFileId = Values.getInt(request.getParameter("redfile_id"));
567    File red = redFileId == 0 ? null : File.getById(dc, redFileId);
568    int greenFileId = Values.getInt(request.getParameter("greenfile_id"));
569    File green = greenFileId == 0 ? null : File.getById(dc, greenFileId);
570    int blueFileId = Values.getInt(request.getParameter("bluefile_id"));
571    File blue = blueFileId == 0 ? null : File.getById(dc, blueFileId);
572
573    String path = Values.getStringOrNull(request.getParameter("path"));
574    if (path.startsWith("~/"))
575    {
576      User user = User.getById(dc, sc.getLoggedInUserId());
577      path = "~"+user.getLogin()+path.substring(1);
578    }
579    Path p = new Path(path, Path.Type.FILE);
580    File saveAs = File.getByPath(dc, p, true);
581    if (saveAs.isInDatabase() && !Values.getBoolean(request.getParameter("overwrite")))
582    {
583      throw new ItemAlreadyExistsException("File[path="+path+"]");
584    }
585   
586    IntegerParameterType integerParameter = new IntegerParameterType();
587    FloatParameterType floatParameter = new FloatParameterType();
588    FileParameterType fileParameter = new FileParameterType();
589    ItemParameterType<RawBioAssay> itemParameter = new ItemParameterType(RawBioAssay.class, null);
590    StringParameterType stringParameter = new StringParameterType();
591    BooleanParameterType booleanParameter = new BooleanParameterType();
592   
593    PluginDefinition plugin = PluginDefinition.getByClassName(dc, "net.sf.basedb.plugins.SpotImageCreator");
594    Job job = Job.getNew(dc, plugin, null, null);
595    job.setName("Create spot images for raw bioassay: " + rba.getName());
596    job.setParameterValue("rawBioAssay", "Raw bioassay", 
597      "The raw bioassay to create spot images for", itemParameter, rba);
598    job.setParameterValue("xScale", "X scale factor", 
599      "The raw data X value will be divided by this value to get the pixel coordinate", 
600      integerParameter, Values.getInt(request.getParameter("x_scale")));
601    job.setParameterValue("yScale", "Y scale factor", 
602      "The raw data Y value will be divided by this value to get the pixel coordinate", 
603      integerParameter, Values.getInt(request.getParameter("y_scale")));
604    job.setParameterValue("xOffset", "X offset value",
605      "The offset is subtracted from the raw data X value",
606      integerParameter, Values.getInt(request.getParameter("x_offset")));
607    job.setParameterValue("yOffset", "Y offset value",
608      "The offset is subtracted from the raw data Y value",
609      integerParameter, Values.getInt(request.getParameter("y_offset")));
610    job.setParameterValue("spotsize", "Spot size", "The size of each spot in pixels",
611      integerParameter, Values.getInt(request.getParameter("spotsize")));
612    job.setParameterValue("gamma", "Gamma", "Gamma correction for display",
613      floatParameter, Values.getFloat(request.getParameter("gamma")));
614    job.setParameterValue("quality", "Quality", 
615      "The quality is a number between 0.0 and 1.0, with 1.0 indicating highest quality.", 
616      floatParameter, Values.getFloat(request.getParameter("quality")));
617    job.setParameterValue("redFile", "Red image", 
618      "The file containing the image to use for the red part", fileParameter, red);
619    job.setParameterValue("greenFile", "Green image", 
620      "The file containing the image to use for the green part", fileParameter, green);
621    job.setParameterValue("blueFile", "Blue image",
622      "The file containing the image to use for the red part", fileParameter, blue);
623    job.setParameterValue("path", "Save as", 
624      "The file name where the spot images should be saved", stringParameter, path);
625    job.setParameterValue("overwrite", "Overwrite", 
626      "If an existing file should be overwritten or not", booleanParameter, Values.getBoolean(request.getParameter("overwrite")));
627   
628    dc.saveItem(job);
629    dc.commit();
630
631    redirect = "../jobs/index.jsp?ID="+ID+"&cmd=ViewItem&item_id="+job.getId();
632  }
633  else
634  {
635    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
636  }
637
638
639  /*
640  else if ("ImportRawData".equals(cmd))
641  {
642    RawBioAssay rba = (RawBioAssay)sc.getSessionSetting(itemType.name()+".item");
643    ItemContext context = sc.getCurrentContext(itemType);
644    context.setId(rba.getId());
645    redirect = "../../common/import/configure.jsp?ID="+ID+"&item_type="+itemType.name()+"&context_type=ITEM&title=Import+raw+data+for+"+HTML.urlEncode(rba.getName());
646
647  }
648  */
649}
650finally
651{
652  if (dc != null) dc.close();
653}
654
655if (forward != null)
656{
657  sc.setSessionSetting("alert-message", message);
658  pageContext.forward(forward);
659}
660else if (redirect != null)
661{
662  sc.setSessionSetting("alert-message", message);
663  response.sendRedirect(redirect);
664}
665else if (message == null)
666{
667  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
668}
669else
670{
671  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
672}
673%>
674
Note: See TracBrowser for help on using the repository browser.