4816 |
16 Mar 09 |
martin |
1 |
<%-- $Id$ |
4816 |
16 Mar 09 |
martin |
2 |
------------------------------------------------------------------ |
4816 |
16 Mar 09 |
martin |
Copyright (C) 2009 Martin Svensson |
4816 |
16 Mar 09 |
martin |
4 |
|
4816 |
16 Mar 09 |
martin |
5 |
This file is part of BASE - BioArray Software Environment. |
4816 |
16 Mar 09 |
martin |
6 |
Available at http://base.thep.lu.se/ |
4816 |
16 Mar 09 |
martin |
7 |
|
4816 |
16 Mar 09 |
martin |
8 |
BASE is free software; you can redistribute it and/or |
4816 |
16 Mar 09 |
martin |
9 |
modify it under the terms of the GNU General Public License |
4816 |
16 Mar 09 |
martin |
10 |
as published by the Free Software Foundation; either version 3 |
4816 |
16 Mar 09 |
martin |
11 |
of the License, or (at your option) any later version. |
4816 |
16 Mar 09 |
martin |
12 |
|
4816 |
16 Mar 09 |
martin |
13 |
BASE is distributed in the hope that it will be useful, |
4816 |
16 Mar 09 |
martin |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4816 |
16 Mar 09 |
martin |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4816 |
16 Mar 09 |
martin |
16 |
GNU General Public License for more details. |
4816 |
16 Mar 09 |
martin |
17 |
|
4816 |
16 Mar 09 |
martin |
18 |
You should have received a copy of the GNU General Public License |
4816 |
16 Mar 09 |
martin |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
4816 |
16 Mar 09 |
martin |
20 |
------------------------------------------------------------------ |
4816 |
16 Mar 09 |
martin |
21 |
|
4816 |
16 Mar 09 |
martin |
22 |
--%> |
5556 |
28 Jan 11 |
nicklas |
23 |
<%@ page pageEncoding="UTF-8" session="false" contentType="application/json" |
4816 |
16 Mar 09 |
martin |
24 |
import="net.sf.basedb.core.SessionControl" |
4816 |
16 Mar 09 |
martin |
25 |
import="net.sf.basedb.core.DbControl" |
5145 |
20 Oct 09 |
nicklas |
26 |
import="net.sf.basedb.core.Annotation" |
5145 |
20 Oct 09 |
nicklas |
27 |
import="net.sf.basedb.core.AnnotationType" |
5651 |
08 Jun 11 |
nicklas |
28 |
import="net.sf.basedb.core.ItemSubtype" |
5651 |
08 Jun 11 |
nicklas |
29 |
import="net.sf.basedb.core.Subtypable" |
6214 |
13 Dec 12 |
nicklas |
30 |
import="net.sf.basedb.core.BioPlate" |
6214 |
13 Dec 12 |
nicklas |
31 |
import="net.sf.basedb.core.BioPlateType" |
7315 |
30 Mar 17 |
nicklas |
32 |
import="net.sf.basedb.core.RawDataType" |
7315 |
30 Mar 17 |
nicklas |
33 |
import="net.sf.basedb.core.RawBioAssay" |
4816 |
16 Mar 09 |
martin |
34 |
import="net.sf.basedb.core.Item" |
4816 |
16 Mar 09 |
martin |
35 |
import="net.sf.basedb.util.overview.GenericOverview" |
4816 |
16 Mar 09 |
martin |
36 |
import="net.sf.basedb.util.overview.Node" |
4830 |
23 Mar 09 |
martin |
37 |
import="net.sf.basedb.util.overview.OverviewUtil" |
5556 |
28 Jan 11 |
nicklas |
38 |
import="net.sf.basedb.util.error.ThrowableUtil" |
4816 |
16 Mar 09 |
martin |
39 |
import="net.sf.basedb.clients.web.Base" |
4816 |
16 Mar 09 |
martin |
40 |
import="net.sf.basedb.clients.web.WebException" |
5556 |
28 Jan 11 |
nicklas |
41 |
import="org.json.simple.JSONObject" |
5556 |
28 Jan 11 |
nicklas |
42 |
import="org.json.simple.JSONArray" |
7316 |
30 Mar 17 |
nicklas |
43 |
import="java.util.Arrays" |
7316 |
30 Mar 17 |
nicklas |
44 |
import="java.util.HashSet" |
7316 |
30 Mar 17 |
nicklas |
45 |
import="java.util.Set" |
4816 |
16 Mar 09 |
martin |
46 |
%> |
7316 |
30 Mar 17 |
nicklas |
47 |
<%! |
7316 |
30 Mar 17 |
nicklas |
48 |
Set<Item> collapsedChildNodes = new HashSet<Item>( |
7316 |
30 Mar 17 |
nicklas |
49 |
Arrays.asList(Item.SAMPLE, Item.EXTRACT, Item.PHYSICALBIOASSAY, Item.DERIVEDBIOASSAY, Item.RAWBIOASSAY) |
7316 |
30 Mar 17 |
nicklas |
50 |
); |
7316 |
30 Mar 17 |
nicklas |
51 |
%> |
4816 |
16 Mar 09 |
martin |
52 |
<% |
6124 |
13 Sep 12 |
nicklas |
53 |
response.setHeader("Cache-Control", "no-cache, max-age=0"); |
4816 |
16 Mar 09 |
martin |
54 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
4816 |
16 Mar 09 |
martin |
55 |
final String ID = sc.getId(); |
4816 |
16 Mar 09 |
martin |
56 |
final String cmd = request.getParameter("cmd"); |
4816 |
16 Mar 09 |
martin |
57 |
final String root = request.getContextPath()+"/"; |
4816 |
16 Mar 09 |
martin |
58 |
final String nodeId = request.getParameter("node_id"); |
4816 |
16 Mar 09 |
martin |
59 |
DbControl dc = null; |
4816 |
16 Mar 09 |
martin |
60 |
out.clear(); |
5556 |
28 Jan 11 |
nicklas |
61 |
JSONObject json = new JSONObject(); |
5556 |
28 Jan 11 |
nicklas |
62 |
json.put("status", "ok"); |
4816 |
16 Mar 09 |
martin |
63 |
try |
4816 |
16 Mar 09 |
martin |
64 |
{ |
4816 |
16 Mar 09 |
martin |
65 |
if ("GetSubNodes".equals(cmd)) |
4816 |
16 Mar 09 |
martin |
66 |
{ |
7954 |
12 May 21 |
nicklas |
67 |
dc = sc.newDbControl(":Item overview - Get child nodes"); |
4816 |
16 Mar 09 |
martin |
68 |
GenericOverview overview = OverviewUtil.getCurrentOverview(sc); |
4840 |
24 Mar 09 |
martin |
69 |
Node parent = overview.getNode(nodeId); |
4816 |
16 Mar 09 |
martin |
70 |
overview.expand(dc, parent, false); |
4823 |
19 Mar 09 |
martin |
71 |
overview.updateFailureCountOnNodes(); |
5556 |
28 Jan 11 |
nicklas |
72 |
JSONArray jsonChildNodes = new JSONArray(); |
4816 |
16 Mar 09 |
martin |
73 |
if (parent != null && parent.numChildren() > 0) |
4816 |
16 Mar 09 |
martin |
74 |
{ |
4816 |
16 Mar 09 |
martin |
75 |
for (Node n : parent.getChildren()) |
4830 |
23 Mar 09 |
martin |
76 |
{ |
7316 |
30 Mar 17 |
nicklas |
77 |
if (n.getNodeType() == Node.Type.FOLDER && n.numChildren() == 1) |
7316 |
30 Mar 17 |
nicklas |
78 |
{ |
7316 |
30 Mar 17 |
nicklas |
79 |
Node child = n.getChildren().get(0); |
7316 |
30 Mar 17 |
nicklas |
80 |
if (collapsedChildNodes.contains(child.getItemType())) n = child; |
7316 |
30 Mar 17 |
nicklas |
81 |
} |
4816 |
16 Mar 09 |
martin |
82 |
String folderIcon = n.getNodeType() == Node.Type.FOLDER ? "Folder" : "Item"; |
5145 |
20 Oct 09 |
nicklas |
83 |
if (n.getItemType() == Item.ANNOTATIONTYPE) |
4816 |
16 Mar 09 |
martin |
84 |
{ |
5145 |
20 Oct 09 |
nicklas |
85 |
if (parent.getItemType() == Item.PROTOCOL) |
5145 |
20 Oct 09 |
nicklas |
86 |
{ |
5145 |
20 Oct 09 |
nicklas |
87 |
folderIcon = "ProtocolParameter"; |
5145 |
20 Oct 09 |
nicklas |
88 |
} |
5145 |
20 Oct 09 |
nicklas |
89 |
else |
5145 |
20 Oct 09 |
nicklas |
90 |
{ |
5145 |
20 Oct 09 |
nicklas |
91 |
try |
5145 |
20 Oct 09 |
nicklas |
92 |
{ |
5145 |
20 Oct 09 |
nicklas |
93 |
AnnotationType at = (AnnotationType)n.getItem(dc); |
5145 |
20 Oct 09 |
nicklas |
94 |
if (at.isProtocolParameter()) folderIcon = "ProtocolParameter"; |
5145 |
20 Oct 09 |
nicklas |
95 |
} |
5145 |
20 Oct 09 |
nicklas |
96 |
catch (Throwable t) |
5145 |
20 Oct 09 |
nicklas |
97 |
{} |
5145 |
20 Oct 09 |
nicklas |
98 |
} |
4816 |
16 Mar 09 |
martin |
99 |
} |
4816 |
16 Mar 09 |
martin |
100 |
else if (n.getItemType() == Item.ANNOTATION) |
4816 |
16 Mar 09 |
martin |
101 |
{ |
4816 |
16 Mar 09 |
martin |
102 |
folderIcon = "Annotation"; |
5145 |
20 Oct 09 |
nicklas |
103 |
try |
5145 |
20 Oct 09 |
nicklas |
104 |
{ |
5145 |
20 Oct 09 |
nicklas |
105 |
AnnotationType at = ((Annotation)n.getItem(dc)).getAnnotationType(); |
5145 |
20 Oct 09 |
nicklas |
106 |
if (at.isProtocolParameter()) folderIcon = "ProtocolParameter"; |
5145 |
20 Oct 09 |
nicklas |
107 |
} |
5145 |
20 Oct 09 |
nicklas |
108 |
catch (Throwable t) |
5145 |
20 Oct 09 |
nicklas |
109 |
{} |
5651 |
08 Jun 11 |
nicklas |
110 |
} |
5651 |
08 Jun 11 |
nicklas |
111 |
String subtitle = null; |
5651 |
08 Jun 11 |
nicklas |
112 |
if (n.getNodeType() == Node.Type.FOLDER) |
5651 |
08 Jun 11 |
nicklas |
113 |
{ |
5651 |
08 Jun 11 |
nicklas |
114 |
subtitle = n.getChildren() == null ? "0" : Integer.toString(n.getChildren().size()); |
5651 |
08 Jun 11 |
nicklas |
115 |
} |
5651 |
08 Jun 11 |
nicklas |
116 |
else if (n.getItem() instanceof Subtypable) |
5651 |
08 Jun 11 |
nicklas |
117 |
{ |
5651 |
08 Jun 11 |
nicklas |
118 |
try |
5651 |
08 Jun 11 |
nicklas |
119 |
{ |
5651 |
08 Jun 11 |
nicklas |
120 |
ItemSubtype subtype = ((Subtypable)n.getItem(dc)).getItemSubtype(); |
5651 |
08 Jun 11 |
nicklas |
121 |
if (subtype != null) subtitle = subtype.getName(); |
5651 |
08 Jun 11 |
nicklas |
122 |
} |
5651 |
08 Jun 11 |
nicklas |
123 |
catch (Throwable t) |
5651 |
08 Jun 11 |
nicklas |
124 |
{} |
5651 |
08 Jun 11 |
nicklas |
125 |
} |
6214 |
13 Dec 12 |
nicklas |
126 |
else if (n.getItem() instanceof BioPlate) |
6214 |
13 Dec 12 |
nicklas |
127 |
{ |
6214 |
13 Dec 12 |
nicklas |
128 |
try |
6214 |
13 Dec 12 |
nicklas |
129 |
{ |
6214 |
13 Dec 12 |
nicklas |
130 |
BioPlateType plateType = ((BioPlate)n.getItem(dc)).getBioPlateType(); |
6214 |
13 Dec 12 |
nicklas |
131 |
if (plateType != null) subtitle = plateType.getName(); |
6214 |
13 Dec 12 |
nicklas |
132 |
} |
6214 |
13 Dec 12 |
nicklas |
133 |
catch (Throwable t) |
6214 |
13 Dec 12 |
nicklas |
134 |
{} |
6214 |
13 Dec 12 |
nicklas |
135 |
} |
7315 |
30 Mar 17 |
nicklas |
136 |
else if (n.getItem() instanceof RawBioAssay) |
7315 |
30 Mar 17 |
nicklas |
137 |
{ |
7315 |
30 Mar 17 |
nicklas |
138 |
RawDataType rawDataType = ((RawBioAssay)n.getItem(dc)).getRawDataType(); |
7315 |
30 Mar 17 |
nicklas |
139 |
subtitle = rawDataType.getName(); |
7315 |
30 Mar 17 |
nicklas |
140 |
} |
5651 |
08 Jun 11 |
nicklas |
141 |
|
4864 |
30 Mar 09 |
nicklas |
142 |
int numChildren = n.numChildren(); |
5556 |
28 Jan 11 |
nicklas |
143 |
JSONObject jsonNode = new JSONObject(); |
5556 |
28 Jan 11 |
nicklas |
144 |
jsonNode.put("id", n.getId()); |
6382 |
17 Dec 13 |
nicklas |
145 |
jsonNode.put("text", n.getTitle() + (subtitle != null ? " <span class=\"subtitle\">(" + subtitle + ")</span>" : "")); |
6382 |
17 Dec 13 |
nicklas |
146 |
jsonNode.put("icon", folderIcon); |
6382 |
17 Dec 13 |
nicklas |
147 |
jsonNode.put("isLazy", numChildren == 0 ? 0 : 1); |
7347 |
28 Apr 17 |
nicklas |
148 |
jsonNode.put("className", n.getNodeType().name()); |
5556 |
28 Jan 11 |
nicklas |
149 |
jsonChildNodes.add(jsonNode); |
4816 |
16 Mar 09 |
martin |
150 |
} |
4816 |
16 Mar 09 |
martin |
151 |
dc.commit(); |
4816 |
16 Mar 09 |
martin |
152 |
} |
5556 |
28 Jan 11 |
nicklas |
153 |
json.put("childNodes", jsonChildNodes); |
4816 |
16 Mar 09 |
martin |
154 |
} |
4816 |
16 Mar 09 |
martin |
155 |
else |
4816 |
16 Mar 09 |
martin |
156 |
{ |
4816 |
16 Mar 09 |
martin |
157 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
4816 |
16 Mar 09 |
martin |
158 |
} |
4816 |
16 Mar 09 |
martin |
159 |
} |
5556 |
28 Jan 11 |
nicklas |
160 |
catch (Throwable t) |
5556 |
28 Jan 11 |
nicklas |
161 |
{ |
5556 |
28 Jan 11 |
nicklas |
162 |
t.printStackTrace(); |
5556 |
28 Jan 11 |
nicklas |
163 |
json.clear(); |
5556 |
28 Jan 11 |
nicklas |
164 |
json.put("status", "error"); |
5556 |
28 Jan 11 |
nicklas |
165 |
json.put("message", t.getMessage()); |
5556 |
28 Jan 11 |
nicklas |
166 |
json.put("stacktrace", ThrowableUtil.stackTraceToString(t)); |
5556 |
28 Jan 11 |
nicklas |
167 |
} |
4816 |
16 Mar 09 |
martin |
168 |
finally |
4816 |
16 Mar 09 |
martin |
169 |
{ |
5556 |
28 Jan 11 |
nicklas |
170 |
json.writeJSONString(out); |
5556 |
28 Jan 11 |
nicklas |
171 |
out.flush(); |
4816 |
16 Mar 09 |
martin |
172 |
if (dc != null) dc.close(); |
4816 |
16 Mar 09 |
martin |
173 |
} |
4816 |
16 Mar 09 |
martin |
174 |
%> |