Author: chetanm
Date: Fri Nov 11 12:12:39 2016
New Revision: 1769275

URL: http://svn.apache.org/viewvc?rev=1769275&view=rev
Log:
OAK-5079 - Diff would not work for bundled nodes when done without journal 
support

-- Changed ':doc-self' props to '':doc-self-path" and instead of storing true 
it now stores the bundled node path. This would be later used to determine 
bundling root if only NodeState of bundle nodes is given
-- Changed the constant name accordingly

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorUtils.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlor.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorUtilsTest.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=1769275&r1=1769274&r2=1769275&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
 Fri Nov 11 12:12:39 2016
@@ -803,7 +803,7 @@ public class DocumentNodeState extends A
         }
 
         public boolean hasChildNode(String relativePath){
-            String key = concat(relativePath, DocumentBundlor.META_PROP_NODE);
+            String key = concat(relativePath, 
DocumentBundlor.META_PROP_BUNDLING_PATH);
             return rootProperties.containsKey(key);
         }
 

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java?rev=1769275&r1=1769274&r2=1769275&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java
 Fri Nov 11 12:12:39 2016
@@ -24,20 +24,15 @@ import java.util.Set;
 import com.google.common.collect.Sets;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.commons.PathUtils;
-import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.jackrabbit.oak.commons.PathUtils.ROOT_PATH;
 import static 
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static 
org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
 
 public class BundlingHandler {
-    /**
-     * True property which is used to mark the presence of relative node
-     * This needs to be set when a bundled relative node is added
-     */
-    private static final PropertyState NODE_PRESENCE_MARKER =
-            PropertyStates.createProperty(DocumentBundlor.META_PROP_NODE, 
Boolean.TRUE);
+
     private final BundledTypesRegistry registry;
     private final String path;
     private final BundlingContext ctx;
@@ -101,7 +96,7 @@ public class BundlingHandler {
         Matcher childMatcher = ctx.matcher.next(name);
         if (childMatcher.isMatch()) {
             childContext = createChildContext(childMatcher);
-            childContext.addMetaProp(NODE_PRESENCE_MARKER);
+            
childContext.addMetaProp(createProperty(DocumentBundlor.META_PROP_BUNDLING_PATH,
 childMatcher.getMatchedPath()));
         } else {
             DocumentBundlor bundlor = registry.getBundlor(state);
             if (bundlor != null){
@@ -179,7 +174,7 @@ public class BundlingHandler {
     }
 
     private static void removeDeletedChildProperties(NodeState state, 
BundlingContext childContext) {
-        childContext.removeProperty(DocumentBundlor.META_PROP_NODE);
+        childContext.removeProperty(DocumentBundlor.META_PROP_BUNDLING_PATH);
         for (PropertyState ps : state.getProperties()){
             String propName = ps.getName();
             //In deletion never touch child status related meta props

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorUtils.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorUtils.java?rev=1769275&r1=1769274&r2=1769275&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorUtils.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorUtils.java
 Fri Nov 11 12:12:39 2016
@@ -33,7 +33,7 @@ import com.google.common.collect.Maps;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 
-import static 
org.apache.jackrabbit.oak.plugins.document.bundlor.DocumentBundlor.META_PROP_NODE;
+import static 
org.apache.jackrabbit.oak.plugins.document.bundlor.DocumentBundlor.META_PROP_BUNDLING_PATH;
 
 public final class BundlorUtils {
     public static final Predicate<PropertyState> NOT_BUNDLOR_PROPS = new 
Predicate<PropertyState>() {
@@ -96,7 +96,7 @@ public final class BundlorUtils {
 
             if (depth == expectedDepth
                     && key.startsWith(matcher.getMatchedPath())
-                    && elements.get(elements.size() - 
1).equals(META_PROP_NODE)){
+                    && elements.get(elements.size() - 
1).equals(META_PROP_BUNDLING_PATH)){
                 //Child node name is the second last element
                 //[jcr:content/:self -> [jcr:content, :self]
                 childNodeNames.add(elements.get(elements.size() - 2));

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlor.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlor.java?rev=1769275&r1=1769274&r2=1769275&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlor.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlor.java
 Fri Nov 11 12:12:39 2016
@@ -47,9 +47,11 @@ public class DocumentBundlor {
     /**
      * Hidden property name used as suffix for relative node path
      * to indicate presence of that node. So for a relative node 'jcr:content'
-     * the parent node must have a property 'jcr:content/:self
+     * the parent node must have a property 'jcr:content/:doc-self-path.
+     *
+     * <p>Its value is the depth of the bundled child node
      */
-    public static final String META_PROP_NODE = ":doc-self";
+    public static final String META_PROP_BUNDLING_PATH = ":doc-self-path";
 
     public static final String HAS_CHILD_PROP_PREFIX = ":doc-has-child-";
 

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorUtilsTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorUtilsTest.java?rev=1769275&r1=1769274&r2=1769275&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorUtilsTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorUtilsTest.java
 Fri Nov 11 12:12:39 2016
@@ -29,7 +29,7 @@ import org.junit.Test;
 
 import static java.util.Arrays.asList;
 import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
-import static 
org.apache.jackrabbit.oak.plugins.document.bundlor.DocumentBundlor.META_PROP_NODE;
+import static 
org.apache.jackrabbit.oak.plugins.document.bundlor.DocumentBundlor.META_PROP_BUNDLING_PATH;
 import static 
org.apache.jackrabbit.oak.plugins.document.bundlor.DocumentBundlor.META_PROP_PATTERN;
 import static org.hamcrest.CoreMatchers.hasItem;
 import static org.hamcrest.CoreMatchers.hasItems;
@@ -52,7 +52,7 @@ public class BundlorUtilsTest {
         Matcher m = new Include("jcr:content").createMatcher();
         Map<String, PropertyState> result = BundlorUtils.getMatchingProperties(
                 create("a",
-                        concat("jcr:content", META_PROP_NODE),
+                        concat("jcr:content", META_PROP_BUNDLING_PATH),
                         "jcr:content/jcr:data",
                         "jcr:primaryType",
                         META_PROP_PATTERN
@@ -66,7 +66,7 @@ public class BundlorUtilsTest {
         Matcher m = new 
Include("jcr:content").createMatcher().next("jcr:content");
         Map<String, PropertyState> result = BundlorUtils.getMatchingProperties(
                 create("a",
-                        concat("jcr:content", META_PROP_NODE),
+                        concat("jcr:content", META_PROP_BUNDLING_PATH),
                         "jcr:content/jcr:data",
                         "jcr:content/metadata/format",
                         "jcr:primaryType",
@@ -80,12 +80,12 @@ public class BundlorUtilsTest {
     @Test
     public void childNodeNames() throws Exception{
         List<String> testData = asList("x",
-                concat("jcr:content", META_PROP_NODE),
+                concat("jcr:content", META_PROP_BUNDLING_PATH),
                 "jcr:content/jcr:data",
-                concat("jcr:content/metadata", META_PROP_NODE),
+                concat("jcr:content/metadata", META_PROP_BUNDLING_PATH),
                 "jcr:content/metadata/format",
-                concat("jcr:content/comments", META_PROP_NODE),
-                concat("jcr:content/renditions/original", META_PROP_NODE)
+                concat("jcr:content/comments", META_PROP_BUNDLING_PATH),
+                concat("jcr:content/renditions/original", 
META_PROP_BUNDLING_PATH)
         );
 
         Matcher m = new Include("jcr:content/*").createMatcher();

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=1769275&r1=1769274&r2=1769275&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
 Fri Nov 11 12:12:39 2016
@@ -58,6 +58,7 @@ import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.collect.ImmutableList.copyOf;
 import static java.lang.String.format;
 import static org.apache.commons.io.FileUtils.ONE_MB;
@@ -134,13 +135,14 @@ public class DocumentBundlingTest {
         assertTrue(fileNodeState.getChildNode("book.jpg").exists());
         NodeState contentNode = 
fileNodeState.getChildNode("book.jpg").getChildNode("jcr:content");
         assertTrue(contentNode.exists());
+        assertEquals("jcr:content", getBundlingPath(contentNode));
 
         assertEquals(1, contentNode.getPropertyCount());
         assertEquals(1, Iterables.size(contentNode.getProperties()));
 
         assertNull(getNodeDocument("/test/book.jpg/jcr:content"));
         assertNotNull(getNodeDocument("/test/book.jpg"));
-        assertTrue(hasNodeProperty("/test/book.jpg", concat("jcr:content", 
DocumentBundlor.META_PROP_NODE)));
+        assertTrue(hasNodeProperty("/test/book.jpg", concat("jcr:content", 
DocumentBundlor.META_PROP_BUNDLING_PATH)));
 
         AssertingDiff.assertEquals(fileNode.getNodeState(), 
fileNodeState.getChildNode("book.jpg"));
 
@@ -149,7 +151,6 @@ public class DocumentBundlingTest {
         AssertingDiff.assertEquals(fileNode.getNodeState(), 
dns.fromExternalChange());
     }
 
-
     @Test
     public void bundledParent() throws Exception{
         NodeBuilder builder = store.getRoot().builder();
@@ -163,6 +164,31 @@ public class DocumentBundlingTest {
 
         merge(builder);
     }
+
+    @Test
+    public void bundlingPath() throws Exception{
+        NodeBuilder builder = store.getRoot().builder();
+        NodeBuilder appNB = newNode("app:Asset");
+        createChild(appNB,
+                "jcr:content",
+                "jcr:content/comments", //not bundled
+                "jcr:content/metadata",
+                "jcr:content/metadata/xmp", //not bundled
+                "jcr:content/renditions", //includes all
+                "jcr:content/renditions/original",
+                "jcr:content/renditions/original/jcr:content"
+        );
+        builder.child("test").setChildNode("book.jpg", appNB.getNodeState());
+
+        merge(builder);
+        NodeState appNode = 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")));
+    }
     
     @Test
     public void queryChildren() throws Exception{
@@ -591,7 +617,7 @@ public class DocumentBundlingTest {
         builder.child("test").setChildNode("book.jpg", 
fileNode.getNodeState());
         merge(builder);
 
-        assertTrue(hasNodeProperty("/test/book.jpg", concat("jcr:content", 
DocumentBundlor.META_PROP_NODE)));
+        assertTrue(hasNodeProperty("/test/book.jpg", concat("jcr:content", 
DocumentBundlor.META_PROP_BUNDLING_PATH)));
 
         //Delete the bundled node structure
         builder = store.getRoot().builder();
@@ -614,8 +640,8 @@ public class DocumentBundlingTest {
         merge(builder);
 
         //New pattern should be effective
-        assertTrue(hasNodeProperty("/test/book.jpg", concat("metadata", 
DocumentBundlor.META_PROP_NODE)));
-        assertFalse(hasNodeProperty("/test/book.jpg", concat("comments", 
DocumentBundlor.META_PROP_NODE)));
+        assertTrue(hasNodeProperty("/test/book.jpg", concat("metadata", 
DocumentBundlor.META_PROP_BUNDLING_PATH)));
+        assertFalse(hasNodeProperty("/test/book.jpg", concat("comments", 
DocumentBundlor.META_PROP_BUNDLING_PATH)));
     }
 
     @Test
@@ -626,7 +652,7 @@ public class DocumentBundlingTest {
         builder.child("test").setChildNode("book.jpg", 
fileNode.getNodeState());
         merge(builder);
 
-        assertTrue(hasNodeProperty("/test/book.jpg", concat("jcr:content", 
DocumentBundlor.META_PROP_NODE)));
+        assertTrue(hasNodeProperty("/test/book.jpg", concat("jcr:content", 
DocumentBundlor.META_PROP_BUNDLING_PATH)));
 
         //Delete the bundled node structure
         builder = store.getRoot().builder();
@@ -650,8 +676,8 @@ public class DocumentBundlingTest {
 
         //New pattern should be effective
         assertNotNull(getNodeDocument("/test/book.jpg"));
-        assertFalse(hasNodeProperty("/test/book.jpg", concat("metadata", 
DocumentBundlor.META_PROP_NODE)));
-        assertFalse(hasNodeProperty("/test/book.jpg", concat("comments", 
DocumentBundlor.META_PROP_NODE)));
+        assertFalse(hasNodeProperty("/test/book.jpg", concat("metadata", 
DocumentBundlor.META_PROP_BUNDLING_PATH)));
+        assertFalse(hasNodeProperty("/test/book.jpg", concat("comments", 
DocumentBundlor.META_PROP_BUNDLING_PATH)));
     }
 
     @Test
@@ -751,6 +777,11 @@ public class DocumentBundlingTest {
         return null;
     }
 
+    private static String getBundlingPath(NodeState contentNode) {
+        PropertyState ps = 
contentNode.getProperty(DocumentBundlor.META_PROP_BUNDLING_PATH);
+        return checkNotNull(ps).getValue(Type.STRING);
+    }
+
     private static void dump(NodeState state){
         System.out.println(NodeStateUtils.toString(state));
     }


Reply via email to