1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.scheduler; |
21 |
|
|
22 |
|
import org.quartz.Job; |
23 |
|
import org.quartz.JobDataMap; |
24 |
|
import org.quartz.JobExecutionContext; |
25 |
|
import org.quartz.JobExecutionException; |
26 |
|
import org.xwiki.context.Execution; |
27 |
|
import org.xwiki.context.ExecutionContext; |
28 |
|
import org.xwiki.context.ExecutionContextException; |
29 |
|
import org.xwiki.context.ExecutionContextManager; |
30 |
|
|
31 |
|
import com.xpn.xwiki.XWikiContext; |
32 |
|
import com.xpn.xwiki.web.Utils; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@link@link |
38 |
|
|
39 |
|
@since |
40 |
|
@version |
41 |
|
|
|
|
| 94.1% |
Uncovered Elements: 1 (17) |
Complexity: 3 |
Complexity Density: 0.2 |
|
42 |
|
public abstract class AbstractJob implements Job |
43 |
|
{ |
44 |
|
private XWikiContext xcontext; |
45 |
|
|
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 2 |
Complexity Density: 0.14 |
|
46 |
2 |
@Override... |
47 |
|
public final void execute(JobExecutionContext jobContext) throws JobExecutionException |
48 |
|
{ |
49 |
2 |
JobDataMap data = jobContext.getJobDetail().getJobDataMap(); |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
2 |
this.xcontext = (XWikiContext) data.get("context"); |
54 |
|
|
55 |
|
|
56 |
2 |
this.xcontext = this.xcontext.clone(); |
57 |
|
|
58 |
|
|
59 |
2 |
Execution execution; |
60 |
2 |
try { |
61 |
2 |
ExecutionContextManager ecim = Utils.getComponent(ExecutionContextManager.class); |
62 |
2 |
execution = Utils.getComponent(Execution.class); |
63 |
|
|
64 |
2 |
ExecutionContext context = new ExecutionContext(); |
65 |
|
|
66 |
|
|
67 |
2 |
this.xcontext.declareInExecutionContext(context); |
68 |
|
|
69 |
2 |
ecim.initialize(context); |
70 |
|
} catch (ExecutionContextException e) { |
71 |
0 |
throw new JobExecutionException("Fail to initialize execution context", e); |
72 |
|
} |
73 |
|
|
74 |
2 |
try { |
75 |
|
|
76 |
2 |
executeJob(jobContext); |
77 |
|
} finally { |
78 |
|
|
79 |
|
|
80 |
2 |
execution.removeContext(); |
81 |
|
} |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
12 |
protected XWikiContext getXWikiContext()... |
85 |
|
{ |
86 |
12 |
return this.xcontext; |
87 |
|
} |
88 |
|
|
89 |
|
protected abstract void executeJob(JobExecutionContext jobContext) throws JobExecutionException; |
90 |
|
} |