1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.script; |
21 |
|
|
22 |
|
import java.util.List; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Provider; |
27 |
|
|
28 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
29 |
|
import org.xwiki.context.Execution; |
30 |
|
import org.xwiki.extension.internal.validator.AbstractExtensionValidator; |
31 |
|
import org.xwiki.job.AbstractRequest; |
32 |
|
import org.xwiki.job.JobExecutor; |
33 |
|
import org.xwiki.job.event.status.JobStatus; |
34 |
|
import org.xwiki.job.script.JobScriptService; |
35 |
|
import org.xwiki.script.internal.safe.ScriptSafeProvider; |
36 |
|
import org.xwiki.script.service.ScriptService; |
37 |
|
import org.xwiki.security.authorization.ContextualAuthorizationManager; |
38 |
|
|
39 |
|
import com.xpn.xwiki.XWikiContext; |
40 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 12 |
Complexity Density: 0.67 |
|
48 |
|
public abstract class AbstractExtensionScriptService implements ScriptService |
49 |
|
{ |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
public static final String EXTENSIONERROR_KEY = "scriptservice.extension.error"; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
protected static final String PROPERTY_CONTEXT_WIKI = "context.wiki"; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
protected static final String PROPERTY_CONTEXT_ACTION = "context.action"; |
64 |
|
|
65 |
|
protected static final String PROPERTY_USERREFERENCE = AbstractExtensionValidator.PROPERTY_USERREFERENCE; |
66 |
|
|
67 |
|
protected static final String PROPERTY_CALLERREFERENCE = AbstractExtensionValidator.PROPERTY_CALLERREFERENCE; |
68 |
|
|
69 |
|
protected static final String PROPERTY_CHECKRIGHTS = AbstractExtensionValidator.PROPERTY_CHECKRIGHTS; |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
protected static final String WIKI_NAMESPACE_PREFIX = "wiki:"; |
75 |
|
|
76 |
|
@Inject |
77 |
|
@SuppressWarnings("rawtypes") |
78 |
|
protected ScriptSafeProvider scriptProvider; |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
@Inject |
84 |
|
protected Execution execution; |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
@Inject |
90 |
|
protected DocumentAccessBridge documentAccessBridge; |
91 |
|
|
92 |
|
@Inject |
93 |
|
protected Provider<XWikiContext> xcontextProvider; |
94 |
|
|
95 |
|
@Inject |
96 |
|
protected JobExecutor jobExecutor; |
97 |
|
|
98 |
|
@Inject |
99 |
|
protected ContextualAuthorizationManager authorization; |
100 |
|
|
101 |
|
@Inject |
102 |
|
@Named("job") |
103 |
|
private ScriptService jobScriptService; |
104 |
|
|
105 |
|
|
106 |
|
@param |
107 |
|
@param |
108 |
|
@return |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
110 |
1900 |
@SuppressWarnings("unchecked")... |
111 |
|
protected <T> T safe(T unsafe) |
112 |
|
{ |
113 |
1900 |
return (T) this.scriptProvider.get(unsafe); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
116 |
58 |
protected <T extends AbstractRequest> void setRightsProperties(T extensionRequest)... |
117 |
|
{ |
118 |
58 |
extensionRequest.setProperty(AbstractExtensionValidator.PROPERTY_CHECKRIGHTS, true); |
119 |
58 |
extensionRequest.setProperty(AbstractExtensionValidator.PROPERTY_USERREFERENCE, |
120 |
|
this.documentAccessBridge.getCurrentUserReference()); |
121 |
58 |
XWikiDocument callerDocument = getCallerDocument(); |
122 |
58 |
if (callerDocument != null) { |
123 |
36 |
extensionRequest.setProperty(AbstractExtensionValidator.PROPERTY_CALLERREFERENCE, |
124 |
|
callerDocument.getContentAuthorReference()); |
125 |
|
} |
126 |
|
} |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
128 |
58 |
protected XWikiDocument getCallerDocument()... |
129 |
|
{ |
130 |
58 |
XWikiContext xcontext = this.xcontextProvider.get(); |
131 |
58 |
XWikiDocument sdoc = (XWikiDocument) xcontext.get("sdoc"); |
132 |
58 |
if (sdoc == null) { |
133 |
22 |
sdoc = xcontext.getDoc(); |
134 |
|
} |
135 |
|
|
136 |
58 |
return sdoc; |
137 |
|
} |
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
139 |
4060 |
protected JobStatus getJobStatus(List<String> jobId)... |
140 |
|
{ |
141 |
4060 |
return ((JobScriptService) jobScriptService).getJobStatus(jobId); |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
@since |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
147 |
41 |
protected String toWikiId(String namespace)... |
148 |
|
{ |
149 |
41 |
if (namespace != null && namespace.startsWith(WIKI_NAMESPACE_PREFIX)) { |
150 |
36 |
return namespace.substring(WIKI_NAMESPACE_PREFIX.length()); |
151 |
|
} |
152 |
|
|
153 |
5 |
return null; |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
@since |
158 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
159 |
15 |
protected String fromWikitoNamespace(String wiki)... |
160 |
|
{ |
161 |
15 |
return WIKI_NAMESPACE_PREFIX + wiki; |
162 |
|
} |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
@return |
170 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
171 |
21 |
public Exception getLastError()... |
172 |
|
{ |
173 |
21 |
return (Exception) this.execution.getContext().getProperty(EXTENSIONERROR_KEY); |
174 |
|
} |
175 |
|
|
176 |
|
|
177 |
|
@link |
178 |
|
|
179 |
|
@param |
180 |
|
@see |
181 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
182 |
431 |
protected void setError(Exception e)... |
183 |
|
{ |
184 |
431 |
this.execution.getContext().setProperty(EXTENSIONERROR_KEY, e); |
185 |
|
} |
186 |
|
} |