source: trunk/www/views/experiments/spotdata/index.jsp @ 4476

Last change on this file since 4476 was 4476, checked in by Jari Häkkinen, 15 years ago

Addresses #1106. Moving to GPLv3 in chunked commits.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 5.9 KB
Line 
1<%-- $Id: index.jsp 4476 2008-09-05 15:14:42Z jari $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Hakkinen, Nicklas Nordborg
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 3
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.BioAssaySet"
32  import="net.sf.basedb.core.BioAssay"
33  import="net.sf.basedb.core.RawDataType"
34  import="net.sf.basedb.core.RawDataTypes"
35  import="net.sf.basedb.core.ItemContext"
36  import="net.sf.basedb.core.DynamicSpotQuery"
37  import="net.sf.basedb.clients.web.Base"
38  import="net.sf.basedb.clients.web.WebException"
39  import="net.sf.basedb.util.Values"
40  import="net.sf.basedb.clients.web.util.HTML"
41  import="java.util.Map"
42  import="java.util.HashMap"
43  import="java.util.Collections"
44%>
45<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
46<%!
47  private static final Map<RawDataType, ItemContext> defaultContexts = 
48    new HashMap<RawDataType, ItemContext>();
49
50  static
51  {
52    for (RawDataType rdt : RawDataTypes.getRawDataTypes())
53    {
54      // Default visible columns are: position, ch1, ch2, ...
55      StringBuilder columns = new StringBuilder("POSITION");
56      for (int ch = 1; ch <= rdt.getChannels(); ++ch)
57      {
58        columns.append(",ch").append(ch);
59      }
60      defaultContexts.put(rdt, 
61        Base.createDefaultContext("POSITION", columns.toString()));
62    }
63  }
64  private static final Item itemType = Item.SPOTDATA;
65%>
66<%
67final int bioAssayId = Values.getInt(request.getParameter("bioassay_id"));
68final int bioAssaySetId = Values.getInt(request.getParameter("bioassayset_id"));
69
70final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
71final String ID = sc.getId();
72final String cmd = request.getParameter("cmd");
73final String root = request.getContextPath()+"/";
74final String mode = request.getParameter("mode");
75final String callback = request.getParameter("callback");
76final String itemId = request.getParameter("item_id");
77final String listPage = "list_spotdata.jsp?ID="+ID
78  +"&bioassay_id="+bioAssayId+"&bioassayset_id="+bioAssaySetId
79  +(mode == null ? "" : "&mode="+mode)
80  +(callback == null ? "" : "&callback="+callback)
81  +(itemId == null ? "" : "&item_id="+itemId);
82
83String forward = null;
84String redirect = null;
85String message = null;
86DbControl dc = null;
87
88try
89{
90  dc = sc.newDbControl();
91  final BioAssay ba = bioAssayId == 0 ? null : BioAssay.getById(dc, bioAssayId);
92  final BioAssaySet bas = ba != null ? ba.getBioAssaySet() : BioAssaySet.getById(dc, bioAssaySetId);
93  dc.close();
94  final RawDataType rawDataType = bas.getRawDataType();
95  final ItemContext defaultContext = defaultContexts.get(rawDataType);
96  final String subContext = rawDataType.getId();
97 
98  if (cmd == null || "List".equals(cmd))
99  {
100    // Display the list page without updatinging the current context
101    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, defaultContext);
102    redirect = listPage;
103  }
104  else if ("UpdateContext".equals(cmd))
105  {
106    // Display the list page after updating the current context from the request parameters
107    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
108    redirect = listPage;
109  }
110  else if ("LoadContext".equals(cmd))
111  {
112    // Display the list page after loading a saved context
113    int contextId = Values.getInt(request.getParameter("context"));
114    Base.loadContext(sc, contextId, defaultContext);
115    redirect = listPage;
116  }
117  else if ("ExportItems".equals(cmd))
118  {
119    // Run an export plugin in a list context
120    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
121    dc = sc.newDbControl();
122    if (bas != null) dc.reattachItem(bas);
123    if (ba != null) dc.reattachItem(ba);
124    final DynamicSpotQuery query = ba != null ? ba.getSpotData() : bas.getSpotData();
125    //cc.configureQuery(query, true);
126    dc.close();
127    cc.setQuery(query);
128    redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+spot+data";
129  }
130  else if ("CreateReporterList".equals(cmd))
131  {
132    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
133    dc = sc.newDbControl();
134    if (bas != null) dc.reattachItem(bas);
135    if (ba != null) dc.reattachItem(ba);
136    final DynamicSpotQuery query = ba != null ? ba.getSpotData() : bas.getSpotData();
137    cc.configureQuery(dc, query, Collections.singletonList("@id"));
138    cc.setQuery(query);
139    redirect = "../../../views/reporterlists/index.jsp?ID="+ID+
140      "&cmd=NewItem&addReporters=1&formId=spotdata&fromContext=SPOTDATA&subContext=" + subContext +
141      "&name=" + HTML.urlEncode(ba != null ? ba.getName() : bas.getName());
142  }
143 
144  else
145  {
146    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
147  }
148}
149finally
150{
151  if (dc != null) dc.close();
152}
153
154if (forward != null)
155{
156  pageContext.forward(forward);
157}
158else if (redirect != null)
159{
160  response.sendRedirect(redirect);
161}
162else if (message == null)
163{
164  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
165}
166else
167{
168  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
169}
170%>
171
Note: See TracBrowser for help on using the repository browser.