1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.wiki.internal.manager; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Provider; |
24 |
|
import javax.inject.Singleton; |
25 |
|
|
26 |
|
import org.xwiki.bridge.event.WikiCopiedEvent; |
27 |
|
import org.xwiki.bridge.event.WikiCreateFailedEvent; |
28 |
|
import org.xwiki.bridge.event.WikiCreatedEvent; |
29 |
|
import org.xwiki.bridge.event.WikiCreatingEvent; |
30 |
|
import org.xwiki.bridge.event.WikiDeletedEvent; |
31 |
|
import org.xwiki.component.annotation.Component; |
32 |
|
import org.xwiki.observation.ObservationManager; |
33 |
|
import org.xwiki.wiki.descriptor.WikiDescriptor; |
34 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
35 |
|
import org.xwiki.wiki.manager.WikiManager; |
36 |
|
import org.xwiki.wiki.manager.WikiManagerException; |
37 |
|
import org.xwiki.wiki.provisioning.WikiCopier; |
38 |
|
|
39 |
|
import com.xpn.xwiki.XWiki; |
40 |
|
import com.xpn.xwiki.XWikiContext; |
41 |
|
import com.xpn.xwiki.XWikiException; |
42 |
|
import com.xpn.xwiki.util.Util; |
43 |
|
|
44 |
|
|
45 |
|
@link |
46 |
|
@version |
47 |
|
@since |
48 |
|
|
49 |
|
@Component |
50 |
|
@Singleton |
|
|
| 88.6% |
Uncovered Elements: 4 (35) |
Complexity: 10 |
Complexity Density: 0.38 |
|
51 |
|
public class DefaultWikiManager implements WikiManager |
52 |
|
{ |
53 |
|
@Inject |
54 |
|
private Provider<XWikiContext> xcontextProvider; |
55 |
|
|
56 |
|
@Inject |
57 |
|
private WikiDescriptorManager wikiDescriptorManager; |
58 |
|
|
59 |
|
@Inject |
60 |
|
private ObservationManager observationManager; |
61 |
|
|
62 |
|
@Inject |
63 |
|
private WikiCreator wikiCreator; |
64 |
|
|
65 |
|
@Inject |
66 |
|
private WikiCopier wikiCopier; |
67 |
|
|
68 |
|
@Inject |
69 |
|
private WikiDeleter wikiDeleter; |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 4 |
Complexity Density: 0.36 |
|
71 |
10 |
@Override... |
72 |
|
public WikiDescriptor create(String wikiId, String wikiAlias, boolean failOnExist) throws WikiManagerException |
73 |
|
{ |
74 |
|
|
75 |
10 |
if (failOnExist && !idAvailable(wikiId)) { |
76 |
3 |
throw new WikiManagerException(String.format("wiki id [%s] is already used and is thus not available", |
77 |
|
wikiId)); |
78 |
|
} |
79 |
|
|
80 |
7 |
XWikiContext context = xcontextProvider.get(); |
81 |
7 |
WikiDescriptor descriptor; |
82 |
|
|
83 |
7 |
try { |
84 |
|
|
85 |
7 |
observationManager.notify(new WikiCreatingEvent(wikiId), wikiId, context); |
86 |
|
|
87 |
|
|
88 |
7 |
descriptor = wikiCreator.create(wikiId, wikiAlias); |
89 |
|
|
90 |
|
|
91 |
6 |
observationManager.notify(new WikiCreatedEvent(wikiId), wikiId, context); |
92 |
|
|
93 |
|
} catch (WikiManagerException e) { |
94 |
|
|
95 |
1 |
observationManager.notify(new WikiCreateFailedEvent(wikiId), wikiId, context); |
96 |
|
|
97 |
|
|
98 |
1 |
throw e; |
99 |
|
} |
100 |
|
|
101 |
6 |
return descriptor; |
102 |
|
} |
103 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
104 |
2 |
@Override... |
105 |
|
public WikiDescriptor copy(String fromWikiId, String newWikiId, String newWikiAlias, boolean copyHistory, |
106 |
|
boolean copyRecycleBin, boolean failOnExist) throws WikiManagerException |
107 |
|
{ |
108 |
2 |
WikiDescriptor newWiki = create(newWikiId, newWikiAlias, failOnExist); |
109 |
1 |
wikiCopier.copyDocuments(fromWikiId, newWikiId, copyHistory); |
110 |
1 |
if (copyRecycleBin) { |
111 |
1 |
wikiCopier.copyDeletedDocuments(fromWikiId, newWikiId); |
112 |
|
} |
113 |
1 |
observationManager.notify(new WikiCopiedEvent(fromWikiId, newWikiId), fromWikiId, xcontextProvider.get()); |
114 |
1 |
return newWiki; |
115 |
|
} |
116 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
117 |
0 |
@Override... |
118 |
|
public WikiDescriptor rename(String wikiId, String newWikiId) throws WikiManagerException |
119 |
|
{ |
120 |
0 |
throw new WikiManagerException("This method is not implemented yet"); |
121 |
|
} |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
123 |
4 |
@Override... |
124 |
|
public void delete(String wikiId) throws WikiManagerException |
125 |
|
{ |
126 |
|
|
127 |
4 |
wikiDeleter.delete(wikiId); |
128 |
|
|
129 |
|
|
130 |
4 |
observationManager.notify(new WikiDeletedEvent(wikiId), wikiId); |
131 |
|
} |
132 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
133 |
44 |
@Override... |
134 |
|
public boolean idAvailable(String wikiId) throws WikiManagerException { |
135 |
|
|
136 |
44 |
XWikiContext xcontext = xcontextProvider.get(); |
137 |
44 |
XWiki xwiki = xcontext.getWiki(); |
138 |
|
|
139 |
43 |
String wikiForbiddenList = xcontextProvider.get().getWiki().Param("xwiki.virtual.reserved_wikis"); |
140 |
44 |
try { |
141 |
44 |
return !wikiDescriptorManager.exists(wikiId) && !Util.contains(wikiId, wikiForbiddenList, ", ") |
142 |
|
&& xwiki.getStore().isWikiNameAvailable(wikiId, xcontext); |
143 |
|
} catch (XWikiException e) { |
144 |
0 |
throw new WikiManagerException("Fail to look at the databases."); |
145 |
|
} |
146 |
|
} |
147 |
|
} |