source: trunk/www/lims/arraydesigns/index.jsp @ 3859

Last change on this file since 3859 was 3859, checked in by Nicklas Nordborg, 14 years ago

References #789: Extend "Experiment overview" to check for problems related to platform and data files

  • The validation options and rules have been added. Need a bit more testing.
  • Fixes some other issues with FileSet? and validation of data files.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 14.3 KB
Line 
1<%-- $Id: index.jsp 3859 2007-10-18 10:03:33Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg, Gregory Vincic
4  Copyright (C) 2006 Jari Hakkinen, 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 2
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 this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330,
23  Boston, MA  02111-1307, USA.
24  ------------------------------------------------------------------
25
26  @author Nicklas
27  @version 2.0
28--%>
29<%@ page session="false"
30  import="net.sf.basedb.core.SessionControl"
31  import="net.sf.basedb.core.DbControl"
32  import="net.sf.basedb.core.Item"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.ArrayDesign"
35  import="net.sf.basedb.core.Affymetrix"
36  import="net.sf.basedb.core.Platform"
37  import="net.sf.basedb.core.PlatformVariant"
38  import="net.sf.basedb.core.Plate"
39  import="net.sf.basedb.core.File"
40  import="net.sf.basedb.core.FileType"
41  import="net.sf.basedb.core.FileSet"
42  import="net.sf.basedb.core.Path"
43  import="net.sf.basedb.core.DataFileType"
44  import="net.sf.basedb.core.ItemQuery"
45  import="net.sf.basedb.core.ItemResultIterator"
46  import="net.sf.basedb.core.Permission"
47  import="net.sf.basedb.core.ItemContext"
48  import="net.sf.basedb.core.MultiPermissions"
49  import="net.sf.basedb.core.PermissionDeniedException"
50  import="net.sf.basedb.core.ItemAlreadyExistsException"
51  import="net.sf.basedb.util.RemovableUtil"
52  import="net.sf.basedb.util.ShareableUtil"
53  import="net.sf.basedb.util.OwnableUtil"
54  import="net.sf.basedb.clients.web.Base"
55  import="net.sf.basedb.clients.web.WebException"
56  import="net.sf.basedb.util.Values"
57  import="net.sf.basedb.clients.web.util.HTML"
58  import="java.util.Enumeration"
59  import="java.util.Set"
60  import="java.util.HashSet"
61  import="java.util.List"
62  import="java.util.ArrayList"
63  import="java.util.Collections"
64%>
65<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
66<%!
67  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,platform,numDbFeatures,numFileFeatures,description");
68  private static final Item itemType = Item.ARRAYDESIGN;
69%>
70<%
71final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
72final String ID = sc.getId();
73final String cmd = request.getParameter("cmd");
74final String root = request.getContextPath()+"/";
75final String mode = request.getParameter("mode");
76final String callback = request.getParameter("callback");
77final String itemId = request.getParameter("item_id");
78final String listPage = "list_designs.jsp?ID="+ID
79  +(mode == null ? "" : "&mode="+mode)
80  +(callback == null ? "" : "&callback="+callback)
81  +(itemId == null ? "" : "&item_id="+itemId);
82final String viewPage = "view_design.jsp?ID="+ID;
83final String editPage = "edit_design.jsp?ID="+ID;
84
85String forward = null;
86String redirect = null;
87String message = null;
88DbControl dc = null;
89
90try
91{
92  if (cmd == null || "List".equals(cmd))
93  {
94    // Display the list page without updatinging the current context
95    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
96    redirect = listPage;
97  }
98  else if ("UpdateContext".equals(cmd))
99  {
100    // Display the list page after updating the current context from the request parameters
101    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
102    redirect = listPage;
103  }
104  else if ("LoadContext".equals(cmd))
105  {
106    // Display the list page after loading a saved context
107    int contextId = Values.getInt(request.getParameter("context"));
108    Base.loadContext(sc, contextId, defaultContext);
109    redirect = listPage;
110  }
111
112  else if ("ViewItem".equals(cmd))
113  {
114    // Display the view page for a single item
115    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
116    forward = viewPage;
117  }
118  else if ("EditItem".equals(cmd))
119  {
120    // Display the edit page for a single item (should be opened in a popup)
121    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
122    forward = editPage;
123  }
124  else if ("NewItem".equals(cmd))
125  {
126    // Display the edit page for a new item (should be opened in a popup)
127    if (!sc.hasPermission(Permission.CREATE, itemType))
128    {
129      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
130    }
131    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
132    cc.setId(0);
133    redirect = editPage;
134  }
135  else if ("UpdateItem".equals(cmd))
136  {
137    // Update the properties on an item (will close the popup)
138    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
139    final int maxRecent = Base.getMaxRecent(sc);
140    dc = sc.newDbControl();
141    ArrayDesign design = (ArrayDesign)cc.getObject("item");
142   
143    String[] pv = request.getParameter("platform").split(":");
144    int platformId = Values.getInt(pv[0], -1);
145    int variantId = pv.length > 1 ? Values.getInt(pv[1], -1) : -1;
146    Platform platform = platformId > 0 ? Platform.getById(dc, platformId) : null;
147    PlatformVariant variant = variantId > 0 ? PlatformVariant.getById(dc, variantId) : null;
148    if (design == null)
149    {
150      if (variant != null)
151      {
152        design = ArrayDesign.getNew(dc, variant); 
153      }
154      else
155      {
156        design = ArrayDesign.getNew(dc, platform);
157      }
158      message = "Array design created";
159      dc.saveItem(design);
160    }
161    else
162    {
163      dc.reattachItem(design);
164      if (variant != null)
165      {
166        design.setVariant(variant);
167      }
168      else
169      {
170        design.setPlatform(platform);
171      }
172      message = "Array design updated";
173    }
174    design.setName(Values.getStringOrNull(request.getParameter("name")));
175    design.setDescription(Values.getStringOrNull(request.getParameter("description")));
176
177    // Data files tab
178    boolean validate = Values.getBoolean(request.getParameter("datafiles.validate"));
179    boolean metadata = Values.getBoolean(request.getParameter("datafiles.metadata"));
180    Base.updateFiles(dc, design, request, validate, metadata, cc, maxRecent);
181   
182    // Annotations tab
183    Base.updateAnnotations(dc, design, design, request);
184    dc.commit();
185    cc.removeObject("item");
186  }
187  else if ("DeleteItem".equals(cmd))
188  {
189    // Delete a single item and then return to the view page
190    dc = sc.newDbControl();
191    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
192    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
193    dc.commit();
194    redirect = viewPage;
195  }
196  else if ("DeleteItems".equals(cmd))
197  {
198    // Delete all selected items on the list page
199    dc = sc.newDbControl();
200    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
201    int numTotal = cc.getSelected().size();
202    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
203    dc.commit();
204    if (numTotal != numRemoved)
205    {
206      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
207    }
208    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
209  }
210  else if ("RestoreItem".equals(cmd))
211  {
212    // Restore a single item and then return to the view page
213    dc = sc.newDbControl();
214    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
215    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
216    dc.commit();
217    redirect = viewPage;
218  }
219  else if ("RestoreItems".equals(cmd))
220  {
221    // Restore all selected items on the list page
222    dc = sc.newDbControl();
223    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
224    int numTotal = cc.getSelected().size();
225    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
226    dc.commit();
227    if (numTotal != numRemoved)
228    {
229      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
230    }
231    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
232  }
233  else if ("ShareItem".equals(cmd))
234  {
235    // Display a popup window for sharing a single item
236    dc = sc.newDbControl();
237    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
238    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
239    dc.close();
240    cc.setObject("MultiPermissions", permissions);
241    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
242  }
243  else if ("ShareItems".equals(cmd))
244  {
245    // Display a popup window for sharing all selected items on the list page
246    dc = sc.newDbControl();
247    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
248    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
249    dc.close();
250    cc.setObject("MultiPermissions", permissions);
251    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
252  }
253  else if ("TakeOwnershipOfItem".equals(cmd))
254  {
255    // Take ownership a single item and then return to the view page
256    dc = sc.newDbControl();
257    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
258    OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null);
259    dc.commit();
260    redirect = viewPage;
261  }
262  else if ("TakeOwnershipOfItems".equals(cmd))
263  {
264    // Take ownership all selected items on the list page
265    dc = sc.newDbControl();
266    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
267    int numTotal = cc.getSelected().size();
268    int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null);
269    dc.commit();
270    if (numTotal != numOwned)
271    {
272      message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission";
273    }
274    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
275  }
276  else if ("ExportItems".equals(cmd))
277  {
278    // Run an export plugin in a list context
279    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
280    final ItemQuery<ArrayDesign> query = ArrayDesign.getQuery();
281    cc.configureQuery(query, true);
282    cc.setQuery(query);
283    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+array+designs";
284  }
285  else if ("ExportItem".equals(cmd))
286  {
287    // Run an export plugin in single-item context
288    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
289    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+array+design";
290  }
291  else if ("ImportItems".equals(cmd))
292  {
293    // Run an import plugin in a list context
294    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
295    final ItemQuery<ArrayDesign> query = ArrayDesign.getQuery();
296    cc.configureQuery(query, true);
297    cc.setQuery(query);
298    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+array+designs";
299  }
300  else if ("ImportItem".equals(cmd))
301  {
302    // Run an import plugin in single-item context
303    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
304    // Set file type filter
305    ItemContext fileContext = sc.getCurrentContext(Item.FILE);
306    fileContext.removePropertyFilter("fileType"); // Can import both print maps and reporter maps
307    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+features";
308  }
309  else if ("RunListPlugin".equals(cmd))
310  {
311    // Run another plugin in a list context
312    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
313    final ItemQuery<ArrayDesign> query = ArrayDesign.getQuery();
314    cc.configureQuery(query, true);
315    cc.setQuery(query);
316    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
317  }
318  else if ("RunPlugin".equals(cmd))
319  {
320    // Run another plugin in single-item context
321    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
322    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
323  }
324  else if ("ManagePlates".equals(cmd))
325  {
326    // Open the attach plates page (in a popup)
327    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
328    forward = "manage_plates.jsp";
329  }
330  else if ("UpdatePlates".equals(cmd))
331  {
332    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
333    dc = sc.newDbControl();
334    ArrayDesign design = (ArrayDesign)cc.getObject("item");
335    dc.reattachItem(design);
336   
337    List<Plate> plates = new java.util.LinkedList<Plate>();
338    String[] plateIds = request.getParameterValues("plates");
339    if (plateIds != null)
340    {
341      for (String pId : plateIds)
342      {
343        plates.add(Plate.getById(dc, Values.getInt(pId)));
344      }
345    }
346    design.setPlateList(plates);
347   
348    dc.commit();
349    cc.removeObject("item");
350  }
351  else if ("VerifyReporters".equals(cmd))
352  {
353    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
354    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=NewJob&plugin_class=net.sf.basedb.plugins.CdfFileReporterImporter";
355    redirect += "&item_type=ARRAYDESIGN&context_type=LIST&title=Verify+reporters&parameter:mode=verify";
356  }
357  else
358  {
359    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
360  }
361}
362finally
363{
364  if (dc != null) dc.close();
365}
366
367if (forward != null)
368{
369  pageContext.forward(forward);
370}
371else if (redirect != null)
372{
373  response.sendRedirect(redirect);
374}
375else if (message == null)
376{
377  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
378}
379else
380{
381  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
382}
383%>
384
Note: See TracBrowser for help on using the repository browser.