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.nestedspaces.parentchild; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import javax.inject.Inject; |
28 |
|
import javax.inject.Named; |
29 |
|
|
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
32 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
33 |
|
import org.xwiki.model.reference.DocumentReference; |
34 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
35 |
|
import org.xwiki.model.reference.EntityReference; |
36 |
|
import org.xwiki.model.reference.SpaceReference; |
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("space/parentChildOnNestedSpaces") |
50 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 3 |
Complexity Density: 0.19 |
|
51 |
|
public class SpaceTreeNode extends org.xwiki.index.tree.internal.nestedspaces.SpaceTreeNode |
52 |
|
{ |
53 |
|
private static final String PARAMETER_ABSOLUTE_REFERENCE = "absoluteRef"; |
54 |
|
|
55 |
|
private static final String PARAMETER_LOCAL_REFERENCE = "localRef"; |
56 |
|
|
57 |
|
@Inject |
58 |
|
@Named("explicit") |
59 |
|
private DocumentReferenceResolver<String> explicitDocumentReferenceResolver; |
60 |
|
|
61 |
|
@Inject |
62 |
|
@Named("topLevelPage/parentChildOnNestedSpaces") |
63 |
|
private QueryFilter topLevelPageFilter; |
64 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
65 |
0 |
@Override... |
66 |
|
protected List<? extends EntityReference> getChildren(SpaceReference spaceReference, int offset, int limit) |
67 |
|
throws QueryException |
68 |
|
{ |
69 |
0 |
Query query = getChildrenQuery(spaceReference, offset, limit); |
70 |
|
|
71 |
0 |
if (areTerminalDocumentsShown()) { |
72 |
|
|
73 |
|
|
74 |
0 |
query.addFilter(this.topLevelPageFilter); |
75 |
0 |
DocumentReference absoluteReference = |
76 |
|
this.explicitDocumentReferenceResolver.resolve(String.valueOf('%'), spaceReference); |
77 |
0 |
query.bindValue(PARAMETER_ABSOLUTE_REFERENCE, |
78 |
|
this.defaultEntityReferenceSerializer.serialize(absoluteReference)); |
79 |
0 |
query.bindValue(PARAMETER_LOCAL_REFERENCE, |
80 |
|
this.localEntityReferenceSerializer.serialize(absoluteReference)); |
81 |
|
} |
82 |
|
|
83 |
0 |
return query.execute(); |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
86 |
0 |
@Override... |
87 |
|
protected int getChildDocumentsCount(SpaceReference spaceReference) throws QueryException |
88 |
|
{ |
89 |
0 |
List<String> constraints = new ArrayList<String>(); |
90 |
0 |
Map<String, Object> parameters = new HashMap<String, Object>(); |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
0 |
String hasNoParent = "doc.parent = '' or doc.parent is null"; |
95 |
0 |
String hasParentOutsideSpace = |
96 |
|
"doc.parent like '%.%' and doc.parent not like :absoluteRef and doc.parent not like :localRef"; |
97 |
0 |
constraints.add(String.format("((%s) or (%s))", hasNoParent, hasParentOutsideSpace)); |
98 |
|
|
99 |
0 |
DocumentReference absoluteReference = |
100 |
|
this.explicitDocumentReferenceResolver.resolve(String.valueOf('%'), spaceReference); |
101 |
0 |
parameters.put(PARAMETER_ABSOLUTE_REFERENCE, |
102 |
|
this.defaultEntityReferenceSerializer.serialize(absoluteReference)); |
103 |
0 |
parameters.put(PARAMETER_LOCAL_REFERENCE, this.localEntityReferenceSerializer.serialize(absoluteReference)); |
104 |
|
|
105 |
0 |
return getChildDocumentsCount(spaceReference, constraints, parameters); |
106 |
|
} |
107 |
|
} |