5897 |
02 Dec 11 |
nicklas |
1 |
<%-- $Id$ |
5897 |
02 Dec 11 |
nicklas |
2 |
------------------------------------------------------------------ |
5897 |
02 Dec 11 |
nicklas |
Copyright (C) 2011 Nicklas Nordborg |
5897 |
02 Dec 11 |
nicklas |
4 |
|
5897 |
02 Dec 11 |
nicklas |
5 |
This file is part of BASE - BioArray Software Environment. |
5897 |
02 Dec 11 |
nicklas |
6 |
Available at http://base.thep.lu.se/ |
5897 |
02 Dec 11 |
nicklas |
7 |
|
5897 |
02 Dec 11 |
nicklas |
8 |
This file is part of BASE. |
5897 |
02 Dec 11 |
nicklas |
9 |
|
5897 |
02 Dec 11 |
nicklas |
10 |
BASE is free software; you can redistribute it and/or |
5897 |
02 Dec 11 |
nicklas |
11 |
modify it under the terms of the GNU General Public License |
5897 |
02 Dec 11 |
nicklas |
12 |
as published by the Free Software Foundation; either version 3 |
5897 |
02 Dec 11 |
nicklas |
13 |
of the License, or (at your option) any later version. |
5897 |
02 Dec 11 |
nicklas |
14 |
|
5897 |
02 Dec 11 |
nicklas |
15 |
BASE is distributed in the hope that it will be useful, |
5897 |
02 Dec 11 |
nicklas |
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5897 |
02 Dec 11 |
nicklas |
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5897 |
02 Dec 11 |
nicklas |
18 |
GNU General Public License for more details. |
5897 |
02 Dec 11 |
nicklas |
19 |
|
5897 |
02 Dec 11 |
nicklas |
20 |
You should have received a copy of the GNU General Public License |
5897 |
02 Dec 11 |
nicklas |
21 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5897 |
02 Dec 11 |
nicklas |
22 |
------------------------------------------------------------------ |
5897 |
02 Dec 11 |
nicklas |
23 |
--%> |
5897 |
02 Dec 11 |
nicklas |
24 |
<%@ page pageEncoding="UTF-8" session="false" |
5897 |
02 Dec 11 |
nicklas |
25 |
import="net.sf.basedb.core.SessionControl" |
5897 |
02 Dec 11 |
nicklas |
26 |
import="net.sf.basedb.core.DbControl" |
5897 |
02 Dec 11 |
nicklas |
27 |
import="net.sf.basedb.core.Item" |
5897 |
02 Dec 11 |
nicklas |
28 |
import="net.sf.basedb.core.Include" |
5897 |
02 Dec 11 |
nicklas |
29 |
import="net.sf.basedb.core.Experiment" |
5897 |
02 Dec 11 |
nicklas |
30 |
import="net.sf.basedb.core.VirtualDb" |
5897 |
02 Dec 11 |
nicklas |
31 |
import="net.sf.basedb.core.Job" |
5897 |
02 Dec 11 |
nicklas |
32 |
import="net.sf.basedb.core.Reporter" |
5897 |
02 Dec 11 |
nicklas |
33 |
import="net.sf.basedb.core.ReporterCloneTemplate" |
5897 |
02 Dec 11 |
nicklas |
34 |
import="net.sf.basedb.core.StringParameterType" |
5897 |
02 Dec 11 |
nicklas |
35 |
import="net.sf.basedb.core.IntegerParameterType" |
5897 |
02 Dec 11 |
nicklas |
36 |
import="net.sf.basedb.core.ItemParameterType" |
5897 |
02 Dec 11 |
nicklas |
37 |
import="net.sf.basedb.core.User" |
5897 |
02 Dec 11 |
nicklas |
38 |
import="net.sf.basedb.core.ItemQuery" |
5897 |
02 Dec 11 |
nicklas |
39 |
import="net.sf.basedb.core.ItemResultIterator" |
5897 |
02 Dec 11 |
nicklas |
40 |
import="net.sf.basedb.core.Permission" |
5897 |
02 Dec 11 |
nicklas |
41 |
import="net.sf.basedb.core.PluginDefinition" |
5897 |
02 Dec 11 |
nicklas |
42 |
import="net.sf.basedb.core.ItemContext" |
5897 |
02 Dec 11 |
nicklas |
43 |
import="net.sf.basedb.core.MultiPermissions" |
5897 |
02 Dec 11 |
nicklas |
44 |
import="net.sf.basedb.core.PermissionDeniedException" |
5897 |
02 Dec 11 |
nicklas |
45 |
import="net.sf.basedb.core.ItemAlreadyExistsException" |
5897 |
02 Dec 11 |
nicklas |
46 |
import="net.sf.basedb.core.query.Restriction" |
7603 |
22 Feb 19 |
nicklas |
47 |
import="net.sf.basedb.core.query.SqlQuery" |
5897 |
02 Dec 11 |
nicklas |
48 |
import="net.sf.basedb.plugins.CloneReportersPlugin" |
5897 |
02 Dec 11 |
nicklas |
49 |
import="net.sf.basedb.clients.web.Base" |
5897 |
02 Dec 11 |
nicklas |
50 |
import="net.sf.basedb.clients.web.WebException" |
5897 |
02 Dec 11 |
nicklas |
51 |
import="net.sf.basedb.util.Values" |
5897 |
02 Dec 11 |
nicklas |
52 |
import="net.sf.basedb.clients.web.util.HTML" |
5897 |
02 Dec 11 |
nicklas |
53 |
import="net.sf.basedb.core.plugin.GuiContext" |
5897 |
02 Dec 11 |
nicklas |
54 |
import="java.util.Enumeration" |
5897 |
02 Dec 11 |
nicklas |
55 |
import="java.util.Set" |
5897 |
02 Dec 11 |
nicklas |
56 |
import="java.util.HashSet" |
5897 |
02 Dec 11 |
nicklas |
57 |
import="java.util.List" |
5897 |
02 Dec 11 |
nicklas |
58 |
import="java.util.LinkedList" |
5897 |
02 Dec 11 |
nicklas |
59 |
import="java.util.Collections" |
5897 |
02 Dec 11 |
nicklas |
60 |
import="java.util.Arrays" |
5897 |
02 Dec 11 |
nicklas |
61 |
%> |
5897 |
02 Dec 11 |
nicklas |
62 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
5897 |
02 Dec 11 |
nicklas |
63 |
<%! |
7982 |
14 Jun 21 |
nicklas |
64 |
private static final ItemContext defaultContext = Base.createDefaultContext("@externalId", "cln.externalId,upToDate","cln.externalId"); |
5897 |
02 Dec 11 |
nicklas |
65 |
private static final Item itemType = Item.REPORTER; |
5897 |
02 Dec 11 |
nicklas |
66 |
%> |
5897 |
02 Dec 11 |
nicklas |
67 |
<% |
5897 |
02 Dec 11 |
nicklas |
68 |
final int experimentId = Values.getInt(request.getParameter("experiment_id")); |
5897 |
02 Dec 11 |
nicklas |
69 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
5897 |
02 Dec 11 |
nicklas |
70 |
final String ID = sc.getId(); |
5897 |
02 Dec 11 |
nicklas |
71 |
final String cmd = request.getParameter("cmd"); |
5897 |
02 Dec 11 |
nicklas |
72 |
final String root = request.getContextPath()+"/"; |
5897 |
02 Dec 11 |
nicklas |
73 |
final String mode = request.getParameter("mode"); |
5897 |
02 Dec 11 |
nicklas |
74 |
final String callback = request.getParameter("callback"); |
5897 |
02 Dec 11 |
nicklas |
75 |
final String listPage = "list_reporters.jsp?ID="+ID+"&experiment_id="+experimentId; |
5897 |
02 Dec 11 |
nicklas |
76 |
final String subContext = "clonedreporters." + experimentId; |
5897 |
02 Dec 11 |
nicklas |
77 |
if (experimentId != 0) sc.getCurrentContext(Item.EXPERIMENT).setId(experimentId); |
5897 |
02 Dec 11 |
nicklas |
78 |
|
5897 |
02 Dec 11 |
nicklas |
79 |
String forward = null; |
5897 |
02 Dec 11 |
nicklas |
80 |
String redirect = null; |
5897 |
02 Dec 11 |
nicklas |
81 |
String message = null; |
5897 |
02 Dec 11 |
nicklas |
82 |
DbControl dc = null; |
5897 |
02 Dec 11 |
nicklas |
83 |
|
5897 |
02 Dec 11 |
nicklas |
84 |
try |
5897 |
02 Dec 11 |
nicklas |
85 |
{ |
5897 |
02 Dec 11 |
nicklas |
86 |
if (cmd == null || "List".equals(cmd)) |
5897 |
02 Dec 11 |
nicklas |
87 |
{ |
5897 |
02 Dec 11 |
nicklas |
88 |
// Display the list page without updatinging the current context |
5897 |
02 Dec 11 |
nicklas |
89 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, (PageContext)null, defaultContext, true); |
5897 |
02 Dec 11 |
nicklas |
90 |
redirect = listPage; |
5897 |
02 Dec 11 |
nicklas |
91 |
} |
5897 |
02 Dec 11 |
nicklas |
92 |
else if ("UpdateContext".equals(cmd)) |
5897 |
02 Dec 11 |
nicklas |
93 |
{ |
5897 |
02 Dec 11 |
nicklas |
94 |
// Display the list page after updating the current context from the request parameters |
5897 |
02 Dec 11 |
nicklas |
95 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
5897 |
02 Dec 11 |
nicklas |
96 |
redirect = listPage; |
5897 |
02 Dec 11 |
nicklas |
97 |
} |
5897 |
02 Dec 11 |
nicklas |
98 |
else if ("LoadContext".equals(cmd)) |
5897 |
02 Dec 11 |
nicklas |
99 |
{ |
5897 |
02 Dec 11 |
nicklas |
100 |
// Display the list page after loading a saved context |
5897 |
02 Dec 11 |
nicklas |
101 |
int contextId = Values.getInt(request.getParameter("context")); |
5897 |
02 Dec 11 |
nicklas |
102 |
Base.loadContext(sc, contextId, defaultContext); |
5897 |
02 Dec 11 |
nicklas |
103 |
redirect = listPage; |
5897 |
02 Dec 11 |
nicklas |
104 |
} |
5897 |
02 Dec 11 |
nicklas |
105 |
else if ("ExportItems".equals(cmd)) |
5897 |
02 Dec 11 |
nicklas |
106 |
{ |
5897 |
02 Dec 11 |
nicklas |
107 |
// Run an export plugin in a list context |
5897 |
02 Dec 11 |
nicklas |
108 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
7954 |
12 May 21 |
nicklas |
109 |
dc = sc.newDbControl(":Export "+itemType); |
5897 |
02 Dec 11 |
nicklas |
110 |
final Experiment experiment = Experiment.getById(dc, experimentId); |
7603 |
22 Feb 19 |
nicklas |
111 |
final SqlQuery query = Reporter.getDynamicQuery(experiment); |
5897 |
02 Dec 11 |
nicklas |
112 |
dc.close(); |
5897 |
02 Dec 11 |
nicklas |
113 |
cc.setQuery(query); |
5897 |
02 Dec 11 |
nicklas |
114 |
redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&subcontext="+subContext+"&context_type=LIST&title=Export+bioassay+sets"; |
5897 |
02 Dec 11 |
nicklas |
115 |
} |
5897 |
02 Dec 11 |
nicklas |
116 |
else if ("RunListPlugin".equals(cmd)) |
5897 |
02 Dec 11 |
nicklas |
117 |
{ |
5897 |
02 Dec 11 |
nicklas |
118 |
// Run another plugin in a list context |
5897 |
02 Dec 11 |
nicklas |
119 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
7954 |
12 May 21 |
nicklas |
120 |
dc = sc.newDbControl(":Run plugin "+itemType); |
5897 |
02 Dec 11 |
nicklas |
121 |
final Experiment experiment = Experiment.getById(dc, experimentId); |
7603 |
22 Feb 19 |
nicklas |
122 |
final SqlQuery query = Reporter.getDynamicQuery(experiment); |
5897 |
02 Dec 11 |
nicklas |
123 |
dc.close(); |
5897 |
02 Dec 11 |
nicklas |
124 |
cc.setQuery(query); |
5897 |
02 Dec 11 |
nicklas |
125 |
redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&subcontext="+subContext+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
5897 |
02 Dec 11 |
nicklas |
126 |
} |
5897 |
02 Dec 11 |
nicklas |
127 |
else if ("CreateReporterList".equals(cmd)) |
5897 |
02 Dec 11 |
nicklas |
128 |
{ |
5897 |
02 Dec 11 |
nicklas |
129 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); |
7954 |
12 May 21 |
nicklas |
130 |
dc = sc.newDbControl(":Create reporter list"); |
5897 |
02 Dec 11 |
nicklas |
131 |
final Experiment experiment = Experiment.getById(dc, experimentId); |
7603 |
22 Feb 19 |
nicklas |
132 |
final SqlQuery query = Reporter.getDynamicQuery(experiment); |
5897 |
02 Dec 11 |
nicklas |
133 |
cc.configureQuery(dc, query, Collections.singletonList("@id")); |
5897 |
02 Dec 11 |
nicklas |
134 |
dc.close(); |
5897 |
02 Dec 11 |
nicklas |
135 |
cc.setQuery(query); |
5897 |
02 Dec 11 |
nicklas |
136 |
redirect = "../../../views/reporterlists/index.jsp?ID="+ID+ |
5897 |
02 Dec 11 |
nicklas |
137 |
"&cmd=NewItem&addReporters=1&formId=reporters&fromContext=" + itemType.name() + "&subContext=" + subContext + |
5897 |
02 Dec 11 |
nicklas |
138 |
"&name=" + HTML.urlEncode(experiment.getName()); |
5897 |
02 Dec 11 |
nicklas |
139 |
} |
5897 |
02 Dec 11 |
nicklas |
140 |
else if ("UpdateClonedReporters".equals(cmd)) |
5897 |
02 Dec 11 |
nicklas |
141 |
{ |
5897 |
02 Dec 11 |
nicklas |
142 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
5897 |
02 Dec 11 |
nicklas |
143 |
|
7954 |
12 May 21 |
nicklas |
144 |
dc = sc.newDbControl(":Update cloned reporters"); |
5897 |
02 Dec 11 |
nicklas |
145 |
Experiment exp = Experiment.getById(dc, experimentId); |
5897 |
02 Dec 11 |
nicklas |
146 |
VirtualDb virtualDb = exp.getVirtualDb(); |
5897 |
02 Dec 11 |
nicklas |
147 |
if (!virtualDb.hasClonedReporters()) |
5897 |
02 Dec 11 |
nicklas |
148 |
{ |
5897 |
02 Dec 11 |
nicklas |
149 |
throw new WebException("popup", "This experiment has no cloned reporters", ""); |
5897 |
02 Dec 11 |
nicklas |
150 |
} |
5897 |
02 Dec 11 |
nicklas |
151 |
ReporterCloneTemplate template = exp.getVirtualDb().getReporterCloneTemplate(); |
5897 |
02 Dec 11 |
nicklas |
152 |
|
5897 |
02 Dec 11 |
nicklas |
153 |
PluginDefinition clonePlugin = PluginDefinition.getByClassName(dc, CloneReportersPlugin.class.getName()); |
5897 |
02 Dec 11 |
nicklas |
154 |
Job cloneJob = Job.getNew(dc, clonePlugin, null, exp); |
5897 |
02 Dec 11 |
nicklas |
155 |
cloneJob.setName("Update cloned reporters using template '" + template.getName() + "'"); |
5897 |
02 Dec 11 |
nicklas |
156 |
|
5897 |
02 Dec 11 |
nicklas |
157 |
cloneJob.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
5897 |
02 Dec 11 |
nicklas |
158 |
cloneJob.setParameterValue("template", "Reporter clone template", null, |
5897 |
02 Dec 11 |
nicklas |
159 |
new ItemParameterType<ReporterCloneTemplate>(ReporterCloneTemplate.class, null), template); |
5897 |
02 Dec 11 |
nicklas |
160 |
cloneJob.setParameterValue("cloneSource", "Clone source", null, new StringParameterType(), "VIRTUAL"); |
7432 |
08 Dec 17 |
nicklas |
161 |
cloneJob.setScheduled(null, null); |
5897 |
02 Dec 11 |
nicklas |
162 |
dc.saveItem(cloneJob); |
5897 |
02 Dec 11 |
nicklas |
163 |
dc.commit(); |
5897 |
02 Dec 11 |
nicklas |
164 |
|
5897 |
02 Dec 11 |
nicklas |
165 |
redirect = "../../jobs/index.jsp?ID=" + ID + "&cmd=ViewItem&item_id="+cloneJob.getId(); |
5897 |
02 Dec 11 |
nicklas |
166 |
|
5897 |
02 Dec 11 |
nicklas |
167 |
} |
5897 |
02 Dec 11 |
nicklas |
168 |
else |
5897 |
02 Dec 11 |
nicklas |
169 |
{ |
5897 |
02 Dec 11 |
nicklas |
170 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
5897 |
02 Dec 11 |
nicklas |
171 |
} |
5897 |
02 Dec 11 |
nicklas |
172 |
} |
5897 |
02 Dec 11 |
nicklas |
173 |
finally |
5897 |
02 Dec 11 |
nicklas |
174 |
{ |
5897 |
02 Dec 11 |
nicklas |
175 |
if (dc != null) dc.close(); |
5897 |
02 Dec 11 |
nicklas |
176 |
} |
5897 |
02 Dec 11 |
nicklas |
177 |
|
5897 |
02 Dec 11 |
nicklas |
178 |
if (forward != null) |
5897 |
02 Dec 11 |
nicklas |
179 |
{ |
6192 |
31 Oct 12 |
nicklas |
180 |
sc.setSessionSetting("alert-message", message); |
5897 |
02 Dec 11 |
nicklas |
181 |
pageContext.forward(forward); |
5897 |
02 Dec 11 |
nicklas |
182 |
} |
5897 |
02 Dec 11 |
nicklas |
183 |
else if (redirect != null) |
5897 |
02 Dec 11 |
nicklas |
184 |
{ |
6192 |
31 Oct 12 |
nicklas |
185 |
sc.setSessionSetting("alert-message", message); |
5897 |
02 Dec 11 |
nicklas |
186 |
response.sendRedirect(redirect); |
5897 |
02 Dec 11 |
nicklas |
187 |
} |
5897 |
02 Dec 11 |
nicklas |
188 |
else if (message == null) |
5897 |
02 Dec 11 |
nicklas |
189 |
{ |
5897 |
02 Dec 11 |
nicklas |
190 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
5897 |
02 Dec 11 |
nicklas |
191 |
} |
5897 |
02 Dec 11 |
nicklas |
192 |
else |
5897 |
02 Dec 11 |
nicklas |
193 |
{ |
5897 |
02 Dec 11 |
nicklas |
194 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
5897 |
02 Dec 11 |
nicklas |
195 |
} |
5897 |
02 Dec 11 |
nicklas |
196 |
%> |
5897 |
02 Dec 11 |
nicklas |
197 |
|