jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r795136 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ jackrabbit-jcr-tests...
Date Fri, 17 Jul 2009 16:37:27 GMT
Author: jukka
Date: Fri Jul 17 16:37:26 2009
New Revision: 795136

URL: http://svn.apache.org/viewvc?rev=795136&view=rev
Log:
JCR-1565: JSR 283 lifecycle management

Added a simple NodeImpl.assignLifecyclePolicy method for assigning a lifecycle policy and
an initial lifecycle state to a node.

Added simple TCK tests for lifecycle management.

Added:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/LifecycleTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/api/nodetype/spec/mix-lifecycle.txt
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/JackrabbitRepositoryStub.properties
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TestAll.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/PredefinedNodeTypeTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java?rev=795136&r1=795135&r2=795136&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java
Fri Jul 17 16:37:26 2009
@@ -39,6 +39,7 @@
 import javax.jcr.Session;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
+import javax.jcr.nodetype.NodeType;
 import javax.jcr.retention.RetentionPolicy;
 
 import org.apache.commons.io.IOUtils;
@@ -235,6 +236,7 @@
         addPropertyTestData(getOrAddNode(data, "property"));
         addQueryTestData(getOrAddNode(data, "query"));
         addNodeTestData(getOrAddNode(data, "node"));
+        addLifecycleTestData(getOrAddNode(data, "lifecycle"));
         addExportTestData(getOrAddNode(data, "docViewTest"));
 
         Node conf = getOrAddNode(session.getRootNode(), "testconf");
@@ -330,6 +332,22 @@
             });
     }
 
+    /**
+     * Creates a lifecycle policy node and another node with a lifecycle
+     * referencing that policy.
+     */
+    private void addLifecycleTestData(Node node) throws RepositoryException {
+        Node policy = getOrAddNode(node, "policy");
+        policy.addMixin(NodeType.MIX_REFERENCEABLE);
+        Node transitions = getOrAddNode(policy, "transitions");
+        Node transition = getOrAddNode(transitions, "identity");
+        transition.setProperty("from", "identity");
+        transition.setProperty("to", "identity");
+
+        Node lifecycle = getOrAddNode(node, "node");
+        ((NodeImpl) lifecycle).assignLifecyclePolicy(policy, "identity");
+    }
+
     private void addExportTestData(Node node) throws RepositoryException, IOException {
         getOrAddNode(node, "invalidXmlName").setProperty("propName", "some text");
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=795136&r1=795135&r2=795136&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Fri Jul 17 16:37:26 2009
@@ -117,6 +117,8 @@
 
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_LIFECYCLE_POLICY;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_CURRENT_LIFECYCLE_STATE;
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.MIX_LIFECYCLE;
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.MIX_REFERENCEABLE;
 
 /**
  * <code>NodeImpl</code> implements the <code>Node</code> interface.
@@ -5076,7 +5078,7 @@
      * @return allowed transitions for the current lifecycle state of this node
      * @throws UnsupportedRepositoryOperationException
      *             if this node does not have the mix:lifecycle mixin node type
-     * @throws RepositoryException if another error occurs
+     * @throws RepositoryException if a repository error occurs
      */
     public String[] getAllowedLifecycleTransistions()
             throws UnsupportedRepositoryOperationException, RepositoryException {
@@ -5115,7 +5117,7 @@
      * @throws InvalidLifecycleTransitionException
      *             if the given target state is not among the allowed
      *             transitions from the current lifecycle state of this node
-     * @throws RepositoryException if another error occurs
+     * @throws RepositoryException if a repository error occurs
      */
     public void followLifecycleTransition(String transition)
             throws UnsupportedRepositoryOperationException,
@@ -5138,6 +5140,39 @@
                 + transition  + "\" for " + this);
     }
 
+    /**
+     * Assigns the given lifecycle policy to this node and sets the
+     * current state to the one given.
+     * <p>
+     * Note that currently no special checks are made against the given
+     * arguments, and that you will need to explicitly persist these changes
+     * by calling save().
+     * <p>
+     * Note that future versions of Apache Jackrabbit may well use different
+     * lifecycle policy implementations.
+     *
+     * @param policy lifecycle policy node
+     * @param state current lifecycle state
+     * @throws RepositoryException if a repository error occurs
+     */
+    public void assignLifecyclePolicy(Node policy, String state)
+            throws RepositoryException {
+        if (!(policy instanceof NodeImpl)
+                || !((NodeImpl) policy).isNodeType(MIX_REFERENCEABLE)) {
+            throw new RepositoryException(
+                    policy + " is not referenceable, so it can not be"
+                    + " used as a lifecycle policy");
+        }
+
+        addMixin(MIX_LIFECYCLE);
+        internalSetProperty(
+                JCR_LIFECYCLE_POLICY,
+                InternalValue.create(((NodeImpl) policy).getNodeId()));
+        internalSetProperty(
+                JCR_CURRENT_LIFECYCLE_STATE,
+                InternalValue.create(state));
+    }
+
     //--------------------------------------------------------------< Object >
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/JackrabbitRepositoryStub.properties
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/JackrabbitRepositoryStub.properties?rev=795136&r1=795135&r2=795136&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/JackrabbitRepositoryStub.properties
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/JackrabbitRepositoryStub.properties
Fri Jul 17 16:37:26 2009
@@ -515,3 +515,8 @@
 # JAVAX.JCR.RETENTION CONFIGURATION
 # ==============================================================================
 javax.jcr.tck.retentionpolicyholder=/testconf/retentionTest
+
+# ==============================================================================
+# LIFECYCLE MANAGEMENT CONFIGURATION
+# ==============================================================================
+javax.jcr.tck.lifecycleNode=/testdata/lifecycle/node

Added: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/LifecycleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/LifecycleTest.java?rev=795136&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/LifecycleTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/LifecycleTest.java
Fri Jul 17 16:37:26 2009
@@ -0,0 +1,97 @@
+/*
+ * 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.test.api;
+
+import javax.jcr.InvalidLifecycleTransitionException;
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+/**
+ * Compliance tests for section 6.12 Lifecycle Management.
+ *
+ * @test
+ * @sources LifecycleTest.java
+ * @executeClass org.apache.jackrabbit.test.api.LifecycleTest
+ */
+public class LifecycleTest extends AbstractJCRTest {
+
+    private String path;
+
+    private String transition;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        checkSupportedOption(Repository.OPTION_LIFECYCLE_SUPPORTED);
+        ensureKnowsNodeType(superuser, NodeType.MIX_LIFECYCLE);
+
+        path = getProperty("lifecycleNode");
+        if (path == null) {
+            path = testRoot + "/lifecycle";
+        }
+
+        transition = getProperty("lifecycleTransition");
+        if (transition == null) {
+            transition = "identity";
+        }
+    }
+
+    public void testGetAllowedLifecycleTransitions()
+            throws RepositoryException, NotExecutableException {
+        Node node = superuser.getNode(path);
+        try {
+            String[] transitions = node.getAllowedLifecycleTransistions();
+            assertNotNull(
+                    "Return value of getAllowedLifecycleTransitions is null",
+                    transitions);
+
+            for (int i = 0; i < transitions.length; i++) {
+                if (transition.equals(transitions[i])) {
+                    return;
+                }
+            }
+            fail("Configured lifecycle transition \"" + transition
+                    + "\" is not among the allowed transitions from node "
+                    + path);
+        } catch (UnsupportedRepositoryOperationException e) {
+            fail("Unable to get allowed lifecycle transitions for node "
+                    + path + ": " + e.getMessage());
+        }
+    }
+
+    public void testFollowLifecycleTransition()
+            throws RepositoryException, NotExecutableException {
+        Node node = superuser.getNode(path);
+        try {
+            node.followLifecycleTransition(transition);
+            // Note that there is nothing much here for us to check,
+            // as the spec doesn't specify any fixed behaviour for
+            // this method!
+        } catch (UnsupportedRepositoryOperationException e) {
+            fail("Unable to follow lifecycle transition \"" + transition
+                    + "\" for node " + path + ": " + e.getMessage());
+        } catch (InvalidLifecycleTransitionException e) {
+            fail("Unable to follow lifecycle transition \"" + transition
+                    + "\" for node " + path + ": " + e.getMessage());
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/LifecycleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TestAll.java?rev=795136&r1=795135&r2=795136&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TestAll.java
Fri Jul 17 16:37:26 2009
@@ -148,22 +148,21 @@
         suite.addTestSuite(GetWeakReferencesTest.class);
 
         //// new Session features
-        
         suite.addTestSuite(SessionRemoveItemTest.class);
         suite.addTestSuite(HasPermissionTest.class);
 
         //// new Workspace features
-        
         suite.addTestSuite(WorkspaceTest.class);
-        
+
         //// shareable nodes
-        
         suite.addTestSuite(ShareableNodeTest.class);
-        
+
         //// repository factory
-        
         suite.addTestSuite(RepositoryFactoryTest.class);
-        
+
+        //// lifecycle management
+        suite.addTestSuite(LifecycleTest.class);
+
         return suite;
     }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/PredefinedNodeTypeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/PredefinedNodeTypeTest.java?rev=795136&r1=795135&r2=795136&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/PredefinedNodeTypeTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/PredefinedNodeTypeTest.java
Fri Jul 17 16:37:26 2009
@@ -97,6 +97,11 @@
         }
     }
 
+    /** Test for the predefined mix:lifecycle node type. */
+    public void testLifecycle() throws NotExecutableException {
+        testPredefinedNodeType("mix:lifecycle");
+    }
+
     /** Test for the predefined mix:lockable node type. */
     public void testLockable() throws NotExecutableException {
         testPredefinedNodeType("mix:lockable");

Added: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/api/nodetype/spec/mix-lifecycle.txt
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/api/nodetype/spec/mix-lifecycle.txt?rev=795136&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/api/nodetype/spec/mix-lifecycle.txt
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/api/nodetype/spec/mix-lifecycle.txt
Fri Jul 17 16:37:26 2009
@@ -0,0 +1,28 @@
+NodeTypeName
+  mix:lifecycle
+Supertypes
+  []
+IsMixin
+  true
+HasOrderableChildNodes
+  false
+PrimaryItemName
+  null
+PropertyDefinition
+  Name jcr:currentLifecycleState
+  RequiredType STRING
+  DefaultValues null
+  AutoCreated false
+  Mandatory false
+  OnParentVersion INITIALIZE
+  Protected true
+  Multiple false
+PropertyDefinition
+  Name jcr:lifecyclePolicy
+  RequiredType REFERENCE
+  DefaultValues null
+  AutoCreated false
+  Mandatory false
+  OnParentVersion INITIALIZE
+  Protected true
+  Multiple false

Propchange: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/api/nodetype/spec/mix-lifecycle.txt
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message