Clover icon

Magnolia REST Content Delivery 2.0-rc1

  1. Project Clover database Mon Oct 30 2017 16:36:57 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
375
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    return null;
95    }
96   
 
97  0 toggle @Override
98    public String getPath() throws RepositoryException {
99  0 StringBuffer buffer = new StringBuffer(getParent().getPath());
100  0 if (buffer.length() > 1) {
101  0 buffer.append('/');
102    }
103  0 buffer.append("@" + this.name);
104   
105  0 return buffer.toString();
106    }
107   
 
108    toggle @Override
109    public String getName() throws RepositoryException {
110    return this.name;
111    }
112   
 
113    toggle @Override
114    public int getIndex() throws RepositoryException {
115    return 0;
116    }
117   
 
118    toggle @Override
119    public boolean isNew() {
120    return false;
121    }
122   
 
123    toggle @Override
124    public boolean isModified() {
125    return false;
126    }
127   
 
128  0 toggle @Override
129    public boolean isSame(Item item) throws RepositoryException {
130  0 return false;
131    }
132   
 
133  0 toggle @Override
134    public void accept(ItemVisitor visitor) throws RepositoryException {
135  0 visitor.visit(this);
136    }
137   
 
138    toggle @Override
139    public Node getParent() throws RepositoryException {
140    return parent;
141    }
142   
 
143    toggle @Override
144    public Session getSession() throws RepositoryException {
145    return parent.getSession();
146    }
147   
 
148    toggle @Override
149    public NodeType getPrimaryNodeType() throws RepositoryException {
150    return parent.getPrimaryNodeType();
151    }
152   
 
153  0 toggle @Override
154    public Node getNode(String relPath) throws RepositoryException {
155  0 return children.stream()
156    .filter(node -> relPath.equals(NodeUtil.getPathIfPossible(node)))
157    .findFirst()
158    .orElseThrow(() -> new PathNotFoundException(String.format("%s not found!", relPath)));
159    }
160   
 
161    toggle @Override
162    public NodeIterator getNodes() throws RepositoryException {
163    return new NodeIteratorAdapter(this.children.iterator());
164    }
165   
 
166  0 toggle @Override
167    public NodeIterator getNodes(String namePattern) throws RepositoryException {
168  0 return ChildrenCollectorFilter.collectChildNodes(this, namePattern);
169    }
170   
 
171  0 toggle @Override
172    public NodeIterator getNodes(String[] nameGlobs) throws RepositoryException {
173  0 return ChildrenCollectorFilter.collectChildNodes(this, nameGlobs);
174    }
175   
 
176    toggle @Override
177    public PropertyIterator getProperties() throws RepositoryException {
178    return new PropertyIteratorAdapter(this.properties);
179    }
180   
 
181  0 toggle @Override
182    public PropertyIterator getProperties(String namePattern) throws RepositoryException {
183  0 return ChildrenCollectorFilter.collectProperties(this, namePattern);
184    }
185   
 
186  0 toggle @Override
187    public PropertyIterator getProperties(String[] nameGlobs) throws RepositoryException {
188  0 return ChildrenCollectorFilter.collectProperties(this, nameGlobs);
189    }
190   
 
191    toggle @Override
192    public void setPrimaryType(String primaryType) throws RepositoryException {
193    throw new UnsupportedOperationException("Not implemented.");
194    }
195   
 
196  0 toggle @Override
197    public Node addNode(String s) throws RepositoryException {
198  0 throw new UnsupportedOperationException("Not implemented.");
199    }
200   
 
201  0 toggle @Override
202    public Node addNode(String s, String s1) throws RepositoryException {
203  0 throw new UnsupportedOperationException("Not implemented.");
204    }
205   
 
206  0 toggle @Override
207    public void orderBefore(String s, String s1) throws RepositoryException {
208  0 throw new UnsupportedOperationException("Not implemented.");
209    }
210   
 
211  0 toggle @Override
212    public Property setProperty(String s, Value value) throws RepositoryException {
213  0 throw new UnsupportedOperationException("Not implemented.");
214    }
215   
 
216  0 toggle @Override
217    public Property setProperty(String s, Value[] values) throws RepositoryException {
218  0 throw new UnsupportedOperationException("Not implemented.");
219    }
220   
 
221  0 toggle @Override
222    public Property setProperty(String s, Binary binary) throws RepositoryException {
223  0 throw new UnsupportedOperationException("Not implemented.");
224    }
225   
 
226  0 toggle @Override
227    public Property setProperty(String s, BigDecimal bigDecimal) throws RepositoryException {
228  0 throw new UnsupportedOperationException("Not implemented.");
229    }
230   
 
231    toggle @Override
232    public PropertyIterator getReferences() throws RepositoryException {
233    throw new UnsupportedOperationException("Not implemented.");
234    }
235   
 
236  0 toggle @Override
237    public PropertyIterator getReferences(String s) throws RepositoryException {
238  0 throw new UnsupportedOperationException("Not implemented.");
239    }
240   
 
241    toggle @Override
242    public PropertyIterator getWeakReferences() throws RepositoryException {
243    throw new UnsupportedOperationException("Not implemented.");
244    }
245   
 
246  0 toggle @Override
247    public PropertyIterator getWeakReferences(String s) throws RepositoryException {
248  0 throw new UnsupportedOperationException("Not implemented.");
249    }
250   
 
251    toggle @Override
252    public Item getPrimaryItem() throws RepositoryException {
253    throw new UnsupportedOperationException("Not implemented.");
254    }
255   
 
256  0 toggle @Override
257    public void addMixin(String s) throws RepositoryException {
258  0 throw new UnsupportedOperationException("Not implemented.");
259    }
260   
 
261  0 toggle @Override
262    public void removeMixin(String s) throws RepositoryException {
263  0 throw new UnsupportedOperationException("Not implemented.");
264    }
265   
 
266  0 toggle @Override
267    public boolean canAddMixin(String s) throws RepositoryException {
268  0 return false;
269    }
270   
 
271    toggle @Override
272    public NodeDefinition getDefinition() throws RepositoryException {
273    throw new UnsupportedOperationException("Not implemented.");
274    }
275   
 
276  0 toggle @Override
277    public Version checkin() throws RepositoryException {
278  0 throw new UnsupportedOperationException("Not implemented.");
279    }
280   
 
281  0 toggle @Override
282    public void checkout() throws RepositoryException {
283  0 throw new UnsupportedOperationException("Not implemented.");
284    }
285   
 
286  0 toggle @Override
287    public void doneMerge(Version version) throws RepositoryException {
288  0 throw new UnsupportedOperationException("Not implemented.");
289    }
290   
 
291  0 toggle @Override
292    public void cancelMerge(Version version) throws RepositoryException {
293  0 throw new UnsupportedOperationException("Not implemented.");
294    }
295   
 
296  0 toggle @Override
297    public void update(String s) throws RepositoryException {
298  0 throw new UnsupportedOperationException("Not implemented.");
299    }
300   
 
301  0 toggle @Override
302    public NodeIterator merge(String s, boolean b) throws RepositoryException {
303  0 throw new UnsupportedOperationException("Not implemented.");
304    }
305   
 
306  0 toggle @Override
307    public String getCorrespondingNodePath(String s) throws RepositoryException {
308  0 throw new UnsupportedOperationException("Not implemented.");
309    }
310   
 
311    toggle @Override
312    public NodeIterator getSharedSet() throws RepositoryException {
313    throw new UnsupportedOperationException("Not implemented.");
314    }
315   
 
316  0 toggle @Override
317    public void removeSharedSet() throws RepositoryException {
318  0 throw new UnsupportedOperationException("Not implemented.");
319    }
320   
 
321  0 toggle @Override
322    public void removeShare() throws RepositoryException {
323  0 throw new UnsupportedOperationException("Not implemented.");
324    }
325   
 
326  0 toggle @Override
327    public void restore(Version version, String s, boolean b) throws RepositoryException {
328  0 throw new UnsupportedOperationException("Not implemented.");
329    }
330   
 
331    toggle @Override
332    public Version getBaseVersion() throws RepositoryException {
333    throw new UnsupportedOperationException("Not implemented.");
334    }
335   
 
336  0 toggle @Override
337    public Lock lock(boolean b, boolean b1) throws RepositoryException {
338  0 throw new UnsupportedOperationException("Not implemented.");
339    }
340   
 
341    toggle @Override
342    public Lock getLock() throws RepositoryException {
343    throw new UnsupportedOperationException("Not implemented.");
344    }
345   
 
346  0 toggle @Override
347    public void unlock() throws RepositoryException {
348  0 throw new UnsupportedOperationException("Not implemented.");
349    }
350   
 
351  0 toggle @Override
352    public void followLifecycleTransition(String s) throws RepositoryException {
353  0 throw new UnsupportedOperationException("Not implemented.");
354    }
355   
 
356    toggle @Override
357    public String[] getAllowedLifecycleTransistions() throws RepositoryException {
358    return new String[0];
359    }
360   
 
361  0 toggle @Override
362    public void save() throws RepositoryException {
363  0 throw new UnsupportedOperationException("Not implemented.");
364    }
365   
 
366  0 toggle @Override
367    public void refresh(boolean b) throws RepositoryException {
368  0 throw new UnsupportedOperationException("Not implemented.");
369    }
370   
 
371  0 toggle @Override
372    public void remove() throws RepositoryException {
373  0 throw new UnsupportedOperationException("Not implemented.");
374    }
375    }