1 | <%-- $Id: index.jsp 5662 2011-06-20 11:55:13Z 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 import="net.sf.basedb.core.BioMaterialEventSource"%> |
---|
25 | <%@ page pageEncoding="UTF-8" session="false" |
---|
26 | import="net.sf.basedb.core.SessionControl" |
---|
27 | import="net.sf.basedb.core.BioMaterial" |
---|
28 | import="net.sf.basedb.core.BioMaterialEvent" |
---|
29 | import="net.sf.basedb.core.BioPlate" |
---|
30 | import="net.sf.basedb.core.BioPlateType" |
---|
31 | import="net.sf.basedb.core.BioPlateEvent" |
---|
32 | import="net.sf.basedb.core.BioPlateEventType" |
---|
33 | import="net.sf.basedb.core.BioPlateEventParticipant" |
---|
34 | import="net.sf.basedb.core.BioWell" |
---|
35 | import="net.sf.basedb.core.PhysicalBioAssay" |
---|
36 | import="net.sf.basedb.core.DbControl" |
---|
37 | import="net.sf.basedb.core.Item" |
---|
38 | import="net.sf.basedb.core.ItemContext" |
---|
39 | import="net.sf.basedb.core.MeasuredBioMaterial" |
---|
40 | import="net.sf.basedb.core.Hardware" |
---|
41 | import="net.sf.basedb.core.Protocol" |
---|
42 | import="net.sf.basedb.core.Sample" |
---|
43 | import="net.sf.basedb.core.Extract" |
---|
44 | import="net.sf.basedb.core.Tag" |
---|
45 | import="net.sf.basedb.core.PlateGeometry" |
---|
46 | import="net.sf.basedb.core.InvalidDataException" |
---|
47 | import="net.sf.basedb.clients.web.Base" |
---|
48 | import="net.sf.basedb.clients.web.WebException" |
---|
49 | import="net.sf.basedb.util.Values" |
---|
50 | import="net.sf.basedb.util.formatter.Formatter" |
---|
51 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
52 | import="net.sf.basedb.clients.web.formatter.FormatterSettings" |
---|
53 | import="net.sf.basedb.clients.web.util.HTML" |
---|
54 | import="java.util.Set" |
---|
55 | import="java.util.Date" |
---|
56 | %> |
---|
57 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
58 | <% |
---|
59 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
60 | final String ID = sc.getId(); |
---|
61 | final String cmd = request.getParameter("cmd"); |
---|
62 | final String root = request.getContextPath()+"/"; |
---|
63 | final String mode = request.getParameter("mode"); |
---|
64 | final String callback = request.getParameter("callback"); |
---|
65 | String forward = null; |
---|
66 | String redirect = null; |
---|
67 | String message = null; |
---|
68 | DbControl dc = null; |
---|
69 | |
---|
70 | try |
---|
71 | { |
---|
72 | if ("PlaceOnPlate".equals(cmd)) |
---|
73 | { |
---|
74 | dc = sc.newDbControl(); |
---|
75 | Item bioMaterialType = Item.valueOf(request.getParameter("itemType")); |
---|
76 | String subContext = Values.getString(request.getParameter("subcontext"), ""); |
---|
77 | ItemContext cc = sc.getCurrentContext(Item.BIOPLATEEVENT, BioPlateEventType.PLACE_ON_PLATE); |
---|
78 | final int maxRecent = Base.getMaxRecent(sc); |
---|
79 | |
---|
80 | sc.setUserClientSetting("place-on-plate.auto-select-unmapped-item", |
---|
81 | Values.getBoolean(request.getParameter("autoSelectUnmappedItem")) ? "1" : "0"); |
---|
82 | BioPlate plate = BioPlate.getById(dc, Values.getInt(request.getParameter("plate_id"))); |
---|
83 | int rows = Values.getInt(request.getParameter("rows")); |
---|
84 | int columns = Values.getInt(request.getParameter("columns")); |
---|
85 | |
---|
86 | BioPlateEventType placeOnPlate = BioPlateEventType.getById(dc, BioPlateEventType.PLACE_ON_PLATE); |
---|
87 | BioPlateEvent event = BioPlateEvent.getNew(dc, placeOnPlate); |
---|
88 | BioPlateEventParticipant destination = event.addParticipant(plate, "destination", 1); |
---|
89 | |
---|
90 | event.setName(Values.getStringOrNull(request.getParameter("name"))); |
---|
91 | event.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
---|
92 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
93 | event.setEventDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("event_date")))); |
---|
94 | int protocolId = Values.getInt(request.getParameter("protocol_id")); |
---|
95 | if (protocolId > 0) |
---|
96 | { |
---|
97 | Protocol pt = Protocol.getById(dc, protocolId); |
---|
98 | event.setProtocol(pt); |
---|
99 | cc.setRecent(pt, maxRecent); |
---|
100 | } |
---|
101 | int hardwareId = Values.getInt(request.getParameter("hardware_id")); |
---|
102 | if (hardwareId > 0) |
---|
103 | { |
---|
104 | Hardware hw = Hardware.getById(dc, hardwareId); |
---|
105 | event.setHardware(hw); |
---|
106 | cc.setRecent(hw, maxRecent); |
---|
107 | } |
---|
108 | dc.saveItem(event); |
---|
109 | |
---|
110 | int numPlaced = 0; |
---|
111 | for (int row = 0; row < rows; ++row) |
---|
112 | { |
---|
113 | for (int column = 0; column < columns; ++column) |
---|
114 | { |
---|
115 | int bioMaterialId = Values.getInt(request.getParameter("well." + row + "." + column)); |
---|
116 | if (bioMaterialId > 0) |
---|
117 | { |
---|
118 | MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId); |
---|
119 | BioWell well = plate.getBioWell(row, column); |
---|
120 | bioMaterial.setBioWell(well); |
---|
121 | BioMaterialEvent bmEvent = bioMaterial.newEvent(destination); |
---|
122 | bmEvent.setComment("Well: " + well.getCoordinate()); |
---|
123 | dc.saveItem(bmEvent); |
---|
124 | numPlaced++; |
---|
125 | } |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | dc.commit(); |
---|
130 | message = "Placed " + numPlaced + " items on plate " + plate.getName(); |
---|
131 | } |
---|
132 | else if ("MoveBioMaterial".equals(cmd)) |
---|
133 | { |
---|
134 | dc = sc.newDbControl(); |
---|
135 | ItemContext cc = sc.getCurrentContext(Item.BIOPLATEEVENT, BioPlateEventType.MOVE); |
---|
136 | final int maxRecent = Base.getMaxRecent(sc); |
---|
137 | sc.setUserClientSetting("move-biomaterial.show-source-coordinates", |
---|
138 | Values.getBoolean(request.getParameter("showSourceCoordinates")) ? "1" : "0"); |
---|
139 | |
---|
140 | BioPlate sourcePlate = BioPlate.getById(dc, Values.getInt(request.getParameter("sourceplate_id"))); |
---|
141 | BioPlate destPlate = BioPlate.getById(dc, Values.getInt(request.getParameter("destplate_id"))); |
---|
142 | int rows = Values.getInt(request.getParameter("rows")); |
---|
143 | int columns = Values.getInt(request.getParameter("columns")); |
---|
144 | |
---|
145 | BioPlateEventType moveBioMaterial = BioPlateEventType.getById(dc, BioPlateEventType.MOVE); |
---|
146 | BioPlateEvent event = BioPlateEvent.getNew(dc, moveBioMaterial); |
---|
147 | BioPlateEventParticipant destination = event.addParticipant(destPlate, "destination", 1); |
---|
148 | BioPlateEventParticipant source = event.addParticipant(sourcePlate, "source", 1); |
---|
149 | |
---|
150 | event.setName(Values.getStringOrNull(request.getParameter("name"))); |
---|
151 | event.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
---|
152 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
153 | event.setEventDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("event_date")))); |
---|
154 | int protocolId = Values.getInt(request.getParameter("protocol_id")); |
---|
155 | if (protocolId > 0) |
---|
156 | { |
---|
157 | Protocol pt = Protocol.getById(dc, protocolId); |
---|
158 | event.setProtocol(pt); |
---|
159 | cc.setRecent(pt, maxRecent); |
---|
160 | } |
---|
161 | int hardwareId = Values.getInt(request.getParameter("hardware_id")); |
---|
162 | if (hardwareId > 0) |
---|
163 | { |
---|
164 | Hardware hw = Hardware.getById(dc, hardwareId); |
---|
165 | event.setHardware(hw); |
---|
166 | cc.setRecent(hw, maxRecent); |
---|
167 | } |
---|
168 | dc.saveItem(event); |
---|
169 | |
---|
170 | int numMoved = 0; |
---|
171 | for (int row = 0; row < rows; ++row) |
---|
172 | { |
---|
173 | for (int column = 0; column < columns; ++column) |
---|
174 | { |
---|
175 | int bioMaterialId = Values.getInt(request.getParameter("well." + row + "." + column)); |
---|
176 | if (bioMaterialId > 0) |
---|
177 | { |
---|
178 | MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)BioMaterial.getById(dc, bioMaterialId); |
---|
179 | BioWell well = destPlate.getBioWell(row, column); |
---|
180 | bioMaterial.setBioWell(well); |
---|
181 | BioMaterialEvent bmEvent = bioMaterial.newEvent(destination); |
---|
182 | bmEvent.setComment("Well: " + well.getCoordinate()); |
---|
183 | dc.saveItem(bmEvent); |
---|
184 | numMoved++; |
---|
185 | } |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | dc.commit(); |
---|
190 | message = "Moved " + numMoved + " items to plate " + destPlate.getName(); |
---|
191 | } |
---|
192 | else if ("CreateChildPlate".equals(cmd)) |
---|
193 | { |
---|
194 | dc = sc.newDbControl(); |
---|
195 | ItemContext cc = sc.getCurrentContext(Item.BIOPLATEEVENT, BioPlateEventType.CREATE_BIOMATERIAL); |
---|
196 | final int maxRecent = Base.getMaxRecent(sc); |
---|
197 | sc.setUserClientSetting("create-child-plate.show-source-coordinates", |
---|
198 | Values.getBoolean(request.getParameter("showSourceCoordinates")) ? "1" : "0"); |
---|
199 | |
---|
200 | BioPlate sourcePlate = BioPlate.getById(dc, Values.getInt(request.getParameter("sourceplate_id"))); |
---|
201 | Item sourceBioMaterialType = sourcePlate.getBioPlateType().getBioMaterialType(); |
---|
202 | Item childBioMaterialType = Item.valueOf(request.getParameter("child_biomaterial_type")); |
---|
203 | boolean isBioAssayEvent = childBioMaterialType == Item.PHYSICALBIOASSAY; |
---|
204 | |
---|
205 | // The event object |
---|
206 | BioPlateEventType createBioMaterial = BioPlateEventType.getById(dc, |
---|
207 | isBioAssayEvent ? BioPlateEventType.PHYSICAL_BIOASSAY : BioPlateEventType.CREATE_BIOMATERIAL); |
---|
208 | BioPlateEvent event = BioPlateEvent.getNew(dc, createBioMaterial); |
---|
209 | event.setName(Values.getStringOrNull(request.getParameter("event_name"))); |
---|
210 | event.setDescription(Values.getStringOrNull(request.getParameter("event_description"))); |
---|
211 | BioPlateEventParticipant sourceParticipant = event.addParticipant(sourcePlate, "source", 1); |
---|
212 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
213 | event.setEventDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("event_date")))); |
---|
214 | int protocolId = Values.getInt(request.getParameter("protocol_id")); |
---|
215 | if (protocolId > 0) |
---|
216 | { |
---|
217 | Protocol pt = Protocol.getById(dc, protocolId); |
---|
218 | event.setProtocol(pt); |
---|
219 | cc.setRecent(pt, sourceBioMaterialType.name(), maxRecent); |
---|
220 | } |
---|
221 | int hardwareId = Values.getInt(request.getParameter("hardware_id")); |
---|
222 | if (hardwareId > 0) |
---|
223 | { |
---|
224 | Hardware hw = Hardware.getById(dc, hardwareId); |
---|
225 | event.setHardware(hw); |
---|
226 | cc.setRecent(hw, sourceBioMaterialType.name(), maxRecent); |
---|
227 | } |
---|
228 | dc.saveItem(event); |
---|
229 | |
---|
230 | // Child plates & biomaterial |
---|
231 | Hardware freezer = null; |
---|
232 | if (!isBioAssayEvent) |
---|
233 | { |
---|
234 | int freezerId = Values.getInt(request.getParameter("freezer_id")); |
---|
235 | if (freezerId > 0) |
---|
236 | { |
---|
237 | freezer = Hardware.getById(dc, freezerId); |
---|
238 | cc.setRecent(freezer, "freezer", maxRecent); |
---|
239 | } |
---|
240 | } |
---|
241 | int numChildPlates = Values.getInt(request.getParameter("number_of_plates")); |
---|
242 | int size = Values.getInt(request.getParameter("size")); |
---|
243 | PlateGeometry childGeometry = null; |
---|
244 | if (!isBioAssayEvent) |
---|
245 | { |
---|
246 | childGeometry = PlateGeometry.getById(dc, Values.getInt(request.getParameter("plategeometry_id"))); |
---|
247 | cc.setRecent(childGeometry, sourceBioMaterialType.name(), maxRecent); |
---|
248 | } |
---|
249 | int rows = isBioAssayEvent ? 1 : childGeometry.getRows(); |
---|
250 | int columns = isBioAssayEvent ? size : childGeometry.getColumns(); |
---|
251 | int numCreated = 0; |
---|
252 | BioPlateType childPlateType = null; |
---|
253 | if (!isBioAssayEvent) |
---|
254 | { |
---|
255 | childPlateType = BioPlateType.getById(dc, Values.getInt(request.getParameter("bioplatetype_id"))); |
---|
256 | cc.setRecent(childPlateType, sourceBioMaterialType.name(), maxRecent); |
---|
257 | } |
---|
258 | Float usedQuantity = Values.getFloat(request.getParameter("used_quantity")); |
---|
259 | Float originalQuantity = Values.getFloat(request.getParameter("original_quantity")); |
---|
260 | for (int plateNo = 0; plateNo < numChildPlates; ++plateNo) |
---|
261 | { |
---|
262 | PhysicalBioAssay pba = null; |
---|
263 | BioMaterialEvent pbaCreationEvent = null; |
---|
264 | BioPlate childPlate = null; |
---|
265 | BioPlateEventParticipant destParticipant = null; |
---|
266 | if (isBioAssayEvent) |
---|
267 | { |
---|
268 | pba = PhysicalBioAssay.getNew(dc, sourceParticipant); |
---|
269 | pba.setName(Values.getStringOrNull(request.getParameter("plate." + plateNo + ".name"))); |
---|
270 | pba.setDescription(Values.getStringOrNull(request.getParameter("plate_description"))); |
---|
271 | pba.setSize(size); |
---|
272 | dc.saveItem(pba); |
---|
273 | pbaCreationEvent = pba.getCreationEvent(); |
---|
274 | } |
---|
275 | else |
---|
276 | { |
---|
277 | childPlate = BioPlate.getNew(dc, childGeometry, childPlateType); |
---|
278 | childPlate.setName(Values.getStringOrNull(request.getParameter("plate." + plateNo + ".name"))); |
---|
279 | childPlate.setDescription(Values.getStringOrNull(request.getParameter("plate_description"))); |
---|
280 | if (freezer != null) childPlate.setFreezer(freezer); |
---|
281 | childPlate.setBarcode(Values.getStringOrNull(request.getParameter("plate." + plateNo + ".barcode"))); |
---|
282 | dc.saveItem(childPlate); |
---|
283 | destParticipant = event.addParticipant(childPlate, "destination", plateNo); |
---|
284 | } |
---|
285 | for (int row = 0; row < rows; ++row) |
---|
286 | { |
---|
287 | for (int column = 0; column < columns; ++column) |
---|
288 | { |
---|
289 | String prefix = "well." + +plateNo + "." + row + "." + column; |
---|
290 | int bioMaterialId = Values.getInt(request.getParameter(prefix)); |
---|
291 | if (bioMaterialId > 0) |
---|
292 | { |
---|
293 | MeasuredBioMaterial parent = (MeasuredBioMaterial)sourceBioMaterialType.getById(dc, bioMaterialId); |
---|
294 | if (isBioAssayEvent) |
---|
295 | { |
---|
296 | BioMaterialEventSource evtSrc = pbaCreationEvent.addSource(parent); |
---|
297 | evtSrc.setUsedQuantity(usedQuantity); |
---|
298 | evtSrc.setPosition(column+1); |
---|
299 | } |
---|
300 | else |
---|
301 | { |
---|
302 | BioWell well = childPlate.getBioWell(row, column); |
---|
303 | MeasuredBioMaterial child = null; |
---|
304 | boolean pooled = childBioMaterialType == sourceBioMaterialType; |
---|
305 | if (childBioMaterialType == Item.SAMPLE) |
---|
306 | { |
---|
307 | child = Sample.getNew(dc, destParticipant); |
---|
308 | } |
---|
309 | else if (childBioMaterialType == Item.EXTRACT) |
---|
310 | { |
---|
311 | child = Extract.getNew(dc, destParticipant); |
---|
312 | if (!pooled) ((Extract)child).setSample((Sample)parent).setUsedQuantity(usedQuantity); |
---|
313 | } |
---|
314 | /* |
---|
315 | else if (childBioMaterialType == Item.LABELEDEXTRACT) |
---|
316 | { |
---|
317 | Label label = Label.getById(dc, Values.getInt(request.getParameter("label_id"))); |
---|
318 | child = LabeledExtract.getNew(dc, label, destParticipant); |
---|
319 | if (!pooled) ((LabeledExtract)child).setExtract((Extract)parent, usedQuantity); |
---|
320 | } |
---|
321 | */ |
---|
322 | else |
---|
323 | { |
---|
324 | throw new InvalidDataException("Can't create child biomaterial of type: " + childBioMaterialType); |
---|
325 | } |
---|
326 | child.setName(Values.getStringOrNull(request.getParameter(prefix + ".name"))); |
---|
327 | child.setDescription(Values.getStringOrNull(request.getParameter("child_description"))); |
---|
328 | child.setBioWell(well); |
---|
329 | child.setOriginalQuantity(originalQuantity); |
---|
330 | |
---|
331 | if (pooled) |
---|
332 | { |
---|
333 | child.getCreationEvent().addSource(parent).setUsedQuantity(usedQuantity); |
---|
334 | } |
---|
335 | dc.saveItem(child); |
---|
336 | } |
---|
337 | numCreated++; |
---|
338 | } |
---|
339 | } |
---|
340 | } |
---|
341 | |
---|
342 | } |
---|
343 | |
---|
344 | dc.commit(); |
---|
345 | if (isBioAssayEvent) |
---|
346 | { |
---|
347 | message = "Used " + numCreated + " items on " + numChildPlates + " physical bioassay(s)"; |
---|
348 | } |
---|
349 | else |
---|
350 | { |
---|
351 | message = "Created " + numCreated + " items on " + numChildPlates + " child plate(s)"; |
---|
352 | } |
---|
353 | } |
---|
354 | else |
---|
355 | { |
---|
356 | throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
---|
357 | } |
---|
358 | } |
---|
359 | finally |
---|
360 | { |
---|
361 | if (dc != null) dc.close(); |
---|
362 | } |
---|
363 | |
---|
364 | if (forward != null) |
---|
365 | { |
---|
366 | pageContext.forward(forward); |
---|
367 | } |
---|
368 | else if (redirect != null) |
---|
369 | { |
---|
370 | response.sendRedirect(redirect); |
---|
371 | } |
---|
372 | else if (message == null) |
---|
373 | { |
---|
374 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
---|
375 | } |
---|
376 | else |
---|
377 | { |
---|
378 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
---|
379 | } |
---|
380 | %> |
---|