2102 |
22 Mar 06 |
nicklas |
1 |
<%-- $Id$ |
2102 |
22 Mar 06 |
nicklas |
2 |
------------------------------------------------------------------ |
5425 |
23 Sep 10 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
2102 |
22 Mar 06 |
nicklas |
4 |
|
2304 |
22 May 06 |
jari |
5 |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
6 |
Available at http://base.thep.lu.se/ |
2102 |
22 Mar 06 |
nicklas |
7 |
|
2102 |
22 Mar 06 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or |
2102 |
22 Mar 06 |
nicklas |
9 |
modify it under the terms of the GNU General Public License |
4476 |
05 Sep 08 |
jari |
10 |
as published by the Free Software Foundation; either version 3 |
2102 |
22 Mar 06 |
nicklas |
11 |
of the License, or (at your option) any later version. |
2102 |
22 Mar 06 |
nicklas |
12 |
|
2102 |
22 Mar 06 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, |
2102 |
22 Mar 06 |
nicklas |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2102 |
22 Mar 06 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2102 |
22 Mar 06 |
nicklas |
16 |
GNU General Public License for more details. |
2102 |
22 Mar 06 |
nicklas |
17 |
|
2102 |
22 Mar 06 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
4511 |
11 Sep 08 |
jari |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
2102 |
22 Mar 06 |
nicklas |
20 |
------------------------------------------------------------------ |
2102 |
22 Mar 06 |
nicklas |
21 |
|
2102 |
22 Mar 06 |
nicklas |
22 |
@author Nicklas |
2102 |
22 Mar 06 |
nicklas |
23 |
@version 2.0 |
2102 |
22 Mar 06 |
nicklas |
24 |
--%> |
5426 |
24 Sep 10 |
nicklas |
25 |
<%@ page pageEncoding="UTF-8" session="false" |
2102 |
22 Mar 06 |
nicklas |
26 |
import="net.sf.basedb.core.SessionControl" |
2102 |
22 Mar 06 |
nicklas |
27 |
import="net.sf.basedb.core.DbControl" |
2102 |
22 Mar 06 |
nicklas |
28 |
import="net.sf.basedb.core.Item" |
2678 |
28 Sep 06 |
nicklas |
29 |
import="net.sf.basedb.core.BioAssaySet" |
2102 |
22 Mar 06 |
nicklas |
30 |
import="net.sf.basedb.core.BioAssay" |
2102 |
22 Mar 06 |
nicklas |
31 |
import="net.sf.basedb.core.RawDataType" |
2174 |
21 Apr 06 |
nicklas |
32 |
import="net.sf.basedb.core.RawDataTypes" |
2102 |
22 Mar 06 |
nicklas |
33 |
import="net.sf.basedb.core.ItemContext" |
7603 |
22 Feb 19 |
nicklas |
34 |
import="net.sf.basedb.core.query.SqlQuery" |
2102 |
22 Mar 06 |
nicklas |
35 |
import="net.sf.basedb.clients.web.Base" |
2102 |
22 Mar 06 |
nicklas |
36 |
import="net.sf.basedb.clients.web.WebException" |
2753 |
20 Oct 06 |
nicklas |
37 |
import="net.sf.basedb.util.Values" |
4857 |
27 Mar 09 |
nicklas |
38 |
import="net.sf.basedb.util.formatter.LookupFormatter" |
2102 |
22 Mar 06 |
nicklas |
39 |
import="net.sf.basedb.clients.web.util.HTML" |
2174 |
21 Apr 06 |
nicklas |
40 |
import="java.util.Map" |
2174 |
21 Apr 06 |
nicklas |
41 |
import="java.util.HashMap" |
4306 |
21 May 08 |
nicklas |
42 |
import="java.util.Collections" |
2102 |
22 Mar 06 |
nicklas |
43 |
%> |
2102 |
22 Mar 06 |
nicklas |
44 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
2102 |
22 Mar 06 |
nicklas |
45 |
<%! |
2174 |
21 Apr 06 |
nicklas |
46 |
private static final Map<RawDataType, ItemContext> defaultContexts = |
2174 |
21 Apr 06 |
nicklas |
47 |
new HashMap<RawDataType, ItemContext>(); |
2174 |
21 Apr 06 |
nicklas |
48 |
|
2174 |
21 Apr 06 |
nicklas |
49 |
static |
2174 |
21 Apr 06 |
nicklas |
50 |
{ |
2174 |
21 Apr 06 |
nicklas |
51 |
for (RawDataType rdt : RawDataTypes.getRawDataTypes()) |
2174 |
21 Apr 06 |
nicklas |
52 |
{ |
2669 |
27 Sep 06 |
nicklas |
53 |
// Default visible columns are: position, ch1, ch2, ... |
7982 |
14 Jun 21 |
nicklas |
54 |
StringBuilder columns = new StringBuilder("POSITION,rep.externalId"); |
2174 |
21 Apr 06 |
nicklas |
55 |
for (int ch = 1; ch <= rdt.getChannels(); ++ch) |
2174 |
21 Apr 06 |
nicklas |
56 |
{ |
2174 |
21 Apr 06 |
nicklas |
57 |
columns.append(",ch").append(ch); |
2174 |
21 Apr 06 |
nicklas |
58 |
} |
2174 |
21 Apr 06 |
nicklas |
59 |
defaultContexts.put(rdt, |
7982 |
14 Jun 21 |
nicklas |
60 |
Base.createDefaultContext("POSITION", columns.toString(), "rep.externalId")); |
2174 |
21 Apr 06 |
nicklas |
61 |
} |
2174 |
21 Apr 06 |
nicklas |
62 |
} |
2174 |
21 Apr 06 |
nicklas |
63 |
private static final Item itemType = Item.SPOTDATA; |
4857 |
27 Mar 09 |
nicklas |
64 |
|
4857 |
27 Mar 09 |
nicklas |
65 |
private static void registerExportFormatters(DbControl dc, ItemContext cc, |
4857 |
27 Mar 09 |
nicklas |
66 |
BioAssaySet bas, BioAssay ba) |
4857 |
27 Mar 09 |
nicklas |
67 |
{ |
4857 |
27 Mar 09 |
nicklas |
68 |
if (bas != null) |
4857 |
27 Mar 09 |
nicklas |
69 |
{ |
4857 |
27 Mar 09 |
nicklas |
70 |
Map<Number, String> bioAssayMap = new HashMap<Number, String>(); |
4857 |
27 Mar 09 |
nicklas |
71 |
for (BioAssay b : bas.getBioAssays().list(dc)) |
4857 |
27 Mar 09 |
nicklas |
72 |
{ |
4857 |
27 Mar 09 |
nicklas |
73 |
short columnNo = b.getDataCubeColumnNo(); |
4857 |
27 Mar 09 |
nicklas |
74 |
String name = b.getName(); |
4857 |
27 Mar 09 |
nicklas |
75 |
// Safety measure, since JDBC driver seems to return 'short' as 'int' |
4857 |
27 Mar 09 |
nicklas |
76 |
bioAssayMap.put(columnNo, name); |
4857 |
27 Mar 09 |
nicklas |
77 |
bioAssayMap.put((int)columnNo, name); |
4857 |
27 Mar 09 |
nicklas |
78 |
} |
7604 |
25 Feb 19 |
nicklas |
79 |
cc.setObject("export.formatter.COLUMN", new LookupFormatter<>(bioAssayMap)); |
4857 |
27 Mar 09 |
nicklas |
80 |
} |
4857 |
27 Mar 09 |
nicklas |
81 |
} |
2102 |
22 Mar 06 |
nicklas |
82 |
%> |
2102 |
22 Mar 06 |
nicklas |
83 |
<% |
2102 |
22 Mar 06 |
nicklas |
84 |
final int bioAssayId = Values.getInt(request.getParameter("bioassay_id")); |
2678 |
28 Sep 06 |
nicklas |
85 |
final int bioAssaySetId = Values.getInt(request.getParameter("bioassayset_id")); |
2102 |
22 Mar 06 |
nicklas |
86 |
|
2102 |
22 Mar 06 |
nicklas |
87 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
2102 |
22 Mar 06 |
nicklas |
88 |
final String ID = sc.getId(); |
2102 |
22 Mar 06 |
nicklas |
89 |
final String cmd = request.getParameter("cmd"); |
2102 |
22 Mar 06 |
nicklas |
90 |
final String root = request.getContextPath()+"/"; |
2102 |
22 Mar 06 |
nicklas |
91 |
final String mode = request.getParameter("mode"); |
2102 |
22 Mar 06 |
nicklas |
92 |
final String callback = request.getParameter("callback"); |
2102 |
22 Mar 06 |
nicklas |
93 |
final String itemId = request.getParameter("item_id"); |
2678 |
28 Sep 06 |
nicklas |
94 |
final String listPage = "list_spotdata.jsp?ID="+ID |
2678 |
28 Sep 06 |
nicklas |
95 |
+"&bioassay_id="+bioAssayId+"&bioassayset_id="+bioAssaySetId |
2102 |
22 Mar 06 |
nicklas |
96 |
+(mode == null ? "" : "&mode="+mode) |
2102 |
22 Mar 06 |
nicklas |
97 |
+(callback == null ? "" : "&callback="+callback) |
2102 |
22 Mar 06 |
nicklas |
98 |
+(itemId == null ? "" : "&item_id="+itemId); |
2102 |
22 Mar 06 |
nicklas |
99 |
|
2102 |
22 Mar 06 |
nicklas |
100 |
String forward = null; |
2102 |
22 Mar 06 |
nicklas |
101 |
String redirect = null; |
2102 |
22 Mar 06 |
nicklas |
102 |
String message = null; |
2102 |
22 Mar 06 |
nicklas |
103 |
DbControl dc = null; |
2102 |
22 Mar 06 |
nicklas |
104 |
|
2102 |
22 Mar 06 |
nicklas |
105 |
try |
2102 |
22 Mar 06 |
nicklas |
106 |
{ |
7954 |
12 May 21 |
nicklas |
107 |
dc = sc.newDbControl(":Load bioassays"); |
2678 |
28 Sep 06 |
nicklas |
108 |
final BioAssay ba = bioAssayId == 0 ? null : BioAssay.getById(dc, bioAssayId); |
2678 |
28 Sep 06 |
nicklas |
109 |
final BioAssaySet bas = ba != null ? ba.getBioAssaySet() : BioAssaySet.getById(dc, bioAssaySetId); |
2174 |
21 Apr 06 |
nicklas |
110 |
dc.close(); |
2678 |
28 Sep 06 |
nicklas |
111 |
final RawDataType rawDataType = bas.getRawDataType(); |
2174 |
21 Apr 06 |
nicklas |
112 |
final ItemContext defaultContext = defaultContexts.get(rawDataType); |
2174 |
21 Apr 06 |
nicklas |
113 |
final String subContext = rawDataType.getId(); |
2102 |
22 Mar 06 |
nicklas |
114 |
|
2102 |
22 Mar 06 |
nicklas |
115 |
if (cmd == null || "List".equals(cmd)) |
2102 |
22 Mar 06 |
nicklas |
116 |
{ |
2102 |
22 Mar 06 |
nicklas |
117 |
// Display the list page without updatinging the current context |
2102 |
22 Mar 06 |
nicklas |
118 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, defaultContext); |
2102 |
22 Mar 06 |
nicklas |
119 |
redirect = listPage; |
2102 |
22 Mar 06 |
nicklas |
120 |
} |
2102 |
22 Mar 06 |
nicklas |
121 |
else if ("UpdateContext".equals(cmd)) |
2102 |
22 Mar 06 |
nicklas |
122 |
{ |
2102 |
22 Mar 06 |
nicklas |
123 |
// Display the list page after updating the current context from the request parameters |
2102 |
22 Mar 06 |
nicklas |
124 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
2102 |
22 Mar 06 |
nicklas |
125 |
redirect = listPage; |
2102 |
22 Mar 06 |
nicklas |
126 |
} |
2102 |
22 Mar 06 |
nicklas |
127 |
else if ("LoadContext".equals(cmd)) |
2102 |
22 Mar 06 |
nicklas |
128 |
{ |
2102 |
22 Mar 06 |
nicklas |
129 |
// Display the list page after loading a saved context |
2102 |
22 Mar 06 |
nicklas |
130 |
int contextId = Values.getInt(request.getParameter("context")); |
2102 |
22 Mar 06 |
nicklas |
131 |
Base.loadContext(sc, contextId, defaultContext); |
2102 |
22 Mar 06 |
nicklas |
132 |
redirect = listPage; |
2102 |
22 Mar 06 |
nicklas |
133 |
} |
2102 |
22 Mar 06 |
nicklas |
134 |
else if ("ExportItems".equals(cmd)) |
2102 |
22 Mar 06 |
nicklas |
135 |
{ |
2102 |
22 Mar 06 |
nicklas |
136 |
// Run an export plugin in a list context |
4951 |
27 May 09 |
nicklas |
137 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
7954 |
12 May 21 |
nicklas |
138 |
dc = sc.newDbControl(":Export "+itemType); |
5060 |
19 Aug 09 |
nicklas |
139 |
if (bas != null) dc.reattachItem(bas, false); |
5060 |
19 Aug 09 |
nicklas |
140 |
if (ba != null) dc.reattachItem(ba, false); |
7603 |
22 Feb 19 |
nicklas |
141 |
final SqlQuery query = ba != null ? ba.getSpotData() : bas.getSpotData(); |
4857 |
27 Mar 09 |
nicklas |
142 |
registerExportFormatters(dc, cc, bas, ba); |
2102 |
22 Mar 06 |
nicklas |
143 |
dc.close(); |
2102 |
22 Mar 06 |
nicklas |
144 |
cc.setQuery(query); |
4951 |
27 May 09 |
nicklas |
145 |
redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&subcontext="+subContext+"&context_type=LIST&title=Export+spot+data"; |
2102 |
22 Mar 06 |
nicklas |
146 |
} |
4306 |
21 May 08 |
nicklas |
147 |
else if ("CreateReporterList".equals(cmd)) |
4306 |
21 May 08 |
nicklas |
148 |
{ |
4306 |
21 May 08 |
nicklas |
149 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
7954 |
12 May 21 |
nicklas |
150 |
dc = sc.newDbControl(":Create reporter list"); |
5060 |
19 Aug 09 |
nicklas |
151 |
if (bas != null) dc.reattachItem(bas, false); |
5060 |
19 Aug 09 |
nicklas |
152 |
if (ba != null) dc.reattachItem(ba, false); |
7603 |
22 Feb 19 |
nicklas |
153 |
final SqlQuery query = ba != null ? ba.getSpotData() : bas.getSpotData(); |
4306 |
21 May 08 |
nicklas |
154 |
cc.configureQuery(dc, query, Collections.singletonList("@id")); |
5590 |
16 Mar 11 |
nicklas |
155 |
dc.close(); |
4306 |
21 May 08 |
nicklas |
156 |
cc.setQuery(query); |
4306 |
21 May 08 |
nicklas |
157 |
redirect = "../../../views/reporterlists/index.jsp?ID="+ID+ |
4455 |
05 Sep 08 |
martin |
158 |
"&cmd=NewItem&addReporters=1&formId=spotdata&fromContext=SPOTDATA&subContext=" + subContext + |
4306 |
21 May 08 |
nicklas |
159 |
"&name=" + HTML.urlEncode(ba != null ? ba.getName() : bas.getName()); |
4306 |
21 May 08 |
nicklas |
160 |
} |
4306 |
21 May 08 |
nicklas |
161 |
|
2102 |
22 Mar 06 |
nicklas |
162 |
else |
2102 |
22 Mar 06 |
nicklas |
163 |
{ |
2102 |
22 Mar 06 |
nicklas |
164 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
2102 |
22 Mar 06 |
nicklas |
165 |
} |
2102 |
22 Mar 06 |
nicklas |
166 |
} |
2102 |
22 Mar 06 |
nicklas |
167 |
finally |
2102 |
22 Mar 06 |
nicklas |
168 |
{ |
2102 |
22 Mar 06 |
nicklas |
169 |
if (dc != null) dc.close(); |
2102 |
22 Mar 06 |
nicklas |
170 |
} |
2102 |
22 Mar 06 |
nicklas |
171 |
|
2102 |
22 Mar 06 |
nicklas |
172 |
if (forward != null) |
2102 |
22 Mar 06 |
nicklas |
173 |
{ |
6192 |
31 Oct 12 |
nicklas |
174 |
sc.setSessionSetting("alert-message", message); |
2102 |
22 Mar 06 |
nicklas |
175 |
pageContext.forward(forward); |
2102 |
22 Mar 06 |
nicklas |
176 |
} |
2102 |
22 Mar 06 |
nicklas |
177 |
else if (redirect != null) |
2102 |
22 Mar 06 |
nicklas |
178 |
{ |
6192 |
31 Oct 12 |
nicklas |
179 |
sc.setSessionSetting("alert-message", message); |
2102 |
22 Mar 06 |
nicklas |
180 |
response.sendRedirect(redirect); |
2102 |
22 Mar 06 |
nicklas |
181 |
} |
2102 |
22 Mar 06 |
nicklas |
182 |
else if (message == null) |
2102 |
22 Mar 06 |
nicklas |
183 |
{ |
2102 |
22 Mar 06 |
nicklas |
184 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
2102 |
22 Mar 06 |
nicklas |
185 |
} |
2102 |
22 Mar 06 |
nicklas |
186 |
else |
2102 |
22 Mar 06 |
nicklas |
187 |
{ |
2102 |
22 Mar 06 |
nicklas |
188 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
2102 |
22 Mar 06 |
nicklas |
189 |
} |
2102 |
22 Mar 06 |
nicklas |
190 |
%> |
2102 |
22 Mar 06 |
nicklas |
191 |
|