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

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

References #721: Store data in files instead of in the database

Remember most recently used platform/variant when creating raw bioassays/array designs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 14.4 KB
Line 
1<%-- $Id: index.jsp 3909 2007-11-06 07:57:58Z 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 (platform != null) cc.setRecent(platform, maxRecent);
149    if (variant != null) cc.setRecent(variant, maxRecent);
150    if (design == null)
151    {
152      if (variant != null)
153      {
154        design = ArrayDesign.getNew(dc, variant); 
155      }
156      else
157      {
158        design = ArrayDesign.getNew(dc, platform);
159      }
160      message = "Array design created";
161      dc.saveItem(design);
162    }
163    else
164    {
165      dc.reattachItem(design);
166      if (variant != null)
167      {
168        design.setVariant(variant);
169      }
170      else
171      {
172        design.setPlatform(platform);
173      }
174      message = "Array design updated";
175    }
176    design.setName(Values.getStringOrNull(request.getParameter("name")));
177    design.setDescription(Values.getStringOrNull(request.getParameter("description")));
178
179    // Data files tab
180    boolean validate = Values.getBoolean(request.getParameter("datafiles.validate"));
181    boolean metadata = Values.getBoolean(request.getParameter("datafiles.metadata"));
182    Base.updateFiles(dc, design, request, validate, metadata, cc, maxRecent);
183   
184    // Annotations tab
185    Base.updateAnnotations(dc, design, design, request);
186    dc.commit();
187    cc.removeObject("item");
188  }
189  else if ("DeleteItem".equals(cmd))
190  {
191    // Delete a single item and then return to the view page
192    dc = sc.newDbControl();
193    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
194    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
195    dc.commit();
196    redirect = viewPage;
197  }
198  else if ("DeleteItems".equals(cmd))
199  {
200    // Delete all selected items on the list page
201    dc = sc.newDbControl();
202    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
203    int numTotal = cc.getSelected().size();
204    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
205    dc.commit();
206    if (numTotal != numRemoved)
207    {
208      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
209    }
210    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
211  }
212  else if ("RestoreItem".equals(cmd))
213  {
214    // Restore a single item and then return to the view page
215    dc = sc.newDbControl();
216    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
217    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
218    dc.commit();
219    redirect = viewPage;
220  }
221  else if ("RestoreItems".equals(cmd))
222  {
223    // Restore all selected items on the list page
224    dc = sc.newDbControl();
225    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
226    int numTotal = cc.getSelected().size();
227    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
228    dc.commit();
229    if (numTotal != numRemoved)
230    {
231      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
232    }
233    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
234  }
235  else if ("ShareItem".equals(cmd))
236  {
237    // Display a popup window for sharing a single item
238    dc = sc.newDbControl();
239    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
240    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
241    dc.close();
242    cc.setObject("MultiPermissions", permissions);
243    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
244  }
245  else if ("ShareItems".equals(cmd))
246  {
247    // Display a popup window for sharing all selected items on the list page
248    dc = sc.newDbControl();
249    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
250    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
251    dc.close();
252    cc.setObject("MultiPermissions", permissions);
253    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
254  }
255  else if ("TakeOwnershipOfItem".equals(cmd))
256  {
257    // Take ownership a single item and then return to the view page
258    dc = sc.newDbControl();
259    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
260    OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null);
261    dc.commit();
262    redirect = viewPage;
263  }
264  else if ("TakeOwnershipOfItems".equals(cmd))
265  {
266    // Take ownership all selected items on the list page
267    dc = sc.newDbControl();
268    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
269    int numTotal = cc.getSelected().size();
270    int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null);
271    dc.commit();
272    if (numTotal != numOwned)
273    {
274      message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission";
275    }
276    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
277  }
278  else if ("ExportItems".equals(cmd))
279  {
280    // Run an export plugin in a list context
281    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
282    final ItemQuery<ArrayDesign> query = ArrayDesign.getQuery();
283    cc.configureQuery(query, true);
284    cc.setQuery(query);
285    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+array+designs";
286  }
287  else if ("ExportItem".equals(cmd))
288  {
289    // Run an export plugin in single-item context
290    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
291    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+array+design";
292  }
293  else if ("ImportItems".equals(cmd))
294  {
295    // Run an import plugin in a list context
296    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
297    final ItemQuery<ArrayDesign> query = ArrayDesign.getQuery();
298    cc.configureQuery(query, true);
299    cc.setQuery(query);
300    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+array+designs";
301  }
302  else if ("ImportItem".equals(cmd))
303  {
304    // Run an import plugin in single-item context
305    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
306    // Set file type filter
307    ItemContext fileContext = sc.getCurrentContext(Item.FILE);
308    fileContext.removePropertyFilter("fileType"); // Can import both print maps and reporter maps
309    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+features";
310  }
311  else if ("RunListPlugin".equals(cmd))
312  {
313    // Run another plugin in a list context
314    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
315    final ItemQuery<ArrayDesign> query = ArrayDesign.getQuery();
316    cc.configureQuery(query, true);
317    cc.setQuery(query);
318    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
319  }
320  else if ("RunPlugin".equals(cmd))
321  {
322    // Run another plugin in single-item context
323    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
324    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
325  }
326  else if ("ManagePlates".equals(cmd))
327  {
328    // Open the attach plates page (in a popup)
329    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
330    forward = "manage_plates.jsp";
331  }
332  else if ("UpdatePlates".equals(cmd))
333  {
334    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
335    dc = sc.newDbControl();
336    ArrayDesign design = (ArrayDesign)cc.getObject("item");
337    dc.reattachItem(design);
338   
339    List<Plate> plates = new java.util.LinkedList<Plate>();
340    String[] plateIds = request.getParameterValues("plates");
341    if (plateIds != null)
342    {
343      for (String pId : plateIds)
344      {
345        plates.add(Plate.getById(dc, Values.getInt(pId)));
346      }
347    }
348    design.setPlateList(plates);
349   
350    dc.commit();
351    cc.removeObject("item");
352  }
353  else if ("VerifyReporters".equals(cmd))
354  {
355    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
356    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=NewJob&plugin_class=net.sf.basedb.plugins.CdfFileReporterImporter";
357    redirect += "&item_type=ARRAYDESIGN&context_type=LIST&title=Verify+reporters&parameter:mode=verify";
358  }
359  else
360  {
361    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
362  }
363}
364finally
365{
366  if (dc != null) dc.close();
367}
368
369if (forward != null)
370{
371  pageContext.forward(forward);
372}
373else if (redirect != null)
374{
375  response.sendRedirect(redirect);
376}
377else if (message == null)
378{
379  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
380}
381else
382{
383  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
384}
385%>
386
Note: See TracBrowser for help on using the repository browser.