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.resources.pages; |
21 |
|
|
22 |
|
import java.util.List; |
23 |
|
|
24 |
|
import javax.inject.Named; |
25 |
|
|
26 |
|
import org.xwiki.component.annotation.Component; |
27 |
|
import org.xwiki.query.Query; |
28 |
|
import org.xwiki.rest.XWikiResource; |
29 |
|
import org.xwiki.rest.XWikiRestException; |
30 |
|
import org.xwiki.rest.internal.DomainObjectFactory; |
31 |
|
import org.xwiki.rest.internal.Utils; |
32 |
|
import org.xwiki.rest.model.jaxb.Pages; |
33 |
|
import org.xwiki.rest.resources.pages.PageChildrenResource; |
34 |
|
|
35 |
|
import com.xpn.xwiki.api.Document; |
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
|
40 |
|
@Component |
41 |
|
@Named("org.xwiki.rest.internal.resources.pages.PageChildrenResourceImpl") |
|
|
| 80% |
Uncovered Elements: 4 (20) |
Complexity: 4 |
Complexity Density: 0.27 |
|
42 |
|
public class PageChildrenResourceImpl extends XWikiResource implements PageChildrenResource |
43 |
|
{ |
|
|
| 78.9% |
Uncovered Elements: 4 (19) |
Complexity: 4 |
Complexity Density: 0.27 |
|
44 |
3 |
@Override... |
45 |
|
public Pages getPageChildren(String wikiName, String spaceName, String pageName, Integer start, Integer number, |
46 |
|
Boolean withPrettyNames) throws XWikiRestException |
47 |
|
{ |
48 |
3 |
try { |
49 |
3 |
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false); |
50 |
|
|
51 |
3 |
Document doc = documentInfo.getDocument(); |
52 |
|
|
53 |
3 |
Pages pages = objectFactory.createPages(); |
54 |
|
|
55 |
|
|
56 |
3 |
String queryString = |
57 |
|
"select distinct doc.fullName from XWikiDocument as doc where doc.parent = :parent order by doc.fullName asc"; |
58 |
3 |
List<String> childPageFullNames = |
59 |
|
queryManager.createQuery(queryString, Query.XWQL).bindValue("parent", doc.getFullName()).setOffset( |
60 |
|
start).setLimit(number).execute(); |
61 |
|
|
62 |
3 |
for (String childPageFullName : childPageFullNames) { |
63 |
3 |
String pageId = Utils.getPageId(wikiName, childPageFullName); |
64 |
|
|
65 |
3 |
if (!Utils.getXWikiApi(componentManager).exists(pageId)) { |
66 |
0 |
logger.warning( |
67 |
|
String.format("[Page '%s' appears to be in space '%s' but no information is available.]", |
68 |
|
pageName, spaceName)); |
69 |
|
} else { |
70 |
3 |
Document childDoc = Utils.getXWikiApi(componentManager).getDocument(pageId); |
71 |
|
|
72 |
|
|
73 |
3 |
if (childDoc != null) { |
74 |
3 |
pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory, |
75 |
|
uriInfo.getBaseUri(), childDoc, Utils.getXWikiApi(componentManager), withPrettyNames)); |
76 |
|
} |
77 |
|
} |
78 |
|
} |
79 |
|
|
80 |
3 |
return pages; |
81 |
|
} catch (Exception e) { |
82 |
0 |
throw new XWikiRestException(e); |
83 |
|
} |
84 |
|
} |
85 |
|
} |