jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1574935 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/HiddenNodeTest.java
Date Thu, 06 Mar 2014 15:56:34 GMT
Author: angela
Date: Thu Mar  6 15:56:33 2014
New Revision: 1574935

URL: http://svn.apache.org/r1574935
Log:
OAK-1226 : Hidden item handling in VersionEditor

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/HiddenNodeTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java?rev=1574935&r1=1574934&r2=1574935&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
Thu Mar  6 15:56:33 2014
@@ -39,8 +39,10 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
 import org.apache.jackrabbit.oak.plugins.tree.ImmutableTree;
+import org.apache.jackrabbit.oak.plugins.tree.TreeConstants;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -458,9 +460,13 @@ class VersionableState {
                                  NodeBuilder dest,
                                  PropertyState prop)
                     throws RepositoryException {
-                if (BASIC_FROZEN_PROPERTIES.contains(prop.getName())) {
+                String propName = prop.getName();
+                if (BASIC_FROZEN_PROPERTIES.contains(propName)) {
                     // OAK-940: do not overwrite basic frozen properties
                     return IGNORE;
+                } else if (isHiddenProperty(propName)) {
+                    // don't copy hidden properties except for :childOrder
+                    return IGNORE;
                 }
                 return getOPV(src, prop);
             }
@@ -468,6 +474,9 @@ class VersionableState {
 
         // add the frozen children and histories
         for (String name : src.getChildNodeNames()) {
+            if (NodeStateUtils.isHidden(name)) {
+                continue;
+            }
             NodeBuilder child = src.getChildNode(name);
             String childId = getChildId(srcId, child, name);
             int opv = getOPV(src, child, name);
@@ -504,8 +513,10 @@ class VersionableState {
         initFrozen(dest, src, srcId);
         copyProperties(src, dest, OPVForceCopy.INSTANCE, true);
         for (String name : src.getChildNodeNames()) {
-            NodeBuilder child = src.getChildNode(name);
-            copy(child, getChildId(srcId, child, name), dest.child(name));
+            if (!NodeStateUtils.isHidden(name)) {
+                NodeBuilder child = src.getChildNode(name);
+                copy(child, getChildId(srcId, child, name), dest.child(name));
+            }
         }
     }
 
@@ -545,6 +556,9 @@ class VersionableState {
             if (ignoreTypeAndUUID && BASIC_PROPERTIES.contains(propName)) {
                 continue;
             }
+            if (isHiddenProperty(propName)) {
+                continue;
+            }
             if (opv == OnParentVersionAction.VERSION
                     || opv == COPY) {
                 dest.setProperty(prop);
@@ -562,6 +576,10 @@ class VersionableState {
         return ntMgr.isNodeType(tree, MIX_REFERENCEABLE);
     }
 
+    private static boolean isHiddenProperty(@Nonnull String propName) {
+        return NodeStateUtils.isHidden(propName) && !TreeConstants.OAK_CHILD_ORDER.equals(propName);
+    }
+
     private int getOPV(NodeBuilder parent, NodeBuilder child, String childName)
             throws RepositoryException {
         // ignore hidden tree

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/HiddenNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/HiddenNodeTest.java?rev=1574935&r1=1574934&r2=1574935&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/HiddenNodeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/HiddenNodeTest.java
Thu Mar  6 15:56:33 2014
@@ -27,6 +27,8 @@ import org.apache.jackrabbit.oak.commons
 import org.apache.jackrabbit.oak.jcr.Jcr;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore;
 import org.apache.jackrabbit.oak.plugins.segment.memory.MemoryStore;
+import org.apache.jackrabbit.oak.plugins.tree.TreeConstants;
+import org.apache.jackrabbit.oak.plugins.version.VersionConstants;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -41,7 +43,7 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertTrue;
 
 /**
- * Checks if hidden nodes are properly handled on checkin and restore (OAK-1219).
+ * Checks if hidden nodes are properly handled on checkin and restore (OAK-1219, OAK-OAK-1226).
  */
 public class HiddenNodeTest {
 
@@ -94,4 +96,154 @@ public class HiddenNodeTest {
         state = store.getRoot().getChildNode("test");
         assertTrue(state.hasChildNode(":hidden"));
     }
+
+    @Test
+    public void hiddenProperty() throws Exception {
+        Node test = session.getRootNode().addNode("test", "nt:unstructured");
+        test.addMixin("mix:versionable");
+        session.save();
+
+        NodeBuilder builder = store.getRoot().builder();
+        NodeBuilder testBuilder = builder.getChildNode("test");
+        testBuilder.setProperty(":hiddenProperty", "value");
+        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+        session.refresh(false);
+        Version v1 = vMgr.checkpoint("/test");
+        Version v2 = vMgr.checkpoint("/test");
+
+        NodeState state = store.getRoot();
+        for (String name : PathUtils.elements(v2.getPath())) {
+            state = state.getChildNode(name);
+        }
+        state = state.getChildNode(VersionConstants.JCR_FROZENNODE);
+        assertTrue(state.exists());
+        assertFalse(state.hasProperty(":hiddenProperty"));
+
+        vMgr.restore(v1, true);
+
+        state = store.getRoot().getChildNode("test");
+        assertFalse(state.hasProperty(":hiddenProperty"));
+    }
+
+    @Test
+    public void hiddenOrderProperty() throws Exception {
+        Node test = session.getRootNode().addNode("test", "nt:unstructured");
+        test.addNode("a");
+        test.addNode("b");
+        test.addNode("c");
+        test.addMixin("mix:versionable");
+        session.save();
+
+        NodeBuilder testBuilder = store.getRoot().builder().getChildNode("test");
+        assertTrue(testBuilder.hasProperty(TreeConstants.OAK_CHILD_ORDER));
+
+        session.refresh(false);
+        Version v1 = vMgr.checkpoint("/test");
+        Version v2 = vMgr.checkpoint("/test");
+
+        NodeState state = store.getRoot();
+        for (String name : PathUtils.elements(v2.getPath())) {
+            state = state.getChildNode(name);
+        }
+        state = state.getChildNode(VersionConstants.JCR_FROZENNODE);
+        assertTrue(state.exists());
+        assertTrue(state.hasProperty(TreeConstants.OAK_CHILD_ORDER));
+
+        vMgr.restore(v1, true);
+
+        state = store.getRoot().getChildNode("test");
+        assertTrue(state.hasProperty(TreeConstants.OAK_CHILD_ORDER));
+    }
+
+    @Test
+    public void hiddenChildNode() throws Exception {
+        Node test = session.getRootNode().addNode("test", "nt:unstructured");
+        test.addMixin("mix:versionable");
+        test.addNode("child");
+        session.save();
+
+        NodeBuilder builder = store.getRoot().builder();
+        NodeBuilder testBuilder = builder.getChildNode("test").getChildNode("child");
+        testBuilder.child(":hidden").setProperty("property", "value");
+        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+        session.refresh(false);
+        Version v1 = vMgr.checkpoint("/test");
+        Version v2 = vMgr.checkpoint("/test");
+
+        NodeState state = store.getRoot();
+        for (String name : PathUtils.elements(v2.getPath())) {
+            state = state.getChildNode(name);
+        }
+        state = state.getChildNode("jcr:frozenNode").getChildNode("child");
+        assertTrue(state.exists());
+        assertFalse(state.hasChildNode(":hidden"));
+
+        vMgr.restore(v1, true);
+
+        state = store.getRoot().getChildNode("test").getChildNode("child");
+        assertFalse(state.hasChildNode(":hidden"));
+    }
+
+    @Test
+    public void hiddenChildProperty() throws Exception {
+        Node test = session.getRootNode().addNode("test", "nt:unstructured");
+        test.addMixin("mix:versionable");
+        test.addNode("child");
+        session.save();
+
+        NodeBuilder builder = store.getRoot().builder();
+        NodeBuilder testBuilder = builder.getChildNode("test").getChildNode("child");
+        testBuilder.setProperty(":hiddenProperty", "value");
+        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+        session.refresh(false);
+        Version v1 = vMgr.checkpoint("/test");
+        Version v2 = vMgr.checkpoint("/test");
+
+        NodeState state = store.getRoot();
+        for (String name : PathUtils.elements(v2.getPath())) {
+            state = state.getChildNode(name);
+        }
+        state = state.getChildNode(VersionConstants.JCR_FROZENNODE).getChildNode("child");
+        assertTrue(state.exists());
+        assertFalse(state.hasProperty(":hiddenProperty"));
+
+        vMgr.restore(v1, true);
+
+        state = store.getRoot().getChildNode("test").getChildNode("child");
+        assertFalse(state.hasProperty(":hiddenProperty"));
+    }
+
+    @Test
+    public void hiddenChildOrderProperty() throws Exception {
+        Node test = session.getRootNode().addNode("test", "nt:unstructured");
+        Node child = test.addNode("child");
+        child.addNode("a");
+        child.addNode("b");
+        child.addNode("c");
+        test.addMixin("mix:versionable");
+        session.save();
+
+        NodeBuilder testBuilder = store.getRoot().builder().getChildNode("test").getChildNode("child");
+        assertTrue(testBuilder.hasProperty(TreeConstants.OAK_CHILD_ORDER));
+
+        session.refresh(false);
+        Version v1 = vMgr.checkpoint("/test");
+        Version v2 = vMgr.checkpoint("/test");
+
+        NodeState state = store.getRoot();
+        for (String name : PathUtils.elements(v2.getPath())) {
+            state = state.getChildNode(name);
+        }
+        state = state.getChildNode(VersionConstants.JCR_FROZENNODE).getChildNode("child");
+        assertTrue(state.exists());
+        assertTrue(state.hasProperty(TreeConstants.OAK_CHILD_ORDER));
+
+        vMgr.restore(v1, true);
+
+        state = store.getRoot().getChildNode("test").getChildNode("child");
+        assertTrue(state.hasProperty(TreeConstants.OAK_CHILD_ORDER));
+    }
 }



Mime
View raw message