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

Last change on this file since 7605 was 7605, checked in by Nicklas Nordborg, 3 years ago

References #2151: Pre-compile all JSP pages before releases

Getting rid of a lot of unchecked warnings. Most of them are solved by changed the API in several BASE core clases to use implict casting of return types instead of explicit (this moved the 'unchecked' warning to the API method from the caller). Example:

// Before
ItemContext cc = ...
Hardware hardware = (Hardware)cc.getObject("item");
// After
Hardware hardware = cc.getObject("item");

In most cases both the old and new version of the code will work, but if the returned object is using a "type" parameter it will not compile:

// This will not compile!
Set<AnnotatedItem> items = (Set<AnnotatedItem>)cc.getObject("AnnotatedItems");
// But this will!
Set<AnnotatedItem> items = cc.getObject("AnnotatedItems");

Note that existing compiled code will still work, but that some changes may be needed when compiling agains BASE 3.15. The issues should be easy to solve (eg. remove an explict cast).

Extensions that uses JSP files that works in BASE 3.14 may stop working in BASE 3.15 since the compilation of the JSP files happens on the BASE server as they are accessed.

Another issues is that there are still a lot of unchecked warnings related to the JSON library. This build on regular Map and List API:s but has not specified generic type parameters so there is no way to get rid of those warnings without fixing the JSON library source code. The latest released version is from 2012 so it is not likely that this should happen unless we do it ourselves (the warnings are really annoying so maybe we should!).

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