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