1 | <%-- $Id: index.jsp 4974 2009-06-15 09:05:06Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Johan Enell, Jari Häkkinen, Nicklas Nordborg |
---|
5 | Copyright (C) 2007 Nicklas Nordborg, Martin Svensson |
---|
6 | |
---|
7 | This file is part of BASE - BioArray Software Environment. |
---|
8 | Available at http://base.thep.lu.se/ |
---|
9 | |
---|
10 | BASE is free software; you can redistribute it and/or |
---|
11 | modify it under the terms of the GNU General Public License |
---|
12 | as published by the Free Software Foundation; either version 3 |
---|
13 | of the License, or (at your option) any later version. |
---|
14 | |
---|
15 | BASE is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | GNU General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License |
---|
21 | along with BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
22 | ------------------------------------------------------------------ |
---|
23 | |
---|
24 | @author Nicklas |
---|
25 | @version 2.0 |
---|
26 | --%> |
---|
27 | <%@ page session="false" |
---|
28 | import="net.sf.basedb.core.SessionControl" |
---|
29 | import="net.sf.basedb.core.DbControl" |
---|
30 | import="net.sf.basedb.core.BasicItem" |
---|
31 | import="net.sf.basedb.core.Item" |
---|
32 | import="net.sf.basedb.core.ItemContext" |
---|
33 | import="net.sf.basedb.core.ItemQuery" |
---|
34 | import="net.sf.basedb.core.PluginDefinition" |
---|
35 | import="net.sf.basedb.core.PluginConfiguration" |
---|
36 | import="net.sf.basedb.core.PluginParameter" |
---|
37 | import="net.sf.basedb.core.ParameterType" |
---|
38 | import="net.sf.basedb.core.StringParameterType" |
---|
39 | import="net.sf.basedb.core.IntegerParameterType" |
---|
40 | import="net.sf.basedb.core.LongParameterType" |
---|
41 | import="net.sf.basedb.core.FloatParameterType" |
---|
42 | import="net.sf.basedb.core.DoubleParameterType" |
---|
43 | import="net.sf.basedb.core.ItemParameterType" |
---|
44 | import="net.sf.basedb.core.DateParameterType" |
---|
45 | import="net.sf.basedb.core.BooleanParameterType" |
---|
46 | import="net.sf.basedb.core.FileParameterType" |
---|
47 | import="net.sf.basedb.core.PathParameterType" |
---|
48 | import="net.sf.basedb.core.File" |
---|
49 | import="net.sf.basedb.core.Path" |
---|
50 | import="net.sf.basedb.core.Job" |
---|
51 | import="net.sf.basedb.core.JobAgent" |
---|
52 | import="net.sf.basedb.core.Type" |
---|
53 | import="net.sf.basedb.core.Experiment" |
---|
54 | import="net.sf.basedb.core.InternalJobQueue" |
---|
55 | import="net.sf.basedb.core.BaseException" |
---|
56 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
57 | import="net.sf.basedb.core.PluginConfigurationRequest" |
---|
58 | import="net.sf.basedb.core.PluginExecutionRequest" |
---|
59 | import="net.sf.basedb.core.PluginResponse" |
---|
60 | import="net.sf.basedb.core.Include" |
---|
61 | import="net.sf.basedb.core.SimpleProgressReporter" |
---|
62 | import="net.sf.basedb.core.query.Hql" |
---|
63 | import="net.sf.basedb.core.query.Expressions" |
---|
64 | import="net.sf.basedb.core.query.Restrictions" |
---|
65 | import="net.sf.basedb.core.query.Orders" |
---|
66 | import="net.sf.basedb.core.plugin.Plugin" |
---|
67 | import="net.sf.basedb.core.plugin.Response" |
---|
68 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
69 | import="net.sf.basedb.core.plugin.InteractivePlugin" |
---|
70 | import="net.sf.basedb.core.plugin.ExportOutputStream" |
---|
71 | import="net.sf.basedb.core.signal.Signal" |
---|
72 | import="net.sf.basedb.core.signal.SignalHandler" |
---|
73 | import="net.sf.basedb.core.signal.SignalTarget" |
---|
74 | import="net.sf.basedb.clients.web.Base" |
---|
75 | import="net.sf.basedb.clients.web.WebException" |
---|
76 | import="net.sf.basedb.clients.web.DuplicateWizardException" |
---|
77 | import="net.sf.basedb.util.Values" |
---|
78 | import="net.sf.basedb.util.ContextUtil" |
---|
79 | import="net.sf.basedb.util.ContextUtil.ContextResult" |
---|
80 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
81 | import="net.sf.basedb.clients.web.util.HTML" |
---|
82 | import="net.sf.basedb.clients.web.util.ServletExportOutputStream" |
---|
83 | import="net.sf.basedb.clients.web.util.SimpleSignalProgressReporter" |
---|
84 | import="java.util.List" |
---|
85 | import="java.util.LinkedList" |
---|
86 | import="java.util.Arrays" |
---|
87 | import="java.util.Map" |
---|
88 | import="java.util.HashMap" |
---|
89 | import="java.util.LinkedHashMap" |
---|
90 | import="java.util.Set" |
---|
91 | import="java.util.HashSet" |
---|
92 | import="java.util.EnumSet" |
---|
93 | import="java.io.PrintWriter" |
---|
94 | %> |
---|
95 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
96 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
97 | |
---|
98 | <%! |
---|
99 | private static final Set<Item> EXPERIMENT_CONTEXTS = |
---|
100 | EnumSet.of(Item.EXPERIMENT, Item.BIOASSAYSET, Item.BIOASSAY); |
---|
101 | |
---|
102 | private static String getJspPage(PluginConfigurationRequest request, |
---|
103 | PluginDefinition plugin, String defaultPage, String root) |
---|
104 | { |
---|
105 | String jspPage = request.getRequestInformation().getJspPage(); |
---|
106 | if (jspPage == null) |
---|
107 | { |
---|
108 | jspPage = defaultPage; |
---|
109 | } |
---|
110 | else if (jspPage.startsWith("/")) |
---|
111 | { |
---|
112 | // The path is absolute... if it starts with the context root |
---|
113 | // it must be removed because we are doing a forward action |
---|
114 | if (jspPage.startsWith(root)) jspPage = jspPage.substring(root.length()-1); |
---|
115 | } |
---|
116 | else |
---|
117 | { |
---|
118 | String className = plugin.getClassName(); |
---|
119 | int lastDot = className.lastIndexOf('.'); |
---|
120 | String packageName = lastDot == -1 ? "" : className.substring(0, lastDot+1); |
---|
121 | jspPage = "/plugins/"+packageName.replace('.', '/')+jspPage; |
---|
122 | } |
---|
123 | jspPage += "?requestId="+System.identityHashCode(request); |
---|
124 | return jspPage; |
---|
125 | } |
---|
126 | private static Experiment getCurrentExperiment(DbControl dc, GuiContext context) |
---|
127 | { |
---|
128 | if (!EXPERIMENT_CONTEXTS.contains(context.getItem())) return null; |
---|
129 | SessionControl sc = dc.getSessionControl(); |
---|
130 | ItemContext expCtx = sc.getCurrentContext(Item.EXPERIMENT); |
---|
131 | if (expCtx.getId() == 0) return null; |
---|
132 | return Experiment.getById(dc, expCtx.getId()); |
---|
133 | } |
---|
134 | %> |
---|
135 | |
---|
136 | <% |
---|
137 | final String root = request.getContextPath()+"/"; |
---|
138 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
139 | final String ID = sc.getId(); |
---|
140 | final String cmd = request.getParameter("cmd"); |
---|
141 | final boolean warnIfOpen = Values.getBoolean(request.getParameter("warnIfOpen"), true); |
---|
142 | final boolean anotherIsOpen = sc.getSessionSetting("plugin.configure.plugin") != null; |
---|
143 | |
---|
144 | DbControl dc = null; |
---|
145 | String forward = null; |
---|
146 | String message = null; |
---|
147 | String redirect = null; |
---|
148 | try |
---|
149 | { |
---|
150 | |
---|
151 | if ("SelectPlugin".equals(cmd)) |
---|
152 | { |
---|
153 | Item itemType = Item.valueOf(request.getParameter("item_type")); |
---|
154 | String subContext = Values.getString(request.getParameter("subcontext"), ""); |
---|
155 | GuiContext.Type contextType = GuiContext.Type.valueOf(request.getParameter("context_type")); |
---|
156 | GuiContext context = new GuiContext(itemType, contextType, subContext); |
---|
157 | Plugin.MainType mainType = Plugin.MainType.valueOf(request.getParameter("main_type")); |
---|
158 | String pluginType = request.getParameter("plugin_type"); |
---|
159 | |
---|
160 | ItemQuery<PluginDefinition> pluginQuery = PluginDefinition.getQuery(context, pluginType); |
---|
161 | pluginQuery.restrict( |
---|
162 | Restrictions.eq( |
---|
163 | Hql.property("mainType"), |
---|
164 | Expressions.integer(mainType.getValue()) |
---|
165 | ) |
---|
166 | ); |
---|
167 | pluginQuery.order(Orders.asc(Hql.property("name"))); |
---|
168 | pluginQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS); |
---|
169 | |
---|
170 | ItemQuery<PluginConfiguration> configQuery = PluginConfiguration.getQuery(); |
---|
171 | configQuery.restrict( |
---|
172 | Restrictions.eq( |
---|
173 | Hql.property("pluginDefinition"), |
---|
174 | Expressions.parameter("plugin") |
---|
175 | ) |
---|
176 | ); |
---|
177 | configQuery.order(Orders.asc(Hql.property("name"))); |
---|
178 | configQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS); |
---|
179 | |
---|
180 | dc = sc.newDbControl(); |
---|
181 | Object currentItem = null; |
---|
182 | if (contextType == GuiContext.Type.ITEM) |
---|
183 | { |
---|
184 | currentItem = itemType.getById(dc, sc.getCurrentContext(itemType).getId()); |
---|
185 | } |
---|
186 | List<ContextResult> contextResult = ContextUtil.checkContext(dc, pluginQuery, configQuery, context, currentItem); |
---|
187 | dc.close(); |
---|
188 | |
---|
189 | boolean showWarnings = Values.getBoolean(sc.getUserClientSetting("plugins.showWarnings"), false); |
---|
190 | int totalPlugins = ContextUtil.countUsuablePlugins(contextResult); |
---|
191 | Set<String> contextMessages = ContextUtil.getContextMessages(contextResult, showWarnings, true); |
---|
192 | |
---|
193 | if (totalPlugins == 0) |
---|
194 | { |
---|
195 | String msg = "No plugins can be used in this context, for the following reasons:<br><ul><li>"; |
---|
196 | if (contextMessages.size() == 0) |
---|
197 | { |
---|
198 | msg += "Could not find any plugins that you have permission to use</ul>"; |
---|
199 | } |
---|
200 | else |
---|
201 | { |
---|
202 | msg += Values.getString(contextMessages, "<li>", true) + "</ul>"; |
---|
203 | } |
---|
204 | throw new WebException("popup", "No usable plugins found", msg); |
---|
205 | } |
---|
206 | sc.setSessionSetting("MESSAGES", contextMessages); |
---|
207 | sc.setSessionSetting("PLUGINS", contextResult); |
---|
208 | if (totalPlugins == 1 && contextMessages.size() == 0 && !(warnIfOpen && anotherIsOpen)) |
---|
209 | { |
---|
210 | // Only one plug-in, that can be used, exists, find it in contextResult and |
---|
211 | //go directly to parameter input page |
---|
212 | int i = 0; |
---|
213 | PluginDefinition thePlugin = null; |
---|
214 | PluginConfiguration theConfig = null; |
---|
215 | while (i < contextResult.size() && thePlugin == null) |
---|
216 | { |
---|
217 | if (contextResult.get(i).isInContext()) |
---|
218 | { |
---|
219 | thePlugin = contextResult.get(i).getPluginDefinition(); |
---|
220 | theConfig = contextResult.get(i).getPluginConfiguration(); |
---|
221 | } |
---|
222 | i++; |
---|
223 | } |
---|
224 | int pluginDefinitionId = thePlugin.getId(); |
---|
225 | int pluginConfigurationId = theConfig == null ? 0 : theConfig.getId(); |
---|
226 | forward = "index.jsp?cmd=NewJob"+ |
---|
227 | "&plugindefinition_id="+pluginDefinitionId+ |
---|
228 | "&pluginconfiguration_id="+pluginConfigurationId; |
---|
229 | } |
---|
230 | else |
---|
231 | { |
---|
232 | forward = "select_plugin.jsp"; |
---|
233 | } |
---|
234 | } |
---|
235 | else if ("ConfigurePlugin".equals(cmd)) |
---|
236 | { |
---|
237 | if (warnIfOpen && anotherIsOpen) |
---|
238 | { |
---|
239 | throw new DuplicateWizardException(); |
---|
240 | } |
---|
241 | int pluginConfigurationId = Values.getInt(request.getParameter("pluginconfiguration_id")); |
---|
242 | |
---|
243 | dc = sc.newDbControl(); |
---|
244 | PluginConfiguration pluginConfig = PluginConfiguration.getById(dc, pluginConfigurationId); |
---|
245 | PluginDefinition plugin = pluginConfig.getPluginDefinition(); |
---|
246 | |
---|
247 | if (!plugin.supportsConfigurations()) |
---|
248 | { |
---|
249 | throw new WebException("popup", "Configurations are not supported", |
---|
250 | "The plugin {1} doesn't support configurations.", HTML.encodeTags(plugin.getName())); |
---|
251 | } |
---|
252 | PluginConfigurationRequest pcRequest = pluginConfig.configure(); |
---|
253 | |
---|
254 | sc.setSessionSetting("plugin.configure.request", pcRequest); |
---|
255 | sc.setSessionSetting("plugin.configure.job", null); |
---|
256 | sc.setSessionSetting("plugin.configure.plugin", plugin); |
---|
257 | sc.setSessionSetting("plugin.configure.config", pluginConfig); |
---|
258 | sc.setSessionSetting("plugin.configure.errors.message", null); |
---|
259 | sc.setSessionSetting("plugin.configure.errors.list", null); |
---|
260 | forward = getJspPage(pcRequest, plugin, "configure.jsp", root); |
---|
261 | } |
---|
262 | |
---|
263 | else if ("NewJob".equals(cmd)) |
---|
264 | { |
---|
265 | if (warnIfOpen && anotherIsOpen) |
---|
266 | { |
---|
267 | throw new DuplicateWizardException(); |
---|
268 | } |
---|
269 | String pluginClass = request.getParameter("plugin_class"); |
---|
270 | int pluginDefinitionId = Values.getInt(request.getParameter("plugindefinition_id")); |
---|
271 | int pluginConfigurationId = Values.getInt(request.getParameter("pluginconfiguration_id")); |
---|
272 | Item itemType = Item.valueOf(request.getParameter("item_type")); |
---|
273 | String subContext = Values.getString(request.getParameter("subcontext"), ""); |
---|
274 | ItemContext currentContext = sc.getCurrentContext(itemType, subContext); |
---|
275 | GuiContext.Type contextType = GuiContext.Type.valueOf(request.getParameter("context_type")); |
---|
276 | GuiContext context = new GuiContext(itemType, contextType, subContext); |
---|
277 | |
---|
278 | dc = sc.newDbControl(); |
---|
279 | PluginDefinition plugin = pluginClass == null ? |
---|
280 | PluginDefinition.getById(dc, pluginDefinitionId) : PluginDefinition.getByClassName(dc, pluginClass); |
---|
281 | PluginConfiguration pluginConfig = pluginConfigurationId == 0 ? null : PluginConfiguration.getById(dc, pluginConfigurationId); |
---|
282 | Job job = Job.getNew(dc, plugin, pluginConfig, getCurrentExperiment(dc, context)); |
---|
283 | String jobName = Values.getStringOrNull(request.getParameter("job_name")); |
---|
284 | job.setName(jobName == null ? "Run plugin: " + plugin.getName() : jobName); |
---|
285 | job.setDescription(request.getParameter("job_description")); |
---|
286 | |
---|
287 | PluginConfigurationRequest pcRequest = job.configure(context); |
---|
288 | sc.setSessionSetting("plugin.configure.request", pcRequest); |
---|
289 | sc.setSessionSetting("plugin.configure.job", job); |
---|
290 | sc.setSessionSetting("plugin.configure.plugin", plugin); |
---|
291 | sc.setSessionSetting("plugin.configure.config", pluginConfig); |
---|
292 | sc.setSessionSetting("plugin.configure.errors.message", null); |
---|
293 | sc.setSessionSetting("plugin.configure.errors.list", null); |
---|
294 | sc.setSessionSetting("plugin.configure.currentContext", currentContext); |
---|
295 | forward = getJspPage(pcRequest, plugin, "configure.jsp", root); |
---|
296 | } |
---|
297 | |
---|
298 | else if ("CopyJob".equals(cmd)) |
---|
299 | { |
---|
300 | dc = sc.newDbControl(); |
---|
301 | int jobId = Values.getInt(request.getParameter("job_id")); |
---|
302 | Job copyFrom = Job.getById(dc, jobId); |
---|
303 | PluginDefinition plugin = copyFrom.getPluginDefinition(); |
---|
304 | PluginConfiguration pluginConfig = copyFrom.getPluginConfiguration(); |
---|
305 | |
---|
306 | Item itemType = Item.valueOf(request.getParameter("item_type")); |
---|
307 | String subContext = Values.getString(request.getParameter("subcontext"), ""); |
---|
308 | ItemContext currentContext = sc.getCurrentContext(itemType, subContext); |
---|
309 | GuiContext.Type contextType = GuiContext.Type.valueOf(request.getParameter("context_type")); |
---|
310 | GuiContext context = new GuiContext(itemType, contextType, subContext); |
---|
311 | |
---|
312 | Job job = Job.getNew(dc, plugin, pluginConfig, getCurrentExperiment(dc, context)); |
---|
313 | job.copyParametersFrom(copyFrom); |
---|
314 | |
---|
315 | PluginConfigurationRequest pcRequest = job.configure(context); |
---|
316 | sc.setSessionSetting("plugin.configure.request", pcRequest); |
---|
317 | sc.setSessionSetting("plugin.configure.job", job); |
---|
318 | sc.setSessionSetting("plugin.configure.plugin", plugin); |
---|
319 | sc.setSessionSetting("plugin.configure.config", pluginConfig); |
---|
320 | sc.setSessionSetting("plugin.configure.errors.message", null); |
---|
321 | sc.setSessionSetting("plugin.configure.errors.list", null); |
---|
322 | sc.setSessionSetting("plugin.configure.currentContext", currentContext); |
---|
323 | forward = getJspPage(pcRequest, plugin, "configure.jsp", root); |
---|
324 | } |
---|
325 | |
---|
326 | else if ("ConfigureJob".equals(cmd)) |
---|
327 | { |
---|
328 | dc = sc.newDbControl(); |
---|
329 | |
---|
330 | int jobId = Values.getInt(request.getParameter("job_id")); |
---|
331 | Job job = Job.getById(dc, jobId); |
---|
332 | |
---|
333 | //Item itemType = Item.valueOf(request.getParameter("item_type")); |
---|
334 | //String subContext = Values.getString(request.getParameter("subcontext"), ""); |
---|
335 | //GuiContext.Type contextType = GuiContext.Type.valueOf(request.getParameter("context_type")); |
---|
336 | GuiContext context = job.getLastGuiContext(); |
---|
337 | |
---|
338 | PluginDefinition plugin = job.getPluginDefinition(); |
---|
339 | PluginConfiguration pluginConfig = job.getPluginConfiguration(); |
---|
340 | |
---|
341 | PluginConfigurationRequest pcRequest = job.configure(context); |
---|
342 | sc.setSessionSetting("plugin.configure.request", pcRequest); |
---|
343 | sc.setSessionSetting("plugin.configure.job", job); |
---|
344 | sc.setSessionSetting("plugin.configure.plugin", plugin); |
---|
345 | sc.setSessionSetting("plugin.configure.config", pluginConfig); |
---|
346 | sc.setSessionSetting("plugin.configure.errors.message", null); |
---|
347 | sc.setSessionSetting("plugin.configure.errors.list", null); |
---|
348 | forward = getJspPage(pcRequest, plugin, "configure.jsp", root); |
---|
349 | } |
---|
350 | |
---|
351 | else if ("SetParameters".equals(cmd)) |
---|
352 | { |
---|
353 | int maxRecent = Base.getMaxRecent(sc); |
---|
354 | PluginConfigurationRequest pcRequest = (PluginConfigurationRequest)sc.getSessionSetting("plugin.configure.request"); |
---|
355 | String requestId = request.getParameter("requestId"); |
---|
356 | if (requestId != null && !requestId.equals(Integer.toString(System.identityHashCode(pcRequest)))) |
---|
357 | { |
---|
358 | throw new WebException("popup", "Invalid request ID", "Data in your configuration wizard has become corrupted. Please re-start and try again."); |
---|
359 | } |
---|
360 | List<PluginParameter<?>> parameters = pcRequest.getRequestInformation().getParameters(); |
---|
361 | List<Throwable> parseErrors = new LinkedList<Throwable>(); |
---|
362 | ItemContext currentContext = (ItemContext)sc.getSessionSetting("plugin.configure.currentContext"); |
---|
363 | // Clear old errors |
---|
364 | sc.setSessionSetting("plugin.configure.errors.message", null); |
---|
365 | sc.setSessionSetting("plugin.configure.errors.list", null); |
---|
366 | if (parameters != null && parameters.size() > 0) |
---|
367 | { |
---|
368 | for (PluginParameter<?> param : parameters) |
---|
369 | { |
---|
370 | ParameterType pType = param.getParameterType(); |
---|
371 | if (pType != null) |
---|
372 | { |
---|
373 | String[] sValues = request.getParameterValues("parameter:"+param.getName()); |
---|
374 | boolean emptyIsNull = Values.getBoolean(request.getParameter("parameter:" + param.getName() + ":emptyIsNull")); |
---|
375 | if (emptyIsNull) |
---|
376 | { |
---|
377 | for (int i = 0; i < sValues.length; ++i) |
---|
378 | { |
---|
379 | if ("".equals(sValues[i])) sValues[i] = null; |
---|
380 | } |
---|
381 | } |
---|
382 | Object[] oValues = null; |
---|
383 | try |
---|
384 | { |
---|
385 | if (sValues != null) |
---|
386 | { |
---|
387 | if (pType instanceof StringParameterType) |
---|
388 | { |
---|
389 | oValues = sValues; |
---|
390 | } |
---|
391 | else if (pType instanceof IntegerParameterType) |
---|
392 | { |
---|
393 | oValues = Values.getInt(sValues); |
---|
394 | } |
---|
395 | else if (pType instanceof LongParameterType) |
---|
396 | { |
---|
397 | oValues = Values.getLong(sValues); |
---|
398 | } |
---|
399 | else if (pType instanceof FloatParameterType) |
---|
400 | { |
---|
401 | oValues = Values.getFloat(sValues); |
---|
402 | } |
---|
403 | else if (pType instanceof DoubleParameterType) |
---|
404 | { |
---|
405 | oValues = Values.getDouble(sValues); |
---|
406 | } |
---|
407 | else if (pType instanceof BooleanParameterType) |
---|
408 | { |
---|
409 | oValues = Type.BOOLEAN.parseStrings(sValues); |
---|
410 | } |
---|
411 | else if (pType instanceof DateParameterType) |
---|
412 | { |
---|
413 | oValues = Values.getDate(sValues, FormatterFactory.getDateFormatter(sc)); |
---|
414 | } |
---|
415 | else if (pType instanceof ItemParameterType) |
---|
416 | { |
---|
417 | Integer[] itemId = Values.getInt(sValues); |
---|
418 | oValues = new Object[itemId.length]; |
---|
419 | Item iType = Item.fromItemClass(pType.getParameterClass()); |
---|
420 | dc = sc.newDbControl(); |
---|
421 | for (int i = 0; i < itemId.length; ++i) |
---|
422 | { |
---|
423 | Integer id = itemId[i]; |
---|
424 | if (id != null && id != 0) |
---|
425 | { |
---|
426 | BasicItem item = iType.getById(dc, id); |
---|
427 | oValues[i] = item; |
---|
428 | if (currentContext != null) |
---|
429 | { |
---|
430 | currentContext.setRecent(item, maxRecent); |
---|
431 | } |
---|
432 | } |
---|
433 | } |
---|
434 | dc.close(); |
---|
435 | } |
---|
436 | else if (pType instanceof FileParameterType) |
---|
437 | { |
---|
438 | oValues = new Object[sValues.length]; |
---|
439 | dc = sc.newDbControl(); |
---|
440 | for (int i = 0; i < sValues.length; ++i) |
---|
441 | { |
---|
442 | File file = File.getByPath(dc, new Path(sValues[i], Path.Type.FILE), false); |
---|
443 | oValues[i] = file; |
---|
444 | if (currentContext != null) |
---|
445 | { |
---|
446 | currentContext.setRecent(file, maxRecent); |
---|
447 | } |
---|
448 | } |
---|
449 | dc.close(); |
---|
450 | } |
---|
451 | else if (pType instanceof PathParameterType) |
---|
452 | { |
---|
453 | oValues = sValues; |
---|
454 | } |
---|
455 | } |
---|
456 | } |
---|
457 | catch (Throwable t) |
---|
458 | { |
---|
459 | parseErrors.add(t); |
---|
460 | } |
---|
461 | pcRequest.setParameterValues(param.getName(), oValues == null ? null : Arrays.asList(oValues)); |
---|
462 | } |
---|
463 | } |
---|
464 | } |
---|
465 | PluginResponse pluginResponse = null; |
---|
466 | Response.Status status = null; |
---|
467 | if (parseErrors.size() == 0) |
---|
468 | { |
---|
469 | pluginResponse = pcRequest.invoke(); |
---|
470 | status = pluginResponse.getStatus(); |
---|
471 | } |
---|
472 | else |
---|
473 | { |
---|
474 | status = Response.Status.ERROR; |
---|
475 | } |
---|
476 | if (status == Response.Status.DONE || status == Response.Status.EXECUTE_IMMEDIATELY) |
---|
477 | { |
---|
478 | Job job = (Job)sc.getSessionSetting("plugin.configure.job"); |
---|
479 | if (job != null) |
---|
480 | { |
---|
481 | sc.setSessionSetting("plugin.configure.response", pluginResponse); |
---|
482 | forward = "finish_job.jsp"; |
---|
483 | } |
---|
484 | else |
---|
485 | { |
---|
486 | dc = sc.newDbControl(); |
---|
487 | pluginResponse.saveParameters(dc); |
---|
488 | dc.commit(); |
---|
489 | sc.setSessionSetting("plugin.configure.request", null); |
---|
490 | sc.setSessionSetting("plugin.configure.plugin", null); |
---|
491 | sc.setSessionSetting("plugin.configure.config", null); |
---|
492 | sc.setSessionSetting("plugin.configure.currentContext", null); |
---|
493 | message = "Plugin configured"; |
---|
494 | } |
---|
495 | } |
---|
496 | else if (status == Response.Status.CONTINUE) |
---|
497 | { |
---|
498 | pcRequest = pluginResponse.getNextRequest(); |
---|
499 | sc.setSessionSetting("plugin.configure.request", pcRequest); |
---|
500 | PluginDefinition plugin = (PluginDefinition)sc.getSessionSetting("plugin.configure.plugin"); |
---|
501 | forward = getJspPage(pcRequest, plugin, "configure.jsp", root); |
---|
502 | } |
---|
503 | else if (status == Response.Status.ERROR) |
---|
504 | { |
---|
505 | PluginDefinition plugin = (PluginDefinition)sc.getSessionSetting("plugin.configure.plugin"); |
---|
506 | if (parseErrors.size() > 0) |
---|
507 | { |
---|
508 | sc.setSessionSetting("plugin.configure.errors.message", |
---|
509 | parseErrors.size() + " parameter value(s) are invalid"); |
---|
510 | sc.setSessionSetting("plugin.configure.errors.list", parseErrors); |
---|
511 | } |
---|
512 | else |
---|
513 | { |
---|
514 | sc.setSessionSetting("plugin.configure.errors.message", pluginResponse.getMessage()); |
---|
515 | sc.setSessionSetting("plugin.configure.errors.list", pluginResponse.getErrorList()); |
---|
516 | } |
---|
517 | forward = getJspPage(pcRequest, plugin, "configure.jsp", root); |
---|
518 | } |
---|
519 | else if (status == Response.Status.DOWNLOAD_IMMEDIATELY) |
---|
520 | { |
---|
521 | sc.setSessionSetting("plugin.configure.response", pluginResponse); |
---|
522 | forward = "download_immediately.jsp"; |
---|
523 | } |
---|
524 | else |
---|
525 | { |
---|
526 | throw new WebException("popup", "Unknown response from plugin", status.toString()); |
---|
527 | } |
---|
528 | } |
---|
529 | else if ("FinishNewJob".equals(cmd)) |
---|
530 | { |
---|
531 | dc = sc.newDbControl(); |
---|
532 | Job job = (Job)sc.getSessionSetting("plugin.configure.job"); |
---|
533 | if (job.isInDatabase()) |
---|
534 | { |
---|
535 | dc.reattachItem(job); |
---|
536 | } |
---|
537 | else |
---|
538 | { |
---|
539 | dc.saveItem(job); |
---|
540 | } |
---|
541 | |
---|
542 | PluginResponse pluginResponse = (PluginResponse)sc.getSessionSetting("plugin.configure.response"); |
---|
543 | boolean executeImmediately = |
---|
544 | pluginResponse != null && pluginResponse.getStatus() == Response.Status.EXECUTE_IMMEDIATELY; |
---|
545 | |
---|
546 | job.setName(Values.getStringOrNull(request.getParameter("name"))); |
---|
547 | job.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
---|
548 | job.setSendMessage(Values.getBoolean(request.getParameter("send_message"))); |
---|
549 | job.setRemoveJobWhenFinished(Values.getBoolean(request.getParameter("remove_job"))); |
---|
550 | |
---|
551 | if (!executeImmediately) |
---|
552 | { |
---|
553 | int agentId = Values.getInt(request.getParameter("agent_id"), -1); |
---|
554 | if (agentId >= 0) |
---|
555 | { |
---|
556 | job.setJobAgent(agentId == 0 ? null : JobAgent.getById(dc, agentId)); |
---|
557 | } |
---|
558 | } |
---|
559 | |
---|
560 | if (pluginResponse != null) pluginResponse.saveParameters(dc); |
---|
561 | dc.commit(); |
---|
562 | redirect = "../../views/jobs/index.jsp?ID="+ID+"&cmd=ViewItem&item_id="+job.getId(); |
---|
563 | sc.setSessionSetting("plugin.configure.job", null); |
---|
564 | sc.setSessionSetting("plugin.configure.request", null); |
---|
565 | sc.setSessionSetting("plugin.configure.response", null); |
---|
566 | sc.setSessionSetting("plugin.configure.plugin", null); |
---|
567 | sc.setSessionSetting("plugin.configure.config", null); |
---|
568 | sc.setSessionSetting("plugin.configure.currentContext", null); |
---|
569 | if (executeImmediately) |
---|
570 | { |
---|
571 | PluginExecutionRequest executionRequest = pluginResponse.getExecutionRequest(null); |
---|
572 | executionRequest.registerSignalReceiver(InternalJobQueue.getSignalReceiver()); |
---|
573 | Thread t = new Thread(executionRequest); |
---|
574 | t.setPriority(Thread.currentThread().getPriority() - 1); |
---|
575 | t.start(); |
---|
576 | } |
---|
577 | } |
---|
578 | else if ("ExportImmediately".equals(cmd)) |
---|
579 | { |
---|
580 | PluginResponse pluginResponse = (PluginResponse)sc.getSessionSetting("plugin.configure.response"); |
---|
581 | ExportOutputStream exportStream = new ServletExportOutputStream(response); |
---|
582 | SimpleSignalProgressReporter progress = new SimpleSignalProgressReporter(null); |
---|
583 | sc.setSessionSetting("plugin.configure.progress.reporter", progress); |
---|
584 | try |
---|
585 | { |
---|
586 | pluginResponse.downloadImmediately(exportStream, progress); |
---|
587 | } |
---|
588 | catch (Throwable t) |
---|
589 | { |
---|
590 | PrintWriter pw = new PrintWriter(exportStream, true); |
---|
591 | t.printStackTrace(pw); |
---|
592 | pw.flush(); |
---|
593 | pw.close(); |
---|
594 | } |
---|
595 | exportStream.flush(); |
---|
596 | exportStream.close(); |
---|
597 | sc.setSessionSetting("plugin.configure.job", null); |
---|
598 | sc.setSessionSetting("plugin.configure.request", null); |
---|
599 | sc.setSessionSetting("plugin.configure.response", null); |
---|
600 | sc.setSessionSetting("plugin.configure.plugin", null); |
---|
601 | sc.setSessionSetting("plugin.configure.config", null); |
---|
602 | sc.setSessionSetting("plugin.configure.errors.message", null); |
---|
603 | sc.setSessionSetting("plugin.configure.errors.list", null); |
---|
604 | sc.setSessionSetting("plugin.configure.currentContext", null); |
---|
605 | return; |
---|
606 | } |
---|
607 | else if ("CancelWizard".equals(cmd)) |
---|
608 | { |
---|
609 | PluginConfigurationRequest pcRequest = |
---|
610 | (PluginConfigurationRequest)sc.setSessionSetting("plugin.configure.request", null); |
---|
611 | SimpleSignalProgressReporter progress = (SimpleSignalProgressReporter)sc.getSessionSetting("plugin.configure.progress.reporter"); |
---|
612 | if (progress != null) progress.sendToAll(Signal.ABORT); |
---|
613 | if (pcRequest != null) pcRequest.done(); |
---|
614 | sc.setSessionSetting("plugin.configure.response", null); |
---|
615 | sc.setSessionSetting("plugin.configure.plugin", null); |
---|
616 | sc.setSessionSetting("plugin.configure.config", null); |
---|
617 | sc.setSessionSetting("plugin.configure.job", null); |
---|
618 | sc.setSessionSetting("plugin.configure.errors.message", null); |
---|
619 | sc.setSessionSetting("plugin.configure.errors.list", null); |
---|
620 | sc.setSessionSetting("plugin.configure.currentContext", null); |
---|
621 | sc.setSessionSetting("plugin.configure.progress.reporter", null); |
---|
622 | redirect = root + "common/close_popup.jsp?refresh_opener=0&wait=0"; |
---|
623 | } |
---|
624 | else |
---|
625 | { |
---|
626 | throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
---|
627 | } |
---|
628 | } |
---|
629 | finally |
---|
630 | { |
---|
631 | if (dc != null) dc.close(); |
---|
632 | } |
---|
633 | |
---|
634 | if (forward != null) |
---|
635 | { |
---|
636 | pageContext.forward(forward); |
---|
637 | } |
---|
638 | else if (redirect != null) |
---|
639 | { |
---|
640 | response.sendRedirect(redirect); |
---|
641 | } |
---|
642 | else if (message == null) |
---|
643 | { |
---|
644 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
---|
645 | } |
---|
646 | else |
---|
647 | { |
---|
648 | response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
---|
649 | } |
---|
650 | %> |
---|