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.decorator; |
35 |
|
|
36 |
|
import info.magnolia.jcr.util.NodeUtil; |
37 |
|
import info.magnolia.jcr.wrapper.DelegateNodeWrapper; |
38 |
|
|
39 |
|
import java.util.ArrayList; |
40 |
|
import java.util.Collection; |
41 |
|
import java.util.Collections; |
42 |
|
import java.util.Iterator; |
43 |
|
import java.util.List; |
44 |
|
import java.util.stream.Collectors; |
45 |
|
|
46 |
|
import javax.jcr.Item; |
47 |
|
import javax.jcr.Node; |
48 |
|
import javax.jcr.NodeIterator; |
49 |
|
import javax.jcr.Property; |
50 |
|
import javax.jcr.PropertyIterator; |
51 |
|
import javax.jcr.RepositoryException; |
52 |
|
|
53 |
|
import org.apache.jackrabbit.commons.ItemNameMatcher; |
54 |
|
import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter; |
55 |
|
import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter; |
56 |
|
import org.apache.jackrabbit.spi.commons.iterator.Iterators; |
57 |
|
import org.slf4j.Logger; |
58 |
|
import org.slf4j.LoggerFactory; |
59 |
|
|
60 |
|
import com.google.common.collect.Lists; |
61 |
|
|
62 |
|
|
63 |
|
@link |
64 |
|
|
|
|
| 0% |
Uncovered Elements: 44 (44) |
Complexity: 14 |
Complexity Density: 0.45 |
|
65 |
|
public class AdditionNodeWrapper extends DelegateNodeWrapper { |
66 |
|
private static final Logger log = LoggerFactory.getLogger(AdditionNodeWrapper.class); |
67 |
|
|
68 |
|
private final String placeholderName; |
69 |
|
private final List<Item> additionItems; |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
71 |
0 |
public AdditionNodeWrapper(Node node, String placeholderName, List<Item> additionItems) {... |
72 |
0 |
super(node); |
73 |
0 |
this.placeholderName = placeholderName; |
74 |
0 |
this.additionItems = additionItems; |
75 |
|
} |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0 |
public AdditionNodeWrapper(Node node, String placeholderName) {... |
78 |
0 |
this(node, placeholderName, Collections.emptyList()); |
79 |
|
} |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
0 |
public AdditionNodeWrapper(Node node, List<Item> additionItems) {... |
82 |
0 |
this(node, null, additionItems); |
83 |
|
} |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
0 |
protected List<Item> getAdditionItems() {... |
86 |
0 |
return additionItems; |
87 |
|
} |
88 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
89 |
0 |
@Override... |
90 |
|
public String getName() throws RepositoryException { |
91 |
0 |
return placeholderName == null ? super.getName() : placeholderName; |
92 |
|
} |
93 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
94 |
|
@Override... |
95 |
|
public PropertyIterator getProperties() throws RepositoryException { |
96 |
|
return getProperties("*"); |
97 |
|
} |
98 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
99 |
0 |
@Override... |
100 |
|
public PropertyIterator getProperties(String namePattern) throws RepositoryException { |
101 |
0 |
return getProperties(new String[] { namePattern }); |
102 |
|
} |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
104 |
0 |
@Override... |
105 |
|
public PropertyIterator getProperties(String[] nameGlobs) throws RepositoryException { |
106 |
0 |
Iterator<Property> properties = Iterators.properties(super.getProperties(nameGlobs)); |
107 |
|
|
108 |
0 |
List<Property> merged = Lists.newArrayList(properties); |
109 |
0 |
List<Property> resolvedProperties = getAdditionItems().stream() |
110 |
|
.filter(item -> { |
111 |
0 |
try { |
112 |
0 |
return !item.isNode() && ItemNameMatcher.matches(item.getName(), nameGlobs); |
113 |
|
} catch (RepositoryException e) { |
114 |
0 |
log.warn("Cannot get name of item {}:", item, e); |
115 |
|
} |
116 |
|
|
117 |
0 |
return false; |
118 |
|
}) |
119 |
|
.map(item -> (Property) item) |
120 |
|
.collect(Collectors.toList()); |
121 |
0 |
merged.addAll(resolvedProperties); |
122 |
|
|
123 |
0 |
return new PropertyIteratorAdapter(merged); |
124 |
|
} |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
126 |
0 |
@Override... |
127 |
|
public boolean hasNodes() throws RepositoryException { |
128 |
0 |
boolean hasNodes = getAdditionItems().stream().anyMatch(Item::isNode); |
129 |
0 |
return hasNodes || super.hasNodes(); |
130 |
|
} |
131 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
132 |
0 |
@Override... |
133 |
|
public boolean hasProperties() throws RepositoryException { |
134 |
0 |
boolean hasProperties = getAdditionItems().stream().anyMatch(item -> !item.isNode()); |
135 |
0 |
return hasProperties || super.hasProperties(); |
136 |
|
} |
137 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
138 |
|
@Override... |
139 |
|
public NodeIterator getNodes() throws RepositoryException { |
140 |
|
return getNodes("*"); |
141 |
|
} |
142 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
143 |
0 |
@Override... |
144 |
|
public NodeIterator getNodes(String namePattern) throws RepositoryException { |
145 |
0 |
return getNodes(new String[] { namePattern }); |
146 |
|
} |
147 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
148 |
0 |
@Override... |
149 |
|
public NodeIterator getNodes(String[] nameGlobs) throws RepositoryException { |
150 |
0 |
Collection<Node> children = NodeUtil.getCollectionFromNodeIterator(getWrappedNode().getNodes(nameGlobs)); |
151 |
|
|
152 |
0 |
List<Node> merged = new ArrayList<>(children); |
153 |
0 |
List<Node> resolvedNodes = getAdditionItems().stream() |
154 |
|
.filter(item -> { |
155 |
0 |
try { |
156 |
0 |
return item.isNode() && ItemNameMatcher.matches(item.getName(), nameGlobs); |
157 |
|
} catch (RepositoryException e) { |
158 |
0 |
log.warn("Cannot get name of item {}:", item, e); |
159 |
|
} |
160 |
|
|
161 |
0 |
return false; |
162 |
|
}) |
163 |
|
.map(item -> (Node) item) |
164 |
|
.collect(Collectors.toList()); |
165 |
0 |
merged.addAll(resolvedNodes); |
166 |
|
|
167 |
0 |
return new NodeIteratorAdapter(merged); |
168 |
|
} |
169 |
|
} |