1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.index.tree.internal.nestedpages; |
21 |
|
|
22 |
|
import java.util.Collections; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
|
28 |
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
31 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
32 |
|
import org.xwiki.index.tree.internal.AbstractEntityTreeNode; |
33 |
|
import org.xwiki.localization.LocalizationContext; |
34 |
|
import org.xwiki.model.EntityType; |
35 |
|
import org.xwiki.model.reference.EntityReference; |
36 |
|
import org.xwiki.model.reference.WikiReference; |
37 |
|
import org.xwiki.query.Query; |
38 |
|
import org.xwiki.query.QueryException; |
39 |
|
import org.xwiki.query.QueryFilter; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
@since |
47 |
|
|
48 |
|
@Component |
49 |
|
@Named("wiki") |
50 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 52.5% |
Uncovered Elements: 19 (40) |
Complexity: 13 |
Complexity Density: 0.48 |
|
51 |
|
public class WikiTreeNode extends AbstractEntityTreeNode |
52 |
|
{ |
53 |
|
@Inject |
54 |
|
private LocalizationContext localizationContext; |
55 |
|
|
56 |
|
@Inject |
57 |
|
@Named("topLevelPage/nestedPages") |
58 |
|
private QueryFilter topLevelPageFilter; |
59 |
|
|
60 |
|
@Inject |
61 |
|
@Named("hiddenPage/nestedPages") |
62 |
|
private QueryFilter hiddenPageFilter; |
63 |
|
|
64 |
|
@Inject |
65 |
|
@Named("documentReferenceResolver/nestedPages") |
66 |
|
private QueryFilter documentReferenceResolverFilter; |
67 |
|
|
|
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 4 |
Complexity Density: 0.67 |
|
68 |
3 |
@Override... |
69 |
|
public List<String> getChildren(String nodeId, int offset, int limit) |
70 |
|
{ |
71 |
3 |
EntityReference wikiReference = resolve(nodeId); |
72 |
3 |
if (wikiReference != null && wikiReference.getType() == EntityType.WIKI) { |
73 |
3 |
try { |
74 |
3 |
return serialize(getChildren(new WikiReference(wikiReference), offset, limit)); |
75 |
|
} catch (QueryException e) { |
76 |
0 |
this.logger.warn("Failed to retrieve the children of [{}]. Root cause [{}].", nodeId, |
77 |
|
ExceptionUtils.getRootCauseMessage(e)); |
78 |
|
} |
79 |
|
} |
80 |
0 |
return Collections.emptyList(); |
81 |
|
} |
82 |
|
|
|
|
| 82.4% |
Uncovered Elements: 3 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
83 |
3 |
protected List<? extends EntityReference> getChildren(WikiReference wikiReference, int offset, int limit)... |
84 |
|
throws QueryException |
85 |
|
{ |
86 |
3 |
String orderBy = getOrderBy(); |
87 |
3 |
Query query; |
88 |
3 |
if ("title".equals(orderBy)) { |
89 |
3 |
query = this.queryManager.getNamedQuery("nonTerminalPagesOrderedByTitle"); |
90 |
3 |
query.bindValue("locale", this.localizationContext.getCurrentLocale().toString()); |
91 |
|
} else { |
92 |
|
|
93 |
0 |
query = this.queryManager.createQuery( |
94 |
|
"select reference, 0 as terminal from XWikiSpace page order by lower(name), name", Query.HQL); |
95 |
|
} |
96 |
3 |
query.setWiki(wikiReference.getName()); |
97 |
3 |
query.setOffset(offset); |
98 |
3 |
query.setLimit(limit); |
99 |
|
|
100 |
3 |
query.addFilter(this.topLevelPageFilter); |
101 |
|
|
102 |
3 |
if (!areHiddenEntitiesShown()) { |
103 |
3 |
query.addFilter(this.hiddenPageFilter); |
104 |
|
} |
105 |
|
|
106 |
3 |
return query.addFilter(this.documentReferenceResolverFilter).execute(); |
107 |
|
} |
108 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 4 |
Complexity Density: 0.67 |
|
109 |
0 |
@Override... |
110 |
|
public int getChildCount(String nodeId) |
111 |
|
{ |
112 |
0 |
EntityReference wikiReference = resolve(nodeId); |
113 |
0 |
if (wikiReference != null && wikiReference.getType() == EntityType.WIKI) { |
114 |
0 |
try { |
115 |
0 |
return getChildCount(new WikiReference(wikiReference)); |
116 |
|
} catch (QueryException e) { |
117 |
0 |
this.logger.warn("Failed to count the children of [{}]. Root cause [{}].", nodeId, |
118 |
|
ExceptionUtils.getRootCauseMessage(e)); |
119 |
|
} |
120 |
|
} |
121 |
0 |
return 0; |
122 |
|
} |
123 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
0 |
protected int getChildCount(WikiReference wikiReference) throws QueryException... |
125 |
|
{ |
126 |
0 |
return getChildSpacesCount(wikiReference); |
127 |
|
} |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
129 |
0 |
@Override... |
130 |
|
public String getParent(String nodeId) |
131 |
|
{ |
132 |
0 |
return "farm:*"; |
133 |
|
} |
134 |
|
} |