You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2016/10/19 15:08:55 UTC

svn commit: r1765630 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/ main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/ test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/

Author: chetanm
Date: Wed Oct 19 15:08:54 2016
New Revision: 1765630

URL: http://svn.apache.org/viewvc?rev=1765630&view=rev
Log:
OAK-1312 -  [bundling] Bundle nodes into a document

Handle deletes

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitDiff.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.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/CommitDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitDiff.java?rev=1765630&r1=1765629&r2=1765630&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitDiff.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitDiff.java Wed Oct 19 15:08:54 2016
@@ -60,8 +60,7 @@ class CommitDiff implements NodeStateDif
         this.bundlingHandler = bundlingHandler;
         this.builder = builder;
         this.blobs = blobs;
-        setMetaProperties();
-        informCommitAboutBundledNodes();
+        performBundlingRelatedOperations();
     }
 
     @Override
@@ -117,6 +116,12 @@ class CommitDiff implements NodeStateDif
 
     //----------------------------< internal >----------------------------------
 
+    private void performBundlingRelatedOperations() {
+        setMetaProperties();
+        informCommitAboutBundledNodes();
+        removeRemovedProps();
+    }
+
     private void setMetaProperties() {
         for (PropertyState ps : bundlingHandler.getMetaProps()){
             setProperty(ps);
@@ -129,6 +134,13 @@ class CommitDiff implements NodeStateDif
         }
     }
 
+    private void removeRemovedProps() {
+        for (String propName : bundlingHandler.getRemovedProps()){
+            commit.updateProperty(bundlingHandler.getRootBundlePath(),
+                    bundlingHandler.getPropertyPath(propName), null);
+        }
+    }
+
     private void setProperty(PropertyState property) {
         builder.resetWriter();
         JsonSerializer serializer = new JsonSerializer(builder, blobs);

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=1765630&r1=1765629&r2=1765630&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 Wed Oct 19 15:08:54 2016
@@ -19,9 +19,9 @@
 
 package org.apache.jackrabbit.oak.plugins.document.bundlor;
 
-import java.util.Collections;
 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;
@@ -39,21 +39,15 @@ public class BundlingHandler {
     private final BundledTypesRegistry registry;
     private final String path;
     private final BundlingContext ctx;
-    private final Set<PropertyState> metaProps;
 
     public BundlingHandler(BundledTypesRegistry registry) {
-        this(registry, BundlingContext.NULL, ROOT_PATH, Collections.<PropertyState>emptySet());
+        this(registry, BundlingContext.NULL, ROOT_PATH);
     }
 
     private BundlingHandler(BundledTypesRegistry registry, BundlingContext ctx, String path) {
-        this(registry, ctx, path, Collections.<PropertyState>emptySet());
-    }
-
-    private BundlingHandler(BundledTypesRegistry registry, BundlingContext ctx, String path, Set<PropertyState> metaProps) {
         this.registry = registry;
         this.path = path;
         this.ctx = ctx;
-        this.metaProps = metaProps;
     }
 
     public String getPropertyPath(String propertyName) {
@@ -75,7 +69,11 @@ public class BundlingHandler {
     }
 
     public Set<PropertyState> getMetaProps() {
-        return metaProps;
+        return ctx.metaProps;
+    }
+
+    public Set<String> getRemovedProps(){
+        return ctx.removedProps;
     }
 
     public String getRootBundlePath() {
@@ -85,22 +83,21 @@ public class BundlingHandler {
     public BundlingHandler childAdded(String name, NodeState state){
         String childPath = childPath(name);
         BundlingContext childContext;
-        Set<PropertyState> metaProps = Collections.emptySet();
         Matcher childMatcher = ctx.matcher.next(name);
         if (childMatcher.isMatch()) {
-            metaProps = Collections.singleton(NODE_PRESENCE_MARKER);
             childContext = createChildContext(childMatcher);
+            childContext.addMetaProp(NODE_PRESENCE_MARKER);
         } else {
             DocumentBundlor bundlor = registry.getBundlor(state);
             if (bundlor != null){
                 PropertyState bundlorConfig = bundlor.asPropertyState();
-                metaProps = Collections.singleton(bundlorConfig);
                 childContext = new BundlingContext(childPath, bundlor.createMatcher());
+                childContext.addMetaProp(bundlorConfig);
             } else {
                 childContext = BundlingContext.NULL;
             }
         }
-        return new BundlingHandler(registry, childContext, childPath, metaProps);
+        return new BundlingHandler(registry, childContext, childPath);
     }
 
     public BundlingHandler childDeleted(String name, NodeState state){
@@ -108,9 +105,11 @@ public class BundlingHandler {
         BundlingContext childContext;
         Matcher childMatcher = ctx.matcher.next(name);
         if (childMatcher.isMatch()) {
-            //TODO Add meta prop for bundled child node
-            //TODO Delete should nullify all properties
             childContext = createChildContext(childMatcher);
+            childContext.removeProperty(DocumentBundlor.META_PROP_NODE);
+            for (PropertyState ps : state.getProperties()){
+                childContext.removeProperty(ps.getName());
+            }
         } else {
             childContext = getBundlorContext(childPath, state);
         }
@@ -159,6 +158,8 @@ public class BundlingHandler {
         static final BundlingContext NULL = new BundlingContext("", Matcher.NON_MATCHING);
         final String bundlingPath;
         final Matcher matcher;
+        final Set<PropertyState> metaProps = Sets.newHashSet();
+        final Set<String> removedProps = Sets.newHashSet();
 
         public BundlingContext(String bundlingPath, Matcher matcher) {
             this.bundlingPath = bundlingPath;
@@ -176,5 +177,13 @@ public class BundlingHandler {
         public String getPropertyPath(String propertyName) {
             return PathUtils.concat(matcher.getMatchedPath(), propertyName);
         }
+
+        public void addMetaProp(PropertyState state){
+            metaProps.add(state);
+        }
+
+        public void removeProperty(String name){
+            removedProps.add(name);
+        }
     }
 }

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=1765630&r1=1765629&r2=1765630&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 Wed Oct 19 15:08:54 2016
@@ -233,6 +233,45 @@ public class DocumentBundlingTest {
         assertTrue(PartialEqualsDiff.equals(state, getLatestNode("/test/book.jpg")));
     }
 
+    @Test
+    public void deleteBundledNode() 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"
+        );
+
+        childBuilder(appNB, "jcr:content/metadata").setProperty("foo", "bar");
+        childBuilder(appNB, "jcr:content/comments").setProperty("foo", "bar");
+        builder.child("test").setChildNode("book.jpg", appNB.getNodeState());
+
+        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+        //Delete a bundled node jcr:content/metadata
+        builder = store.getRoot().builder();
+        childBuilder(builder, "/test/book.jpg/jcr:content/metadata").remove();
+        NodeState appNode_v2 = childBuilder(builder, "/test/book.jpg").getNodeState();
+        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+        assertTrue(PartialEqualsDiff.equals(appNode_v2, getLatestNode("/test/book.jpg")));
+
+
+        //Delete unbundled child jcr:content/comments
+        builder = store.getRoot().builder();
+        childBuilder(builder, "/test/book.jpg/jcr:content/comments").remove();
+        NodeState appNode_v3 = childBuilder(builder, "/test/book.jpg").getNodeState();
+        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+        assertTrue(PartialEqualsDiff.equals(appNode_v3, getLatestNode("/test/book.jpg")));
+
+    }
+
     private NodeState getLatestNode(String path){
         return getNode(store.getRoot(), path);
     }