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

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

References #1908: Batch inheriting multiple annotations

Added InheritAnnotationsManager, InheritSpecification and a few other changes.

A test case has been implemented from the raw bioassays lists page which allows the user to select one or more annotation types to inherit to the selected raw bioassays. It is possible to select if existing inherited annotations should be removed or if new annotations should be inherited. For each annotation type is possible to select the parent type to inherit from (to avoid duplicate inheritance).

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