Clover icon

Magnolia REST Content Delivery 2.0.1

  1. Project Clover database Thu Dec 21 2017 11:02:58 CET
  2. Package info.magnolia.rest.delivery.jcr.decorator

File ReadOnlyNode.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
73% of files have more coverage

Code metrics

2
48
38
1
376
276
39
0.81
1.26
38
1.03
30.2% of code in this file is excluded from these metrics.

Classes

Class Line # Actions
ReadOnlyNode 66 48 30.2% 39 88
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /**
2    * This file Copyright (c) 2017 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.rest.delivery.jcr.decorator;
35   
36    import info.magnolia.jcr.util.NodeUtil;
37   
38    import java.math.BigDecimal;
39    import java.util.List;
40    import java.util.stream.Collectors;
41   
42    import javax.jcr.Binary;
43    import javax.jcr.Item;
44    import javax.jcr.ItemVisitor;
45    import javax.jcr.Node;
46    import javax.jcr.NodeIterator;
47    import javax.jcr.PathNotFoundException;
48    import javax.jcr.Property;
49    import javax.jcr.PropertyIterator;
50    import javax.jcr.RepositoryException;
51    import javax.jcr.Session;
52    import javax.jcr.Value;
53    import javax.jcr.lock.Lock;
54    import javax.jcr.nodetype.NodeDefinition;
55    import javax.jcr.nodetype.NodeType;
56    import javax.jcr.version.Version;
57   
58    import org.apache.jackrabbit.commons.AbstractNode;
59    import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
60    import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;
61    import org.apache.jackrabbit.util.ChildrenCollectorFilter;
62   
63    /**
64    * Read only {@link Node} implementation.
65    */
 
66    public class ReadOnlyNode extends AbstractNode {
67    private final String name;
68    private final Node parent;
69    private final List<Property> properties;
70    private final List<Node> children;
71   
 
72  0 toggle public ReadOnlyNode(String name, Node parent, List<Node> children, List<Property> properties) {
73  0 this.name = name;
74  0 this.parent = parent;
75  0 this.children = children;
76  0 this.properties = properties;
77    }
78   
 
79  0 toggle public ReadOnlyNode(String name, Node parent, List<Item> items) {
80  0 this.name = name;
81  0 this.parent = parent;
82  0 this.children = items.stream()
83    .filter(item -> item.isNode())
84    .map(item -> (Node) item)
85    .collect(Collectors.toList());
86  0 this.properties = items.stream()
87    .filter(item -> !item.isNode())
88    .map(item -> (Property) item)
89    .collect(Collectors.toList());
90    }
91   
 
92    toggle @Override
93    public String getIdentifier() throws RepositoryException {
94    //TODO will be fixed with ref improvement feature.
95    return "";
96    }
97   
 
98  0 toggle @Override
99    public String getPath() throws RepositoryException {
100  0 StringBuffer buffer = new StringBuffer(getParent().getPath());
101  0 if (buffer.length() > 1) {
102  0 buffer.append('/');
103    }
104  0 buffer.append("@" + this.name);
105   
106  0 return buffer.toString();
107    }
108   
 
109    toggle @Override
110    public String getName() throws RepositoryException {
111    return this.name;
112    }
113   
 
114    toggle @Override
115    public int getIndex() throws RepositoryException {
116    return 0;
117    }
118   
 
119    toggle @Override
120    public boolean isNew() {
121    return false;
122    }
123   
 
124    toggle @Override
125    public boolean isModified() {
126    return false;
127    }
128   
 
129  0 toggle @Override
130    public boolean isSame(Item item) throws RepositoryException {
131  0 return false;
132    }
133   
 
134  0 toggle @Override
135    public void accept(ItemVisitor visitor) throws RepositoryException {
136  0 visitor.visit(this);
137    }
138   
 
139    toggle @Override
140    public Node getParent() throws RepositoryException {
141    return parent;
142    }
143   
 
144    toggle @Override
145    public Session getSession() throws RepositoryException {
146    return parent.getSession();
147    }
148   
 
149    toggle @Override
150    public NodeType getPrimaryNodeType() throws RepositoryException {
151    return parent.getPrimaryNodeType();
152    }
153   
 
154  0 toggle @Override
155    public Node getNode(String relPath) throws RepositoryException {
156  0 return children.stream()
157    .filter(node -> relPath.equals(NodeUtil.getPathIfPossible(node)))
158    .findFirst()
159    .orElseThrow(() -> new PathNotFoundException(String.format("%s not found!", relPath)));
160    }
161   
 
162    toggle @Override
163    public NodeIterator getNodes() throws RepositoryException {
164    return new NodeIteratorAdapter(this.children.iterator());
165    }
166   
 
167  0 toggle @Override
168    public NodeIterator getNodes(String namePattern) throws RepositoryException {
169  0 return ChildrenCollectorFilter.collectChildNodes(this, namePattern);
170    }
171   
 
172  0 toggle @Override
173    public NodeIterator getNodes(String[] nameGlobs) throws RepositoryException {
174  0 return ChildrenCollectorFilter.collectChildNodes(this, nameGlobs);
175    }
176   
 
177    toggle @Override
178    public PropertyIterator getProperties() throws RepositoryException {
179    return new PropertyIteratorAdapter(this.properties);
180    }
181   
 
182  0 toggle @Override
183    public PropertyIterator getProperties(String namePattern) throws RepositoryException {
184  0 return ChildrenCollectorFilter.collectProperties(this, namePattern);
185    }
186   
 
187  0 toggle @Override
188    public PropertyIterator getProperties(String[] nameGlobs) throws RepositoryException {
189  0 return ChildrenCollectorFilter.collectProperties(this, nameGlobs);
190    }
191   
 
192    toggle @Override
193    public void setPrimaryType(String primaryType) throws RepositoryException {
194    throw new UnsupportedOperationException("Not implemented.");
195    }
196   
 
197  0 toggle @Override
198    public Node addNode(String s) throws RepositoryException {
199  0 throw new UnsupportedOperationException("Not implemented.");
200    }
201   
 
202  0 toggle @Override
203    public Node addNode(String s, String s1) throws RepositoryException {
204  0 throw new UnsupportedOperationException("Not implemented.");
205    }
206   
 
207  0 toggle @Override
208    public void orderBefore(String s, String s1) throws RepositoryException {
209  0 throw new UnsupportedOperationException("Not implemented.");
210    }
211   
 
212  0 toggle @Override
213    public Property setProperty(String s, Value value) throws RepositoryException {
214  0 throw new UnsupportedOperationException("Not implemented.");
215    }
216   
 
217  0 toggle @Override
218    public Property setProperty(String s, Value[] values) throws RepositoryException {
219  0 throw new UnsupportedOperationException("Not implemented.");
220    }
221   
 
222  0 toggle @Override
223    public Property setProperty(String s, Binary binary) throws RepositoryException {
224  0 throw new UnsupportedOperationException("Not implemented.");
225    }
226   
 
227  0 toggle @Override
228    public Property setProperty(String s, BigDecimal bigDecimal) throws RepositoryException {
229  0 throw new UnsupportedOperationException("Not implemented.");
230    }
231   
 
232    toggle @Override
233    public PropertyIterator getReferences() throws RepositoryException {
234    throw new UnsupportedOperationException("Not implemented.");
235    }
236   
 
237  0 toggle @Override
238    public PropertyIterator getReferences(String s) throws RepositoryException {
239  0 throw new UnsupportedOperationException("Not implemented.");
240    }
241   
 
242    toggle @Override
243    public PropertyIterator getWeakReferences() throws RepositoryException {
244    throw new UnsupportedOperationException("Not implemented.");
245    }
246   
 
247  0 toggle @Override
248    public PropertyIterator getWeakReferences(String s) throws RepositoryException {
249  0 throw new UnsupportedOperationException("Not implemented.");
250    }
251   
 
252    toggle @Override
253    public Item getPrimaryItem() throws RepositoryException {
254    throw new UnsupportedOperationException("Not implemented.");
255    }
256   
 
257  0 toggle @Override
258    public void addMixin(String s) throws RepositoryException {
259  0 throw new UnsupportedOperationException("Not implemented.");
260    }
261   
 
262  0 toggle @Override
263    public void removeMixin(String s) throws RepositoryException {
264  0 throw new UnsupportedOperationException("Not implemented.");
265    }
266   
 
267  0 toggle @Override
268    public boolean canAddMixin(String s) throws RepositoryException {
269  0 return false;
270    }
271   
 
272    toggle @Override
273    public NodeDefinition getDefinition() throws RepositoryException {
274    throw new UnsupportedOperationException("Not implemented.");
275    }
276   
 
277  0 toggle @Override
278    public Version checkin() throws RepositoryException {
279  0 throw new UnsupportedOperationException("Not implemented.");
280    }
281   
 
282  0 toggle @Override
283    public void checkout() throws RepositoryException {
284  0 throw new UnsupportedOperationException("Not implemented.");
285    }
286   
 
287  0 toggle @Override
288    public void doneMerge(Version version) throws RepositoryException {
289  0 throw new UnsupportedOperationException("Not implemented.");
290    }
291   
 
292  0 toggle @Override
293    public void cancelMerge(Version version) throws RepositoryException {
294  0 throw new UnsupportedOperationException("Not implemented.");
295    }
296   
 
297  0 toggle @Override
298    public void update(String s) throws RepositoryException {
299  0 throw new UnsupportedOperationException("Not implemented.");
300    }
301   
 
302  0 toggle @Override
303    public NodeIterator merge(String s, boolean b) throws RepositoryException {
304  0 throw new UnsupportedOperationException("Not implemented.");
305    }
306   
 
307  0 toggle @Override
308    public String getCorrespondingNodePath(String s) throws RepositoryException {
309  0 throw new UnsupportedOperationException("Not implemented.");
310    }
311   
 
312    toggle @Override
313    public NodeIterator getSharedSet() throws RepositoryException {
314    throw new UnsupportedOperationException("Not implemented.");
315    }
316   
 
317  0 toggle @Override
318    public void removeSharedSet() throws RepositoryException {
319  0 throw new UnsupportedOperationException("Not implemented.");
320    }
321   
 
322  0 toggle @Override
323    public void removeShare() throws RepositoryException {
324  0 throw new UnsupportedOperationException("Not implemented.");
325    }
326   
 
327  0 toggle @Override
328    public void restore(Version version, String s, boolean b) throws RepositoryException {
329  0 throw new UnsupportedOperationException("Not implemented.");
330    }
331   
 
332    toggle @Override
333    public Version getBaseVersion() throws RepositoryException {
334    throw new UnsupportedOperationException("Not implemented.");
335    }
336   
 
337  0 toggle @Override
338    public Lock lock(boolean b, boolean b1) throws RepositoryException {
339  0 throw new UnsupportedOperationException("Not implemented.");
340    }
341   
 
342    toggle @Override
343    public Lock getLock() throws RepositoryException {
344    throw new UnsupportedOperationException("Not implemented.");
345    }
346   
 
347  0 toggle @Override
348    public void unlock() throws RepositoryException {
349  0 throw new UnsupportedOperationException("Not implemented.");
350    }
351   
 
352  0 toggle @Override
353    public void followLifecycleTransition(String s) throws RepositoryException {
354  0 throw new UnsupportedOperationException("Not implemented.");
355    }
356   
 
357    toggle @Override
358    public String[] getAllowedLifecycleTransistions() throws RepositoryException {
359    return new String[0];
360    }
361   
 
362  0 toggle @Override
363    public void save() throws RepositoryException {
364  0 throw new UnsupportedOperationException("Not implemented.");
365    }
366   
 
367  0 toggle @Override
368    public void refresh(boolean b) throws RepositoryException {
369  0 throw new UnsupportedOperationException("Not implemented.");
370    }
371   
 
372  0 toggle @Override
373    public void remove() throws RepositoryException {
374  0 throw new UnsupportedOperationException("Not implemented.");
375    }
376    }