6694 |
26 Jan 15 |
nicklas |
1 |
<%-- $Id $ |
6694 |
26 Jan 15 |
nicklas |
2 |
------------------------------------------------------------------ |
6694 |
26 Jan 15 |
nicklas |
Copyright (C) 2015 Nicklas Nordborg |
6694 |
26 Jan 15 |
nicklas |
4 |
|
6694 |
26 Jan 15 |
nicklas |
5 |
This file is part of BASE - BioArray Software Environment. |
6694 |
26 Jan 15 |
nicklas |
6 |
Available at http://base.thep.lu.se/ |
6694 |
26 Jan 15 |
nicklas |
7 |
|
6694 |
26 Jan 15 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or |
6694 |
26 Jan 15 |
nicklas |
9 |
modify it under the terms of the GNU General Public License |
6694 |
26 Jan 15 |
nicklas |
10 |
as published by the Free Software Foundation; either version 3 |
6694 |
26 Jan 15 |
nicklas |
11 |
of the License, or (at your option) any later version. |
6694 |
26 Jan 15 |
nicklas |
12 |
|
6694 |
26 Jan 15 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, |
6694 |
26 Jan 15 |
nicklas |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
6694 |
26 Jan 15 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6694 |
26 Jan 15 |
nicklas |
16 |
GNU General Public License for more details. |
6694 |
26 Jan 15 |
nicklas |
17 |
|
6694 |
26 Jan 15 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
6694 |
26 Jan 15 |
nicklas |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
6694 |
26 Jan 15 |
nicklas |
20 |
------------------------------------------------------------------ |
6694 |
26 Jan 15 |
nicklas |
21 |
|
6694 |
26 Jan 15 |
nicklas |
22 |
--%> |
6694 |
26 Jan 15 |
nicklas |
23 |
<%@ page pageEncoding="UTF-8" session="false" contentType="application/json" |
6694 |
26 Jan 15 |
nicklas |
24 |
import="net.sf.basedb.core.SessionControl" |
6694 |
26 Jan 15 |
nicklas |
25 |
import="net.sf.basedb.core.DbControl" |
6694 |
26 Jan 15 |
nicklas |
26 |
import="net.sf.basedb.core.AnnotationType" |
6947 |
08 Sep 15 |
nicklas |
27 |
import="net.sf.basedb.core.Annotation" |
6694 |
26 Jan 15 |
nicklas |
28 |
import="net.sf.basedb.core.Item" |
6694 |
26 Jan 15 |
nicklas |
29 |
import="net.sf.basedb.core.Type" |
6694 |
26 Jan 15 |
nicklas |
30 |
import="net.sf.basedb.util.Values" |
6694 |
26 Jan 15 |
nicklas |
31 |
import="net.sf.basedb.util.error.ThrowableUtil" |
6696 |
28 Jan 15 |
nicklas |
32 |
import="net.sf.basedb.clients.web.AnnotationUtil" |
6694 |
26 Jan 15 |
nicklas |
33 |
import="net.sf.basedb.clients.web.Base" |
6694 |
26 Jan 15 |
nicklas |
34 |
import="net.sf.basedb.clients.web.WebException" |
6694 |
26 Jan 15 |
nicklas |
35 |
import="org.json.simple.JSONObject" |
6694 |
26 Jan 15 |
nicklas |
36 |
import="org.json.simple.JSONArray" |
6947 |
08 Sep 15 |
nicklas |
37 |
import="java.util.HashSet" |
6694 |
26 Jan 15 |
nicklas |
38 |
%> |
6694 |
26 Jan 15 |
nicklas |
39 |
<% |
6694 |
26 Jan 15 |
nicklas |
40 |
response.setHeader("Cache-Control", "no-cache, max-age=0"); |
6694 |
26 Jan 15 |
nicklas |
41 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
6694 |
26 Jan 15 |
nicklas |
42 |
final String ID = sc.getId(); |
6694 |
26 Jan 15 |
nicklas |
43 |
final String cmd = request.getParameter("cmd"); |
6694 |
26 Jan 15 |
nicklas |
44 |
final String root = request.getContextPath()+"/"; |
6694 |
26 Jan 15 |
nicklas |
45 |
final int itemId = Values.getInt(request.getParameter("item_id")); |
6694 |
26 Jan 15 |
nicklas |
46 |
DbControl dc = null; |
6694 |
26 Jan 15 |
nicklas |
47 |
out.clear(); |
6694 |
26 Jan 15 |
nicklas |
48 |
JSONObject json = new JSONObject(); |
6694 |
26 Jan 15 |
nicklas |
49 |
json.put("status", "ok"); |
6694 |
26 Jan 15 |
nicklas |
50 |
try |
6694 |
26 Jan 15 |
nicklas |
51 |
{ |
6694 |
26 Jan 15 |
nicklas |
52 |
if ("GetAnnotationTypeInfo".equals(cmd)) |
6694 |
26 Jan 15 |
nicklas |
53 |
{ |
7954 |
12 May 21 |
nicklas |
54 |
dc = sc.newDbControl(":Get annotation type information"); |
6694 |
26 Jan 15 |
nicklas |
55 |
AnnotationType at = AnnotationType.getById(dc, itemId); |
6696 |
28 Jan 15 |
nicklas |
56 |
json.put("annotationType", AnnotationUtil.loadJsonForBatchInherit(dc, at)); |
6694 |
26 Jan 15 |
nicklas |
57 |
} |
6947 |
08 Sep 15 |
nicklas |
58 |
else if ("GetAnnotationInfoForInherit".equals(cmd)) |
6947 |
08 Sep 15 |
nicklas |
59 |
{ |
7954 |
12 May 21 |
nicklas |
60 |
dc = sc.newDbControl(":Get annotation information"); |
6947 |
08 Sep 15 |
nicklas |
61 |
Annotation a = Annotation.getById(dc, itemId); |
6947 |
08 Sep 15 |
nicklas |
62 |
AnnotationType at = a.getAnnotationType(); |
7604 |
25 Feb 19 |
nicklas |
63 |
JSONObject jsonInfo = AnnotationUtil.createJsonForAnnotationTypeAndAnnotation(dc, at, null, a, false, new HashSet<>()); |
6947 |
08 Sep 15 |
nicklas |
64 |
json.put("info", jsonInfo); |
6947 |
08 Sep 15 |
nicklas |
65 |
} |
6694 |
26 Jan 15 |
nicklas |
66 |
else |
6694 |
26 Jan 15 |
nicklas |
67 |
{ |
6694 |
26 Jan 15 |
nicklas |
68 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
6694 |
26 Jan 15 |
nicklas |
69 |
} |
6694 |
26 Jan 15 |
nicklas |
70 |
} |
6694 |
26 Jan 15 |
nicklas |
71 |
catch (Throwable t) |
6694 |
26 Jan 15 |
nicklas |
72 |
{ |
6694 |
26 Jan 15 |
nicklas |
73 |
t.printStackTrace(); |
6694 |
26 Jan 15 |
nicklas |
74 |
json.clear(); |
6694 |
26 Jan 15 |
nicklas |
75 |
json.put("status", "error"); |
6694 |
26 Jan 15 |
nicklas |
76 |
json.put("message", t.getMessage()); |
6694 |
26 Jan 15 |
nicklas |
77 |
json.put("stacktrace", ThrowableUtil.stackTraceToString(t)); |
6694 |
26 Jan 15 |
nicklas |
78 |
} |
6694 |
26 Jan 15 |
nicklas |
79 |
finally |
6694 |
26 Jan 15 |
nicklas |
80 |
{ |
6694 |
26 Jan 15 |
nicklas |
81 |
json.writeJSONString(out); |
6694 |
26 Jan 15 |
nicklas |
82 |
out.flush(); |
6694 |
26 Jan 15 |
nicklas |
83 |
if (dc != null) dc.close(); |
6694 |
26 Jan 15 |
nicklas |
84 |
} |
6694 |
26 Jan 15 |
nicklas |
85 |
%> |