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