1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.distribution.internal; |
21 |
|
|
22 |
|
import java.util.Map; |
23 |
|
import java.util.TreeMap; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Provider; |
28 |
|
import javax.inject.Singleton; |
29 |
|
|
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
import org.xwiki.extension.CoreExtension; |
32 |
|
import org.xwiki.extension.ExtensionId; |
33 |
|
import org.xwiki.extension.distribution.internal.DistributionManager.DistributionState; |
34 |
|
import org.xwiki.extension.distribution.internal.DocumentsModifiedDuringDistributionListener.DocumentStatus; |
35 |
|
import org.xwiki.extension.distribution.internal.job.DistributionJob; |
36 |
|
import org.xwiki.extension.distribution.internal.job.DistributionJobStatus; |
37 |
|
import org.xwiki.job.event.status.JobStatus; |
38 |
|
import org.xwiki.job.event.status.JobStatus.State; |
39 |
|
import org.xwiki.model.reference.DocumentReference; |
40 |
|
import org.xwiki.observation.EventListener; |
41 |
|
import org.xwiki.rendering.block.Block; |
42 |
|
import org.xwiki.rendering.renderer.BlockRenderer; |
43 |
|
import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter; |
44 |
|
import org.xwiki.rendering.renderer.printer.WikiPrinter; |
45 |
|
import org.xwiki.rendering.transformation.RenderingContext; |
46 |
|
import org.xwiki.script.internal.safe.ScriptSafeProvider; |
47 |
|
import org.xwiki.script.service.ScriptService; |
48 |
|
import org.xwiki.text.StringUtils; |
49 |
|
|
50 |
|
import com.xpn.xwiki.XWikiContext; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@version |
58 |
|
@since |
59 |
|
|
60 |
|
@Component |
61 |
|
@Named("distribution") |
62 |
|
@Singleton |
|
|
| 8.2% |
Uncovered Elements: 89 (97) |
Complexity: 29 |
Complexity Density: 0.51 |
|
63 |
|
public class DistributionInternalScriptService implements ScriptService |
64 |
|
{ |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
public static final String EXTENSIONERROR_KEY = "scriptservice.distribution.error"; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@Inject |
74 |
|
protected DistributionManager distributionManager; |
75 |
|
|
76 |
|
|
77 |
|
@link |
78 |
|
|
79 |
|
@Inject |
80 |
|
protected Provider<XWikiContext> xcontextProvider; |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
@Inject |
86 |
|
@SuppressWarnings("rawtypes") |
87 |
|
private ScriptSafeProvider scriptProvider; |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
@Inject |
93 |
|
@Named("xhtml/1.0") |
94 |
|
private BlockRenderer xhtmlRenderer; |
95 |
|
|
96 |
|
@Inject |
97 |
|
@Named(DocumentsModifiedDuringDistributionListener.NAME) |
98 |
|
private EventListener modifiedDocumentsListener; |
99 |
|
|
100 |
|
@Inject |
101 |
|
private RenderingContext renderingContext; |
102 |
|
|
103 |
|
|
104 |
|
@param |
105 |
|
@param |
106 |
|
@return |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
0 |
@SuppressWarnings("unchecked")... |
109 |
|
private <T> T safe(T unsafe) |
110 |
|
{ |
111 |
0 |
return (T) this.scriptProvider.get(unsafe); |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
@return |
118 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
119 |
0 |
public DistributionState getState()... |
120 |
|
{ |
121 |
0 |
XWikiContext xcontext = this.xcontextProvider.get(); |
122 |
|
|
123 |
0 |
return getState(xcontext.getWikiId()); |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
|
@return |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
129 |
0 |
public DistributionState getState(String wiki)... |
130 |
|
{ |
131 |
0 |
XWikiContext xcontext = this.xcontextProvider.get(); |
132 |
|
|
133 |
0 |
return xcontext.isMainWiki(wiki) ? this.distributionManager.getFarmDistributionState() |
134 |
|
: this.distributionManager.getWikiDistributionState(wiki); |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
@return |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
140 |
0 |
public CoreExtension getDistributionExtension()... |
141 |
|
{ |
142 |
0 |
return this.distributionManager.getDistributionExtension(); |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
|
@return |
147 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
148 |
0 |
public boolean hasMainDefaultUIExtension()... |
149 |
|
{ |
150 |
0 |
ExtensionId extension = this.distributionManager.getMainUIExtensionId(); |
151 |
0 |
return extension != null && StringUtils.isNotBlank(extension.getId()); |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
|
@return |
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
157 |
7 |
public boolean hasWikiDefaultUIExtension()... |
158 |
|
{ |
159 |
7 |
ExtensionId extension = this.distributionManager.getWikiUIExtensionId(); |
160 |
7 |
return extension != null && StringUtils.isNotBlank(extension.getId()); |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
@return |
165 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
166 |
0 |
public ExtensionId getUIExtensionId()... |
167 |
|
{ |
168 |
0 |
XWikiContext xcontext = this.xcontextProvider.get(); |
169 |
|
|
170 |
0 |
return getUIExtensionId(xcontext.getWikiId()); |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
@param |
175 |
|
@return |
176 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
177 |
0 |
public ExtensionId getUIExtensionId(String wiki)... |
178 |
|
{ |
179 |
0 |
XWikiContext xcontext = this.xcontextProvider.get(); |
180 |
|
|
181 |
0 |
return xcontext.isMainWiki(wiki) ? this.distributionManager.getMainUIExtensionId() : this.distributionManager |
182 |
|
.getWikiUIExtensionId(); |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
|
@return |
187 |
|
|
188 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
189 |
0 |
public DistributionJobStatus< ? > getPreviousJobStatus()... |
190 |
|
{ |
191 |
0 |
XWikiContext xcontext = this.xcontextProvider.get(); |
192 |
|
|
193 |
0 |
return getPreviousJobStatus(xcontext.getWikiId()); |
194 |
|
} |
195 |
|
|
196 |
|
|
197 |
|
@param |
198 |
|
@return |
199 |
|
|
200 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
201 |
0 |
public DistributionJobStatus< ? > getPreviousJobStatus(String wiki)... |
202 |
|
{ |
203 |
0 |
XWikiContext xcontext = this.xcontextProvider.get(); |
204 |
|
|
205 |
0 |
return xcontext.isMainWiki(wiki) ? this.distributionManager.getPreviousFarmJobStatus() |
206 |
|
: this.distributionManager.getPreviousWikiJobStatus(wiki); |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
|
@return |
211 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
212 |
0 |
public boolean canDisplayDistributionWizard()... |
213 |
|
{ |
214 |
0 |
return this.distributionManager.canDisplayDistributionWizard(); |
215 |
|
} |
216 |
|
|
217 |
|
|
218 |
|
@return |
219 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
220 |
72 |
public DistributionJobStatus< ? > getJobStatus()... |
221 |
|
{ |
222 |
72 |
DistributionJob job = this.distributionManager.getCurrentDistributionJob(); |
223 |
|
|
224 |
72 |
return job != null ? (DistributionJobStatus< ? >) job.getStatus() : null; |
225 |
|
} |
226 |
|
|
227 |
|
|
228 |
|
@return |
229 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
230 |
0 |
public String renderCurrentStepToXHTML()... |
231 |
|
{ |
232 |
0 |
return renderCurrentStepToXHTML(this.renderingContext.getTransformationId()); |
233 |
|
} |
234 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.45 |
|
235 |
0 |
public String renderCurrentStepToXHTML(String transformationId)... |
236 |
|
{ |
237 |
0 |
DistributionJob job = this.distributionManager.getCurrentDistributionJob(); |
238 |
|
|
239 |
0 |
if (job != null) { |
240 |
0 |
JobStatus jobStatus = job.getStatus(); |
241 |
|
|
242 |
0 |
if (jobStatus != null) { |
243 |
0 |
State jobState = jobStatus.getState(); |
244 |
|
|
245 |
0 |
if (jobState == State.RUNNING || jobState == State.WAITING) { |
246 |
0 |
Block block = job.getCurrentStep().execute(); |
247 |
|
|
248 |
0 |
WikiPrinter printer = new DefaultWikiPrinter(); |
249 |
|
|
250 |
0 |
this.xhtmlRenderer.render(block, printer); |
251 |
|
|
252 |
0 |
return printer.toString(); |
253 |
|
} |
254 |
|
} |
255 |
|
} |
256 |
|
|
257 |
0 |
return null; |
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
|
@return |
262 |
|
@since |
263 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
264 |
0 |
public Map<DocumentReference, DocumentStatus> getModifiedDocuments()... |
265 |
|
{ |
266 |
0 |
return ((DocumentsModifiedDuringDistributionListener) this.modifiedDocumentsListener).getDocuments().get( |
267 |
|
this.xcontextProvider.get().getWikiId()); |
268 |
|
} |
269 |
|
|
270 |
|
|
271 |
|
@return |
272 |
|
@since |
273 |
|
|
|
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 6 |
Complexity Density: 0.26 |
|
274 |
0 |
public Map<String, Map<String, Map<String, Map<String, DocumentStatus>>>> getModifiedDocumentsTree()... |
275 |
|
{ |
276 |
0 |
Map<DocumentReference, DocumentStatus> documents = |
277 |
|
((DocumentsModifiedDuringDistributionListener) this.modifiedDocumentsListener).getDocuments().get( |
278 |
|
this.xcontextProvider.get().getWikiId()); |
279 |
|
|
280 |
0 |
Map<String, Map<String, Map<String, Map<String, DocumentStatus>>>> tree = |
281 |
|
new TreeMap<String, Map<String, Map<String, Map<String, DocumentStatus>>>>(); |
282 |
|
|
283 |
0 |
if (documents != null) { |
284 |
0 |
for (Map.Entry<DocumentReference, DocumentStatus> document : documents.entrySet()) { |
285 |
0 |
DocumentReference reference = document.getKey(); |
286 |
0 |
String wiki = reference.getWikiReference().getName(); |
287 |
|
|
288 |
0 |
String space = reference.getLastSpaceReference().getName(); |
289 |
0 |
String page = reference.getName(); |
290 |
0 |
String locale = reference.getLocale() != null ? reference.getLocale().toString() : ""; |
291 |
|
|
292 |
0 |
Map<String, Map<String, Map<String, DocumentStatus>>> spaces = tree.get(wiki); |
293 |
0 |
if (spaces == null) { |
294 |
0 |
spaces = new TreeMap<String, Map<String, Map<String, DocumentStatus>>>(); |
295 |
0 |
tree.put(wiki, spaces); |
296 |
|
} |
297 |
|
|
298 |
0 |
Map<String, Map<String, DocumentStatus>> pages = spaces.get(space); |
299 |
0 |
if (pages == null) { |
300 |
0 |
pages = new TreeMap<String, Map<String, DocumentStatus>>(); |
301 |
0 |
spaces.put(space, pages); |
302 |
|
} |
303 |
|
|
304 |
0 |
Map<String, DocumentStatus> locales = pages.get(page); |
305 |
0 |
if (locales == null) { |
306 |
0 |
locales = new TreeMap<String, DocumentStatus>(); |
307 |
0 |
pages.put(page, locales); |
308 |
|
} |
309 |
|
|
310 |
0 |
locales.put(locale, document.getValue()); |
311 |
|
} |
312 |
|
} |
313 |
|
|
314 |
0 |
return tree; |
315 |
|
} |
316 |
|
} |