5527 |
13 Dec 10 |
nicklas |
1 |
<%-- $Id$ |
5527 |
13 Dec 10 |
nicklas |
2 |
------------------------------------------------------------------ |
5527 |
13 Dec 10 |
nicklas |
Copyright (C) 2010 Nicklas Nordborg |
5527 |
13 Dec 10 |
nicklas |
4 |
|
5527 |
13 Dec 10 |
nicklas |
5 |
This file is part of BASE - BioArray Software Environment. |
5527 |
13 Dec 10 |
nicklas |
6 |
Available at http://base.thep.lu.se/ |
5527 |
13 Dec 10 |
nicklas |
7 |
|
5527 |
13 Dec 10 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or |
5527 |
13 Dec 10 |
nicklas |
9 |
modify it under the terms of the GNU General Public License |
5527 |
13 Dec 10 |
nicklas |
10 |
as published by the Free Software Foundation; either version 3 |
5527 |
13 Dec 10 |
nicklas |
11 |
of the License, or (at your option) any later version. |
5527 |
13 Dec 10 |
nicklas |
12 |
|
5527 |
13 Dec 10 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, |
5527 |
13 Dec 10 |
nicklas |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5527 |
13 Dec 10 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5527 |
13 Dec 10 |
nicklas |
16 |
GNU General Public License for more details. |
5527 |
13 Dec 10 |
nicklas |
17 |
|
5527 |
13 Dec 10 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
5527 |
13 Dec 10 |
nicklas |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5527 |
13 Dec 10 |
nicklas |
20 |
------------------------------------------------------------------ |
5527 |
13 Dec 10 |
nicklas |
21 |
|
5527 |
13 Dec 10 |
nicklas |
22 |
@author Nicklas |
5527 |
13 Dec 10 |
nicklas |
23 |
--%> |
5557 |
28 Jan 11 |
nicklas |
24 |
<%@ page pageEncoding="UTF-8" session="false" contentType="application/json" |
5527 |
13 Dec 10 |
nicklas |
25 |
import="net.sf.basedb.core.BioPlate" |
5527 |
13 Dec 10 |
nicklas |
26 |
import="net.sf.basedb.core.BioWell" |
5527 |
13 Dec 10 |
nicklas |
27 |
import="net.sf.basedb.core.DbControl" |
5527 |
13 Dec 10 |
nicklas |
28 |
import="net.sf.basedb.core.MeasuredBioMaterial" |
5527 |
13 Dec 10 |
nicklas |
29 |
import="net.sf.basedb.core.PlateGeometry" |
5527 |
13 Dec 10 |
nicklas |
30 |
import="net.sf.basedb.core.SessionControl" |
5527 |
13 Dec 10 |
nicklas |
31 |
import="net.sf.basedb.util.Values" |
5527 |
13 Dec 10 |
nicklas |
32 |
import="net.sf.basedb.util.error.ThrowableUtil" |
5527 |
13 Dec 10 |
nicklas |
33 |
import="net.sf.basedb.clients.web.Base" |
5527 |
13 Dec 10 |
nicklas |
34 |
import="net.sf.basedb.clients.web.WebException" |
5557 |
28 Jan 11 |
nicklas |
35 |
import="org.json.simple.JSONObject" |
5557 |
28 Jan 11 |
nicklas |
36 |
import="org.json.simple.JSONArray" |
5527 |
13 Dec 10 |
nicklas |
37 |
%> |
5527 |
13 Dec 10 |
nicklas |
38 |
<% |
6124 |
13 Sep 12 |
nicklas |
39 |
response.setHeader("Cache-Control", "no-cache, max-age=0"); |
5527 |
13 Dec 10 |
nicklas |
40 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
5527 |
13 Dec 10 |
nicklas |
41 |
final String ID = sc.getId(); |
5527 |
13 Dec 10 |
nicklas |
42 |
final String cmd = request.getParameter("cmd"); |
5527 |
13 Dec 10 |
nicklas |
43 |
final String root = request.getContextPath()+"/"; |
5527 |
13 Dec 10 |
nicklas |
44 |
final int itemId = Values.getInt(request.getParameter("item_id")); |
5527 |
13 Dec 10 |
nicklas |
45 |
DbControl dc = null; |
5527 |
13 Dec 10 |
nicklas |
46 |
out.clear(); |
5557 |
28 Jan 11 |
nicklas |
47 |
JSONObject json = new JSONObject(); |
5557 |
28 Jan 11 |
nicklas |
48 |
json.put("status", "ok"); |
5527 |
13 Dec 10 |
nicklas |
49 |
try |
5527 |
13 Dec 10 |
nicklas |
50 |
{ |
5527 |
13 Dec 10 |
nicklas |
51 |
if ("GetFullPlateInfo".equals(cmd)) |
5527 |
13 Dec 10 |
nicklas |
52 |
{ |
5549 |
26 Jan 11 |
nicklas |
53 |
boolean countChildren = Values.getBoolean(request.getParameter("countChildren")); |
5549 |
26 Jan 11 |
nicklas |
54 |
boolean countPooled = countChildren && "pooled".equals(request.getParameter("countChildren")); |
7954 |
12 May 21 |
nicklas |
55 |
dc = sc.newDbControl(":Get plate information"); |
5527 |
13 Dec 10 |
nicklas |
56 |
|
5527 |
13 Dec 10 |
nicklas |
57 |
BioPlate plate = BioPlate.getById(dc, itemId); |
5527 |
13 Dec 10 |
nicklas |
58 |
PlateGeometry geometry = plate.getPlateGeometry(); |
5527 |
13 Dec 10 |
nicklas |
59 |
|
5557 |
28 Jan 11 |
nicklas |
60 |
json.put("id", plate.getId()); |
5557 |
28 Jan 11 |
nicklas |
61 |
json.put("name", plate.getName()); |
5557 |
28 Jan 11 |
nicklas |
62 |
json.put("barcode", plate.getBarcode()); |
5557 |
28 Jan 11 |
nicklas |
63 |
json.put("rows", geometry.getRows()); |
5557 |
28 Jan 11 |
nicklas |
64 |
json.put("columns", geometry.getColumns()); |
5527 |
13 Dec 10 |
nicklas |
65 |
|
5557 |
28 Jan 11 |
nicklas |
66 |
JSONArray jsonWells = new JSONArray(); |
5527 |
13 Dec 10 |
nicklas |
67 |
for (BioWell well : plate.getBioWells().list(dc)) |
5527 |
13 Dec 10 |
nicklas |
68 |
{ |
5557 |
28 Jan 11 |
nicklas |
69 |
JSONObject jsonWell = new JSONObject(); |
5557 |
28 Jan 11 |
nicklas |
70 |
jsonWell.put("id", well.getId()); |
5557 |
28 Jan 11 |
nicklas |
71 |
jsonWell.put("row", well.getRow()); |
5557 |
28 Jan 11 |
nicklas |
72 |
jsonWell.put("column", well.getColumn()); |
5557 |
28 Jan 11 |
nicklas |
73 |
jsonWell.put("canAdd", well.canAddBioMaterial()); |
5557 |
28 Jan 11 |
nicklas |
74 |
jsonWell.put("canClear", well.canClearBioMaterial()); |
5557 |
28 Jan 11 |
nicklas |
75 |
jsonWell.put("isEmpty", well.isEmpty()); |
5527 |
13 Dec 10 |
nicklas |
76 |
if (!well.isEmpty()) |
5527 |
13 Dec 10 |
nicklas |
77 |
{ |
5557 |
28 Jan 11 |
nicklas |
78 |
JSONObject jsonBioMaterial = new JSONObject(); |
5527 |
13 Dec 10 |
nicklas |
79 |
MeasuredBioMaterial bm = well.getBioMaterial(); |
5557 |
28 Jan 11 |
nicklas |
80 |
jsonBioMaterial.put("id", bm.getId()); |
5557 |
28 Jan 11 |
nicklas |
81 |
jsonBioMaterial.put("type", bm.getType().name()); |
5557 |
28 Jan 11 |
nicklas |
82 |
jsonBioMaterial.put("name", bm.getName()); |
5549 |
26 Jan 11 |
nicklas |
83 |
if (countChildren) |
5549 |
26 Jan 11 |
nicklas |
84 |
{ |
5557 |
28 Jan 11 |
nicklas |
85 |
jsonBioMaterial.put("childCount", bm.countChildren(countPooled)); |
5549 |
26 Jan 11 |
nicklas |
86 |
} |
5557 |
28 Jan 11 |
nicklas |
87 |
jsonWell.put("bioMaterial", jsonBioMaterial); |
5527 |
13 Dec 10 |
nicklas |
88 |
} |
5557 |
28 Jan 11 |
nicklas |
89 |
jsonWells.add(jsonWell); |
5527 |
13 Dec 10 |
nicklas |
90 |
} |
5557 |
28 Jan 11 |
nicklas |
91 |
json.put("wells", jsonWells); |
5527 |
13 Dec 10 |
nicklas |
92 |
dc.close(); |
5527 |
13 Dec 10 |
nicklas |
93 |
} |
5527 |
13 Dec 10 |
nicklas |
94 |
else |
5527 |
13 Dec 10 |
nicklas |
95 |
{ |
5527 |
13 Dec 10 |
nicklas |
96 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
5527 |
13 Dec 10 |
nicklas |
97 |
} |
5527 |
13 Dec 10 |
nicklas |
98 |
} |
5527 |
13 Dec 10 |
nicklas |
99 |
catch (Throwable t) |
5527 |
13 Dec 10 |
nicklas |
100 |
{ |
5527 |
13 Dec 10 |
nicklas |
101 |
t.printStackTrace(); |
5557 |
28 Jan 11 |
nicklas |
102 |
json.clear(); |
5557 |
28 Jan 11 |
nicklas |
103 |
json.put("status", "error"); |
5557 |
28 Jan 11 |
nicklas |
104 |
json.put("message", t.getMessage()); |
5557 |
28 Jan 11 |
nicklas |
105 |
json.put("stacktrace", ThrowableUtil.stackTraceToString(t)); |
5527 |
13 Dec 10 |
nicklas |
106 |
} |
5527 |
13 Dec 10 |
nicklas |
107 |
finally |
5527 |
13 Dec 10 |
nicklas |
108 |
{ |
5557 |
28 Jan 11 |
nicklas |
109 |
json.writeJSONString(out); |
5557 |
28 Jan 11 |
nicklas |
110 |
out.flush(); |
5527 |
13 Dec 10 |
nicklas |
111 |
if (dc != null) dc.close(); |
5527 |
13 Dec 10 |
nicklas |
112 |
} |
5527 |
13 Dec 10 |
nicklas |
113 |
%> |