1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.job.script; |
21 |
|
|
22 |
|
import java.util.Collection; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.context.Execution; |
31 |
|
import org.xwiki.job.Job; |
32 |
|
import org.xwiki.job.JobException; |
33 |
|
import org.xwiki.job.JobExecutor; |
34 |
|
import org.xwiki.job.JobGroupPath; |
35 |
|
import org.xwiki.job.JobStatusStore; |
36 |
|
import org.xwiki.job.event.status.JobStatus; |
37 |
|
import org.xwiki.script.internal.safe.ScriptSafeProvider; |
38 |
|
import org.xwiki.script.service.ScriptService; |
39 |
|
import org.xwiki.security.authorization.ContextualAuthorizationManager; |
40 |
|
import org.xwiki.security.authorization.Right; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
|
48 |
|
@Component |
49 |
|
@Named("job") |
50 |
|
@Singleton |
|
|
| 28.2% |
Uncovered Elements: 28 (39) |
Complexity: 12 |
Complexity Density: 0.52 |
|
51 |
|
public class JobScriptService implements ScriptService |
52 |
|
{ |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
public static final String JOB_ERROR_KEY = "scriptservice.job.error"; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
@Inject |
62 |
|
private JobExecutor jobExecutor; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@Inject |
68 |
|
private JobStatusStore jobStore; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@Inject |
74 |
|
private ContextualAuthorizationManager authorization; |
75 |
|
|
76 |
|
@Inject |
77 |
|
@SuppressWarnings("rawtypes") |
78 |
|
private ScriptSafeProvider scriptSafeProvider; |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
@Inject |
84 |
|
private Execution execution; |
85 |
|
|
86 |
|
|
87 |
|
@param |
88 |
|
@return |
89 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
90 |
4069 |
public JobStatus getJobStatus(List<String> jobId)... |
91 |
|
{ |
92 |
4069 |
JobStatus jobStatus; |
93 |
|
|
94 |
4069 |
Job job = this.jobExecutor.getJob(jobId); |
95 |
4069 |
if (job == null) { |
96 |
4012 |
jobStatus = this.jobStore.getJobStatus(jobId); |
97 |
|
} else { |
98 |
57 |
jobStatus = job.getStatus(); |
99 |
|
} |
100 |
|
|
101 |
4069 |
if (jobStatus != null && !this.authorization.hasAccess(Right.PROGRAM)) { |
102 |
0 |
jobStatus = safe(jobStatus); |
103 |
|
} |
104 |
|
|
105 |
4069 |
return jobStatus; |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
@param |
112 |
|
@return |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
114 |
0 |
public Job getCurrentJob(Collection<String> path)... |
115 |
|
{ |
116 |
0 |
setError(null); |
117 |
|
|
118 |
0 |
if (this.authorization.hasAccess(Right.PROGRAM)) { |
119 |
0 |
return this.jobExecutor.getCurrentJob(new JobGroupPath(path)); |
120 |
|
} else { |
121 |
0 |
setError(new JobException("You need programming rights to get the current job.")); |
122 |
0 |
return null; |
123 |
|
} |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
@param |
130 |
|
@return |
131 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
132 |
0 |
public JobStatus getCurrentJobStatus(Collection<String> path)... |
133 |
|
{ |
134 |
0 |
Job job = this.jobExecutor.getCurrentJob(new JobGroupPath(path)); |
135 |
|
|
136 |
0 |
JobStatus jobStatus = null; |
137 |
0 |
if (job != null) { |
138 |
0 |
jobStatus = job.getStatus(); |
139 |
0 |
if (!this.authorization.hasAccess(Right.PROGRAM)) { |
140 |
0 |
jobStatus = safe(jobStatus); |
141 |
|
} |
142 |
|
} |
143 |
|
|
144 |
0 |
return jobStatus; |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
@param |
149 |
|
@param |
150 |
|
@return |
151 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
152 |
0 |
@SuppressWarnings("unchecked")... |
153 |
|
protected <T> T safe(T unsafe) |
154 |
|
{ |
155 |
0 |
return (T) this.scriptSafeProvider.get(unsafe); |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
@return |
162 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
163 |
0 |
public Exception getLastError()... |
164 |
|
{ |
165 |
0 |
return (Exception) this.execution.getContext().getProperty(JOB_ERROR_KEY); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
@link |
170 |
|
|
171 |
|
@param |
172 |
|
@see |
173 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
0 |
private void setError(Exception e)... |
175 |
|
{ |
176 |
0 |
this.execution.getContext().setProperty(JOB_ERROR_KEY, e); |
177 |
|
} |
178 |
|
} |