1 | <%-- $Id: index.jsp 5541 2011-01-17 10:00:42Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2010 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 | --%> |
---|
24 | <%@ page pageEncoding="UTF-8" session="false" |
---|
25 | import="net.sf.basedb.core.SessionControl" |
---|
26 | import="net.sf.basedb.core.BioMaterial" |
---|
27 | import="net.sf.basedb.core.BioMaterialEvent" |
---|
28 | import="net.sf.basedb.core.BioPlate" |
---|
29 | import="net.sf.basedb.core.BioPlateEvent" |
---|
30 | import="net.sf.basedb.core.BioPlateEventType" |
---|
31 | import="net.sf.basedb.core.BioPlateEventParticipant" |
---|
32 | import="net.sf.basedb.core.BioWell" |
---|
33 | import="net.sf.basedb.core.DbControl" |
---|
34 | import="net.sf.basedb.core.Item" |
---|
35 | import="net.sf.basedb.core.ItemContext" |
---|
36 | import="net.sf.basedb.core.MeasuredBioMaterial" |
---|
37 | import="net.sf.basedb.core.Hardware" |
---|
38 | import="net.sf.basedb.core.Protocol" |
---|
39 | import="net.sf.basedb.core.PlateGeometry" |
---|
40 | import="net.sf.basedb.clients.web.Base" |
---|
41 | import="net.sf.basedb.clients.web.WebException" |
---|
42 | import="net.sf.basedb.util.Values" |
---|
43 | import="net.sf.basedb.util.formatter.Formatter" |
---|
44 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
45 | import="net.sf.basedb.clients.web.formatter.FormatterSettings" |
---|
46 | import="net.sf.basedb.clients.web.util.HTML" |
---|
47 | import="java.util.Set" |
---|
48 | import="java.util.Date" |
---|
49 | %> |
---|
50 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
51 | <% |
---|
52 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
53 | final String ID = sc.getId(); |
---|
54 | final String cmd = request.getParameter("cmd"); |
---|
55 | final String root = request.getContextPath()+"/"; |
---|
56 | final String mode = request.getParameter("mode"); |
---|
57 | final String callback = request.getParameter("callback"); |
---|
58 | String forward = null; |
---|
59 | String redirect = null; |
---|
60 | String message = null; |
---|
61 | DbControl dc = null; |
---|
62 | |
---|
63 | try |
---|
64 | { |
---|
65 | if ("PlaceOnPlate".equals(cmd)) |
---|
66 | { |
---|
67 | dc = sc.newDbControl(); |
---|
68 | Item bioMaterialType = Item.valueOf(request.getParameter("itemType")); |
---|
69 | String subContext = Values.getString(request.getParameter("subcontext"), ""); |
---|
70 | ItemContext cc = sc.getCurrentContext(Item.BIOPLATEEVENT, BioPlateEventType.PLACE_ON_PLATE); |
---|
71 | final int maxRecent = Base.getMaxRecent(sc); |
---|
72 | |
---|
73 | sc.setUserClientSetting("place-on-plate.auto-select-unmapped-item", |
---|
74 | Values.getBoolean(request.getParameter("autoSelectUnmappedItem")) ? "1" : "0"); |
---|
75 | BioPlate plate = BioPlate.getById(dc, Values.getInt(request.getParameter("plate_id"))); |
---|
76 | int rows = Values.getInt(request.getParameter("rows")); |
---|
77 | int columns = Values.getInt(request.getParameter("columns")); |
---|
78 | |
---|
79 | BioPlateEventType placeOnPlate = BioPlateEventType.getById(dc, BioPlateEventType.PLACE_ON_PLATE); |
---|
80 | BioPlateEvent event = BioPlateEvent.getNew(dc, placeOnPlate); |
---|
81 | BioPlateEventParticipant destination = event.addParticipant(plate, "destination", 1); |
---|
82 | |
---|
83 | event.setName(Values.getStringOrNull(request.getParameter("name"))); |
---|
84 | event.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
---|
85 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
86 | event.setEventDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("event_date")))); |
---|
87 | int protocolId = Values.getInt(request.getParameter("protocol_id")); |
---|
88 | if (protocolId > 0) |
---|
89 | { |
---|
90 | Protocol pt = Protocol.getById(dc, protocolId); |
---|
91 | event.setProtocol(pt); |
---|
92 | cc.setRecent(pt, maxRecent); |
---|
93 | } |
---|
94 | int hardwareId = Values.getInt(request.getParameter("hardware_id")); |
---|
95 | if (hardwareId > 0) |
---|
96 | { |
---|
97 | Hardware hw = Hardware.getById(dc, hardwareId); |
---|
98 | event.setHardware(hw); |
---|
99 | cc.setRecent(hw, maxRecent); |
---|
100 | } |
---|
101 | dc.saveItem(event); |
---|
102 | |
---|
103 | int numPlaced = 0; |
---|
104 | for (int row = 0; row < rows; ++row) |
---|
105 | { |
---|
106 | for (int column = 0; column < columns; ++column) |
---|
107 | { |
---|
108 | int bioMaterialId = Values.getInt(request.getParameter("well." + row + "." + column)); |
---|
109 | if (bioMaterialId > 0) |
---|
110 | { |
---|
111 | MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId); |
---|
112 | BioWell well = plate.getBioWell(row, column); |
---|
113 | bioMaterial.setBioWell(well); |
---|
114 | BioMaterialEvent bmEvent = bioMaterial.newEvent(destination); |
---|
115 | bmEvent.setComment("Well: " + well.getCoordinate()); |
---|
116 | dc.saveItem(bmEvent); |
---|
117 | numPlaced++; |
---|
118 | } |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | dc.commit(); |
---|
123 | message = "Placed " + numPlaced + " items on plate " + plate.getName(); |
---|
124 | } |
---|
125 | else if ("MoveBioMaterial".equals(cmd)) |
---|
126 | { |
---|
127 | dc = sc.newDbControl(); |
---|
128 | ItemContext cc = sc.getCurrentContext(Item.BIOPLATEEVENT, BioPlateEventType.MOVE); |
---|
129 | final int maxRecent = Base.getMaxRecent(sc); |
---|
130 | sc.setUserClientSetting("move-biomaterial.show-source-coordinates", |
---|
131 | Values.getBoolean(request.getParameter("showSourceCoordinates")) ? "1" : "0"); |
---|
132 | |
---|
133 | BioPlate sourcePlate = BioPlate.getById(dc, Values.getInt(request.getParameter("sourceplate_id"))); |
---|
134 | BioPlate destPlate = BioPlate.getById(dc, Values.getInt(request.getParameter("destplate_id"))); |
---|
135 | int rows = Values.getInt(request.getParameter("rows")); |
---|
136 | int columns = Values.getInt(request.getParameter("columns")); |
---|
137 | |
---|
138 | BioPlateEventType moveBioMaterial = BioPlateEventType.getById(dc, BioPlateEventType.MOVE); |
---|
139 | BioPlateEvent event = BioPlateEvent.getNew(dc, moveBioMaterial); |
---|
140 | BioPlateEventParticipant destination = event.addParticipant(destPlate, "destination", 1); |
---|
141 | BioPlateEventParticipant source = event.addParticipant(sourcePlate, "source", 1); |
---|
142 | |
---|
143 | event.setName(Values.getStringOrNull(request.getParameter("name"))); |
---|
144 | event.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
---|
145 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
146 | event.setEventDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("event_date")))); |
---|
147 | int protocolId = Values.getInt(request.getParameter("protocol_id")); |
---|
148 | if (protocolId > 0) |
---|
149 | { |
---|
150 | Protocol pt = Protocol.getById(dc, protocolId); |
---|
151 | event.setProtocol(pt); |
---|
152 | cc.setRecent(pt, maxRecent); |
---|
153 | } |
---|
154 | int hardwareId = Values.getInt(request.getParameter("hardware_id")); |
---|
155 | if (hardwareId > 0) |
---|
156 | { |
---|
157 | Hardware hw = Hardware.getById(dc, hardwareId); |
---|
158 | event.setHardware(hw); |
---|
159 | cc.setRecent(hw, maxRecent); |
---|
160 | } |
---|
161 | dc.saveItem(event); |
---|
162 | |
---|
163 | int numMoved = 0; |
---|
164 | for (int row = 0; row < rows; ++row) |
---|
165 | { |
---|
166 | for (int column = 0; column < columns; ++column) |
---|
167 | { |
---|
168 | int bioMaterialId = Values.getInt(request.getParameter("well." + row + "." + column)); |
---|
169 | if (bioMaterialId > 0) |
---|
170 | { |
---|
171 | MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)BioMaterial.getById(dc, bioMaterialId); |
---|
172 | BioWell well = destPlate.getBioWell(row, column); |
---|
173 | bioMaterial.setBioWell(well); |
---|
174 | BioMaterialEvent bmEvent = bioMaterial.newEvent(destination); |
---|
175 | bmEvent.setComment("Well: " + well.getCoordinate()); |
---|
176 | dc.saveItem(bmEvent); |
---|
177 | numMoved++; |
---|
178 | } |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|
182 | dc.commit(); |
---|
183 | message = "Moved " + numMoved + " items to plate " + destPlate.getName(); |
---|
184 | } |
---|
185 | else |
---|
186 | { |
---|
187 | throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
---|
188 | } |
---|
189 | } |
---|
190 | finally |
---|
191 | { |
---|
192 | if (dc != null) dc.close(); |
---|
193 | } |
---|
194 | |
---|
195 | if (forward != null) |
---|
196 | { |
---|
197 | pageContext.forward(forward); |
---|
198 | } |
---|
199 | else if (redirect != null) |
---|
200 | { |
---|
201 | response.sendRedirect(redirect); |
---|
202 | } |
---|
203 | else if (message == null) |
---|
204 | { |
---|
205 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
---|
206 | } |
---|
207 | else |
---|
208 | { |
---|
209 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
---|
210 | } |
---|
211 | %> |
---|