1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.platform.wiki.creationjob.internal.steps; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Named; |
24 |
|
import javax.inject.Provider; |
25 |
|
|
26 |
|
import org.xwiki.bridge.event.WikiCopiedEvent; |
27 |
|
import org.xwiki.bridge.event.WikiProvisionedEvent; |
28 |
|
import org.xwiki.bridge.event.WikiProvisioningEvent; |
29 |
|
import org.xwiki.bridge.event.WikiProvisioningFailedEvent; |
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
32 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
33 |
|
import org.xwiki.observation.ObservationManager; |
34 |
|
import org.xwiki.platform.wiki.creationjob.WikiCreationRequest; |
35 |
|
import org.xwiki.platform.wiki.creationjob.WikiCreationStep; |
36 |
|
import org.xwiki.platform.wiki.creationjob.WikiCreationException; |
37 |
|
import org.xwiki.platform.wiki.creationjob.internal.ExtensionInstaller; |
38 |
|
import org.xwiki.wiki.provisioning.WikiCopier; |
39 |
|
import org.xwiki.wiki.manager.WikiManagerException; |
40 |
|
|
41 |
|
import com.xpn.xwiki.XWikiContext; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
@version |
47 |
|
@since |
48 |
|
|
49 |
|
@Component |
50 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
51 |
|
@Named("provision") |
|
|
| 85.7% |
Uncovered Elements: 4 (28) |
Complexity: 8 |
Complexity Density: 0.36 |
|
52 |
|
public class ProvisionWikiStep implements WikiCreationStep |
53 |
|
{ |
54 |
|
@Inject |
55 |
|
private WikiCopier wikiCopier; |
56 |
|
|
57 |
|
@Inject |
58 |
|
private ExtensionInstaller extensionInstaller; |
59 |
|
|
60 |
|
@Inject |
61 |
|
private ObservationManager observationManager; |
62 |
|
|
63 |
|
@Inject |
64 |
|
private Provider<XWikiContext> xcontextProvider; |
65 |
|
|
|
|
| 81% |
Uncovered Elements: 4 (21) |
Complexity: 5 |
Complexity Density: 0.26 |
|
66 |
6 |
@Override... |
67 |
|
public void execute(WikiCreationRequest request) throws WikiCreationException |
68 |
|
{ |
69 |
6 |
try { |
70 |
6 |
if (request.getWikiSource() == null) { |
71 |
|
|
72 |
0 |
return; |
73 |
|
} |
74 |
6 |
switch (request.getWikiSource()) { |
75 |
3 |
case EXTENSION: |
76 |
3 |
sendWikiProvisioningEvent(request); |
77 |
|
|
78 |
3 |
extensionInstaller.installExtension(request.getWikiId(), request.getExtensionId()); |
79 |
|
|
80 |
2 |
sendWikiProvisionedEvent(request); |
81 |
2 |
break; |
82 |
3 |
case TEMPLATE: |
83 |
3 |
sendWikiProvisioningEvent(request); |
84 |
|
|
85 |
3 |
wikiCopier.copyDocuments(request.getTemplateId(), request.getWikiId(), false); |
86 |
3 |
observationManager.notify(new WikiCopiedEvent(request.getTemplateId(), request.getWikiId()), |
87 |
|
request.getTemplateId(), xcontextProvider.get()); |
88 |
|
|
89 |
3 |
sendWikiProvisionedEvent(request); |
90 |
3 |
break; |
91 |
0 |
default: |
92 |
|
|
93 |
0 |
break; |
94 |
|
} |
95 |
|
} catch (WikiManagerException | WikiCreationException e) { |
96 |
1 |
observationManager.notify(new WikiProvisioningFailedEvent(request.getWikiId()), request.getWikiId(), |
97 |
|
xcontextProvider.get()); |
98 |
1 |
throw new WikiCreationException(String.format("Failed to provision the wiki [%s].", |
99 |
|
request.getWikiId()), e); |
100 |
|
} |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
6 |
private void sendWikiProvisioningEvent(WikiCreationRequest request)... |
104 |
|
{ |
105 |
6 |
observationManager.notify(new WikiProvisioningEvent(request.getWikiId()), request.getWikiId(), |
106 |
|
xcontextProvider.get()); |
107 |
|
} |
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
109 |
5 |
private void sendWikiProvisionedEvent(WikiCreationRequest request)... |
110 |
|
{ |
111 |
5 |
observationManager.notify(new WikiProvisionedEvent(request.getWikiId()), request.getWikiId(), |
112 |
|
xcontextProvider.get()); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
115 |
13 |
@Override... |
116 |
|
public int getOrder() |
117 |
|
{ |
118 |
13 |
return 3000; |
119 |
|
} |
120 |
|
} |