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 | <% |
---|
67 | final int bioAssayId = Values.getInt(request.getParameter("bioassay_id")); |
---|
68 | final int bioAssaySetId = Values.getInt(request.getParameter("bioassayset_id")); |
---|
69 | |
---|
70 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
71 | final String ID = sc.getId(); |
---|
72 | final String cmd = request.getParameter("cmd"); |
---|
73 | final String root = request.getContextPath()+"/"; |
---|
74 | final String mode = request.getParameter("mode"); |
---|
75 | final String callback = request.getParameter("callback"); |
---|
76 | final String itemId = request.getParameter("item_id"); |
---|
77 | final 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 | |
---|
83 | String forward = null; |
---|
84 | String redirect = null; |
---|
85 | String message = null; |
---|
86 | DbControl dc = null; |
---|
87 | |
---|
88 | try |
---|
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 | } |
---|
149 | finally |
---|
150 | { |
---|
151 | if (dc != null) dc.close(); |
---|
152 | } |
---|
153 | |
---|
154 | if (forward != null) |
---|
155 | { |
---|
156 | pageContext.forward(forward); |
---|
157 | } |
---|
158 | else if (redirect != null) |
---|
159 | { |
---|
160 | response.sendRedirect(redirect); |
---|
161 | } |
---|
162 | else if (message == null) |
---|
163 | { |
---|
164 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
---|
165 | } |
---|
166 | else |
---|
167 | { |
---|
168 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
---|
169 | } |
---|
170 | %> |
---|
171 | |
---|