jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1591704 - in /jackrabbit/oak/trunk/oak-upgrade/src: main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java
Date Thu, 01 May 2014 16:32:42 GMT
Author: jukka
Date: Thu May  1 16:32:42 2014
New Revision: 1591704

URL: http://svn.apache.org/r1591704
Log:
OAK-1789: Upgraded version history has UUIDs as jcr:frozenUuid of non-referenceable nodes

Automatically convert UUIDs to path identifiers where needed.

Modified:
    jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java
    jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java

Modified: jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java?rev=1591704&r1=1591703&r2=1591704&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java
Thu May  1 16:32:42 2014
@@ -18,16 +18,25 @@ package org.apache.jackrabbit.oak.upgrad
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Iterables.addAll;
 import static com.google.common.collect.Lists.newArrayList;
 import static com.google.common.collect.Lists.newArrayListWithCapacity;
 import static com.google.common.collect.Maps.newHashMap;
 import static com.google.common.collect.Maps.newLinkedHashMap;
+import static com.google.common.collect.Sets.newHashSet;
 import static com.google.common.collect.Sets.newLinkedHashSet;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENMIXINTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENPRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENUUID;
 import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
 import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
 import static org.apache.jackrabbit.JcrConstants.MIX_REFERENCEABLE;
+import static org.apache.jackrabbit.JcrConstants.NT_FROZENNODE;
 import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
+import static org.apache.jackrabbit.oak.api.Type.NAME;
+import static org.apache.jackrabbit.oak.api.Type.NAMES;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
 import static org.apache.jackrabbit.oak.plugins.tree.TreeConstants.OAK_CHILD_ORDER;
 
 import java.io.ByteArrayInputStream;
@@ -97,6 +106,8 @@ class JackrabbitNodeState extends Abstra
 
     private final TypePredicate isOrderable;
 
+    private final TypePredicate isFrozenNode;
+
     /**
      * Source namespace mappings (URI -< prefix).
      */
@@ -116,6 +127,7 @@ class JackrabbitNodeState extends Abstra
         this.loader = parent.loader;
         this.isReferenceable = parent.isReferenceable;
         this.isOrderable = parent.isOrderable;
+        this.isFrozenNode = parent.isFrozenNode;
         this.uriToPrefix = parent.uriToPrefix;
         this.nodes = createNodes(bundle);
         this.properties = createProperties(bundle);
@@ -133,6 +145,7 @@ class JackrabbitNodeState extends Abstra
         this.loader = new BundleLoader(source);
         this.isReferenceable = new TypePredicate(root, MIX_REFERENCEABLE);
         this.isOrderable = TypePredicate.isOrderable(root);
+        this.isFrozenNode = new TypePredicate(root, NT_FROZENNODE);
         this.uriToPrefix = uriToPrefix;
         try {
             NodePropBundle bundle = loader.loadBundle(id);
@@ -239,7 +252,7 @@ class JackrabbitNodeState extends Abstra
         return children;
     }
 
-    public Map<String, PropertyState> createProperties(NodePropBundle bundle) {
+    private Map<String, PropertyState> createProperties(NodePropBundle bundle) {
         Map<String, PropertyState> properties = newHashMap();
 
         String primary;
@@ -290,6 +303,32 @@ class JackrabbitNodeState extends Abstra
             }
         }
 
+        // OAK-1789: Convert the jcr:frozenUuid of a non-referenceable
+        // frozen node from UUID to a path identifier
+        PropertyState frozenUuid = properties.get(JCR_FROZENUUID);
+        if (frozenUuid != null
+                && frozenUuid.getType() == STRING
+                && isFrozenNode.apply(primary, mixins)) {
+            String frozenPrimary = NT_UNSTRUCTURED;
+            Set<String> frozenMixins = newHashSet();
+
+            PropertyState property = properties.get(JCR_FROZENPRIMARYTYPE);
+            if (property != null && property.getType() == NAME) {
+                primary = property.getValue(NAME);
+            }
+            property = properties.get(JCR_FROZENMIXINTYPES);
+            if (property != null && property.getType() == NAMES) {
+                addAll(frozenMixins, property.getValue(NAMES));
+            }
+
+            if (!isReferenceable.apply(frozenPrimary, frozenMixins)) {
+                frozenUuid = PropertyStates.createProperty(
+                        JCR_FROZENUUID,
+                        parent.getString(JCR_FROZENUUID) + "/" + name);
+                properties.put(JCR_FROZENUUID, frozenUuid);
+            }
+        }
+
         return properties;
     }
 

Modified: jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java?rev=1591704&r1=1591703&r2=1591704&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java
Thu May  1 16:32:42 2014
@@ -22,6 +22,10 @@ import static junit.framework.Assert.ass
 import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertTrue;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENMIXINTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENPRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENUUID;
+import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
@@ -35,6 +39,7 @@ import javax.jcr.Node;
 import javax.jcr.PropertyIterator;
 import javax.jcr.PropertyType;
 import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
 import javax.jcr.nodetype.NodeType;
@@ -43,6 +48,8 @@ import javax.jcr.nodetype.NodeTypeTempla
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.nodetype.PropertyDefinitionTemplate;
 import javax.jcr.security.Privilege;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
 
 import org.apache.jackrabbit.api.JackrabbitSession;
 import org.apache.jackrabbit.api.JackrabbitWorkspace;
@@ -61,9 +68,7 @@ public class RepositoryUpgradeTest exten
         new Random().nextBytes(BINARY);
     }
 
-    // needs to be static because the content is created during the @BeforeClass phase
-    private static String testNodeIdentifier;
-
+    @SuppressWarnings("unchecked")
     protected void createSourceContent(Repository repository) throws Exception {
         Session session = repository.login(CREDENTIALS);
         try {
@@ -104,11 +109,13 @@ public class RepositoryUpgradeTest exten
             Node referenceable =
                 root.addNode("referenceable", "test:unstructured");
             referenceable.addMixin(NodeType.MIX_REFERENCEABLE);
-            Node referenceable2 =
-                root.addNode("referenceable2", "test:unstructured");
-            referenceable2.addMixin(NodeType.MIX_REFERENCEABLE);
+            Node versionable =
+                root.addNode("versionable", "test:unstructured");
+            versionable.addMixin(NodeType.MIX_VERSIONABLE);
+            versionable.addNode("child", "test:unstructured");
             session.save();
-            testNodeIdentifier = referenceable.getIdentifier();
+
+            session.getWorkspace().getVersionManager().checkin("/versionable");
 
             Node properties = root.addNode("properties", "test:unstructured");
             properties.setProperty("boolean", true);
@@ -125,8 +132,8 @@ public class RepositoryUpgradeTest exten
             properties.setProperty("long", 9876543210L);
             properties.setProperty("reference", referenceable);
             properties.setProperty("weak_reference", session.getValueFactory().createValue(referenceable,
true));
-            properties.setProperty("mv_reference", new Value[]{session.getValueFactory().createValue(referenceable2,
false)});
-            properties.setProperty("mv_weak_reference", new Value[]{session.getValueFactory().createValue(referenceable2,
true)});
+            properties.setProperty("mv_reference", new Value[]{session.getValueFactory().createValue(versionable,
false)});
+            properties.setProperty("mv_weak_reference", new Value[]{session.getValueFactory().createValue(versionable,
true)});
             properties.setProperty("string", "test");
             properties.setProperty("multiple", "a,b,c".split(","));
             session.save();
@@ -316,6 +323,10 @@ public class RepositoryUpgradeTest exten
     public void verifyReferencePropertiesContent() throws Exception {
         Session session = createAdminSession();
         try {
+            assertTrue(session.nodeExists("/referenceable"));
+            String testNodeIdentifier =
+                    session.getNode("/referenceable").getIdentifier();
+
             assertTrue(session.nodeExists("/properties"));
             Node properties = session.getNode("/properties");
 
@@ -333,7 +344,7 @@ public class RepositoryUpgradeTest exten
             assertEquals(properties.getPath() + "/reference", refs.nextProperty().getPath());
             assertFalse(refs.hasNext());
 
-            PropertyIterator refs2 = session.getNode("/referenceable2").getReferences();
+            PropertyIterator refs2 = session.getNode("/versionable").getReferences();
             assertTrue(refs2.hasNext());
             assertEquals(properties.getPath() + "/mv_reference", refs2.nextProperty().getPath());
             assertFalse(refs2.hasNext());
@@ -351,7 +362,7 @@ public class RepositoryUpgradeTest exten
             assertTrue(weakRefs.hasNext());
             assertEquals(properties.getPath() + "/weak_reference", weakRefs.nextProperty().getPath());
             assertFalse(weakRefs.hasNext());
-            PropertyIterator weakRefs2 = session.getNode("/referenceable2").getWeakReferences();
+            PropertyIterator weakRefs2 = session.getNode("/versionable").getWeakReferences();
             assertTrue(weakRefs2.hasNext());
             assertEquals(properties.getPath() + "/mv_weak_reference", weakRefs2.nextProperty().getPath());
             assertFalse(weakRefs2.hasNext());
@@ -360,4 +371,46 @@ public class RepositoryUpgradeTest exten
         }
     }
 
+    @Test
+    public void verifyVersionHistory() throws RepositoryException {
+        Session session = createAdminSession();
+        try {
+            assertTrue(session.nodeExists("/versionable"));
+            Node versionable = session.getNode("/versionable");
+            assertTrue(versionable.hasNode("child"));
+            Node child = versionable.getNode("child");
+
+            assertFalse(versionable.isCheckedOut());
+            assertTrue(versionable.hasProperty(JCR_UUID));
+            assertFalse(versionable.getNode("child").isCheckedOut());
+            assertFalse(versionable.getNode("child").hasProperty(JCR_UUID));
+
+            VersionManager manager = session.getWorkspace().getVersionManager();
+            Version version = manager.getBaseVersion("/versionable");
+
+            Node frozen = version.getFrozenNode();
+            assertEquals(
+                    versionable.getPrimaryNodeType().getName(),
+                    frozen.getProperty(JCR_FROZENPRIMARYTYPE).getString());
+            assertEquals(
+                    versionable.getMixinNodeTypes()[0].getName(),
+                    frozen.getProperty(JCR_FROZENMIXINTYPES).getValues()[0].getString());
+            assertEquals(
+                    versionable.getIdentifier(),
+                    frozen.getProperty(JCR_FROZENUUID).getString());
+
+            Node frozenChild = frozen.getNode("child");
+            assertEquals(
+                    child.getPrimaryNodeType().getName(),
+                    frozenChild.getProperty(JCR_FROZENPRIMARYTYPE).getString());
+            assertFalse(frozenChild.hasProperty(JCR_FROZENMIXINTYPES));
+            assertEquals(
+                    "OAK-1789",
+                    child.getIdentifier(),
+                    frozenChild.getProperty(JCR_FROZENUUID).getString());
+        } finally {
+            session.logout();
+        }
+    }
+
 }



Mime
View raw message