1 | <%-- $Id: index.jsp 4305 2008-05-21 11:11:20Z nicklas $ |
---|
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 2 |
---|
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.ItemContext" |
---|
32 | import="net.sf.basedb.core.Plate" |
---|
33 | import="net.sf.basedb.core.Well" |
---|
34 | import="net.sf.basedb.core.ItemQuery" |
---|
35 | import="net.sf.basedb.core.DataQuery" |
---|
36 | import="net.sf.basedb.core.Permission" |
---|
37 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
38 | import="net.sf.basedb.core.data.ReporterData" |
---|
39 | import="net.sf.basedb.util.RemovableUtil" |
---|
40 | import="net.sf.basedb.clients.web.Base" |
---|
41 | import="net.sf.basedb.clients.web.WebException" |
---|
42 | import="net.sf.basedb.clients.web.util.HTML" |
---|
43 | import="net.sf.basedb.util.Values" |
---|
44 | import="java.util.List" |
---|
45 | import="java.util.Collections" |
---|
46 | %> |
---|
47 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
48 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
49 | <%! |
---|
50 | private static final ItemContext defaultContext = Base.createDefaultContext("row", "row,column,reporter.name,reporter.externalId"); |
---|
51 | private static final Item itemType = Item.WELL; |
---|
52 | %> |
---|
53 | <% |
---|
54 | final int plateId = Values.getInt(request.getParameter("plate_id")); |
---|
55 | |
---|
56 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
57 | final String ID = sc.getId(); |
---|
58 | final String cmd = request.getParameter("cmd"); |
---|
59 | final String root = request.getContextPath()+"/"; |
---|
60 | final String mode = request.getParameter("mode"); |
---|
61 | final String callback = request.getParameter("callback"); |
---|
62 | final String itemId = request.getParameter("item_id"); |
---|
63 | final String listPage = "list_wells.jsp?ID="+ID |
---|
64 | +"&plate_id="+plateId |
---|
65 | +(mode == null ? "" : "&mode="+mode) |
---|
66 | +(callback == null ? "" : "&callback="+callback) |
---|
67 | +(itemId == null ? "" : "&item_id="+itemId); |
---|
68 | final String viewPage = "view_well.jsp?ID="+ID+"&plate_id="+plateId; |
---|
69 | final String editPage = "edit_well.jsp?ID="+ID+"&plate_id="+plateId; |
---|
70 | |
---|
71 | String forward = null; |
---|
72 | String redirect = null; |
---|
73 | String message = null; |
---|
74 | DbControl dc = null; |
---|
75 | |
---|
76 | try |
---|
77 | { |
---|
78 | if (cmd == null || "List".equals(cmd)) |
---|
79 | { |
---|
80 | // Display the list page without updatinging the current context |
---|
81 | Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true); |
---|
82 | redirect = listPage; |
---|
83 | } |
---|
84 | else if ("UpdateContext".equals(cmd)) |
---|
85 | { |
---|
86 | // Display the list page after updating the current context from the request parameters |
---|
87 | Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
88 | redirect = listPage; |
---|
89 | } |
---|
90 | else if ("LoadContext".equals(cmd)) |
---|
91 | { |
---|
92 | // Display the list page after loading a saved context |
---|
93 | int contextId = Values.getInt(request.getParameter("context")); |
---|
94 | Base.loadContext(sc, contextId, defaultContext); |
---|
95 | redirect = listPage; |
---|
96 | } |
---|
97 | else if ("ViewItem".equals(cmd)) |
---|
98 | { |
---|
99 | // Display the view page for a single item |
---|
100 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
101 | forward = viewPage; |
---|
102 | } |
---|
103 | else if ("EditItem".equals(cmd)) |
---|
104 | { |
---|
105 | // Display the edit page for a single item (should be opened in a popup) |
---|
106 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
107 | redirect = editPage; |
---|
108 | } |
---|
109 | else if ("UpdateItem".equals(cmd)) |
---|
110 | { |
---|
111 | // Update the properties on an item (will close the popup) |
---|
112 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
---|
113 | dc = sc.newDbControl(); |
---|
114 | Well well = (Well)cc.getObject("item"); |
---|
115 | dc.reattachItem(well); |
---|
116 | message = "Well updated"; |
---|
117 | |
---|
118 | // Annotations tab |
---|
119 | Base.updateAnnotations(dc, well, well, request); |
---|
120 | |
---|
121 | dc.commit(); |
---|
122 | cc.removeObject("item"); |
---|
123 | } |
---|
124 | else if ("ExportItems".equals(cmd)) |
---|
125 | { |
---|
126 | // Run an export plugin in a list context |
---|
127 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
128 | dc = sc.newDbControl(); |
---|
129 | final Plate plate = Plate.getById(dc, plateId); |
---|
130 | dc.close(); |
---|
131 | final ItemQuery<Well> query = plate.getWells(); |
---|
132 | cc.configureQuery(query, true); |
---|
133 | cc.setQuery(query); |
---|
134 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+wells"; |
---|
135 | } |
---|
136 | else if ("ExportItem".equals(cmd)) |
---|
137 | { |
---|
138 | // Run an export plugin in single-item context |
---|
139 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
140 | redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+well"; |
---|
141 | } |
---|
142 | else if ("ImportItems".equals(cmd)) |
---|
143 | { |
---|
144 | // Run an import plugin in a list context |
---|
145 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
146 | dc = sc.newDbControl(); |
---|
147 | final Plate plate = Plate.getById(dc, plateId); |
---|
148 | dc.close(); |
---|
149 | final ItemQuery<Well> query = plate.getWells(); |
---|
150 | cc.configureQuery(query, true); |
---|
151 | cc.setQuery(query); |
---|
152 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+wells"; |
---|
153 | } |
---|
154 | else if ("ImportItem".equals(cmd)) |
---|
155 | { |
---|
156 | // Run an import plugin in single-item context |
---|
157 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
158 | redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+well"; |
---|
159 | } |
---|
160 | else if ("RunListPlugin".equals(cmd)) |
---|
161 | { |
---|
162 | // Run another plugin in a list context |
---|
163 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
164 | dc = sc.newDbControl(); |
---|
165 | final Plate plate = Plate.getById(dc, plateId); |
---|
166 | dc.close(); |
---|
167 | final ItemQuery<Well> query = plate.getWells(); |
---|
168 | cc.configureQuery(query, true); |
---|
169 | cc.setQuery(query); |
---|
170 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
---|
171 | } |
---|
172 | else if ("RunPlugin".equals(cmd)) |
---|
173 | { |
---|
174 | // Run another plugin in single-item context |
---|
175 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
176 | redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; |
---|
177 | } |
---|
178 | else if ("CreateReporterList".equals(cmd)) |
---|
179 | { |
---|
180 | ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
---|
181 | dc = sc.newDbControl(); |
---|
182 | final Plate plate = Plate.getById(dc, plateId); |
---|
183 | final DataQuery<ReporterData> query = plate.getReporters(); |
---|
184 | cc.configureQuery(query, true); |
---|
185 | cc.setQuery(query); |
---|
186 | redirect = "../../../views/reporterlists/index.jsp?ID="+ID+ |
---|
187 | "&cmd=NewItem&addReporters=1&formId=wells&fromContext=WELL"+ |
---|
188 | "&name=" + HTML.urlEncode(plate.getName()); |
---|
189 | } |
---|
190 | else |
---|
191 | { |
---|
192 | throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
---|
193 | } |
---|
194 | |
---|
195 | } |
---|
196 | finally |
---|
197 | { |
---|
198 | if (dc != null) dc.close(); |
---|
199 | } |
---|
200 | if (forward != null) |
---|
201 | { |
---|
202 | pageContext.forward(forward); |
---|
203 | } |
---|
204 | else if (redirect != null) |
---|
205 | { |
---|
206 | response.sendRedirect(redirect); |
---|
207 | } |
---|
208 | else if (message == null) |
---|
209 | { |
---|
210 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
---|
211 | } |
---|
212 | else |
---|
213 | { |
---|
214 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
---|
215 | } |
---|
216 | |
---|
217 | %> |
---|