1257 |
06 Sep 05 |
enell |
1 |
/* |
1257 |
06 Sep 05 |
enell |
$Id$ |
1257 |
06 Sep 05 |
enell |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Johan Enell, Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Johan Enell, Jari Häkkinen, Nicklas Nordborg |
1257 |
06 Sep 05 |
enell |
6 |
|
2304 |
22 May 06 |
jari |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
Available at http://base.thep.lu.se/ |
1257 |
06 Sep 05 |
enell |
9 |
|
1257 |
06 Sep 05 |
enell |
BASE is free software; you can redistribute it and/or |
1257 |
06 Sep 05 |
enell |
modify it under the terms of the GNU General Public License |
4480 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
1257 |
06 Sep 05 |
enell |
of the License, or (at your option) any later version. |
1257 |
06 Sep 05 |
enell |
14 |
|
1257 |
06 Sep 05 |
enell |
BASE is distributed in the hope that it will be useful, |
1257 |
06 Sep 05 |
enell |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1257 |
06 Sep 05 |
enell |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1257 |
06 Sep 05 |
enell |
GNU General Public License for more details. |
1257 |
06 Sep 05 |
enell |
19 |
|
1257 |
06 Sep 05 |
enell |
You should have received a copy of the GNU General Public License |
4514 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
1257 |
06 Sep 05 |
enell |
22 |
*/ |
1257 |
06 Sep 05 |
enell |
23 |
import net.sf.basedb.core.BaseException; |
1257 |
06 Sep 05 |
enell |
24 |
import net.sf.basedb.core.DbControl; |
1257 |
06 Sep 05 |
enell |
25 |
import net.sf.basedb.core.Item; |
5340 |
10 May 10 |
nicklas |
26 |
import net.sf.basedb.core.ItemProxy; |
1257 |
06 Sep 05 |
enell |
27 |
import net.sf.basedb.core.Job; |
2348 |
01 Jun 06 |
nicklas |
28 |
import net.sf.basedb.core.ParameterInfo; |
5228 |
03 Feb 10 |
nicklas |
29 |
import net.sf.basedb.core.ParameterType; |
1257 |
06 Sep 05 |
enell |
30 |
import net.sf.basedb.core.Permission; |
1257 |
06 Sep 05 |
enell |
31 |
import net.sf.basedb.core.PluginConfiguration; |
1376 |
22 Sep 05 |
nicklas |
32 |
import net.sf.basedb.core.PluginConfigurationRequest; |
1376 |
22 Sep 05 |
nicklas |
33 |
import net.sf.basedb.core.PluginExecutionRequest; |
5228 |
03 Feb 10 |
nicklas |
34 |
import net.sf.basedb.core.PluginParameter; |
1264 |
06 Sep 05 |
enell |
35 |
import net.sf.basedb.core.PluginResponse; |
1418 |
07 Oct 05 |
nicklas |
36 |
import net.sf.basedb.core.ItemQuery; |
1418 |
07 Oct 05 |
nicklas |
37 |
import net.sf.basedb.core.ItemResultList; |
5228 |
03 Feb 10 |
nicklas |
38 |
import net.sf.basedb.core.RequestInformation; |
1264 |
06 Sep 05 |
enell |
39 |
import net.sf.basedb.core.plugin.Response; |
1257 |
06 Sep 05 |
enell |
40 |
|
1290 |
08 Sep 05 |
nicklas |
41 |
import net.sf.basedb.util.ConsoleProgressReporter; |
1290 |
08 Sep 05 |
nicklas |
42 |
|
1264 |
06 Sep 05 |
enell |
43 |
import java.util.List; |
1779 |
17 Jan 06 |
nicklas |
44 |
import java.util.Arrays; |
5340 |
10 May 10 |
nicklas |
45 |
import java.util.Set; |
1264 |
06 Sep 05 |
enell |
46 |
|
1257 |
06 Sep 05 |
enell |
47 |
public class TestJob |
1257 |
06 Sep 05 |
enell |
48 |
{ |
1257 |
06 Sep 05 |
enell |
49 |
|
1257 |
06 Sep 05 |
enell |
50 |
static boolean ok = true; |
1257 |
06 Sep 05 |
enell |
51 |
public static void main(String[] args) |
1257 |
06 Sep 05 |
enell |
52 |
{ |
1257 |
06 Sep 05 |
enell |
53 |
TestUtil.checkArgs(args); |
1257 |
06 Sep 05 |
enell |
54 |
TestUtil.begin(); |
1257 |
06 Sep 05 |
enell |
55 |
ok = test_all(); |
1257 |
06 Sep 05 |
enell |
56 |
TestUtil.stop(); |
1257 |
06 Sep 05 |
enell |
57 |
} |
1257 |
06 Sep 05 |
enell |
58 |
|
1257 |
06 Sep 05 |
enell |
59 |
static boolean test_all() |
1257 |
06 Sep 05 |
enell |
60 |
{ |
1257 |
06 Sep 05 |
enell |
61 |
write("++Testing job"); |
1257 |
06 Sep 05 |
enell |
62 |
write_header(); |
1345 |
19 Sep 05 |
nicklas |
63 |
int definitionId = TestPluginDefinition.test_create("NullPlugin", null); |
1257 |
06 Sep 05 |
enell |
64 |
int configurationId = TestPluginConfiguration.test_create(definitionId); |
1264 |
06 Sep 05 |
enell |
65 |
TestPluginConfiguration.test_configure(configurationId); |
1290 |
08 Sep 05 |
nicklas |
66 |
|
1264 |
06 Sep 05 |
enell |
// Standard tests: create, load, list |
1257 |
06 Sep 05 |
enell |
68 |
int id = test_create(configurationId); |
1264 |
06 Sep 05 |
enell |
69 |
test_list(); |
1264 |
06 Sep 05 |
enell |
70 |
test_load(id); |
1257 |
06 Sep 05 |
enell |
71 |
|
1264 |
06 Sep 05 |
enell |
// extra test: configure, execute |
1264 |
06 Sep 05 |
enell |
73 |
test_configure(id); |
5319 |
20 Apr 10 |
nicklas |
74 |
test_execute(id, false); |
1264 |
06 Sep 05 |
enell |
75 |
|
1257 |
06 Sep 05 |
enell |
// Standard test: Delete |
1529 |
27 Oct 05 |
nicklas |
77 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
1257 |
06 Sep 05 |
enell |
78 |
test_delete(id); |
1257 |
06 Sep 05 |
enell |
79 |
TestPluginConfiguration.test_delete(configurationId); |
1257 |
06 Sep 05 |
enell |
80 |
TestPluginDefinition.test_delete(definitionId); |
1264 |
06 Sep 05 |
enell |
81 |
write("++Testing job "+(ok ? "OK" : "Failed")+"\n"); |
1257 |
06 Sep 05 |
enell |
82 |
return ok; |
1257 |
06 Sep 05 |
enell |
83 |
} |
1257 |
06 Sep 05 |
enell |
84 |
|
5319 |
20 Apr 10 |
nicklas |
85 |
static boolean test_execute(int id, boolean expectError) |
1264 |
06 Sep 05 |
enell |
86 |
{ |
1783 |
18 Jan 06 |
enell |
87 |
if (id == 0) return ok; |
1264 |
06 Sep 05 |
enell |
88 |
DbControl dc = null; |
1264 |
06 Sep 05 |
enell |
89 |
try |
1264 |
06 Sep 05 |
enell |
90 |
{ |
1264 |
06 Sep 05 |
enell |
91 |
dc = TestUtil.getDbControl(); |
1264 |
06 Sep 05 |
enell |
92 |
Job job = Job.getById(dc, id); |
1264 |
06 Sep 05 |
enell |
93 |
|
1626 |
17 Nov 05 |
nicklas |
94 |
PluginExecutionRequest request = |
1626 |
17 Nov 05 |
nicklas |
95 |
job.execute(TestUtil.getSilent() ? null : new ConsoleProgressReporter(), TestUtil.getLocalIp()); |
1311 |
09 Sep 05 |
nicklas |
96 |
dc.close(); |
7749 |
26 Sep 19 |
nicklas |
97 |
request.setParameterValue("isSilent", TestUtil.getSilent()); |
1311 |
09 Sep 05 |
nicklas |
98 |
PluginResponse response = request.invoke(); |
5319 |
20 Apr 10 |
nicklas |
99 |
Response.Status status = response.getStatus(); |
5319 |
20 Apr 10 |
nicklas |
100 |
if (expectError) |
1264 |
06 Sep 05 |
enell |
101 |
{ |
5319 |
20 Apr 10 |
nicklas |
102 |
if (status != Response.Status.ERROR) |
5319 |
20 Apr 10 |
nicklas |
103 |
{ |
5319 |
20 Apr 10 |
nicklas |
104 |
throw new BaseException("Expected job to fail. Got " + |
5319 |
20 Apr 10 |
nicklas |
105 |
status + "; " + response.getMessage()); |
5319 |
20 Apr 10 |
nicklas |
106 |
} |
1264 |
06 Sep 05 |
enell |
107 |
} |
5319 |
20 Apr 10 |
nicklas |
108 |
else |
5319 |
20 Apr 10 |
nicklas |
109 |
{ |
5319 |
20 Apr 10 |
nicklas |
110 |
if (status == Response.Status.ERROR) |
5319 |
20 Apr 10 |
nicklas |
111 |
{ |
5319 |
20 Apr 10 |
nicklas |
112 |
Throwable cause = response.getErrorList() != null && |
5319 |
20 Apr 10 |
nicklas |
113 |
response.getErrorList().size() > 0 ? response.getErrorList().get(0) : null; |
5319 |
20 Apr 10 |
nicklas |
114 |
throw new BaseException(response.getMessage(), cause); |
5319 |
20 Apr 10 |
nicklas |
115 |
} |
5319 |
20 Apr 10 |
nicklas |
116 |
} |
1264 |
06 Sep 05 |
enell |
117 |
|
1311 |
09 Sep 05 |
nicklas |
118 |
dc = TestUtil.getDbControl(); |
1311 |
09 Sep 05 |
nicklas |
119 |
job = Job.getById(dc, id); |
4930 |
14 May 09 |
nicklas |
120 |
if (!TestUtil.getSilent()) write(""); |
1264 |
06 Sep 05 |
enell |
121 |
write_item(0, job); |
1622 |
16 Nov 05 |
nicklas |
122 |
write("--Execute job OK ("+response.getMessage()+")"); |
1264 |
06 Sep 05 |
enell |
123 |
} |
1290 |
08 Sep 05 |
nicklas |
124 |
catch (Throwable ex) |
1264 |
06 Sep 05 |
enell |
125 |
{ |
1264 |
06 Sep 05 |
enell |
126 |
write("--Execute job FAILED"); |
1264 |
06 Sep 05 |
enell |
127 |
ex.printStackTrace(); |
1264 |
06 Sep 05 |
enell |
128 |
ok = false; |
1783 |
18 Jan 06 |
enell |
129 |
return false; |
1264 |
06 Sep 05 |
enell |
130 |
} |
1264 |
06 Sep 05 |
enell |
131 |
finally |
1264 |
06 Sep 05 |
enell |
132 |
{ |
1264 |
06 Sep 05 |
enell |
133 |
if (dc != null) dc.close(); |
1264 |
06 Sep 05 |
enell |
134 |
} |
1783 |
18 Jan 06 |
enell |
135 |
return true; |
1264 |
06 Sep 05 |
enell |
136 |
} |
1264 |
06 Sep 05 |
enell |
137 |
|
1264 |
06 Sep 05 |
enell |
138 |
static void test_configure(int id) |
1264 |
06 Sep 05 |
enell |
139 |
{ |
1264 |
06 Sep 05 |
enell |
140 |
if (id == 0) return; |
1264 |
06 Sep 05 |
enell |
141 |
DbControl dc = null; |
1264 |
06 Sep 05 |
enell |
142 |
try |
1264 |
06 Sep 05 |
enell |
143 |
{ |
1264 |
06 Sep 05 |
enell |
144 |
dc = TestUtil.getDbControl(); |
1264 |
06 Sep 05 |
enell |
145 |
Job job = Job.getById(dc, id); |
1264 |
06 Sep 05 |
enell |
146 |
|
1789 |
18 Jan 06 |
nicklas |
147 |
PluginConfigurationRequest pr = job.configure(null); |
2348 |
01 Jun 06 |
nicklas |
148 |
pr.getRequestInformation(); |
1264 |
06 Sep 05 |
enell |
149 |
|
1779 |
17 Jan 06 |
nicklas |
150 |
pr.setParameterValue("oneString", "aString"); |
1779 |
17 Jan 06 |
nicklas |
151 |
pr.setParameterValues("manyStrings", Arrays.asList("A", "C")); |
1779 |
17 Jan 06 |
nicklas |
152 |
pr.setParameterValue("selectOneString", "B"); |
1779 |
17 Jan 06 |
nicklas |
153 |
pr.setParameterValues("selectMultipleStrings", Arrays.asList("One", "Three")); |
1779 |
17 Jan 06 |
nicklas |
154 |
PluginResponse response = pr.invoke(); |
1779 |
17 Jan 06 |
nicklas |
155 |
if (response.getStatus() == Response.Status.DONE) |
1779 |
17 Jan 06 |
nicklas |
156 |
{ |
1779 |
17 Jan 06 |
nicklas |
157 |
response.saveParameters(dc); |
1779 |
17 Jan 06 |
nicklas |
158 |
dc.commit(); |
1779 |
17 Jan 06 |
nicklas |
159 |
} |
1779 |
17 Jan 06 |
nicklas |
160 |
else |
1779 |
17 Jan 06 |
nicklas |
161 |
{ |
1779 |
17 Jan 06 |
nicklas |
162 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
1779 |
17 Jan 06 |
nicklas |
163 |
} |
1779 |
17 Jan 06 |
nicklas |
164 |
|
1264 |
06 Sep 05 |
enell |
165 |
dc = TestUtil.getDbControl(); |
2348 |
01 Jun 06 |
nicklas |
166 |
job = Job.getById(dc, id); |
1264 |
06 Sep 05 |
enell |
167 |
|
1778 |
17 Jan 06 |
enell |
168 |
List<?> value = job.getParameterValues("oneString"); |
1779 |
17 Jan 06 |
nicklas |
169 |
if (value == null || value.size() != 1 || !value.get(0).equals("aString")) |
1264 |
06 Sep 05 |
enell |
170 |
{ |
1779 |
17 Jan 06 |
nicklas |
171 |
throw new Exception("Cant find the correct value for job parameter 'oneString'"); |
1264 |
06 Sep 05 |
enell |
172 |
} |
1779 |
17 Jan 06 |
nicklas |
173 |
value = job.getParameterValues("manyStrings"); |
1779 |
17 Jan 06 |
nicklas |
174 |
if (value == null || value.size() != 2 || !value.contains("A") || !value.contains("C")) |
1264 |
06 Sep 05 |
enell |
175 |
{ |
1779 |
17 Jan 06 |
nicklas |
176 |
throw new Exception("Cant find the correct value for job parameter 'manyStrings'"); |
1264 |
06 Sep 05 |
enell |
177 |
} |
1779 |
17 Jan 06 |
nicklas |
178 |
value = job.getParameterValues("selectOneString"); |
1779 |
17 Jan 06 |
nicklas |
179 |
if (value == null || value.size() != 1 || !value.get(0).equals("B")) |
1779 |
17 Jan 06 |
nicklas |
180 |
{ |
1779 |
17 Jan 06 |
nicklas |
181 |
throw new Exception("Cant find the correct value for job parameter 'oneString'"); |
1779 |
17 Jan 06 |
nicklas |
182 |
} |
1779 |
17 Jan 06 |
nicklas |
183 |
value = job.getParameterValues("selectMultipleStrings"); |
1779 |
17 Jan 06 |
nicklas |
184 |
if (value == null || value.size() != 2 || !value.contains("One") || !value.contains("Three")) |
1779 |
17 Jan 06 |
nicklas |
185 |
{ |
1779 |
17 Jan 06 |
nicklas |
186 |
throw new Exception("Cant find the correct value for job parameter 'manyStrings'"); |
1779 |
17 Jan 06 |
nicklas |
187 |
} |
1264 |
06 Sep 05 |
enell |
188 |
|
1264 |
06 Sep 05 |
enell |
189 |
write_item(0, job); |
1264 |
06 Sep 05 |
enell |
190 |
write_values(job); |
1264 |
06 Sep 05 |
enell |
191 |
write("--Configure job OK"); |
1264 |
06 Sep 05 |
enell |
192 |
} |
1290 |
08 Sep 05 |
nicklas |
193 |
catch (Throwable ex) |
1264 |
06 Sep 05 |
enell |
194 |
{ |
1264 |
06 Sep 05 |
enell |
195 |
write("--Configure job FAILED"); |
1264 |
06 Sep 05 |
enell |
196 |
ex.printStackTrace(); |
1264 |
06 Sep 05 |
enell |
197 |
ok = false; |
1264 |
06 Sep 05 |
enell |
198 |
} |
1264 |
06 Sep 05 |
enell |
199 |
finally |
1264 |
06 Sep 05 |
enell |
200 |
{ |
1264 |
06 Sep 05 |
enell |
201 |
if (dc != null) dc.close(); |
1264 |
06 Sep 05 |
enell |
202 |
} |
1264 |
06 Sep 05 |
enell |
203 |
} |
1264 |
06 Sep 05 |
enell |
204 |
|
1257 |
06 Sep 05 |
enell |
205 |
static int test_create(int configurationId) |
1257 |
06 Sep 05 |
enell |
206 |
{ |
1257 |
06 Sep 05 |
enell |
207 |
if (configurationId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.JOB)) return 0; |
1257 |
06 Sep 05 |
enell |
208 |
int id = 0; |
1257 |
06 Sep 05 |
enell |
209 |
DbControl dc = null; |
1257 |
06 Sep 05 |
enell |
210 |
try |
1257 |
06 Sep 05 |
enell |
211 |
{ |
1257 |
06 Sep 05 |
enell |
212 |
dc = TestUtil.getDbControl(); |
1257 |
06 Sep 05 |
enell |
213 |
PluginConfiguration pc = PluginConfiguration.getById(dc, configurationId); |
4254 |
28 Apr 08 |
nicklas |
214 |
Job job = Job.getNew(dc, pc.getPluginDefinition(), pc, null); |
1257 |
06 Sep 05 |
enell |
215 |
job.setName(pc.getName()); |
1257 |
06 Sep 05 |
enell |
216 |
dc.saveItem(job); |
1257 |
06 Sep 05 |
enell |
217 |
dc.commit(); |
1257 |
06 Sep 05 |
enell |
218 |
id = job.getId(); |
1257 |
06 Sep 05 |
enell |
219 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
220 |
dc.reattachItem(job, false); |
1257 |
06 Sep 05 |
enell |
221 |
write_item(0, job); |
1257 |
06 Sep 05 |
enell |
222 |
write("--Create job OK"); |
1257 |
06 Sep 05 |
enell |
223 |
} |
1290 |
08 Sep 05 |
nicklas |
224 |
catch (Throwable ex) |
1257 |
06 Sep 05 |
enell |
225 |
{ |
1257 |
06 Sep 05 |
enell |
226 |
write("--Create job FAILED"); |
1257 |
06 Sep 05 |
enell |
227 |
ex.printStackTrace(); |
1257 |
06 Sep 05 |
enell |
228 |
ok = false; |
1257 |
06 Sep 05 |
enell |
229 |
} |
1257 |
06 Sep 05 |
enell |
230 |
finally |
1257 |
06 Sep 05 |
enell |
231 |
{ |
1257 |
06 Sep 05 |
enell |
232 |
if (dc != null) dc.close(); |
1257 |
06 Sep 05 |
enell |
233 |
} |
1257 |
06 Sep 05 |
enell |
234 |
|
1257 |
06 Sep 05 |
enell |
235 |
return id; |
1257 |
06 Sep 05 |
enell |
236 |
} |
1264 |
06 Sep 05 |
enell |
237 |
|
1264 |
06 Sep 05 |
enell |
238 |
static void test_list() |
1264 |
06 Sep 05 |
enell |
239 |
{ |
1264 |
06 Sep 05 |
enell |
240 |
DbControl dc = null; |
1264 |
06 Sep 05 |
enell |
241 |
try |
1264 |
06 Sep 05 |
enell |
242 |
{ |
1264 |
06 Sep 05 |
enell |
243 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
244 |
ItemQuery<Job> q = Job.getQuery(); |
1418 |
07 Oct 05 |
nicklas |
245 |
ItemResultList<Job> l = q.list(dc); |
1264 |
06 Sep 05 |
enell |
246 |
for (int i = 0; i<l.size(); i++) |
1264 |
06 Sep 05 |
enell |
247 |
{ |
1264 |
06 Sep 05 |
enell |
248 |
write_item(i, l.get(i)); |
1264 |
06 Sep 05 |
enell |
249 |
} |
1264 |
06 Sep 05 |
enell |
250 |
write("--List job OK ("+l.size()+")"); |
1264 |
06 Sep 05 |
enell |
251 |
} |
1290 |
08 Sep 05 |
nicklas |
252 |
catch (Throwable ex) |
1264 |
06 Sep 05 |
enell |
253 |
{ |
1264 |
06 Sep 05 |
enell |
254 |
write("--List job FAILED"); |
1264 |
06 Sep 05 |
enell |
255 |
ex.printStackTrace(); |
1264 |
06 Sep 05 |
enell |
256 |
ok = false; |
1264 |
06 Sep 05 |
enell |
257 |
} |
1264 |
06 Sep 05 |
enell |
258 |
finally |
1264 |
06 Sep 05 |
enell |
259 |
{ |
1264 |
06 Sep 05 |
enell |
260 |
if (dc != null) dc.close(); |
1264 |
06 Sep 05 |
enell |
261 |
} |
1264 |
06 Sep 05 |
enell |
262 |
} |
1264 |
06 Sep 05 |
enell |
263 |
|
1264 |
06 Sep 05 |
enell |
264 |
static void test_load(int id) |
1264 |
06 Sep 05 |
enell |
265 |
{ |
1264 |
06 Sep 05 |
enell |
266 |
if (id == 0) return; |
1264 |
06 Sep 05 |
enell |
267 |
DbControl dc = null; |
1264 |
06 Sep 05 |
enell |
268 |
try |
1264 |
06 Sep 05 |
enell |
269 |
{ |
1264 |
06 Sep 05 |
enell |
270 |
dc = TestUtil.getDbControl(); |
1264 |
06 Sep 05 |
enell |
271 |
Job job = Job.getById(dc, id); |
1264 |
06 Sep 05 |
enell |
272 |
write_item(0, job); |
1264 |
06 Sep 05 |
enell |
273 |
write_values(job); |
1264 |
06 Sep 05 |
enell |
274 |
write("--Load job OK"); |
1264 |
06 Sep 05 |
enell |
275 |
} |
1290 |
08 Sep 05 |
nicklas |
276 |
catch (Throwable ex) |
1264 |
06 Sep 05 |
enell |
277 |
{ |
1264 |
06 Sep 05 |
enell |
278 |
write("--Load job FAILED"); |
1264 |
06 Sep 05 |
enell |
279 |
ex.printStackTrace(); |
1264 |
06 Sep 05 |
enell |
280 |
ok = false; |
1264 |
06 Sep 05 |
enell |
281 |
} |
1264 |
06 Sep 05 |
enell |
282 |
finally |
1264 |
06 Sep 05 |
enell |
283 |
{ |
1264 |
06 Sep 05 |
enell |
284 |
if (dc != null) dc.close(); |
1264 |
06 Sep 05 |
enell |
285 |
} |
1264 |
06 Sep 05 |
enell |
286 |
} |
1257 |
06 Sep 05 |
enell |
287 |
|
1257 |
06 Sep 05 |
enell |
288 |
static void test_delete(int id) |
1257 |
06 Sep 05 |
enell |
289 |
{ |
1257 |
06 Sep 05 |
enell |
290 |
if (id == 0) return; |
1257 |
06 Sep 05 |
enell |
291 |
DbControl dc = null; |
1257 |
06 Sep 05 |
enell |
292 |
try |
1257 |
06 Sep 05 |
enell |
293 |
{ |
1257 |
06 Sep 05 |
enell |
294 |
dc = TestUtil.getDbControl(); |
1257 |
06 Sep 05 |
enell |
295 |
Job job = Job.getById(dc, id); |
1257 |
06 Sep 05 |
enell |
296 |
dc.deleteItem(job); |
5340 |
10 May 10 |
nicklas |
297 |
Set<ItemProxy> using = job.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
298 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
299 |
{ |
5340 |
10 May 10 |
nicklas |
300 |
throw new BaseException(job + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
301 |
} |
1257 |
06 Sep 05 |
enell |
302 |
dc.commit(); |
1257 |
06 Sep 05 |
enell |
303 |
write("--Delete job OK"); |
1257 |
06 Sep 05 |
enell |
304 |
} |
1290 |
08 Sep 05 |
nicklas |
305 |
catch (Throwable ex) |
1257 |
06 Sep 05 |
enell |
306 |
{ |
1257 |
06 Sep 05 |
enell |
307 |
write("--Delete job FAILED"); |
1257 |
06 Sep 05 |
enell |
308 |
ex.printStackTrace(); |
1257 |
06 Sep 05 |
enell |
309 |
ok = false; |
1257 |
06 Sep 05 |
enell |
310 |
} |
1257 |
06 Sep 05 |
enell |
311 |
finally |
1257 |
06 Sep 05 |
enell |
312 |
{ |
1257 |
06 Sep 05 |
enell |
313 |
if (dc != null) dc.close(); |
1257 |
06 Sep 05 |
enell |
314 |
} |
1257 |
06 Sep 05 |
enell |
315 |
} |
1257 |
06 Sep 05 |
enell |
316 |
|
1257 |
06 Sep 05 |
enell |
317 |
static void write_header() |
1257 |
06 Sep 05 |
enell |
318 |
{ |
1257 |
06 Sep 05 |
enell |
319 |
if (!TestUtil.getSilent()) |
1257 |
06 Sep 05 |
enell |
320 |
{ |
1311 |
09 Sep 05 |
nicklas |
321 |
write(" \tID \tName \tDescription\tType \tStatus\tStarted\tEnded\tConfiguration"); |
1311 |
09 Sep 05 |
nicklas |
322 |
write("-- \t-- \t--------- \t-----------\t------\t------\t-------\t-----\t-------------"); |
1257 |
06 Sep 05 |
enell |
323 |
} |
1257 |
06 Sep 05 |
enell |
324 |
} |
1257 |
06 Sep 05 |
enell |
325 |
|
1257 |
06 Sep 05 |
enell |
326 |
static void write_item(int i, Job job) |
1257 |
06 Sep 05 |
enell |
327 |
throws BaseException |
1257 |
06 Sep 05 |
enell |
328 |
{ |
1257 |
06 Sep 05 |
enell |
329 |
if (!TestUtil.getSilent()) |
1257 |
06 Sep 05 |
enell |
330 |
{ |
1311 |
09 Sep 05 |
nicklas |
331 |
System.out.println(i+":\t"+job.getId()+"\t"+job.getName()+"\t"+job.getDescription()+"\t"+job.getJobType()+ |
1311 |
09 Sep 05 |
nicklas |
332 |
"\t"+job.getStatus()+"\t"+job.getStarted()+"\t"+job.getEnded()+"\t"+job.getPluginConfiguration()); |
1257 |
06 Sep 05 |
enell |
333 |
} |
1257 |
06 Sep 05 |
enell |
334 |
} |
1257 |
06 Sep 05 |
enell |
335 |
|
1264 |
06 Sep 05 |
enell |
336 |
static void write_values(Job job) |
1264 |
06 Sep 05 |
enell |
337 |
throws BaseException |
1264 |
06 Sep 05 |
enell |
338 |
{ |
1264 |
06 Sep 05 |
enell |
339 |
if (!TestUtil.getSilent()) |
1264 |
06 Sep 05 |
enell |
340 |
{ |
1264 |
06 Sep 05 |
enell |
341 |
System.out.println("Job values:"); |
1264 |
06 Sep 05 |
enell |
342 |
for(String name : job.getParameterNames()) |
1264 |
06 Sep 05 |
enell |
343 |
{ |
2348 |
01 Jun 06 |
nicklas |
344 |
ParameterInfo pi = job.getParameterInfo(name); |
6988 |
30 Oct 15 |
nicklas |
345 |
System.out.println((pi.getLabel() == null ? name : pi.getLabel()) + "=" + pi.getValuesOrMask()); |
1264 |
06 Sep 05 |
enell |
346 |
} |
1264 |
06 Sep 05 |
enell |
347 |
} |
1264 |
06 Sep 05 |
enell |
348 |
} |
1264 |
06 Sep 05 |
enell |
349 |
|
5228 |
03 Feb 10 |
nicklas |
350 |
static void write_request_information(RequestInformation ri) |
5228 |
03 Feb 10 |
nicklas |
351 |
{ |
5228 |
03 Feb 10 |
nicklas |
352 |
if (TestUtil.getSilent()) return; |
5228 |
03 Feb 10 |
nicklas |
353 |
|
5228 |
03 Feb 10 |
nicklas |
354 |
write("Request information for command: "+ri.getCommand()); |
5228 |
03 Feb 10 |
nicklas |
355 |
write("\tTitle:\t"+ri.getTitle()); |
5228 |
03 Feb 10 |
nicklas |
356 |
write("\tDescription:\t"+ri.getDescription()); |
5228 |
03 Feb 10 |
nicklas |
357 |
for (PluginParameter<?> pp : ri.getParameters()) |
5228 |
03 Feb 10 |
nicklas |
358 |
{ |
6875 |
20 Apr 15 |
nicklas |
359 |
ParameterType<?> pt = pp.getParameterType(); |
5228 |
03 Feb 10 |
nicklas |
360 |
System.out.println("\tParameter:\t"+pp.getName() + "\t" + pp.getLabel() + "\t" + pt ); |
5228 |
03 Feb 10 |
nicklas |
361 |
} |
5228 |
03 Feb 10 |
nicklas |
362 |
} |
5228 |
03 Feb 10 |
nicklas |
363 |
|
5228 |
03 Feb 10 |
nicklas |
364 |
|
1257 |
06 Sep 05 |
enell |
365 |
static void write(String message) |
1257 |
06 Sep 05 |
enell |
366 |
{ |
1257 |
06 Sep 05 |
enell |
367 |
System.out.println(message); |
1257 |
06 Sep 05 |
enell |
368 |
} |
5319 |
20 Apr 10 |
nicklas |
369 |
|
5319 |
20 Apr 10 |
nicklas |
370 |
static void setRequestParameterValues(PluginConfigurationRequest request, Parameter... parameters) |
5319 |
20 Apr 10 |
nicklas |
371 |
{ |
5319 |
20 Apr 10 |
nicklas |
// Set default values first |
5319 |
20 Apr 10 |
nicklas |
373 |
RequestInformation ri = request.getRequestInformation(); |
5319 |
20 Apr 10 |
nicklas |
374 |
for (PluginParameter<?> pp : ri.getParameters()) |
5319 |
20 Apr 10 |
nicklas |
375 |
{ |
5319 |
20 Apr 10 |
nicklas |
376 |
request.setParameterValue(pp.getName(), pp.getDefaultValue()); |
5319 |
20 Apr 10 |
nicklas |
377 |
} |
5319 |
20 Apr 10 |
nicklas |
// Then, set specified parameters |
5319 |
20 Apr 10 |
nicklas |
379 |
if (parameters != null) |
5319 |
20 Apr 10 |
nicklas |
380 |
{ |
5319 |
20 Apr 10 |
nicklas |
381 |
for (Parameter p : parameters) |
5319 |
20 Apr 10 |
nicklas |
382 |
{ |
5319 |
20 Apr 10 |
nicklas |
383 |
if (ri.getParameter(p.name) != null) |
5319 |
20 Apr 10 |
nicklas |
384 |
{ |
5319 |
20 Apr 10 |
nicklas |
385 |
request.setParameterValue(p.name, p.value); |
5319 |
20 Apr 10 |
nicklas |
386 |
} |
5319 |
20 Apr 10 |
nicklas |
387 |
} |
5319 |
20 Apr 10 |
nicklas |
388 |
} |
5319 |
20 Apr 10 |
nicklas |
389 |
} |
5319 |
20 Apr 10 |
nicklas |
390 |
|
5319 |
20 Apr 10 |
nicklas |
391 |
static class Parameter |
5319 |
20 Apr 10 |
nicklas |
392 |
{ |
5319 |
20 Apr 10 |
nicklas |
393 |
final String name; |
5319 |
20 Apr 10 |
nicklas |
394 |
final Object value; |
5319 |
20 Apr 10 |
nicklas |
395 |
Parameter(String name, Object value) |
5319 |
20 Apr 10 |
nicklas |
396 |
{ |
5319 |
20 Apr 10 |
nicklas |
397 |
this.name = name; |
5319 |
20 Apr 10 |
nicklas |
398 |
this.value = value; |
5319 |
20 Apr 10 |
nicklas |
399 |
} |
5319 |
20 Apr 10 |
nicklas |
400 |
} |
5319 |
20 Apr 10 |
nicklas |
401 |
|
1257 |
06 Sep 05 |
enell |
402 |
} |