jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1482261 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ oak-jcr/src/main/java/...
Date Tue, 14 May 2013 09:20:46 GMT
Author: mreutegg
Date: Tue May 14 09:20:45 2013
New Revision: 1482261

URL: http://svn.apache.org/r1482261
Log:
OAK-168: Basic JCR VersionManager support
- Return VersionImpl for nt:version and VersionHistoryImpl for nt:versionHistory nodes

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionExceptionType.java
  (with props)
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionTest.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionEditor.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionEditor.java?rev=1482261&r1=1482260&r2=1482261&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionEditor.java
Tue May 14 09:20:45 2013
@@ -19,14 +19,10 @@
 package org.apache.jackrabbit.oak.plugins.version;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
-import javax.jcr.RepositoryException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.version.VersionException;
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -88,7 +84,8 @@ class VersionEditor implements Editor {
     }
 
     @Override
-    public void propertyAdded(PropertyState after) {
+    public void propertyAdded(PropertyState after)
+            throws CommitFailedException {
         if (!wasReadOnly) {
             return;
         }
@@ -129,7 +126,8 @@ class VersionEditor implements Editor {
     }
 
     @Override
-    public void propertyDeleted(PropertyState before) {
+    public void propertyDeleted(PropertyState before)
+            throws CommitFailedException {
         if (wasReadOnly) {
             if (!isVersionProperty(before)) {
                 throwProtected("Cannot delete property on checked in node");
@@ -191,32 +189,14 @@ class VersionEditor implements Editor {
     }
 
     private static void throwCheckedIn(String msg)
-            throws UncheckedRepositoryException {
-        throwUnchecked(new VersionException(msg));
+            throws CommitFailedException {
+        throw new CommitFailedException(CommitFailedException.VERSION,
+                VersionExceptionType.NODE_CHECKED_IN.ordinal(), msg);
     }
 
     private static void throwProtected(String name)
-            throws UncheckedRepositoryException {
-        throwUnchecked(new ConstraintViolationException(
-                "Property is protected: " + name));
-    }
-
-    private static void throwUnchecked(RepositoryException e)
-            throws UncheckedRepositoryException {
-        // TODO: still necessary?
-        throw new UncheckedRepositoryException(e);
-    }
-
-    private static class UncheckedRepositoryException extends RuntimeException {
-
-        private static final long serialVersionUID = 5220620245610340169L;
-
-        public UncheckedRepositoryException(RepositoryException cause) {
-            super(cause);
-        }
-
-        public RepositoryException getCause() {
-            return (RepositoryException) super.getCause();
-        }
+            throws CommitFailedException {
+        throw new CommitFailedException(CommitFailedException.CONSTRAINT, 100,
+                "Property is protected: " + name);
     }
 }

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionExceptionType.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionExceptionType.java?rev=1482261&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionExceptionType.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionExceptionType.java
Tue May 14 09:20:45 2013
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.version;
+
+/**
+ * <code>VersionExceptionType</code> contains the states for version related
+ * commit failures.
+ */
+public enum VersionExceptionType {
+
+    NODE_CHECKED_IN("Node is checked in");
+
+    private final String desc;
+
+    private VersionExceptionType(String desc) {
+        this.desc = desc;
+    }
+
+    public String getDescription() {
+        return desc;
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionExceptionType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionExceptionType.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1482261&r1=1482260&r2=1482261&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Tue May 14 09:20:45 2013
@@ -884,6 +884,7 @@ public class NodeImpl<T extends NodeDele
                 return sessionContext.getAccessManager().hasPermissions(
                     dlg.getTree(), prop, Permissions.NODE_TYPE_MANAGEMENT)
                         && !dlg.isProtected()
+                        && sessionContext.getVersionManager().isCheckedOut(toJcrPath(dlg.getPath()))
                         && dlg.canAddMixin(oakTypeName);
             }
         });

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1482261&r1=1482260&r2=1482261&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Tue May 14 09:20:45 2013
@@ -40,6 +40,7 @@ import javax.jcr.retention.RetentionMana
 import javax.jcr.security.AccessControlException;
 import javax.jcr.security.AccessControlManager;
 
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.api.JackrabbitSession;
 import org.apache.jackrabbit.api.security.principal.PrincipalManager;
 import org.apache.jackrabbit.api.security.user.UserManager;
@@ -53,6 +54,9 @@ import org.apache.jackrabbit.oak.jcr.del
 import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionOperation;
+import org.apache.jackrabbit.oak.jcr.delegate.VersionManagerDelegate;
+import org.apache.jackrabbit.oak.jcr.version.VersionHistoryImpl;
+import org.apache.jackrabbit.oak.jcr.version.VersionImpl;
 import org.apache.jackrabbit.oak.jcr.xml.ImportHandler;
 import org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials;
 import org.apache.jackrabbit.oak.util.TODO;
@@ -114,8 +118,21 @@ public class SessionImpl implements Jack
         return sessionContext.getOakPathOrThrowNotFound(absPath);
     }
 
-    private NodeImpl<?> createNodeOrNull(NodeDelegate nd) {
-        return nd == null ? null : new NodeImpl<NodeDelegate>(nd, sessionContext);
+    private NodeImpl<?> createNodeOrNull(NodeDelegate nd) throws RepositoryException
{
+        if (nd == null) {
+            return null;
+        }
+        PropertyDelegate pd = nd.getPropertyOrNull(JcrConstants.JCR_PRIMARYTYPE);
+        String type = pd != null ? pd.getString() : null;
+        if (JcrConstants.NT_VERSION.equals(type)) {
+            VersionManagerDelegate delegate = VersionManagerDelegate.create(sd);
+            return new VersionImpl(delegate.createVersion(nd), sessionContext);
+        } else if (JcrConstants.NT_VERSIONHISTORY.equals(type)) {
+            VersionManagerDelegate delegate = VersionManagerDelegate.create(sd);
+            return new VersionHistoryImpl(delegate.createVersionHistory(nd), sessionContext);
+        } else {
+            return new NodeImpl<NodeDelegate>(nd, sessionContext);
+        }
     }
 
     private PropertyImpl createPropertyOrNull(PropertyDelegate pd) {
@@ -123,7 +140,8 @@ public class SessionImpl implements Jack
     }
 
     @CheckForNull
-    private ItemImpl<?> getItemInternal(@Nonnull String oakPath) {
+    private ItemImpl<?> getItemInternal(@Nonnull String oakPath)
+            throws RepositoryException {
         NodeDelegate nd = sd.getNode(oakPath);
         if (nd != null) {
             return createNodeOrNull(nd);
@@ -244,7 +262,7 @@ public class SessionImpl implements Jack
     public Node getRootNode() throws RepositoryException {
         return perform(new CheckedSessionOperation<Node>() {
             @Override
-            protected Node perform() throws AccessDeniedException {
+            protected Node perform() throws AccessDeniedException, RepositoryException {
                 NodeDelegate nd = sd.getRootNode();
                 if (nd == null) {
                     throw new AccessDeniedException("Root node is not accessible.");
@@ -272,7 +290,7 @@ public class SessionImpl implements Jack
     private Node getNodeById(final String id) throws RepositoryException {
         return perform(new CheckedSessionOperation<Node>() {
             @Override
-            public Node perform() throws ItemNotFoundException {
+            public Node perform() throws ItemNotFoundException, RepositoryException {
                 NodeDelegate nd = sd.getNodeByIdentifier(id);
                 if (nd == null) {
                     throw new ItemNotFoundException("Node with id " + id + " does not exist.");

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java?rev=1482261&r1=1482260&r2=1482261&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java
Tue May 14 09:20:45 2013
@@ -84,6 +84,12 @@ public class VersionManagerDelegate {
     }
 
     @Nonnull
+    public VersionDelegate createVersion(@Nonnull NodeDelegate version)
+            throws RepositoryException {
+        return VersionDelegate.create(sessionDelegate, getTree(version));
+    }
+
+    @Nonnull
     public VersionHistoryDelegate getVersionHistory(@Nonnull NodeDelegate versionable)
             throws RepositoryException {
         Tree vh = versionManager.getVersionHistory(getTree(versionable));

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java?rev=1482261&r1=1482260&r2=1482261&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
Tue May 14 09:20:45 2013
@@ -42,7 +42,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.version.VersionConstants;
 import org.apache.jackrabbit.oak.util.TODO;
 
-class VersionImpl extends NodeImpl<VersionDelegate> implements Version {
+public class VersionImpl extends NodeImpl<VersionDelegate> implements Version {
 
     public VersionImpl(VersionDelegate dlg, SessionContext sessionContext) {
         super(dlg, sessionContext);

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryTest.java?rev=1482261&r1=1482260&r2=1482261&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryTest.java
Tue May 14 09:20:45 2013
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.jcr.version;
 
 import javax.jcr.Node;
+import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.version.VersionHistory;
 import javax.jcr.version.VersionManager;
@@ -101,4 +102,25 @@ public class VersionHistoryTest extends 
         assertTrue(superuser.nodeExists(destPath));
         VersionHistory vh = versionManager.getVersionHistory(destPath);
     }
+
+    public void testGetNodeByIdentifier() throws RepositoryException {
+        Node n = testRootNode.addNode(nodeName1, testNodeType);
+        n.addMixin(mixVersionable);
+        superuser.save();
+        VersionManager vMgr = superuser.getWorkspace().getVersionManager();
+        String id = vMgr.getVersionHistory(n.getPath()).getIdentifier();
+        assertTrue("Session.getNodeByIdentifier() did not return VersionHistory object for
a nt:versionHistory node.",
+                superuser.getNodeByIdentifier(id) instanceof VersionHistory);
+    }
+
+    @SuppressWarnings("deprecation")
+    public void testGetNodeByUUID() throws RepositoryException {
+        Node n = testRootNode.addNode(nodeName1, testNodeType);
+        n.addMixin(mixVersionable);
+        superuser.save();
+        VersionManager vMgr = superuser.getWorkspace().getVersionManager();
+        String uuid = vMgr.getVersionHistory(n.getPath()).getUUID();
+        assertTrue("Session.getNodeByUUID() did not return VersionHistory object for a nt:versionHistory
node.",
+                superuser.getNodeByUUID(uuid) instanceof VersionHistory);
+    }
 }
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionTest.java?rev=1482261&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionTest.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionTest.java
Tue May 14 09:20:45 2013
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.version;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * <code>VersionTest</code> performs tests on JCR Version nodes.
+ */
+public class VersionTest extends AbstractJCRTest {
+
+    public void testGetNodeByIdentifier() throws RepositoryException {
+        Node n = testRootNode.addNode(nodeName1, testNodeType);
+        n.addMixin(mixVersionable);
+        superuser.save();
+        VersionManager vMgr = superuser.getWorkspace().getVersionManager();
+        String id = vMgr.getBaseVersion(n.getPath()).getIdentifier();
+        assertTrue("Session.getNodeByIdentifier() did not return Version object for a nt:version
node.",
+                superuser.getNodeByIdentifier(id) instanceof Version);
+    }
+
+    @SuppressWarnings("deprecation")
+    public void testGetNodeByUUID() throws RepositoryException {
+        Node n = testRootNode.addNode(nodeName1, testNodeType);
+        n.addMixin(mixVersionable);
+        superuser.save();
+        VersionManager vMgr = superuser.getWorkspace().getVersionManager();
+        String uuid = vMgr.getBaseVersion(n.getPath()).getUUID();
+        assertTrue("Session.getNodeByUUID() did not return Version object for a nt:version
node.",
+                superuser.getNodeByUUID(uuid) instanceof Version);
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message