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