2629 |
08 Sep 06 |
nicklas |
1 |
<%-- $Id$ |
2629 |
08 Sep 06 |
nicklas |
2 |
------------------------------------------------------------------ |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2006 Nicklas Nordborg |
2629 |
08 Sep 06 |
nicklas |
4 |
|
2629 |
08 Sep 06 |
nicklas |
5 |
This file is part of BASE - BioArray Software Environment. |
2629 |
08 Sep 06 |
nicklas |
6 |
Available at http://base.thep.lu.se/ |
2629 |
08 Sep 06 |
nicklas |
7 |
|
2629 |
08 Sep 06 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or |
2629 |
08 Sep 06 |
nicklas |
9 |
modify it under the terms of the GNU General Public License |
4476 |
05 Sep 08 |
jari |
10 |
as published by the Free Software Foundation; either version 3 |
2629 |
08 Sep 06 |
nicklas |
11 |
of the License, or (at your option) any later version. |
2629 |
08 Sep 06 |
nicklas |
12 |
|
2629 |
08 Sep 06 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, |
2629 |
08 Sep 06 |
nicklas |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2629 |
08 Sep 06 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2629 |
08 Sep 06 |
nicklas |
16 |
GNU General Public License for more details. |
2629 |
08 Sep 06 |
nicklas |
17 |
|
2629 |
08 Sep 06 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
4510 |
11 Sep 08 |
jari |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
2629 |
08 Sep 06 |
nicklas |
20 |
------------------------------------------------------------------ |
2629 |
08 Sep 06 |
nicklas |
21 |
|
2629 |
08 Sep 06 |
nicklas |
22 |
@author Nicklas |
2629 |
08 Sep 06 |
nicklas |
23 |
@version 2.0 |
2629 |
08 Sep 06 |
nicklas |
24 |
--%> |
5426 |
24 Sep 10 |
nicklas |
25 |
<%@ page pageEncoding="UTF-8" session="false" |
2629 |
08 Sep 06 |
nicklas |
26 |
import="net.sf.basedb.core.SessionControl" |
2629 |
08 Sep 06 |
nicklas |
27 |
import="net.sf.basedb.core.DbControl" |
2629 |
08 Sep 06 |
nicklas |
28 |
import="net.sf.basedb.core.Item" |
2629 |
08 Sep 06 |
nicklas |
29 |
import="net.sf.basedb.core.Include" |
2629 |
08 Sep 06 |
nicklas |
30 |
import="net.sf.basedb.core.JobAgent" |
2629 |
08 Sep 06 |
nicklas |
31 |
import="net.sf.basedb.core.JobAgentSettings" |
2629 |
08 Sep 06 |
nicklas |
32 |
import="net.sf.basedb.core.PluginDefinition" |
2629 |
08 Sep 06 |
nicklas |
33 |
import="net.sf.basedb.core.ItemQuery" |
2629 |
08 Sep 06 |
nicklas |
34 |
import="net.sf.basedb.core.Permission" |
2629 |
08 Sep 06 |
nicklas |
35 |
import="net.sf.basedb.core.ItemContext" |
2629 |
08 Sep 06 |
nicklas |
36 |
import="net.sf.basedb.core.MultiPermissions" |
4587 |
15 Oct 08 |
martin |
37 |
import="net.sf.basedb.core.OwnedItem" |
2629 |
08 Sep 06 |
nicklas |
38 |
import="net.sf.basedb.core.PermissionDeniedException" |
2629 |
08 Sep 06 |
nicklas |
39 |
import="net.sf.basedb.core.ItemAlreadyExistsException" |
2629 |
08 Sep 06 |
nicklas |
40 |
import="net.sf.basedb.util.RemovableUtil" |
2629 |
08 Sep 06 |
nicklas |
41 |
import="net.sf.basedb.util.ShareableUtil" |
2921 |
15 Nov 06 |
nicklas |
42 |
import="net.sf.basedb.util.OwnableUtil" |
2648 |
19 Sep 06 |
nicklas |
43 |
import="net.sf.basedb.util.jobagent.JobAgentConnection" |
2629 |
08 Sep 06 |
nicklas |
44 |
import="net.sf.basedb.clients.web.Base" |
2629 |
08 Sep 06 |
nicklas |
45 |
import="net.sf.basedb.clients.web.WebException" |
2753 |
20 Oct 06 |
nicklas |
46 |
import="net.sf.basedb.util.Values" |
2629 |
08 Sep 06 |
nicklas |
47 |
import="net.sf.basedb.clients.web.util.HTML" |
5508 |
19 Nov 10 |
nicklas |
48 |
import="net.sf.basedb.core.plugin.GuiContext" |
5508 |
19 Nov 10 |
nicklas |
49 |
import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
5508 |
19 Nov 10 |
nicklas |
50 |
import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
5508 |
19 Nov 10 |
nicklas |
51 |
import="net.sf.basedb.clients.web.extensions.JspContext" |
5508 |
19 Nov 10 |
nicklas |
52 |
import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
7604 |
25 Feb 19 |
nicklas |
53 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveAction" |
5508 |
19 Nov 10 |
nicklas |
54 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer" |
6045 |
03 Apr 12 |
nicklas |
55 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer" |
7604 |
25 Feb 19 |
nicklas |
56 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnAction" |
6045 |
03 Apr 12 |
nicklas |
57 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil" |
2629 |
08 Sep 06 |
nicklas |
58 |
import="java.util.Enumeration" |
2629 |
08 Sep 06 |
nicklas |
59 |
import="java.util.Set" |
2629 |
08 Sep 06 |
nicklas |
60 |
import="java.util.HashSet" |
2629 |
08 Sep 06 |
nicklas |
61 |
import="java.util.List" |
2629 |
08 Sep 06 |
nicklas |
62 |
import="java.util.ArrayList" |
2629 |
08 Sep 06 |
nicklas |
63 |
import="java.util.Collections" |
2629 |
08 Sep 06 |
nicklas |
64 |
%> |
2629 |
08 Sep 06 |
nicklas |
65 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
2629 |
08 Sep 06 |
nicklas |
66 |
<%! |
2643 |
15 Sep 06 |
nicklas |
67 |
private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,externalId,server,port,status,info"); |
2629 |
08 Sep 06 |
nicklas |
68 |
private static final Item itemType = Item.JOBAGENT; |
2629 |
08 Sep 06 |
nicklas |
69 |
%> |
2629 |
08 Sep 06 |
nicklas |
70 |
<% |
2629 |
08 Sep 06 |
nicklas |
71 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
2629 |
08 Sep 06 |
nicklas |
72 |
final String ID = sc.getId(); |
2629 |
08 Sep 06 |
nicklas |
73 |
final String cmd = request.getParameter("cmd"); |
2629 |
08 Sep 06 |
nicklas |
74 |
final String root = request.getContextPath()+"/"; |
2629 |
08 Sep 06 |
nicklas |
75 |
final String mode = request.getParameter("mode"); |
2629 |
08 Sep 06 |
nicklas |
76 |
final String callback = request.getParameter("callback"); |
2629 |
08 Sep 06 |
nicklas |
77 |
final String itemId = request.getParameter("item_id"); |
2629 |
08 Sep 06 |
nicklas |
78 |
final String listPage = "list_agents.jsp?ID="+ID |
2629 |
08 Sep 06 |
nicklas |
79 |
+(mode == null ? "" : "&mode="+mode) |
2629 |
08 Sep 06 |
nicklas |
80 |
+(callback == null ? "" : "&callback="+callback) |
2629 |
08 Sep 06 |
nicklas |
81 |
+(itemId == null ? "" : "&item_id="+itemId); |
2629 |
08 Sep 06 |
nicklas |
82 |
final String viewPage = "view_agent.jsp?ID="+ID; |
2629 |
08 Sep 06 |
nicklas |
83 |
final String editPage = "edit_agent.jsp?ID="+ID; |
2629 |
08 Sep 06 |
nicklas |
84 |
|
2629 |
08 Sep 06 |
nicklas |
85 |
String forward = null; |
2629 |
08 Sep 06 |
nicklas |
86 |
String redirect = null; |
2629 |
08 Sep 06 |
nicklas |
87 |
String message = null; |
2629 |
08 Sep 06 |
nicklas |
88 |
DbControl dc = null; |
2629 |
08 Sep 06 |
nicklas |
89 |
|
2629 |
08 Sep 06 |
nicklas |
90 |
try |
2629 |
08 Sep 06 |
nicklas |
91 |
{ |
2629 |
08 Sep 06 |
nicklas |
92 |
if (cmd == null || "List".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
93 |
{ |
2629 |
08 Sep 06 |
nicklas |
94 |
// Display the list page without updatinging the current context |
2811 |
26 Oct 06 |
nicklas |
95 |
Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true); |
2629 |
08 Sep 06 |
nicklas |
96 |
redirect = listPage; |
2629 |
08 Sep 06 |
nicklas |
97 |
} |
2629 |
08 Sep 06 |
nicklas |
98 |
else if ("UpdateContext".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
99 |
{ |
2629 |
08 Sep 06 |
nicklas |
100 |
// Display the list page after updating the current context from the request parameters |
2629 |
08 Sep 06 |
nicklas |
101 |
Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
102 |
redirect = listPage; |
2629 |
08 Sep 06 |
nicklas |
103 |
} |
2629 |
08 Sep 06 |
nicklas |
104 |
else if ("LoadContext".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
105 |
{ |
2629 |
08 Sep 06 |
nicklas |
106 |
// Display the list page after loading a saved context |
2629 |
08 Sep 06 |
nicklas |
107 |
int contextId = Values.getInt(request.getParameter("context")); |
2629 |
08 Sep 06 |
nicklas |
108 |
Base.loadContext(sc, contextId, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
109 |
redirect = listPage; |
2629 |
08 Sep 06 |
nicklas |
110 |
} |
2629 |
08 Sep 06 |
nicklas |
111 |
|
2629 |
08 Sep 06 |
nicklas |
112 |
else if ("ViewItem".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
113 |
{ |
2629 |
08 Sep 06 |
nicklas |
114 |
// Display the view page for a single item |
2629 |
08 Sep 06 |
nicklas |
115 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
116 |
forward = viewPage; |
2629 |
08 Sep 06 |
nicklas |
117 |
} |
2629 |
08 Sep 06 |
nicklas |
118 |
else if ("EditItem".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
119 |
{ |
2629 |
08 Sep 06 |
nicklas |
120 |
// Display the edit page for a single item (should be opened in a popup) |
2629 |
08 Sep 06 |
nicklas |
121 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2631 |
08 Sep 06 |
nicklas |
122 |
forward = editPage; |
2629 |
08 Sep 06 |
nicklas |
123 |
} |
2629 |
08 Sep 06 |
nicklas |
124 |
else if ("NewItem".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
125 |
{ |
2629 |
08 Sep 06 |
nicklas |
126 |
// Display the edit page for a new item (should be opened in a popup) |
2629 |
08 Sep 06 |
nicklas |
127 |
if (!sc.hasPermission(Permission.CREATE, itemType)) |
2629 |
08 Sep 06 |
nicklas |
128 |
{ |
2629 |
08 Sep 06 |
nicklas |
129 |
throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
2629 |
08 Sep 06 |
nicklas |
130 |
} |
2629 |
08 Sep 06 |
nicklas |
131 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
132 |
cc.setId(0); |
2629 |
08 Sep 06 |
nicklas |
133 |
redirect = editPage; |
2629 |
08 Sep 06 |
nicklas |
134 |
} |
2629 |
08 Sep 06 |
nicklas |
135 |
else if ("UpdateItem".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
136 |
{ |
2629 |
08 Sep 06 |
nicklas |
137 |
// Update the properties on an item (will close the popup) |
2629 |
08 Sep 06 |
nicklas |
138 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
7954 |
12 May 21 |
nicklas |
139 |
dc = sc.newDbControl(":Edit "+itemType); |
7605 |
26 Feb 19 |
nicklas |
140 |
JobAgent agent = cc.getObject("item"); |
2629 |
08 Sep 06 |
nicklas |
141 |
if (agent == null) |
2629 |
08 Sep 06 |
nicklas |
142 |
{ |
2629 |
08 Sep 06 |
nicklas |
143 |
agent = JobAgent.getNew(dc, Values.getStringOrNull(request.getParameter("external_id"))); |
2629 |
08 Sep 06 |
nicklas |
144 |
message = "Job agent created"; |
2629 |
08 Sep 06 |
nicklas |
145 |
dc.saveItem(agent); |
2629 |
08 Sep 06 |
nicklas |
146 |
} |
2629 |
08 Sep 06 |
nicklas |
147 |
else |
2629 |
08 Sep 06 |
nicklas |
148 |
{ |
5060 |
19 Aug 09 |
nicklas |
149 |
dc.reattachItem(agent, false); |
2629 |
08 Sep 06 |
nicklas |
150 |
agent.setExternalId(Values.getStringOrNull(request.getParameter("external_id"))); |
2629 |
08 Sep 06 |
nicklas |
151 |
message = "Job agent updated"; |
2629 |
08 Sep 06 |
nicklas |
152 |
} |
5508 |
19 Nov 10 |
nicklas |
153 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.JOBAGENT), agent); |
7604 |
25 Feb 19 |
nicklas |
154 |
ExtensionsInvoker<OnSaveAction> invoker = EditUtil.useOnSaveExtensions(jspContext); |
5508 |
19 Nov 10 |
nicklas |
155 |
try |
2629 |
08 Sep 06 |
nicklas |
156 |
{ |
5508 |
19 Nov 10 |
nicklas |
157 |
agent.setName(Values.getStringOrNull(request.getParameter("name"))); |
5508 |
19 Nov 10 |
nicklas |
158 |
agent.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
5508 |
19 Nov 10 |
nicklas |
159 |
agent.setServer(Values.getStringOrNull(request.getParameter("server"))); |
5508 |
19 Nov 10 |
nicklas |
160 |
agent.setPort(Values.getInteger(request.getParameter("port"), null)); |
5508 |
19 Nov 10 |
nicklas |
161 |
|
5508 |
19 Nov 10 |
nicklas |
162 |
// Installed plugins |
6305 |
09 Aug 13 |
nicklas |
163 |
String[] removePlugins = Values.getString(request.getParameter("-PLUGINDEFINITION")).split(","); |
5508 |
19 Nov 10 |
nicklas |
164 |
for (int i = 0; i < removePlugins.length; ++i) |
2629 |
08 Sep 06 |
nicklas |
165 |
{ |
5508 |
19 Nov 10 |
nicklas |
166 |
int pluginId = Values.getInt(removePlugins[i], -1); |
5508 |
19 Nov 10 |
nicklas |
167 |
if (pluginId != -1) |
5508 |
19 Nov 10 |
nicklas |
168 |
{ |
5508 |
19 Nov 10 |
nicklas |
169 |
JobAgentSettings settings = agent.getSettings(PluginDefinition.getById(dc, pluginId), false); |
5508 |
19 Nov 10 |
nicklas |
170 |
if (settings != null && settings.isInDatabase()) dc.deleteItem(settings); |
5508 |
19 Nov 10 |
nicklas |
171 |
} |
2629 |
08 Sep 06 |
nicklas |
172 |
} |
5508 |
19 Nov 10 |
nicklas |
173 |
|
5508 |
19 Nov 10 |
nicklas |
174 |
String[] allPlugins = Values.getString(request.getParameter("allPlugins")).split(","); |
5508 |
19 Nov 10 |
nicklas |
175 |
for (int i = 0; i < allPlugins.length; ++i) |
2629 |
08 Sep 06 |
nicklas |
176 |
{ |
5508 |
19 Nov 10 |
nicklas |
177 |
int pluginId = Values.getInt(allPlugins[i], -1); |
5508 |
19 Nov 10 |
nicklas |
178 |
if (pluginId != -1) |
3871 |
22 Oct 07 |
nicklas |
179 |
{ |
5508 |
19 Nov 10 |
nicklas |
180 |
PluginDefinition plugin = PluginDefinition.getById(dc, pluginId); |
5508 |
19 Nov 10 |
nicklas |
181 |
if (plugin.hasPermission(Permission.WRITE) && plugin.getUseInternalJobQueue()) |
5508 |
19 Nov 10 |
nicklas |
182 |
{ |
5508 |
19 Nov 10 |
nicklas |
183 |
plugin.setUseInternalJobQueue(false); |
5508 |
19 Nov 10 |
nicklas |
184 |
} |
5508 |
19 Nov 10 |
nicklas |
185 |
JobAgentSettings settings = agent.getSettings(plugin, true); |
5508 |
19 Nov 10 |
nicklas |
186 |
if (!settings.isInDatabase()) |
5508 |
19 Nov 10 |
nicklas |
187 |
{ |
5508 |
19 Nov 10 |
nicklas |
188 |
dc.saveItem(settings); |
5508 |
19 Nov 10 |
nicklas |
189 |
} |
5508 |
19 Nov 10 |
nicklas |
190 |
else |
5508 |
19 Nov 10 |
nicklas |
191 |
{ |
5508 |
19 Nov 10 |
nicklas |
192 |
dc.reattachItem(settings, false); |
5508 |
19 Nov 10 |
nicklas |
193 |
} |
5508 |
19 Nov 10 |
nicklas |
194 |
settings.setMaxMemory(Values.parseBytes(request.getParameter("maxMemory."+pluginId), null)); |
5508 |
19 Nov 10 |
nicklas |
195 |
settings.setPriorityBoost(Values.getInt(request.getParameter("priorityBoost."+pluginId))); |
6305 |
09 Aug 13 |
nicklas |
196 |
String trusted = Values.getStringOrNull(request.getParameter("trusted."+pluginId)); |
5508 |
19 Nov 10 |
nicklas |
197 |
settings.setTrusted(trusted == null ? null : Values.getBoolean(trusted)); |
3871 |
22 Oct 07 |
nicklas |
198 |
} |
2629 |
08 Sep 06 |
nicklas |
199 |
} |
5508 |
19 Nov 10 |
nicklas |
200 |
|
5508 |
19 Nov 10 |
nicklas |
201 |
// OnSave extensions |
5508 |
19 Nov 10 |
nicklas |
202 |
invoker.render(OnSaveRenderer.ON_SAVE); |
5508 |
19 Nov 10 |
nicklas |
203 |
dc.commit(); |
5508 |
19 Nov 10 |
nicklas |
204 |
invoker.render(OnSaveRenderer.ON_COMMIT); |
2629 |
08 Sep 06 |
nicklas |
205 |
} |
5508 |
19 Nov 10 |
nicklas |
206 |
catch (Exception ex) |
5508 |
19 Nov 10 |
nicklas |
207 |
{ |
5508 |
19 Nov 10 |
nicklas |
208 |
invoker.render(OnSaveRenderer.onRollback(ex)); |
5508 |
19 Nov 10 |
nicklas |
209 |
throw ex; |
5508 |
19 Nov 10 |
nicklas |
210 |
} |
5508 |
19 Nov 10 |
nicklas |
211 |
finally |
5508 |
19 Nov 10 |
nicklas |
212 |
{ |
5508 |
19 Nov 10 |
nicklas |
213 |
cc.removeObject("item"); |
5508 |
19 Nov 10 |
nicklas |
214 |
} |
2629 |
08 Sep 06 |
nicklas |
215 |
} |
2629 |
08 Sep 06 |
nicklas |
216 |
else if ("DeleteItem".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
217 |
{ |
2629 |
08 Sep 06 |
nicklas |
218 |
// Delete a single item and then return to the view page |
7954 |
12 May 21 |
nicklas |
219 |
dc = sc.newDbControl(":Delete "+itemType); |
2629 |
08 Sep 06 |
nicklas |
220 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
221 |
RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true); |
2629 |
08 Sep 06 |
nicklas |
222 |
dc.commit(); |
2629 |
08 Sep 06 |
nicklas |
223 |
redirect = viewPage; |
2629 |
08 Sep 06 |
nicklas |
224 |
} |
2629 |
08 Sep 06 |
nicklas |
225 |
else if ("DeleteItems".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
226 |
{ |
2629 |
08 Sep 06 |
nicklas |
227 |
// Delete all selected items on the list page |
7954 |
12 May 21 |
nicklas |
228 |
dc = sc.newDbControl(":Delete "+itemType); |
2629 |
08 Sep 06 |
nicklas |
229 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
230 |
int numTotal = cc.getSelected().size(); |
2629 |
08 Sep 06 |
nicklas |
231 |
int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true); |
2629 |
08 Sep 06 |
nicklas |
232 |
dc.commit(); |
2629 |
08 Sep 06 |
nicklas |
233 |
if (numTotal != numRemoved) |
2629 |
08 Sep 06 |
nicklas |
234 |
{ |
2629 |
08 Sep 06 |
nicklas |
235 |
message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission"; |
2629 |
08 Sep 06 |
nicklas |
236 |
} |
6192 |
31 Oct 12 |
nicklas |
237 |
redirect = listPage; |
2629 |
08 Sep 06 |
nicklas |
238 |
} |
2629 |
08 Sep 06 |
nicklas |
239 |
else if ("RestoreItem".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
240 |
{ |
2629 |
08 Sep 06 |
nicklas |
241 |
// Restore a single item and then return to the view page |
7954 |
12 May 21 |
nicklas |
242 |
dc = sc.newDbControl(":Restore "+itemType); |
2629 |
08 Sep 06 |
nicklas |
243 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
244 |
RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false); |
2629 |
08 Sep 06 |
nicklas |
245 |
dc.commit(); |
2629 |
08 Sep 06 |
nicklas |
246 |
redirect = viewPage; |
2629 |
08 Sep 06 |
nicklas |
247 |
} |
2629 |
08 Sep 06 |
nicklas |
248 |
else if ("RestoreItems".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
249 |
{ |
2629 |
08 Sep 06 |
nicklas |
250 |
// Restore all selected items on the list page |
7954 |
12 May 21 |
nicklas |
251 |
dc = sc.newDbControl(":Restore "+itemType); |
2629 |
08 Sep 06 |
nicklas |
252 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
253 |
int numTotal = cc.getSelected().size(); |
2629 |
08 Sep 06 |
nicklas |
254 |
int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false); |
2629 |
08 Sep 06 |
nicklas |
255 |
dc.commit(); |
2629 |
08 Sep 06 |
nicklas |
256 |
if (numTotal != numRemoved) |
2629 |
08 Sep 06 |
nicklas |
257 |
{ |
2629 |
08 Sep 06 |
nicklas |
258 |
message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; |
2629 |
08 Sep 06 |
nicklas |
259 |
} |
6192 |
31 Oct 12 |
nicklas |
260 |
redirect = listPage; |
2629 |
08 Sep 06 |
nicklas |
261 |
} |
2629 |
08 Sep 06 |
nicklas |
262 |
else if ("ShareItem".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
263 |
{ |
2629 |
08 Sep 06 |
nicklas |
264 |
// Display a popup window for sharing a single item |
7954 |
12 May 21 |
nicklas |
265 |
dc = sc.newDbControl(":Share "+itemType); |
2629 |
08 Sep 06 |
nicklas |
266 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
267 |
MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId())); |
2629 |
08 Sep 06 |
nicklas |
268 |
dc.close(); |
2629 |
08 Sep 06 |
nicklas |
269 |
cc.setObject("MultiPermissions", permissions); |
2629 |
08 Sep 06 |
nicklas |
270 |
redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
2629 |
08 Sep 06 |
nicklas |
271 |
} |
2629 |
08 Sep 06 |
nicklas |
272 |
else if ("ShareItems".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
273 |
{ |
2629 |
08 Sep 06 |
nicklas |
274 |
// Display a popup window for sharing all selected items on the list page |
7954 |
12 May 21 |
nicklas |
275 |
dc = sc.newDbControl(":Share "+itemType); |
2629 |
08 Sep 06 |
nicklas |
276 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
277 |
MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected()); |
2629 |
08 Sep 06 |
nicklas |
278 |
dc.close(); |
2629 |
08 Sep 06 |
nicklas |
279 |
cc.setObject("MultiPermissions", permissions); |
2629 |
08 Sep 06 |
nicklas |
280 |
redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name(); |
2629 |
08 Sep 06 |
nicklas |
281 |
} |
4578 |
13 Oct 08 |
martin |
282 |
else if ("SetOwnerOfItem".equals(cmd)) |
2921 |
15 Nov 06 |
nicklas |
283 |
{ |
4578 |
13 Oct 08 |
martin |
284 |
// Change owner of items selected on a list page |
7954 |
12 May 21 |
nicklas |
285 |
dc = sc.newDbControl(":Set owner of "+itemType); |
2921 |
15 Nov 06 |
nicklas |
286 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
4587 |
15 Oct 08 |
martin |
287 |
OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId()); |
4587 |
15 Oct 08 |
martin |
288 |
cc.setObject("OwnedItems", Collections.singleton(item)); |
4578 |
13 Oct 08 |
martin |
289 |
redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name(); |
2921 |
15 Nov 06 |
nicklas |
290 |
} |
4578 |
13 Oct 08 |
martin |
291 |
else if ("SetOwnerOfItems".equals(cmd)) |
2921 |
15 Nov 06 |
nicklas |
292 |
{ |
4578 |
13 Oct 08 |
martin |
293 |
// Change owner of items selected on a list page |
7954 |
12 May 21 |
nicklas |
294 |
dc = sc.newDbControl(":Set owner of "+itemType); |
2921 |
15 Nov 06 |
nicklas |
295 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
4587 |
15 Oct 08 |
martin |
296 |
Set<OwnedItem> items = new HashSet<OwnedItem>(); |
4587 |
15 Oct 08 |
martin |
297 |
for (Integer id : cc.getSelected()) |
4587 |
15 Oct 08 |
martin |
298 |
{ |
4587 |
15 Oct 08 |
martin |
299 |
if (id != null) items.add((OwnedItem)itemType.getById(dc, id)); |
4587 |
15 Oct 08 |
martin |
300 |
} |
4587 |
15 Oct 08 |
martin |
301 |
dc.close(); |
4587 |
15 Oct 08 |
martin |
302 |
cc.setObject("OwnedItems", items); |
4578 |
13 Oct 08 |
martin |
303 |
redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name(); |
2921 |
15 Nov 06 |
nicklas |
304 |
} |
2629 |
08 Sep 06 |
nicklas |
305 |
else if ("ExportItems".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
306 |
{ |
2629 |
08 Sep 06 |
nicklas |
307 |
// Run an export plugin in a list context |
2629 |
08 Sep 06 |
nicklas |
308 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
309 |
final ItemQuery<JobAgent> query = JobAgent.getQuery(); |
7954 |
12 May 21 |
nicklas |
310 |
dc = sc.newDbControl(":Export "+itemType); |
7914 |
23 Feb 21 |
nicklas |
311 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
312 |
cc.configureQuery(dc, query, jspContext, true); |
6045 |
03 Apr 12 |
nicklas |
313 |
cc.setQuery(query); |
7604 |
25 Feb 19 |
nicklas |
314 |
ExtensionsInvoker<ListColumnAction<JobAgent,?>> listInvoker = ListColumnUtil.useExtensions(jspContext); |
7604 |
25 Feb 19 |
nicklas |
315 |
listInvoker.render(new ListColumnExportRenderer<JobAgent>(cc)); |
5590 |
16 Mar 11 |
nicklas |
316 |
dc.close(); |
2629 |
08 Sep 06 |
nicklas |
317 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+job+agents"; |
2629 |
08 Sep 06 |
nicklas |
318 |
} |
2629 |
08 Sep 06 |
nicklas |
319 |
else if ("ExportItem".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
320 |
{ |
2629 |
08 Sep 06 |
nicklas |
321 |
// Run an export plugin in single-item context |
2629 |
08 Sep 06 |
nicklas |
322 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
323 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+job+agent"; |
2629 |
08 Sep 06 |
nicklas |
324 |
} |
2629 |
08 Sep 06 |
nicklas |
325 |
else if ("ImportItems".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
326 |
{ |
2629 |
08 Sep 06 |
nicklas |
327 |
// Run an import plugin in a list context |
2629 |
08 Sep 06 |
nicklas |
328 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
329 |
final ItemQuery<JobAgent> query = JobAgent.getQuery(); |
7954 |
12 May 21 |
nicklas |
330 |
dc = sc.newDbControl(":Import "+itemType); |
7914 |
23 Feb 21 |
nicklas |
331 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
332 |
cc.configureQuery(dc, query, jspContext, true); |
5590 |
16 Mar 11 |
nicklas |
333 |
dc.close(); |
2629 |
08 Sep 06 |
nicklas |
334 |
cc.setQuery(query); |
2629 |
08 Sep 06 |
nicklas |
335 |
redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+job+agents"; |
2629 |
08 Sep 06 |
nicklas |
336 |
} |
2629 |
08 Sep 06 |
nicklas |
337 |
else if ("ImportItem".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
338 |
{ |
2629 |
08 Sep 06 |
nicklas |
339 |
// Run an import plugin in single-item context |
2629 |
08 Sep 06 |
nicklas |
340 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
341 |
redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+job+agent"; |
2629 |
08 Sep 06 |
nicklas |
342 |
} |
2629 |
08 Sep 06 |
nicklas |
343 |
else if ("RunListPlugin".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
344 |
{ |
2629 |
08 Sep 06 |
nicklas |
345 |
// Run another plugin in a list context |
2629 |
08 Sep 06 |
nicklas |
346 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
347 |
final ItemQuery<JobAgent> query = JobAgent.getQuery(); |
7954 |
12 May 21 |
nicklas |
348 |
dc = sc.newDbControl(":Run plugin "+itemType); |
7914 |
23 Feb 21 |
nicklas |
349 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
350 |
cc.configureQuery(dc, query, jspContext, true); |
5590 |
16 Mar 11 |
nicklas |
351 |
dc.close(); |
2629 |
08 Sep 06 |
nicklas |
352 |
cc.setQuery(query); |
2629 |
08 Sep 06 |
nicklas |
353 |
redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
2629 |
08 Sep 06 |
nicklas |
354 |
} |
2629 |
08 Sep 06 |
nicklas |
355 |
else if ("RunPlugin".equals(cmd)) |
2629 |
08 Sep 06 |
nicklas |
356 |
{ |
2629 |
08 Sep 06 |
nicklas |
357 |
// Run another plugin in single-item context |
2629 |
08 Sep 06 |
nicklas |
358 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2629 |
08 Sep 06 |
nicklas |
359 |
redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; |
2629 |
08 Sep 06 |
nicklas |
360 |
} |
2648 |
19 Sep 06 |
nicklas |
361 |
else if ("Pause".equals(cmd) || "Start".equals(cmd)) |
2648 |
19 Sep 06 |
nicklas |
362 |
{ |
2648 |
19 Sep 06 |
nicklas |
363 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
7954 |
12 May 21 |
nicklas |
364 |
dc = sc.newDbControl(":"+cmd+" job agent"); |
2648 |
19 Sep 06 |
nicklas |
365 |
JobAgent agent = JobAgent.getById(dc, cc.getId()); |
2648 |
19 Sep 06 |
nicklas |
366 |
dc.close(); |
2648 |
19 Sep 06 |
nicklas |
367 |
JobAgentConnection conn = agent.getConnection(null); |
2648 |
19 Sep 06 |
nicklas |
368 |
String answer = null; |
2648 |
19 Sep 06 |
nicklas |
369 |
if (conn != null) |
2648 |
19 Sep 06 |
nicklas |
370 |
{ |
2648 |
19 Sep 06 |
nicklas |
371 |
try |
2648 |
19 Sep 06 |
nicklas |
372 |
{ |
2648 |
19 Sep 06 |
nicklas |
373 |
if ("Start".equals(cmd)) |
2648 |
19 Sep 06 |
nicklas |
374 |
{ |
2648 |
19 Sep 06 |
nicklas |
375 |
answer = conn.sendStart(); |
2648 |
19 Sep 06 |
nicklas |
376 |
} |
2648 |
19 Sep 06 |
nicklas |
377 |
else if ("Pause".equals(cmd)) |
2648 |
19 Sep 06 |
nicklas |
378 |
{ |
2648 |
19 Sep 06 |
nicklas |
379 |
answer = conn.sendPause(); |
2648 |
19 Sep 06 |
nicklas |
380 |
} |
2648 |
19 Sep 06 |
nicklas |
381 |
} |
2648 |
19 Sep 06 |
nicklas |
382 |
catch (Throwable t) |
2648 |
19 Sep 06 |
nicklas |
383 |
{ |
2648 |
19 Sep 06 |
nicklas |
384 |
answer = t.getMessage(); |
2648 |
19 Sep 06 |
nicklas |
385 |
} |
2648 |
19 Sep 06 |
nicklas |
386 |
if (!"OK".equals(answer)) |
2648 |
19 Sep 06 |
nicklas |
387 |
{ |
2648 |
19 Sep 06 |
nicklas |
388 |
cc.setMessage("Could not " + cmd.toLowerCase() + " the job agent. The answer is: " + answer); |
2648 |
19 Sep 06 |
nicklas |
389 |
} |
2648 |
19 Sep 06 |
nicklas |
390 |
} |
2648 |
19 Sep 06 |
nicklas |
391 |
else |
2648 |
19 Sep 06 |
nicklas |
392 |
{ |
2648 |
19 Sep 06 |
nicklas |
393 |
cc.setMessage("Could not create connection to job agent, probably because no " + |
2648 |
19 Sep 06 |
nicklas |
394 |
"server and/or port has been specified."); |
2648 |
19 Sep 06 |
nicklas |
395 |
} |
2648 |
19 Sep 06 |
nicklas |
396 |
redirect = viewPage; |
2648 |
19 Sep 06 |
nicklas |
397 |
} |
2648 |
19 Sep 06 |
nicklas |
398 |
else if ("PauseSelected".equals(cmd) || "StartSelected".equals(cmd)) |
2648 |
19 Sep 06 |
nicklas |
399 |
{ |
2648 |
19 Sep 06 |
nicklas |
400 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
2648 |
19 Sep 06 |
nicklas |
401 |
boolean start = "StartSelected".equals(cmd); |
7954 |
12 May 21 |
nicklas |
402 |
dc = sc.newDbControl(":"+(start?"Start":"Pause")+" job agents"); |
2648 |
19 Sep 06 |
nicklas |
403 |
int total = cc.getSelected().size(); |
2648 |
19 Sep 06 |
nicklas |
404 |
int started = 0; |
2648 |
19 Sep 06 |
nicklas |
405 |
int paused = 0; |
2648 |
19 Sep 06 |
nicklas |
406 |
|
2648 |
19 Sep 06 |
nicklas |
407 |
for (int agentId : cc.getSelected()) |
2648 |
19 Sep 06 |
nicklas |
408 |
{ |
2648 |
19 Sep 06 |
nicklas |
409 |
JobAgent agent = JobAgent.getById(dc, agentId); |
2648 |
19 Sep 06 |
nicklas |
410 |
if (agent.hasPermission(Permission.WRITE)) |
2648 |
19 Sep 06 |
nicklas |
411 |
{ |
2648 |
19 Sep 06 |
nicklas |
412 |
try |
2648 |
19 Sep 06 |
nicklas |
413 |
{ |
2648 |
19 Sep 06 |
nicklas |
414 |
JobAgentConnection conn = agent.getConnection(null); |
2648 |
19 Sep 06 |
nicklas |
415 |
if (conn != null) |
2648 |
19 Sep 06 |
nicklas |
416 |
{ |
2648 |
19 Sep 06 |
nicklas |
417 |
if (start) |
2648 |
19 Sep 06 |
nicklas |
418 |
{ |
2648 |
19 Sep 06 |
nicklas |
419 |
String answer = conn.sendStart(); |
2648 |
19 Sep 06 |
nicklas |
420 |
started += "OK".equals(answer) ? 1 : 0; |
2648 |
19 Sep 06 |
nicklas |
421 |
} |
2648 |
19 Sep 06 |
nicklas |
422 |
else |
2648 |
19 Sep 06 |
nicklas |
423 |
{ |
2648 |
19 Sep 06 |
nicklas |
424 |
String answer = conn.sendPause(); |
2648 |
19 Sep 06 |
nicklas |
425 |
paused += "OK".equals(answer) ? 1 : 0; |
2648 |
19 Sep 06 |
nicklas |
426 |
} |
2648 |
19 Sep 06 |
nicklas |
427 |
} |
2648 |
19 Sep 06 |
nicklas |
428 |
} |
2648 |
19 Sep 06 |
nicklas |
429 |
catch (Throwable t) |
2648 |
19 Sep 06 |
nicklas |
430 |
{} |
2648 |
19 Sep 06 |
nicklas |
431 |
} |
2648 |
19 Sep 06 |
nicklas |
432 |
} |
2648 |
19 Sep 06 |
nicklas |
433 |
if (total != started + paused) |
2648 |
19 Sep 06 |
nicklas |
434 |
{ |
2648 |
19 Sep 06 |
nicklas |
435 |
message = "Only " + (start ? started : paused) + " job agents of " + total + |
2648 |
19 Sep 06 |
nicklas |
436 |
" could be " + (start ? "started" : "paused"); |
2648 |
19 Sep 06 |
nicklas |
437 |
} |
6192 |
31 Oct 12 |
nicklas |
438 |
redirect = listPage; |
2648 |
19 Sep 06 |
nicklas |
439 |
} |
2629 |
08 Sep 06 |
nicklas |
440 |
else |
2629 |
08 Sep 06 |
nicklas |
441 |
{ |
2629 |
08 Sep 06 |
nicklas |
442 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
2629 |
08 Sep 06 |
nicklas |
443 |
} |
2629 |
08 Sep 06 |
nicklas |
444 |
} |
2629 |
08 Sep 06 |
nicklas |
445 |
finally |
2629 |
08 Sep 06 |
nicklas |
446 |
{ |
2629 |
08 Sep 06 |
nicklas |
447 |
if (dc != null) dc.close(); |
2629 |
08 Sep 06 |
nicklas |
448 |
} |
2629 |
08 Sep 06 |
nicklas |
449 |
|
2629 |
08 Sep 06 |
nicklas |
450 |
if (forward != null) |
2629 |
08 Sep 06 |
nicklas |
451 |
{ |
6192 |
31 Oct 12 |
nicklas |
452 |
sc.setSessionSetting("alert-message", message); |
2629 |
08 Sep 06 |
nicklas |
453 |
pageContext.forward(forward); |
2629 |
08 Sep 06 |
nicklas |
454 |
} |
2629 |
08 Sep 06 |
nicklas |
455 |
else if (redirect != null) |
2629 |
08 Sep 06 |
nicklas |
456 |
{ |
6192 |
31 Oct 12 |
nicklas |
457 |
sc.setSessionSetting("alert-message", message); |
2629 |
08 Sep 06 |
nicklas |
458 |
response.sendRedirect(redirect); |
2629 |
08 Sep 06 |
nicklas |
459 |
} |
2629 |
08 Sep 06 |
nicklas |
460 |
else if (message == null) |
2629 |
08 Sep 06 |
nicklas |
461 |
{ |
2629 |
08 Sep 06 |
nicklas |
462 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
2629 |
08 Sep 06 |
nicklas |
463 |
} |
2629 |
08 Sep 06 |
nicklas |
464 |
else |
2629 |
08 Sep 06 |
nicklas |
465 |
{ |
2629 |
08 Sep 06 |
nicklas |
466 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
2629 |
08 Sep 06 |
nicklas |
467 |
} |
2629 |
08 Sep 06 |
nicklas |
468 |
%> |
2629 |
08 Sep 06 |
nicklas |
469 |
|