5685 |
04 Aug 11 |
nicklas |
1 |
<%-- $Id $ |
5685 |
04 Aug 11 |
nicklas |
2 |
------------------------------------------------------------------ |
5685 |
04 Aug 11 |
nicklas |
Copyright (C) 2011 Nicklas Nordborg |
5685 |
04 Aug 11 |
nicklas |
4 |
|
5685 |
04 Aug 11 |
nicklas |
5 |
This file is part of BASE - BioArray Software Environment. |
5685 |
04 Aug 11 |
nicklas |
6 |
Available at http://base.thep.lu.se/ |
5685 |
04 Aug 11 |
nicklas |
7 |
|
5685 |
04 Aug 11 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or |
5685 |
04 Aug 11 |
nicklas |
9 |
modify it under the terms of the GNU General Public License |
5685 |
04 Aug 11 |
nicklas |
10 |
as published by the Free Software Foundation; either version 3 |
5685 |
04 Aug 11 |
nicklas |
11 |
of the License, or (at your option) any later version. |
5685 |
04 Aug 11 |
nicklas |
12 |
|
5685 |
04 Aug 11 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, |
5685 |
04 Aug 11 |
nicklas |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5685 |
04 Aug 11 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5685 |
04 Aug 11 |
nicklas |
16 |
GNU General Public License for more details. |
5685 |
04 Aug 11 |
nicklas |
17 |
|
5685 |
04 Aug 11 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
5685 |
04 Aug 11 |
nicklas |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5685 |
04 Aug 11 |
nicklas |
20 |
------------------------------------------------------------------ |
5685 |
04 Aug 11 |
nicklas |
21 |
|
5685 |
04 Aug 11 |
nicklas |
22 |
@author Nicklas |
5685 |
04 Aug 11 |
nicklas |
23 |
--%> |
5685 |
04 Aug 11 |
nicklas |
24 |
<%@ page pageEncoding="UTF-8" session="false" contentType="application/json" |
5685 |
04 Aug 11 |
nicklas |
25 |
import="net.sf.basedb.core.SessionControl" |
5685 |
04 Aug 11 |
nicklas |
26 |
import="net.sf.basedb.core.DbControl" |
5685 |
04 Aug 11 |
nicklas |
27 |
import="net.sf.basedb.core.DerivedBioAssay" |
5685 |
04 Aug 11 |
nicklas |
28 |
import="net.sf.basedb.core.PhysicalBioAssay" |
5685 |
04 Aug 11 |
nicklas |
29 |
import="net.sf.basedb.core.Extract" |
5685 |
04 Aug 11 |
nicklas |
30 |
import="net.sf.basedb.core.BioMaterial" |
5685 |
04 Aug 11 |
nicklas |
31 |
import="net.sf.basedb.core.BioMaterialEventSource" |
5685 |
04 Aug 11 |
nicklas |
32 |
import="net.sf.basedb.core.SpecialQuery" |
6095 |
30 Aug 12 |
nicklas |
33 |
import="net.sf.basedb.core.ItemQuery" |
6095 |
30 Aug 12 |
nicklas |
34 |
import="net.sf.basedb.core.Include" |
6095 |
30 Aug 12 |
nicklas |
35 |
import="net.sf.basedb.core.Type" |
5750 |
20 Sep 11 |
nicklas |
36 |
import="net.sf.basedb.core.ArrayDesign" |
5685 |
04 Aug 11 |
nicklas |
37 |
import="net.sf.basedb.core.PermissionDeniedException" |
6095 |
30 Aug 12 |
nicklas |
38 |
import="net.sf.basedb.core.query.Restrictions" |
6095 |
30 Aug 12 |
nicklas |
39 |
import="net.sf.basedb.core.query.Expressions" |
5685 |
04 Aug 11 |
nicklas |
40 |
import="net.sf.basedb.core.query.Hql" |
5685 |
04 Aug 11 |
nicklas |
41 |
import="net.sf.basedb.core.query.Orders" |
5685 |
04 Aug 11 |
nicklas |
42 |
import="net.sf.basedb.clients.web.Base" |
5685 |
04 Aug 11 |
nicklas |
43 |
import="net.sf.basedb.util.Values" |
6799 |
25 Mar 15 |
nicklas |
44 |
import="net.sf.basedb.util.listable.TransformContext" |
6799 |
25 Mar 15 |
nicklas |
45 |
import="net.sf.basedb.util.listable.ExtractToParentExtractTransformer" |
6799 |
25 Mar 15 |
nicklas |
46 |
import="net.sf.basedb.util.listable.SourceItemTransformer" |
5685 |
04 Aug 11 |
nicklas |
47 |
import="net.sf.basedb.util.error.ThrowableUtil" |
5685 |
04 Aug 11 |
nicklas |
48 |
import="net.sf.basedb.clients.web.WebException" |
5685 |
04 Aug 11 |
nicklas |
49 |
import="net.sf.basedb.clients.web.util.HTML" |
5685 |
04 Aug 11 |
nicklas |
50 |
import="org.json.simple.JSONObject" |
5685 |
04 Aug 11 |
nicklas |
51 |
import="org.json.simple.JSONArray" |
5685 |
04 Aug 11 |
nicklas |
52 |
import="java.util.Date" |
6095 |
30 Aug 12 |
nicklas |
53 |
import="java.util.Arrays" |
6095 |
30 Aug 12 |
nicklas |
54 |
import="java.util.List" |
6095 |
30 Aug 12 |
nicklas |
55 |
import="java.util.Set" |
6095 |
30 Aug 12 |
nicklas |
56 |
import="java.util.HashSet" |
5685 |
04 Aug 11 |
nicklas |
57 |
%> |
5685 |
04 Aug 11 |
nicklas |
58 |
<% |
6124 |
13 Sep 12 |
nicklas |
59 |
response.setHeader("Cache-Control", "no-cache, max-age=0"); |
5685 |
04 Aug 11 |
nicklas |
60 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
5685 |
04 Aug 11 |
nicklas |
61 |
final String ID = sc.getId(); |
5685 |
04 Aug 11 |
nicklas |
62 |
final String cmd = request.getParameter("cmd"); |
5685 |
04 Aug 11 |
nicklas |
63 |
final String root = request.getContextPath()+"/"; |
5685 |
04 Aug 11 |
nicklas |
64 |
final int itemId = Values.getInt(request.getParameter("item_id")); |
5685 |
04 Aug 11 |
nicklas |
65 |
out.clear(); |
5685 |
04 Aug 11 |
nicklas |
66 |
JSONObject json = new JSONObject(); |
5685 |
04 Aug 11 |
nicklas |
67 |
json.put("status", "ok"); |
5685 |
04 Aug 11 |
nicklas |
68 |
DbControl dc = null; |
5685 |
04 Aug 11 |
nicklas |
69 |
try |
5685 |
04 Aug 11 |
nicklas |
70 |
{ |
7603 |
22 Feb 19 |
nicklas |
71 |
if ("GetArrayDesign".equals(cmd)) |
5685 |
04 Aug 11 |
nicklas |
72 |
{ |
7954 |
12 May 21 |
nicklas |
73 |
dc = sc.newDbControl(":Get array design information"); |
5685 |
04 Aug 11 |
nicklas |
74 |
try |
5685 |
04 Aug 11 |
nicklas |
75 |
{ |
5750 |
20 Sep 11 |
nicklas |
76 |
DerivedBioAssay dba = DerivedBioAssay.getById(dc, itemId); |
5750 |
20 Sep 11 |
nicklas |
77 |
ArrayDesign d = dba.getArrayDesign(); |
5750 |
20 Sep 11 |
nicklas |
78 |
if (d != null) |
5750 |
20 Sep 11 |
nicklas |
79 |
{ |
5750 |
20 Sep 11 |
nicklas |
80 |
json.put("id", d.getId()); |
5750 |
20 Sep 11 |
nicklas |
81 |
json.put("name", d.getName()); |
5750 |
20 Sep 11 |
nicklas |
82 |
json.put("description", d.getDescription()); |
5750 |
20 Sep 11 |
nicklas |
83 |
json.put("numArrays", d.getNumArrays()); |
5750 |
20 Sep 11 |
nicklas |
84 |
} |
5750 |
20 Sep 11 |
nicklas |
85 |
} |
5750 |
20 Sep 11 |
nicklas |
86 |
catch (PermissionDeniedException pex) |
5750 |
20 Sep 11 |
nicklas |
87 |
{} |
5750 |
20 Sep 11 |
nicklas |
88 |
dc.close(); |
5750 |
20 Sep 11 |
nicklas |
89 |
} |
6095 |
30 Aug 12 |
nicklas |
90 |
else if ("GetAllExtractIds".equals(cmd)) |
6095 |
30 Aug 12 |
nicklas |
91 |
{ |
7954 |
12 May 21 |
nicklas |
92 |
dc = sc.newDbControl(":Get all extracts"); |
6095 |
30 Aug 12 |
nicklas |
93 |
|
6095 |
30 Aug 12 |
nicklas |
94 |
Integer[] bioAssayIds = Values.getInt(request.getParameter("bioassay_ids").split(",")); |
6095 |
30 Aug 12 |
nicklas |
95 |
|
6095 |
30 Aug 12 |
nicklas |
96 |
// Load all extracts that are directly linked with the given physical bioassays |
6095 |
30 Aug 12 |
nicklas |
97 |
ItemQuery<Extract> query = Extract.getQuery(); |
6095 |
30 Aug 12 |
nicklas |
98 |
query.include(Include.ALL); |
6095 |
30 Aug 12 |
nicklas |
99 |
query.join(Hql.innerJoin("childCreationEvents", "cce")); |
6095 |
30 Aug 12 |
nicklas |
100 |
query.join(Hql.innerJoin("cce", "event", "evt")); |
6095 |
30 Aug 12 |
nicklas |
101 |
query.join(Hql.innerJoin("evt", "physicalBioAssay", "pba")); |
6095 |
30 Aug 12 |
nicklas |
102 |
query.join(Hql.innerJoin("pba", "derivedBioAssays", "dba")); |
6095 |
30 Aug 12 |
nicklas |
103 |
query.restrict(Restrictions.in(Hql.alias("dba"), Expressions.parameter("bioAssays"))); |
6095 |
30 Aug 12 |
nicklas |
104 |
query.setParameter("bioAssays", Arrays.asList(bioAssayIds), Type.INT); |
6799 |
25 Mar 15 |
nicklas |
105 |
Set<Integer> primaryExtracts = new HashSet<Integer>(query.idList(dc)); |
6095 |
30 Aug 12 |
nicklas |
106 |
|
6799 |
25 Mar 15 |
nicklas |
107 |
// Use the ExtractToParentExtractTransformer to load all parent extracts as well |
6799 |
25 Mar 15 |
nicklas |
108 |
SourceItemTransformer transformer = new ExtractToParentExtractTransformer(true); |
6799 |
25 Mar 15 |
nicklas |
109 |
Set<Integer> allExtracts = transformer.transform(new TransformContext(dc), primaryExtracts); |
6095 |
30 Aug 12 |
nicklas |
110 |
|
6095 |
30 Aug 12 |
nicklas |
111 |
JSONArray jsonExtracts = new JSONArray(); |
6799 |
25 Mar 15 |
nicklas |
112 |
for (Integer e : allExtracts) |
6095 |
30 Aug 12 |
nicklas |
113 |
{ |
6799 |
25 Mar 15 |
nicklas |
114 |
jsonExtracts.add(e); |
6095 |
30 Aug 12 |
nicklas |
115 |
} |
6095 |
30 Aug 12 |
nicklas |
116 |
|
6095 |
30 Aug 12 |
nicklas |
117 |
json.put("allExtractIds", jsonExtracts); |
6095 |
30 Aug 12 |
nicklas |
118 |
dc.commit(); |
6095 |
30 Aug 12 |
nicklas |
119 |
} |
5685 |
04 Aug 11 |
nicklas |
120 |
else |
5685 |
04 Aug 11 |
nicklas |
121 |
{ |
5685 |
04 Aug 11 |
nicklas |
122 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
5685 |
04 Aug 11 |
nicklas |
123 |
} |
5685 |
04 Aug 11 |
nicklas |
124 |
} |
5685 |
04 Aug 11 |
nicklas |
125 |
catch (Throwable t) |
5685 |
04 Aug 11 |
nicklas |
126 |
{ |
5685 |
04 Aug 11 |
nicklas |
127 |
t.printStackTrace(); |
5685 |
04 Aug 11 |
nicklas |
128 |
json.clear(); |
5685 |
04 Aug 11 |
nicklas |
129 |
json.put("status", "error"); |
5685 |
04 Aug 11 |
nicklas |
130 |
json.put("message", t.getMessage()); |
5685 |
04 Aug 11 |
nicklas |
131 |
json.put("stacktrace", ThrowableUtil.stackTraceToString(t)); |
5685 |
04 Aug 11 |
nicklas |
132 |
} |
5685 |
04 Aug 11 |
nicklas |
133 |
finally |
5685 |
04 Aug 11 |
nicklas |
134 |
{ |
5685 |
04 Aug 11 |
nicklas |
135 |
json.writeJSONString(out); |
5685 |
04 Aug 11 |
nicklas |
136 |
out.flush(); |
5685 |
04 Aug 11 |
nicklas |
137 |
if (dc != null) dc.close(); |
5685 |
04 Aug 11 |
nicklas |
138 |
} |
5685 |
04 Aug 11 |
nicklas |
139 |
%> |