1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.platform.flavor.script; |
21 |
|
|
22 |
|
import java.util.Arrays; |
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.extension.Extension; |
31 |
|
import org.xwiki.extension.ExtensionId; |
32 |
|
import org.xwiki.extension.repository.result.IterableResult; |
33 |
|
import org.xwiki.extension.script.AbstractExtensionScriptService; |
34 |
|
import org.xwiki.job.Job; |
35 |
|
import org.xwiki.job.JobException; |
36 |
|
import org.xwiki.platform.flavor.FlavorManager; |
37 |
|
import org.xwiki.platform.flavor.FlavorQuery; |
38 |
|
import org.xwiki.platform.flavor.internal.job.FlavorSearchJob; |
39 |
|
import org.xwiki.platform.flavor.internal.job.FlavorSearchStatus; |
40 |
|
import org.xwiki.platform.flavor.job.FlavorSearchRequest; |
41 |
|
import org.xwiki.rest.XWikiRestException; |
42 |
|
import org.xwiki.rest.resources.job.JobStatusResource; |
43 |
|
import org.xwiki.rest.url.ParametrizedRestURLGenerator; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@version |
49 |
|
@since |
50 |
|
|
51 |
|
@Component |
52 |
|
@Named(FlavorManagerScriptService.ROLEHINT) |
53 |
|
@Singleton |
|
|
| 0% |
Uncovered Elements: 52 (52) |
Complexity: 19 |
Complexity Density: 0.53 |
|
54 |
|
public class FlavorManagerScriptService extends AbstractExtensionScriptService |
55 |
|
{ |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
public static final String ROLEHINT = "flavor"; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
public static final String SEARCH_ID = "search"; |
65 |
|
|
66 |
|
@Inject |
67 |
|
private FlavorManager flavorManager; |
68 |
|
|
69 |
|
@Inject |
70 |
|
@Named(JobStatusResource.NAME) |
71 |
|
private ParametrizedRestURLGenerator<List<String>> jobstatusURLGenerator; |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
0 |
private List<String> getSearchJobId(String namespace)... |
74 |
|
{ |
75 |
0 |
return Arrays.asList(ROLEHINT, SEARCH_ID, namespace); |
76 |
|
} |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
@return |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
0 |
public FlavorQuery createFlavorQuery()... |
84 |
|
{ |
85 |
0 |
return new FlavorQuery(); |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
@param |
92 |
|
@return |
93 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
94 |
0 |
public FlavorQuery createFlavorQuery(String query)... |
95 |
|
{ |
96 |
0 |
return new FlavorQuery(query); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
@param |
103 |
|
@return |
104 |
|
@deprecated@link |
105 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
106 |
0 |
@Deprecated... |
107 |
|
public IterableResult<Extension> getFlavors(FlavorQuery query) |
108 |
|
{ |
109 |
0 |
setError(null); |
110 |
|
|
111 |
0 |
try { |
112 |
0 |
return this.flavorManager.getFlavors(query); |
113 |
|
} catch (Exception e) { |
114 |
0 |
setError(e); |
115 |
|
} |
116 |
|
|
117 |
0 |
return null; |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
@param |
124 |
|
@return |
125 |
|
@since |
126 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
127 |
0 |
public IterableResult<Extension> searchFlavors(FlavorQuery query)... |
128 |
|
{ |
129 |
0 |
setError(null); |
130 |
|
|
131 |
0 |
try { |
132 |
0 |
return this.flavorManager.searchFlavors(query); |
133 |
|
} catch (Exception e) { |
134 |
0 |
setError(e); |
135 |
|
} |
136 |
|
|
137 |
0 |
return null; |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
|
@param |
142 |
|
@return |
143 |
|
@since |
144 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
145 |
0 |
public FlavorSearchStatus getSearchValidFlavorsStatus(String namespace)... |
146 |
|
{ |
147 |
0 |
return (FlavorSearchStatus) getJobStatus(getSearchJobId(namespace)); |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
@return |
152 |
|
@since |
153 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
154 |
0 |
public FlavorSearchStatus getSearchValidFlavorsStatus()... |
155 |
|
{ |
156 |
0 |
return getSearchValidFlavorsStatus(currentNamespace()); |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
@param |
161 |
|
@return |
162 |
|
@since |
163 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
164 |
0 |
public String getSearchValidFlavorsStatusURL(String namespace)... |
165 |
|
{ |
166 |
0 |
setError(null); |
167 |
|
|
168 |
0 |
try { |
169 |
0 |
return this.jobstatusURLGenerator.getURL(getSearchJobId(namespace)).getPath(); |
170 |
|
} catch (XWikiRestException e) { |
171 |
0 |
setError(e); |
172 |
|
} |
173 |
|
|
174 |
0 |
return null; |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
|
@return |
179 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
180 |
0 |
public List<Extension> getValidExtensions()... |
181 |
|
{ |
182 |
0 |
FlavorSearchStatus status = getSearchValidFlavorsStatus(); |
183 |
|
|
184 |
0 |
return status != null ? status.getFlavors() : null; |
185 |
|
} |
186 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
187 |
0 |
private String currentNamespace()... |
188 |
|
{ |
189 |
0 |
return "wiki:" + this.xcontextProvider.get().getWikiId(); |
190 |
|
} |
191 |
|
|
192 |
|
|
193 |
|
@return |
194 |
|
@since |
195 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
196 |
0 |
public String getSearchValidFlavorsStatusURL()... |
197 |
|
{ |
198 |
0 |
return getSearchValidFlavorsStatusURL(currentNamespace()); |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
@param |
205 |
|
@return@link |
206 |
|
@since |
207 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
|
208 |
0 |
public Job searchValidFlavors(String namespace)... |
209 |
|
{ |
210 |
0 |
setError(null); |
211 |
|
|
212 |
0 |
Job job = null; |
213 |
0 |
try { |
214 |
0 |
FlavorSearchRequest flavorRequest = new FlavorSearchRequest(); |
215 |
|
|
216 |
0 |
flavorRequest.setId(getSearchJobId(namespace)); |
217 |
0 |
flavorRequest.addNamespace(namespace); |
218 |
|
|
219 |
0 |
setRightsProperties(flavorRequest); |
220 |
|
|
221 |
0 |
job = this.jobExecutor.execute(FlavorSearchJob.JOBTYPE, flavorRequest); |
222 |
|
} catch (JobException e) { |
223 |
0 |
setError(e); |
224 |
|
} |
225 |
|
|
226 |
0 |
return job; |
227 |
|
} |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
@return@link |
233 |
|
@since |
234 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
0 |
public Job searchValidFlavors()... |
236 |
|
{ |
237 |
0 |
return searchValidFlavors(currentNamespace()); |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
@param |
244 |
|
@return |
245 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
246 |
0 |
public ExtensionId getFlavorOfWiki(String wikiId)... |
247 |
|
{ |
248 |
0 |
return this.flavorManager.getFlavorOfWiki(wikiId); |
249 |
|
} |
250 |
|
} |