Author: chetanm
Date: Mon Sep  4 11:52:22 2017
New Revision: 1807212

URL: http://svn.apache.org/viewvc?rev=1807212&view=rev
Log:
OAK-6613 - Provide list of all bundled nodes within a given DocumentNodeState

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java?rev=1807212&r1=1807211&r2=1807212&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
 Mon Sep  4 11:52:22 2017
@@ -32,6 +32,7 @@ import javax.annotation.Nullable;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
+import com.google.common.collect.TreeTraverser;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.cache.CacheValue;
 import org.apache.jackrabbit.oak.commons.json.JsopBuilder;
@@ -458,6 +459,16 @@ public class DocumentNodeState extends A
         return (int) size;
     }
 
+    public Iterable<DocumentNodeState> getAllBundledNodesStates() {
+        return new TreeTraverser<DocumentNodeState>(){
+            @Override
+            public Iterable<DocumentNodeState> children(DocumentNodeState 
root) {
+                return Iterables.transform(() -> root.getBundledChildren(), ce 
-> (DocumentNodeState)ce.getNodeState());
+            }
+        }.preOrderTraversal(this)
+         .filter(dns -> !dns.getPath().equals(this.getPath()) ); //Exclude this
+    }
+
     //------------------------------< internal 
>--------------------------------
 
     @CheckForNull

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java?rev=1807212&r1=1807211&r2=1807212&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
 Mon Sep  4 11:52:22 2017
@@ -80,6 +80,7 @@ import static org.apache.jackrabbit.oak.
 import static 
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 import static org.apache.jackrabbit.oak.spi.state.NodeStateUtils.getNode;
 import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.Matchers.containsInAnyOrder;
 import static org.hamcrest.Matchers.greaterThan;
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertEquals;
@@ -260,13 +261,25 @@ public class DocumentBundlingTest {
         builder.child("test").setChildNode("book.jpg", appNB.getNodeState());
 
         merge(builder);
-        NodeState appNode = getNode(store.getRoot(), "test/book.jpg");
+        DocumentNodeState appNode = 
(DocumentNodeState)getNode(store.getRoot(), "test/book.jpg");
 
         assertEquals("jcr:content", 
getBundlingPath(appNode.getChildNode("jcr:content")));
         assertEquals("jcr:content/metadata",
                 
getBundlingPath(appNode.getChildNode("jcr:content").getChildNode("metadata")));
         assertEquals("jcr:content/renditions/original",
                 
getBundlingPath(appNode.getChildNode("jcr:content").getChildNode("renditions").getChildNode("original")));
+
+        List<String> bundledPaths = new ArrayList<>();
+        for (DocumentNodeState bs : appNode.getAllBundledNodesStates()) {
+            bundledPaths.add(bs.getPath());
+        }
+        assertThat(bundledPaths, containsInAnyOrder(
+                "/test/book.jpg/jcr:content",
+                "/test/book.jpg/jcr:content/metadata",
+                "/test/book.jpg/jcr:content/renditions",
+                "/test/book.jpg/jcr:content/renditions/original",
+                "/test/book.jpg/jcr:content/renditions/original/jcr:content")
+        );
     }
     
     @Test


Reply via email to