You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2012/11/30 16:16:43 UTC

svn commit: r1415685 - in /jackrabbit/trunk/jackrabbit-spi-commons/src: main/java/org/apache/jackrabbit/spi/commons/nodetype/ test/java/org/apache/jackrabbit/spi/commons/nodetype/

Author: stefan
Date: Fri Nov 30 15:16:42 2012
New Revision: 1415685

URL: http://svn.apache.org/viewvc?rev=1415685&view=rev
Log:
JCR-3452: Modified property and child node definition are rejected

trivial modifications:
- adding/removing nt:base as requiredPrimaryType constraint
- making a single-valued property multi-valued
- changing a property's requiredType constraint to UNDEFINED

Added:
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiffTest.java
Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java?rev=1415685&r1=1415684&r2=1415685&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java Fri Nov 30 15:16:42 2012
@@ -602,11 +602,14 @@ public class NodeTypeDefDiff {
                 // no need to check defaultPrimaryType (TRIVIAL change)
 
                 if (type == TRIVIAL) {
-                    List<Name> l1 = Arrays.asList(getOldDef().getRequiredPrimaryTypes());
-                    List<Name> l2 = Arrays.asList(getNewDef().getRequiredPrimaryTypes());
-                    if (!l1.equals(l2)) {
+                    Set<Name> s1 = new HashSet<Name>(Arrays.asList(getOldDef().getRequiredPrimaryTypes()));
+                    Set<Name> s2 = new HashSet<Name>(Arrays.asList(getNewDef().getRequiredPrimaryTypes()));
+                    // normalize sets by removing nt:base (adding/removing nt:base is irrelevant for the diff)
+                    s1.remove(NameConstants.NT_BASE);
+                    s2.remove(NameConstants.NT_BASE);
+                    if (!s1.equals(s2)) {
                         // requiredPrimaryTypes have been modified
-                        if (l1.containsAll(l2)) {
+                        if (s1.containsAll(s2)) {
                             // old list is a superset of new list
                             // => removed requiredPrimaryType (TRIVIAL change)
                             type = TRIVIAL;
@@ -628,16 +631,12 @@ public class NodeTypeDefDiff {
 
         Name declaringNodeType;
         Name name;
-        int requiredType;
         boolean definesResidual;
-        boolean isMultiple;
 
         QPropertyDefinitionId(QPropertyDefinition def) {
             declaringNodeType = def.getDeclaringNodeType();
             name = def.getName();
-            requiredType = def.getRequiredType();
             definesResidual = def.definesResidual();
-            isMultiple = def.isMultiple();
         }
 
         //---------------------------------------< java.lang.Object overrides >
@@ -650,9 +649,7 @@ public class NodeTypeDefDiff {
                 QPropertyDefinitionId other = (QPropertyDefinitionId) obj;
                 return declaringNodeType.equals(other.declaringNodeType)
                         && name.equals(other.name)
-                        && requiredType == other.requiredType
-                        && definesResidual == other.definesResidual
-                        && isMultiple == other.isMultiple;
+                        && definesResidual == other.definesResidual;
             }
             return false;
         }
@@ -663,8 +660,6 @@ public class NodeTypeDefDiff {
             h = 37 * h + declaringNodeType.hashCode();
             h = 37 * h + name.hashCode();
             h = 37 * h + (definesResidual ? 11 : 43);
-            h = 37 * h + (isMultiple ? 11 : 43);
-            h = 37 * h + requiredType;
             return h;
         }
     }
@@ -676,16 +671,10 @@ public class NodeTypeDefDiff {
 
         Name declaringNodeType;
         Name name;
-        Name[] requiredPrimaryTypes;
 
         QNodeDefinitionId(QNodeDefinition def) {
             declaringNodeType = def.getDeclaringNodeType();
             name = def.getName();
-            requiredPrimaryTypes = def.getRequiredPrimaryTypes();
-            if (requiredPrimaryTypes == null || requiredPrimaryTypes.length == 0) {
-                requiredPrimaryTypes = new Name[]{NameConstants.NT_BASE};
-            }
-            Arrays.sort(requiredPrimaryTypes);
         }
 
         //---------------------------------------< java.lang.Object overrides >
@@ -697,8 +686,7 @@ public class NodeTypeDefDiff {
             if (obj instanceof QNodeDefinitionId) {
                 QNodeDefinitionId other = (QNodeDefinitionId) obj;
                 return declaringNodeType.equals(other.declaringNodeType)
-                        && name.equals(other.name)
-                        && Arrays.equals(requiredPrimaryTypes, other.requiredPrimaryTypes);
+                        && name.equals(other.name);
             }
             return false;
         }
@@ -708,9 +696,6 @@ public class NodeTypeDefDiff {
             int h = 17;
             h = 37 * h + declaringNodeType.hashCode();
             h = 37 * h + name.hashCode();
-            for (int i = 0; i < requiredPrimaryTypes.length; i++) {
-                h = 37 * h + requiredPrimaryTypes[i].hashCode();
-            }
             return h;
         }
     }

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiffTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiffTest.java?rev=1415685&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiffTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiffTest.java Fri Nov 30 15:16:42 2012
@@ -0,0 +1,92 @@
+/*
+ * 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.spi.commons.nodetype;
+
+import junit.framework.TestCase;
+
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+
+import javax.jcr.PropertyType;
+
+public class NodeTypeDefDiffTest extends TestCase {
+
+    private static final NameFactory FACTORY = NameFactoryImpl.getInstance();
+
+    private static final Name NODE_TYPE1 = FACTORY.create("{}nodeType1");
+    private static final Name PROP_NAME = FACTORY.create("{}prop");
+    private static final Name CHILD_NAME = FACTORY.create("{}child");
+
+    public void testChangedPropertyDefinition() throws Exception {
+        // old node type definition
+        QNodeTypeDefinitionBuilder oldDef = new QNodeTypeDefinitionBuilder();
+        oldDef.setName(NODE_TYPE1);
+        oldDef.setSupertypes(new Name[] { NameConstants.NT_BASE });
+
+        QPropertyDefinitionBuilder oldPropDef = new QPropertyDefinitionBuilder();
+        oldPropDef.setDeclaringNodeType(NODE_TYPE1);
+        oldPropDef.setName(PROP_NAME);
+        oldPropDef.setRequiredType(PropertyType.STRING);
+        oldPropDef.setMultiple(false);
+
+        oldDef.setPropertyDefs(new QPropertyDefinition[]{oldPropDef.build()});
+
+        QNodeDefinitionBuilder oldChildDef = new QNodeDefinitionBuilder();
+        oldChildDef.setRequiredPrimaryTypes(new Name[]{ NODE_TYPE1, NameConstants.NT_FOLDER });
+        oldChildDef.setName(CHILD_NAME);
+        oldChildDef.setDeclaringNodeType(oldDef.getName());
+
+        oldDef.setChildNodeDefs(new QNodeDefinition[] { oldChildDef.build() });
+
+        // new node type definition
+        QNodeTypeDefinitionBuilder newDef = new QNodeTypeDefinitionBuilder();
+        newDef.setName(NODE_TYPE1);
+        newDef.setSupertypes(new Name[] { NameConstants.NT_BASE });
+
+        QPropertyDefinitionBuilder newPropDef = new QPropertyDefinitionBuilder();
+        newPropDef.setDeclaringNodeType(NODE_TYPE1);
+        newPropDef.setName(PROP_NAME);
+        newPropDef.setRequiredType(PropertyType.UNDEFINED);
+        newPropDef.setMultiple(true);
+
+        newDef.setPropertyDefs(new QPropertyDefinition[]{newPropDef.build()});
+
+        QNodeDefinitionBuilder newChildDef = new QNodeDefinitionBuilder();
+        newChildDef.setRequiredPrimaryTypes(new Name[]{ NameConstants.NT_BASE, NODE_TYPE1, NameConstants.NT_FOLDER });
+        newChildDef.setRequiredPrimaryTypes(new Name[]{ NODE_TYPE1, NameConstants.NT_BASE });
+        newChildDef.setName(CHILD_NAME);
+        newChildDef.setDeclaringNodeType(oldDef.getName());
+
+        newDef.setChildNodeDefs(new QNodeDefinition[] { newChildDef.build() });
+
+        // change a property def isMultiple from false to true and requiredType STRING to UNDEFINED
+        // remove nt:folder from a node def's requiredPrimaryType constraint
+        NodeTypeDefDiff nodeTypeDefDiff = NodeTypeDefDiff.create(oldDef.build(), newDef.build());
+        System.out.println(nodeTypeDefDiff);
+        assertTrue(nodeTypeDefDiff.isTrivial());
+
+        // change a property def isMultiple from true to false and requiredType UNDEFINED to STRING
+        // add nt:folder to a node def's requiredPrimaryType constraint
+        nodeTypeDefDiff = NodeTypeDefDiff.create(newDef.build(), oldDef.build());
+        System.out.println(nodeTypeDefDiff);
+        assertTrue(nodeTypeDefDiff.isMajor());
+    }
+}
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java?rev=1415685&r1=1415684&r2=1415685&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java Fri Nov 30 15:16:42 2012
@@ -32,6 +32,7 @@ public class TestAll extends TestCase {
     public static Test suite() {
         TestSuite suite = new TestSuite("org.apache.jackrabbit.spi.commons.nodetype tests");
 
+        suite.addTestSuite(NodeTypeDefDiffTest.class);
         suite.addTestSuite(NodeDefinitionTemplateImplTest.class);
         suite.addTestSuite(PropertyDefinitionTemplateImplTest.class);