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

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

Addresses #1106. Missed to change reference wherefrom retrive GPLv3 license text. And some other changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 5.8 KB
Line 
1<%-- $Id: index.jsp 4511 2008-09-11 20:04:27Z 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 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.clients.web.util.HTML"
39  import="java.util.Map"
40  import="java.util.HashMap"
41  import="java.util.Collections"
42%>
43<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
44<%!
45  private static final Map<RawDataType, ItemContext> defaultContexts = 
46    new HashMap<RawDataType, ItemContext>();
47
48  static
49  {
50    for (RawDataType rdt : RawDataTypes.getRawDataTypes())
51    {
52      // Default visible columns are: position, ch1, ch2, ...
53      StringBuilder columns = new StringBuilder("POSITION");
54      for (int ch = 1; ch <= rdt.getChannels(); ++ch)
55      {
56        columns.append(",ch").append(ch);
57      }
58      defaultContexts.put(rdt, 
59        Base.createDefaultContext("POSITION", columns.toString()));
60    }
61  }
62  private static final Item itemType = Item.SPOTDATA;
63%>
64<%
65final int bioAssayId = Values.getInt(request.getParameter("bioassay_id"));
66final int bioAssaySetId = Values.getInt(request.getParameter("bioassayset_id"));
67
68final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
69final String ID = sc.getId();
70final String cmd = request.getParameter("cmd");
71final String root = request.getContextPath()+"/";
72final String mode = request.getParameter("mode");
73final String callback = request.getParameter("callback");
74final String itemId = request.getParameter("item_id");
75final String listPage = "list_spotdata.jsp?ID="+ID
76  +"&bioassay_id="+bioAssayId+"&bioassayset_id="+bioAssaySetId
77  +(mode == null ? "" : "&mode="+mode)
78  +(callback == null ? "" : "&callback="+callback)
79  +(itemId == null ? "" : "&item_id="+itemId);
80
81String forward = null;
82String redirect = null;
83String message = null;
84DbControl dc = null;
85
86try
87{
88  dc = sc.newDbControl();
89  final BioAssay ba = bioAssayId == 0 ? null : BioAssay.getById(dc, bioAssayId);
90  final BioAssaySet bas = ba != null ? ba.getBioAssaySet() : BioAssaySet.getById(dc, bioAssaySetId);
91  dc.close();
92  final RawDataType rawDataType = bas.getRawDataType();
93  final ItemContext defaultContext = defaultContexts.get(rawDataType);
94  final String subContext = rawDataType.getId();
95 
96  if (cmd == null || "List".equals(cmd))
97  {
98    // Display the list page without updatinging the current context
99    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, defaultContext);
100    redirect = listPage;
101  }
102  else if ("UpdateContext".equals(cmd))
103  {
104    // Display the list page after updating the current context from the request parameters
105    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
106    redirect = listPage;
107  }
108  else if ("LoadContext".equals(cmd))
109  {
110    // Display the list page after loading a saved context
111    int contextId = Values.getInt(request.getParameter("context"));
112    Base.loadContext(sc, contextId, defaultContext);
113    redirect = listPage;
114  }
115  else if ("ExportItems".equals(cmd))
116  {
117    // Run an export plugin in a list context
118    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
119    dc = sc.newDbControl();
120    if (bas != null) dc.reattachItem(bas);
121    if (ba != null) dc.reattachItem(ba);
122    final DynamicSpotQuery query = ba != null ? ba.getSpotData() : bas.getSpotData();
123    //cc.configureQuery(query, true);
124    dc.close();
125    cc.setQuery(query);
126    redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+spot+data";
127  }
128  else if ("CreateReporterList".equals(cmd))
129  {
130    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
131    dc = sc.newDbControl();
132    if (bas != null) dc.reattachItem(bas);
133    if (ba != null) dc.reattachItem(ba);
134    final DynamicSpotQuery query = ba != null ? ba.getSpotData() : bas.getSpotData();
135    cc.configureQuery(dc, query, Collections.singletonList("@id"));
136    cc.setQuery(query);
137    redirect = "../../../views/reporterlists/index.jsp?ID="+ID+
138      "&cmd=NewItem&addReporters=1&formId=spotdata&fromContext=SPOTDATA&subContext=" + subContext +
139      "&name=" + HTML.urlEncode(ba != null ? ba.getName() : bas.getName());
140  }
141 
142  else
143  {
144    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
145  }
146}
147finally
148{
149  if (dc != null) dc.close();
150}
151
152if (forward != null)
153{
154  pageContext.forward(forward);
155}
156else if (redirect != null)
157{
158  response.sendRedirect(redirect);
159}
160else if (message == null)
161{
162  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
163}
164else
165{
166  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
167}
168%>
169
Note: See TracBrowser for help on using the repository browser.