1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rest.internal; |
21 |
|
|
22 |
|
import java.net.URI; |
23 |
|
import java.util.Calendar; |
24 |
|
import java.util.Collection; |
25 |
|
import java.util.Date; |
26 |
|
import java.util.List; |
27 |
|
|
28 |
|
import org.apache.commons.lang3.StringUtils; |
29 |
|
import org.suigeneris.jrcs.rcs.Version; |
30 |
|
import org.xwiki.logging.event.LogEvent; |
31 |
|
import org.xwiki.rest.Relations; |
32 |
|
import org.xwiki.rest.model.jaxb.Attachment; |
33 |
|
import org.xwiki.rest.model.jaxb.Comment; |
34 |
|
import org.xwiki.rest.model.jaxb.HistorySummary; |
35 |
|
import org.xwiki.rest.model.jaxb.JobLog; |
36 |
|
import org.xwiki.rest.model.jaxb.JobProgress; |
37 |
|
import org.xwiki.rest.model.jaxb.JobStatus; |
38 |
|
import org.xwiki.rest.model.jaxb.Link; |
39 |
|
import org.xwiki.rest.model.jaxb.Object; |
40 |
|
import org.xwiki.rest.model.jaxb.ObjectFactory; |
41 |
|
import org.xwiki.rest.model.jaxb.ObjectSummary; |
42 |
|
import org.xwiki.rest.model.jaxb.Page; |
43 |
|
import org.xwiki.rest.model.jaxb.PageSummary; |
44 |
|
import org.xwiki.rest.model.jaxb.Space; |
45 |
|
import org.xwiki.rest.model.jaxb.Translations; |
46 |
|
import org.xwiki.rest.model.jaxb.Wiki; |
47 |
|
import org.xwiki.rest.model.jaxb.Xwiki; |
48 |
|
import org.xwiki.rest.resources.SyntaxesResource; |
49 |
|
import org.xwiki.rest.resources.pages.PageResource; |
50 |
|
import org.xwiki.rest.resources.pages.PageTranslationVersionResource; |
51 |
|
import org.xwiki.rest.resources.pages.PageVersionResource; |
52 |
|
import org.xwiki.rest.resources.wikis.WikisResource; |
53 |
|
|
54 |
|
import com.xpn.xwiki.XWikiContext; |
55 |
|
import com.xpn.xwiki.XWikiException; |
56 |
|
import com.xpn.xwiki.api.Document; |
57 |
|
import com.xpn.xwiki.api.XWiki; |
58 |
|
import com.xpn.xwiki.objects.BaseObject; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@version |
64 |
|
|
|
|
| 85.5% |
Uncovered Elements: 23 (159) |
Complexity: 30 |
Complexity Density: 0.26 |
|
65 |
|
public class DomainObjectFactory |
66 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
780 |
public static ModelFactory getModelUtils()... |
68 |
|
{ |
69 |
780 |
return com.xpn.xwiki.web.Utils.getComponent(ModelFactory.class); |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
72 |
1 |
public static Xwiki createXWikiRoot(ObjectFactory objectFactory, URI baseUri, String version)... |
73 |
|
{ |
74 |
1 |
Xwiki xwiki = objectFactory.createXwiki().withVersion(version); |
75 |
|
|
76 |
1 |
String wikisUri = uri(baseUri, WikisResource.class); |
77 |
1 |
Link wikisLink = objectFactory.createLink(); |
78 |
1 |
wikisLink.setHref(wikisUri); |
79 |
1 |
wikisLink.setRel(Relations.WIKIS); |
80 |
1 |
xwiki.getLinks().add(wikisLink); |
81 |
|
|
82 |
1 |
String syntaxesUri = uri(baseUri, SyntaxesResource.class); |
83 |
1 |
Link syntaxesLink = objectFactory.createLink(); |
84 |
1 |
syntaxesLink.setHref(syntaxesUri); |
85 |
1 |
syntaxesLink.setRel(Relations.SYNTAXES); |
86 |
1 |
xwiki.getLinks().add(syntaxesLink); |
87 |
|
|
88 |
1 |
return xwiki; |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
@deprecated@link |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
94 |
235 |
@Deprecated... |
95 |
|
public static Wiki createWiki(ObjectFactory objectFactory, URI baseUri, String wikiName) |
96 |
|
{ |
97 |
235 |
return getModelUtils().toRestWiki(baseUri, wikiName); |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
@deprecated@link |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
82 |
@Deprecated... |
104 |
|
public static Space createSpace(ObjectFactory objectFactory, URI baseUri, String wikiName, List<String> spaces, |
105 |
|
Document home) |
106 |
|
{ |
107 |
82 |
return getModelUtils().toRestSpace(baseUri, wikiName, spaces, home); |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
|
@deprecated@link |
112 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
113 |
0 |
@Deprecated... |
114 |
|
public static Translations createTranslations(ObjectFactory objectFactory, URI baseUri, Document doc) |
115 |
|
throws XWikiException |
116 |
|
{ |
117 |
0 |
return getModelUtils().toRestTranslations(baseUri, doc); |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
|
@deprecated@link |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
123 |
138 |
@Deprecated... |
124 |
|
public static PageSummary createPageSummary(ObjectFactory objectFactory, URI baseUri, Document doc, XWiki xwikiApi, |
125 |
|
Boolean withPrettyNames) throws XWikiException |
126 |
|
{ |
127 |
138 |
return getModelUtils().toRestPageSummary(baseUri, doc, withPrettyNames); |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
@deprecated@link |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
133 |
5 |
@Deprecated... |
134 |
|
public static Page createPage(ObjectFactory objectFactory, URI baseUri, URI self, Document doc, boolean useVersion, |
135 |
|
XWiki xwikiApi, Boolean withPrettyNames) throws XWikiException |
136 |
|
{ |
137 |
5 |
return getModelUtils().toRestPage(baseUri, self, doc, useVersion, withPrettyNames, false, false, false); |
138 |
|
} |
139 |
|
|
|
|
| 93.9% |
Uncovered Elements: 2 (33) |
Complexity: 3 |
Complexity Density: 0.1 |
|
140 |
33 |
public static HistorySummary createHistorySummary(ObjectFactory objectFactory, URI baseUri, String wikiName,... |
141 |
|
List<String> spaces, String pageName, String language, Version version, String modifier, Date modified, |
142 |
|
String comment, XWiki xwikiApi, Boolean withPrettyNames) |
143 |
|
{ |
144 |
33 |
HistorySummary historySummary = objectFactory.createHistorySummary(); |
145 |
|
|
146 |
33 |
String pageId = Utils.getPageId(wikiName, spaces, pageName); |
147 |
|
|
148 |
33 |
historySummary.setPageId(pageId); |
149 |
33 |
historySummary.setWiki(wikiName); |
150 |
33 |
historySummary.setSpace(Utils.getLocalSpaceId(spaces)); |
151 |
33 |
historySummary.setName(pageName); |
152 |
33 |
historySummary.setVersion(version.toString()); |
153 |
33 |
historySummary.setMajorVersion(version.at(0)); |
154 |
33 |
historySummary.setMinorVersion(version.at(1)); |
155 |
33 |
historySummary.setComment(comment); |
156 |
33 |
historySummary.setModifier(modifier); |
157 |
33 |
if (withPrettyNames) { |
158 |
0 |
historySummary.setModifierName(xwikiApi.getUserName(modifier, false)); |
159 |
|
} |
160 |
|
|
161 |
33 |
historySummary.setLanguage(language); |
162 |
|
|
163 |
33 |
Calendar calendar = Calendar.getInstance(); |
164 |
33 |
calendar.setTime(modified); |
165 |
33 |
historySummary.setModified(calendar); |
166 |
|
|
167 |
33 |
if (language == null) { |
168 |
32 |
String pageUri = uri(baseUri, PageVersionResource.class, wikiName, spaces, pageName, version); |
169 |
32 |
Link pageLink = objectFactory.createLink(); |
170 |
32 |
pageLink.setHref(pageUri); |
171 |
32 |
pageLink.setRel(Relations.PAGE); |
172 |
32 |
historySummary.getLinks().add(pageLink); |
173 |
|
} else { |
174 |
1 |
String pageUri = |
175 |
|
uri(baseUri, PageTranslationVersionResource.class, wikiName, spaces, pageName, language, version); |
176 |
1 |
Link pageLink = objectFactory.createLink(); |
177 |
1 |
pageLink.setHref(pageUri); |
178 |
1 |
pageLink.setRel(Relations.PAGE); |
179 |
1 |
historySummary.getLinks().add(pageLink); |
180 |
|
} |
181 |
|
|
182 |
33 |
return historySummary; |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
|
@deprecated |
187 |
|
@link |
188 |
|
|
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
190 |
55 |
@Deprecated... |
191 |
|
public static Attachment createAttachment(ObjectFactory objectFactory, URI baseUri, |
192 |
|
com.xpn.xwiki.api.Attachment xwikiAttachment, String xwikiRelativeUrl, String xwikiAbsoluteUrl, XWiki xwikiApi, |
193 |
|
Boolean withPrettyNames) |
194 |
|
{ |
195 |
55 |
return getModelUtils().toRestAttachment(baseUri, xwikiAttachment, xwikiRelativeUrl, xwikiAbsoluteUrl, |
196 |
|
withPrettyNames, false); |
197 |
|
} |
198 |
|
|
199 |
|
|
200 |
|
@deprecated |
201 |
|
@link |
202 |
|
|
203 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
204 |
4 |
@Deprecated... |
205 |
|
public static Attachment createAttachmentAtVersion(ObjectFactory objectFactory, URI baseUri, |
206 |
|
com.xpn.xwiki.api.Attachment xwikiAttachment, String xwikiRelativeUrl, String xwikiAbsoluteUrl, XWiki xwikiApi, |
207 |
|
Boolean withPrettyNames) |
208 |
|
{ |
209 |
4 |
return getModelUtils().toRestAttachment(baseUri, xwikiAttachment, xwikiRelativeUrl, xwikiAbsoluteUrl, |
210 |
|
withPrettyNames, true); |
211 |
|
} |
212 |
|
|
|
|
| 76.9% |
Uncovered Elements: 9 (39) |
Complexity: 7 |
Complexity Density: 0.26 |
|
213 |
6 |
public static Comment createComment(ObjectFactory objectFactory, URI baseUri, Document doc,... |
214 |
|
com.xpn.xwiki.api.Object xwikiComment, XWiki xwikiApi, Boolean withPrettyNames) |
215 |
|
{ |
216 |
6 |
Comment comment = objectFactory.createComment(); |
217 |
6 |
comment.setId(xwikiComment.getNumber()); |
218 |
|
|
219 |
6 |
com.xpn.xwiki.api.Property property = xwikiComment.getProperty("author"); |
220 |
6 |
if (property != null) { |
221 |
6 |
comment.setAuthor((String) property.getValue()); |
222 |
6 |
if (withPrettyNames) { |
223 |
0 |
comment.setAuthorName(xwikiApi.getUserName((String) property.getValue(), false)); |
224 |
|
} |
225 |
|
} |
226 |
|
|
227 |
6 |
property = xwikiComment.getProperty("date"); |
228 |
6 |
if (property != null) { |
229 |
6 |
Calendar calendar = Calendar.getInstance(); |
230 |
6 |
calendar.setTime((Date) property.getValue()); |
231 |
6 |
comment.setDate(calendar); |
232 |
|
} |
233 |
|
|
234 |
6 |
property = xwikiComment.getProperty("highlight"); |
235 |
6 |
if (property != null) { |
236 |
0 |
comment.setHighlight((String) property.getValue()); |
237 |
|
} |
238 |
|
|
239 |
6 |
property = xwikiComment.getProperty("comment"); |
240 |
6 |
if (property != null) { |
241 |
6 |
comment.setText((String) property.getValue()); |
242 |
|
} |
243 |
|
|
244 |
6 |
property = xwikiComment.getProperty("replyto"); |
245 |
6 |
if (property != null) { |
246 |
0 |
comment.setReplyTo((Integer) property.getValue()); |
247 |
|
} |
248 |
|
|
249 |
6 |
String pageUri = |
250 |
|
uri(baseUri, PageResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName()); |
251 |
6 |
Link pageLink = objectFactory.createLink(); |
252 |
6 |
pageLink.setHref(pageUri); |
253 |
6 |
pageLink.setRel(Relations.PAGE); |
254 |
6 |
comment.getLinks().add(pageLink); |
255 |
|
|
256 |
6 |
return comment; |
257 |
|
} |
258 |
|
|
259 |
|
|
260 |
|
@deprecated |
261 |
|
@link |
262 |
|
|
263 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
264 |
16 |
@Deprecated... |
265 |
|
public static ObjectSummary createObjectSummary(ObjectFactory objectFactory, URI baseUri, |
266 |
|
XWikiContext xwikiContext, Document doc, BaseObject xwikiObject, boolean useVersion, XWiki xwikiApi, |
267 |
|
Boolean withPrettyNames) throws XWikiException |
268 |
|
{ |
269 |
16 |
return getModelUtils().toRestObjectSummary(baseUri, doc, xwikiObject, useVersion, withPrettyNames); |
270 |
|
} |
271 |
|
|
272 |
|
|
273 |
|
@deprecated |
274 |
|
@link |
275 |
|
|
276 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
277 |
37 |
@Deprecated... |
278 |
|
public static Object createObject(ObjectFactory objectFactory, URI baseUri, XWikiContext xwikiContext, |
279 |
|
Document doc, BaseObject xwikiObject, boolean useVersion, XWiki xwikiApi, Boolean withPrettyNames) |
280 |
|
throws XWikiException |
281 |
|
{ |
282 |
37 |
return getModelUtils().toRestObject(baseUri, doc, xwikiObject, useVersion, withPrettyNames); |
283 |
|
} |
284 |
|
|
|
|
| 91.7% |
Uncovered Elements: 2 (24) |
Complexity: 4 |
Complexity Density: 0.22 |
|
285 |
35 |
public static JobStatus createJobStatus(ObjectFactory objectFactory, URI self,... |
286 |
|
org.xwiki.job.event.status.JobStatus jobStatus) |
287 |
|
{ |
288 |
35 |
JobStatus status = objectFactory.createJobStatus(); |
289 |
35 |
status.setId(StringUtils.join(jobStatus.getRequest().getId(), "/")); |
290 |
35 |
status.setState(jobStatus.getState().name()); |
291 |
35 |
status.setProgress(createJobProgress(objectFactory, jobStatus.getProgress())); |
292 |
35 |
if (jobStatus.getStartDate() != null) { |
293 |
35 |
Calendar calendarStartDate = Calendar.getInstance(); |
294 |
35 |
calendarStartDate.setTime(jobStatus.getStartDate()); |
295 |
35 |
status.setStartDate(calendarStartDate); |
296 |
|
} |
297 |
35 |
if (jobStatus.getEndDate() != null) { |
298 |
27 |
Calendar calendarEndDate = Calendar.getInstance(); |
299 |
27 |
calendarEndDate.setTime(jobStatus.getEndDate()); |
300 |
27 |
status.setEndDate(calendarEndDate); |
301 |
|
} |
302 |
35 |
if (self != null) { |
303 |
35 |
Link link = objectFactory.createLink(); |
304 |
35 |
link.setHref(self.toString()); |
305 |
35 |
link.setRel(Relations.SELF); |
306 |
35 |
status.getLinks().add(link); |
307 |
|
} |
308 |
|
|
309 |
35 |
return status; |
310 |
|
} |
311 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
312 |
35 |
public static JobProgress createJobProgress(ObjectFactory objectFactory,... |
313 |
|
org.xwiki.job.event.status.JobProgress jobProgress) |
314 |
|
{ |
315 |
35 |
JobProgress progress = objectFactory.createJobProgress(); |
316 |
35 |
progress.setOffset(jobProgress.getOffset()); |
317 |
35 |
progress.setCurrentLevelOffset(jobProgress.getCurrentLevelOffset()); |
318 |
35 |
return progress; |
319 |
|
} |
320 |
|
|
|
|
| 52.9% |
Uncovered Elements: 8 (17) |
Complexity: 2 |
Complexity Density: 0.13 |
|
321 |
7 |
public static JobLog createLog(ObjectFactory objectFactory, URI self, Collection<LogEvent> logs)... |
322 |
|
{ |
323 |
7 |
JobLog log = objectFactory.createJobLog(); |
324 |
7 |
for (LogEvent logEvent : logs) { |
325 |
0 |
org.xwiki.rest.model.jaxb.LogEvent event = objectFactory.createLogEvent(); |
326 |
0 |
event.setLevel(logEvent.getLevel().name()); |
327 |
0 |
Calendar calendarDate = Calendar.getInstance(); |
328 |
0 |
calendarDate.setTimeInMillis(logEvent.getTimeStamp()); |
329 |
0 |
event.setDate(calendarDate); |
330 |
0 |
event.setFormattedMessage(logEvent.getFormattedMessage()); |
331 |
0 |
log.getLogEvents().add(event); |
332 |
|
} |
333 |
7 |
if (self != null) { |
334 |
7 |
Link link = objectFactory.createLink(); |
335 |
7 |
link.setHref(self.toString()); |
336 |
7 |
link.setRel(Relations.SELF); |
337 |
7 |
log.getLinks().add(link); |
338 |
|
} |
339 |
7 |
return log; |
340 |
|
} |
341 |
|
|
342 |
|
|
343 |
|
@deprecated@link |
344 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
345 |
208 |
public static org.xwiki.rest.model.jaxb.Class createClass(ObjectFactory objectFactory, URI baseUri,... |
346 |
|
String wikiName, com.xpn.xwiki.api.Class xwikiClass) |
347 |
|
{ |
348 |
208 |
return getModelUtils().toRestClass(baseUri, xwikiClass); |
349 |
|
} |
350 |
|
|
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
@param |
356 |
|
@param |
357 |
|
@param |
358 |
|
@return |
359 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
360 |
41 |
private static String uri(URI baseURI, java.lang.Class<?> resourceClass, java.lang.Object... pathElements)... |
361 |
|
{ |
362 |
41 |
return Utils.createURI(baseURI, resourceClass, pathElements).toString(); |
363 |
|
} |
364 |
|
} |