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

Last change on this file since 4951 was 4951, checked in by Nicklas Nordborg, 13 years ago

Merged patch release 2.11.1 to the trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 6.5 KB
Line 
1<%-- $Id: index.jsp 4951 2009-05-27 10:07:18Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, 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 BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Nicklas
23  @version 2.0
24--%>
25<%@ page session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.Item"
29  import="net.sf.basedb.core.BioAssaySet"
30  import="net.sf.basedb.core.BioAssay"
31  import="net.sf.basedb.core.RawDataType"
32  import="net.sf.basedb.core.RawDataTypes"
33  import="net.sf.basedb.core.ItemContext"
34  import="net.sf.basedb.core.DynamicSpotQuery"
35  import="net.sf.basedb.clients.web.Base"
36  import="net.sf.basedb.clients.web.WebException"
37  import="net.sf.basedb.util.Values"
38  import="net.sf.basedb.util.formatter.LookupFormatter"
39  import="net.sf.basedb.clients.web.util.HTML"
40  import="java.util.Map"
41  import="java.util.HashMap"
42  import="java.util.Collections"
43%>
44<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
45<%!
46  private static final Map<RawDataType, ItemContext> defaultContexts = 
47    new HashMap<RawDataType, ItemContext>();
48
49  static
50  {
51    for (RawDataType rdt : RawDataTypes.getRawDataTypes())
52    {
53      // Default visible columns are: position, ch1, ch2, ...
54      StringBuilder columns = new StringBuilder("POSITION");
55      for (int ch = 1; ch <= rdt.getChannels(); ++ch)
56      {
57        columns.append(",ch").append(ch);
58      }
59      defaultContexts.put(rdt, 
60        Base.createDefaultContext("POSITION", columns.toString()));
61    }
62  }
63  private static final Item itemType = Item.SPOTDATA;
64 
65  private static void registerExportFormatters(DbControl dc, ItemContext cc, 
66    BioAssaySet bas, BioAssay ba)
67  {
68    if (bas != null)
69    {
70      Map<Number, String> bioAssayMap = new HashMap<Number, String>();
71      for (BioAssay b : bas.getBioAssays().list(dc))
72      {
73        short columnNo = b.getDataCubeColumnNo();
74        String name = b.getName();
75        // Safety measure, since JDBC driver seems to return 'short' as 'int'
76        bioAssayMap.put(columnNo, name);
77        bioAssayMap.put((int)columnNo, name);
78      }
79      cc.setObject("export.formatter.COLUMN", new LookupFormatter(bioAssayMap));
80    }
81  }
82%>
83<%
84final int bioAssayId = Values.getInt(request.getParameter("bioassay_id"));
85final int bioAssaySetId = Values.getInt(request.getParameter("bioassayset_id"));
86
87final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
88final String ID = sc.getId();
89final String cmd = request.getParameter("cmd");
90final String root = request.getContextPath()+"/";
91final String mode = request.getParameter("mode");
92final String callback = request.getParameter("callback");
93final String itemId = request.getParameter("item_id");
94final String listPage = "list_spotdata.jsp?ID="+ID
95  +"&bioassay_id="+bioAssayId+"&bioassayset_id="+bioAssaySetId
96  +(mode == null ? "" : "&mode="+mode)
97  +(callback == null ? "" : "&callback="+callback)
98  +(itemId == null ? "" : "&item_id="+itemId);
99
100String forward = null;
101String redirect = null;
102String message = null;
103DbControl dc = null;
104
105try
106{
107  dc = sc.newDbControl();
108  final BioAssay ba = bioAssayId == 0 ? null : BioAssay.getById(dc, bioAssayId);
109  final BioAssaySet bas = ba != null ? ba.getBioAssaySet() : BioAssaySet.getById(dc, bioAssaySetId);
110  dc.close();
111  final RawDataType rawDataType = bas.getRawDataType();
112  final ItemContext defaultContext = defaultContexts.get(rawDataType);
113  final String subContext = rawDataType.getId();
114 
115  if (cmd == null || "List".equals(cmd))
116  {
117    // Display the list page without updatinging the current context
118    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, defaultContext);
119    redirect = listPage;
120  }
121  else if ("UpdateContext".equals(cmd))
122  {
123    // Display the list page after updating the current context from the request parameters
124    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
125    redirect = listPage;
126  }
127  else if ("LoadContext".equals(cmd))
128  {
129    // Display the list page after loading a saved context
130    int contextId = Values.getInt(request.getParameter("context"));
131    Base.loadContext(sc, contextId, defaultContext);
132    redirect = listPage;
133  }
134  else if ("ExportItems".equals(cmd))
135  {
136    // Run an export plugin in a list context
137    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
138    dc = sc.newDbControl();
139    if (bas != null) dc.reattachItem(bas);
140    if (ba != null) dc.reattachItem(ba);
141    final DynamicSpotQuery query = ba != null ? ba.getSpotData() : bas.getSpotData();
142    //cc.configureQuery(query, true);
143    registerExportFormatters(dc, cc, bas, ba);
144    dc.close();
145    cc.setQuery(query);
146    redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&subcontext="+subContext+"&context_type=LIST&title=Export+spot+data";
147  }
148  else if ("CreateReporterList".equals(cmd))
149  {
150    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
151    dc = sc.newDbControl();
152    if (bas != null) dc.reattachItem(bas);
153    if (ba != null) dc.reattachItem(ba);
154    final DynamicSpotQuery query = ba != null ? ba.getSpotData() : bas.getSpotData();
155    cc.configureQuery(dc, query, Collections.singletonList("@id"));
156    cc.setQuery(query);
157    redirect = "../../../views/reporterlists/index.jsp?ID="+ID+
158      "&cmd=NewItem&addReporters=1&formId=spotdata&fromContext=SPOTDATA&subContext=" + subContext +
159      "&name=" + HTML.urlEncode(ba != null ? ba.getName() : bas.getName());
160  }
161 
162  else
163  {
164    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
165  }
166}
167finally
168{
169  if (dc != null) dc.close();
170}
171
172if (forward != null)
173{
174  pageContext.forward(forward);
175}
176else if (redirect != null)
177{
178  response.sendRedirect(redirect);
179}
180else if (message == null)
181{
182  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
183}
184else
185{
186  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
187}
188%>
189
Note: See TracBrowser for help on using the repository browser.