1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.rest.delivery.jcr.filter; |
35 |
|
|
36 |
|
import info.magnolia.jcr.decoration.ContentDecoratorNodeIterator; |
37 |
|
import info.magnolia.jcr.decoration.ContentDecoratorNodeWrapper; |
38 |
|
import info.magnolia.jcr.predicate.JCRMgnlPropertyHidingPredicate; |
39 |
|
import info.magnolia.jcr.wrapper.ChildFilteringContentDecorator; |
40 |
|
import info.magnolia.jcr.wrapper.PropertyFilteringContentDecorator; |
41 |
|
import info.magnolia.rest.delivery.jcr.decorator.ReferenceExpandDecorator; |
42 |
|
import info.magnolia.rest.delivery.jcr.decorator.ReferenceExpandWrapper; |
43 |
|
import info.magnolia.rest.reference.ReferenceDefinition; |
44 |
|
|
45 |
|
import java.util.ArrayList; |
46 |
|
import java.util.List; |
47 |
|
|
48 |
|
import javax.jcr.Node; |
49 |
|
import javax.jcr.NodeIterator; |
50 |
|
import javax.jcr.RepositoryException; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
|
|
| 84.6% |
Uncovered Elements: 10 (65) |
Complexity: 18 |
Complexity Density: 0.47 |
|
55 |
|
public class FilteringContentDecoratorBuilder { |
56 |
|
private List<String> childNodeTypes = new ArrayList<>(); |
57 |
|
private boolean includeSystemProperties; |
58 |
|
private int depth; |
59 |
|
private List<ReferenceDefinition> references = new ArrayList<>(); |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
61 |
6 |
public FilteringContentDecoratorBuilder childNodeTypes(List<String> childrenNodeTypes) {... |
62 |
6 |
this.childNodeTypes.clear(); |
63 |
6 |
if (childrenNodeTypes != null) { |
64 |
4 |
this.childNodeTypes.addAll(childrenNodeTypes); |
65 |
|
} |
66 |
6 |
return this; |
67 |
|
} |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
69 |
7 |
public FilteringContentDecoratorBuilder includeSystemProperties(boolean includeSystemProperties) {... |
70 |
7 |
this.includeSystemProperties = includeSystemProperties; |
71 |
7 |
return this; |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
74 |
7 |
public FilteringContentDecoratorBuilder depth(int depth) {... |
75 |
7 |
this.depth = depth; |
76 |
7 |
return this; |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
|
@deprecated@link |
81 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
82 |
2 |
@Deprecated... |
83 |
|
public FilteringContentDecoratorBuilder references(List<ReferenceDefinition> references) { |
84 |
2 |
this.references.clear(); |
85 |
2 |
if (references != null) { |
86 |
2 |
this.references.addAll(references); |
87 |
|
} |
88 |
2 |
return this; |
89 |
|
} |
90 |
|
|
|
|
| 80% |
Uncovered Elements: 4 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
91 |
4 |
public Node wrapNode(Node node) {... |
92 |
4 |
if (!childNodeTypes.isEmpty()) { |
93 |
2 |
node = new ContentDecoratorNodeWrapper<>(node, new ChildFilteringContentDecorator(new NodeTypesPredicate(childNodeTypes), true)); |
94 |
|
} |
95 |
|
|
96 |
4 |
if (!includeSystemProperties) { |
97 |
2 |
node = new ContentDecoratorNodeWrapper<>(node, new PropertyFilteringContentDecorator(new JCRMgnlPropertyHidingPredicate())); |
98 |
|
} |
99 |
|
|
100 |
4 |
if (depth >= 0) { |
101 |
2 |
ChildFilteringContentDecorator depthDecorator = new ChildFilteringContentDecorator(new DepthFilteringPredicate(getDepth(node), getDepth(node) + depth), true); |
102 |
2 |
node = new ContentDecoratorNodeWrapper<>(node, depthDecorator); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
4 |
if (!references.isEmpty()) { |
107 |
0 |
FilteringContentDecoratorBuilder expandDecorators = new FilteringContentDecoratorBuilder(); |
108 |
0 |
expandDecorators |
109 |
|
.includeSystemProperties(includeSystemProperties) |
110 |
|
.depth(-1); |
111 |
|
|
112 |
0 |
node = new ReferenceExpandWrapper(node, references, expandDecorators); |
113 |
|
} |
114 |
|
|
115 |
4 |
return node; |
116 |
|
} |
117 |
|
|
|
|
| 78.9% |
Uncovered Elements: 4 (19) |
Complexity: 5 |
Complexity Density: 0.45 |
|
118 |
3 |
public NodeIterator wrapNodeIterator(NodeIterator nodeIterator) {... |
119 |
|
|
120 |
3 |
if (!childNodeTypes.isEmpty()) { |
121 |
2 |
nodeIterator = new ChildNodeTypesFilteringNodeIterator(nodeIterator, childNodeTypes); |
122 |
|
} |
123 |
|
|
124 |
3 |
if (!includeSystemProperties) { |
125 |
1 |
nodeIterator = new ContentDecoratorNodeIterator(nodeIterator, new PropertyFilteringContentDecorator(new JCRMgnlPropertyHidingPredicate())); |
126 |
|
} |
127 |
|
|
128 |
3 |
if (depth >= 0) { |
129 |
2 |
nodeIterator = new DepthFilteringDecoratorNodeIterator(nodeIterator, depth); |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
3 |
if (!references.isEmpty()) { |
134 |
0 |
FilteringContentDecoratorBuilder expandDecorators = new FilteringContentDecoratorBuilder(); |
135 |
0 |
expandDecorators |
136 |
|
.includeSystemProperties(includeSystemProperties) |
137 |
|
.depth(-1); |
138 |
|
|
139 |
0 |
nodeIterator = new ContentDecoratorNodeIterator(nodeIterator, new ReferenceExpandDecorator(references, expandDecorators)); |
140 |
|
} |
141 |
|
|
142 |
3 |
return nodeIterator; |
143 |
|
} |
144 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
145 |
4 |
private int getDepth(Node node) {... |
146 |
4 |
try { |
147 |
4 |
return node.getDepth(); |
148 |
|
} catch (RepositoryException e) { |
149 |
0 |
return 0; |
150 |
|
} |
151 |
|
} |
152 |
|
} |