directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1292307 - in /directory: apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/ apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/exception/ apacheds/trunk/core-integ/src/test/java/org/apache/dir...
Date Wed, 22 Feb 2012 14:26:22 GMT
Author: elecharny
Date: Wed Feb 22 14:26:22 2012
New Revision: 1292307

URL: http://svn.apache.org/viewvc?rev=1292307&view=rev
Log:
Fixed the rename operation : it's now allowed to rename an entry on itself.

Added:
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/rename/RenameIT.java
Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/exception/ExceptionServiceIT.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/RenameReferralIT.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/rename/RenamePerfIT.java
    directory/apacheds/trunk/interceptors/exception/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
    directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifRevertor.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java?rev=1292307&r1=1292306&r2=1292307&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java
Wed Feb 22 14:26:22 2012
@@ -774,9 +774,9 @@ public class LdapCoreSessionConnection i
             }
             else
             {
-                result.setDiagnosticMessage( "Attempt to move entry onto itself." );
-                result.setResultCode( ResultCodeEnum.ENTRY_ALREADY_EXISTS );
-                result.setMatchedDn( modDnRequest.getName() );
+                // This might be a simple change, we will update the DN and the entry
+                // with the new provided value by using a modify operation later on
+                session.rename( modDnRequest );
             }
 
         }

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/exception/ExceptionServiceIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/exception/ExceptionServiceIT.java?rev=1292307&r1=1292306&r2=1292307&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/exception/ExceptionServiceIT.java
(original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/exception/ExceptionServiceIT.java
Wed Feb 22 14:26:22 2012
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.core.exception;
 
@@ -149,25 +149,19 @@ public class ExceptionServiceIT extends 
     {
         LdapConnection connection = getAdminConnection( getService() );
 
-        Entry entry = new DefaultEntry( "ou=users,ou=groups,ou=system" );
-        entry.add( SchemaConstants.OBJECT_CLASS_AT, "OrganizationalUnit" );
-        entry.add( SchemaConstants.OU_AT, "users" );
+        Entry entry = new DefaultEntry( "ou=users,ou=groups,ou=system",
+            "ObjectClass: top",
+            "ObjectClass: OrganizationalUnit",
+            "ou: users" );
 
         connection.add( entry );
 
-        try
-        {
-            connection.rename( entry.getDn(), new Rdn( "ou=users" ) );
-            fail();
-        }
-        catch ( LdapEntryAlreadyExistsException leaee )
-        {
-            assertTrue( true );
-        }
+        connection.rename( entry.getDn(), new Rdn( "ou=users" ) );
 
-        Entry userzEntry = new DefaultEntry( "ou=userz,ou=groups,ou=system" );
-        userzEntry.add( SchemaConstants.OBJECT_CLASS_AT, "OrganizationalUnit" );
-        userzEntry.add( SchemaConstants.OU_AT, "userz" );
+        Entry userzEntry = new DefaultEntry( "ou=userz,ou=groups,ou=system",
+            "ObjectClass: top",
+            "ObjectClass: OrganizationalUnit",
+            "ou: userz" );
 
         connection.add( userzEntry );
 
@@ -238,18 +232,43 @@ public class ExceptionServiceIT extends 
     // ------------------------------------------------------------------------
     // ModifyRdn Operation Tests
     // ------------------------------------------------------------------------
+    /**
+     * Test modifyRdn operation success when the object is renamed in place.
+     *
+     * @throws Exception on error
+     */
+    @Test
+    public void testAllowModifyRdnEntry() throws Exception
+    {
+        LdapConnection connection = getAdminConnection( getService() );
 
+        Entry entry = connection.lookup( "ou=users,ou=system" );
+        
+        assertNotNull( entry );
+        assertEquals( 1, entry.get( "ou" ).size() );
+        assertEquals( "users", entry.get( "ou" ).getString() );
+
+        connection.rename( "ou=users,ou=system", "ou=Users" );
+        
+        entry = connection.lookup( "ou=Users,ou=system" );
+        
+        assertNotNull( entry );
+        assertEquals( 1, entry.get( "ou" ).size() );
+        assertEquals( "Users", entry.get( "ou" ).getString() );
+    }
+
+    
     /**
-     * Test modifyRdn operation failure when the object renamed is non-existant.
+     * Test modifyRdn operation failure when the object renamed is existant.
      *
      * @throws Exception on error
      */
-    @Test(expected = LdapEntryAlreadyExistsException.class)
+    @Test(expected=LdapEntryAlreadyExistsException.class)
     public void testFailModifyRdnEntryAlreadyExists() throws Exception
     {
         LdapConnection connection = getAdminConnection( getService() );
 
-        connection.rename( "ou=users,ou=system", "ou=groups" );
+        connection.rename( "ou=users,ou=system", "ou=Groups" );
     }
 
 

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/RenameReferralIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/RenameReferralIT.java?rev=1292307&r1=1292306&r2=1292307&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/RenameReferralIT.java
(original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/RenameReferralIT.java
Wed Feb 22 14:26:22 2012
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.core.jndi.referral;
 
@@ -53,7 +53,7 @@ import org.junit.runner.RunWith;
 
 
 /**
- * Tests the referral handling functionality for the Modify operation 
+ * Tests the referral handling functionality for the Modify operation
  * within the server's core.
  * 
  * The Move operation is a ModifyDN where the Rdn is changed, not the superior.
@@ -148,7 +148,7 @@ public class RenameReferralIT extends Ab
 
     
     /**
-     * Test a rename of a non existing entry (not a referral), with no referral 
+     * Test a rename of a non existing entry (not a referral), with no referral
      * in its ancestor.
      */
     @Test
@@ -167,7 +167,7 @@ public class RenameReferralIT extends Ab
 
 
     /**
-     * Test a rename of a non existing entry (not a referral), with a referral 
+     * Test a rename of a non existing entry (not a referral), with a referral
      * in its ancestor, using JNDI throw.
      */
     @Test
@@ -185,7 +185,7 @@ public class RenameReferralIT extends Ab
             Set<String> expectedRefs = new HashSet<String>();
             expectedRefs.add( "ldap://hostd/cn=Emmanuel%20Lecharny,ou=apache,ou=Roles,dc=apache,dc=org"
);
             
-            do 
+            do
             {
                 String ref = (String)re.getReferralInfo();
                 
@@ -200,7 +200,7 @@ public class RenameReferralIT extends Ab
 
 
     /**
-     * Test a rename of a non existing entry (not a referral), with a referral 
+     * Test a rename of a non existing entry (not a referral), with a referral
      * in its ancestor, using the Core API without the ManageDsaIT flag.
      */
     @Test
@@ -221,9 +221,9 @@ public class RenameReferralIT extends Ab
             Set<String> expectedRefs = new HashSet<String>();
             expectedRefs.add( "ldap://hostd/cn=Emmanuel%20Lecharny,ou=apache,ou=Roles,dc=apache,dc=org"
);
             
-            do 
+            do
             {
-                String ref = (String)re.getReferralInfo();
+                String ref = re.getReferralInfo();
                 
                 assertTrue( expectedRefs.contains( ref ) );
                 nbRefs ++;
@@ -236,7 +236,7 @@ public class RenameReferralIT extends Ab
 
 
     /**
-     * Test a rename of an existing entry (not a referral), with no referral 
+     * Test a rename of an existing entry (not a referral), with no referral
      * in its ancestor.
      */
     @Test
@@ -278,7 +278,7 @@ public class RenameReferralIT extends Ab
 
 
     /**
-     * Test a rename of an existing referral, using JNDI throw. 
+     * Test a rename of an existing referral, using JNDI throw.
      */
     @Test
     public void testRenameExistingReferralJNDIThrow() throws Exception
@@ -295,7 +295,7 @@ public class RenameReferralIT extends Ab
             Set<String> expectedRefs = new HashSet<String>();
             expectedRefs.add( "ldap://hostd/ou=Roles,dc=apache,dc=org" );
             
-            do 
+            do
             {
                 String ref = (String)re.getReferralInfo();
                 
@@ -310,8 +310,8 @@ public class RenameReferralIT extends Ab
 
 
     /**
-     * Test a rename of an existing referral, using the Core API without 
-     * the ManageDsaIt flag. 
+     * Test a rename of an existing referral, using the Core API without
+     * the ManageDsaIt flag.
      */
     @Test
     public void testRenameExistingReferralCoreApiWithoutManageDsaIt() throws Exception
@@ -331,9 +331,9 @@ public class RenameReferralIT extends Ab
             Set<String> expectedRefs = new HashSet<String>();
             expectedRefs.add( "ldap://hostd/ou=Roles,dc=apache,dc=org" );
             
-            do 
+            do
             {
-                String ref = (String)re.getReferralInfo();
+                String ref = re.getReferralInfo();
                 
                 assertTrue( expectedRefs.contains( ref ) );
                 nbRefs ++;
@@ -382,7 +382,7 @@ public class RenameReferralIT extends Ab
             Set<String> expectedRefs = new HashSet<String>();
             expectedRefs.add( "ldap://hostd/ou=Roles,dc=apache,dc=org" );
             
-            do 
+            do
             {
                 String ref = (String)re.getReferralInfo();
                 
@@ -418,9 +418,9 @@ public class RenameReferralIT extends Ab
             Set<String> expectedRefs = new HashSet<String>();
             expectedRefs.add( "ldap://hostd/ou=Roles,dc=apache,dc=org" );
             
-            do 
+            do
             {
-                String ref = (String)re.getReferralInfo();
+                String ref = re.getReferralInfo();
                 
                 assertTrue( expectedRefs.contains( ref ) );
                 nbRefs ++;

Added: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/rename/RenameIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/rename/RenameIT.java?rev=1292307&view=auto
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/rename/RenameIT.java
(added)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/rename/RenameIT.java
Wed Feb 22 14:26:22 2012
@@ -0,0 +1,117 @@
+/*
+ *  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.directory.server.core.operations.rename;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.server.core.annotations.ContextEntry;
+import org.apache.directory.server.core.annotations.CreateDS;
+import org.apache.directory.server.core.annotations.CreateIndex;
+import org.apache.directory.server.core.annotations.CreatePartition;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.server.core.integ.IntegrationUtils;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.Value;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test the rename operation performances
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+@RunWith(FrameworkRunner.class)
+@CreateDS(name = "RenamePerfDS",
+    partitions =
+    {
+        @CreatePartition(
+            name = "example",
+            suffix = "dc=example,dc=com",
+            contextEntry =
+                @ContextEntry(
+                    entryLdif =
+                        "dn: dc=example,dc=com\n" +
+                        "dc: example\n" +
+                        "objectClass: top\n" +
+                        "objectClass: domain\n\n"),
+            indexes =
+            {
+                @CreateIndex(attribute = "objectClass"),
+                @CreateIndex(attribute = "sn"),
+                @CreateIndex(attribute = "cn")
+            })
+    },
+    enableChangeLog = true)
+public class RenameIT extends AbstractLdapTestUnit
+{
+    @Test
+    public void testRenameUperCaseRdn() throws Exception
+    {
+        LdapConnection connection = IntegrationUtils.getAdminConnection( getService() );
+
+        String oldDn = "cn=test,ou=system";
+
+        Dn dn = new Dn( oldDn );
+        Entry entry = new DefaultEntry( getService().getSchemaManager(), dn,
+            "ObjectClass: top",
+            "ObjectClass: person",
+            "sn: TEST",
+            "cn: test0" );
+
+        connection.add( entry );
+        
+        Entry original = connection.lookup( oldDn );
+        
+        assertNotNull( original );
+
+        connection.rename( oldDn, "cn=TEST" );
+        
+        Entry renamed = connection.lookup( oldDn );
+        
+        assertNotNull( renamed );
+        assertEquals( original.getDn(), renamed.getDn() );
+        Attribute attribute = renamed.get( "cn" );
+        Set<String> expected = new HashSet<String>();
+        expected.add( "test0" );
+        expected.add( "TEST" );
+        int found = 0;
+        
+        for ( Value<?> value : attribute )
+        {
+            String val = value.getString();
+            
+            assertTrue( expected.contains( val ) );
+            found++;
+        }
+        
+        assertEquals( 2, found );
+    }
+}

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/rename/RenamePerfIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/rename/RenamePerfIT.java?rev=1292307&r1=1292306&r2=1292307&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/rename/RenamePerfIT.java
(original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/rename/RenamePerfIT.java
Wed Feb 22 14:26:22 2012
@@ -28,9 +28,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.apache.directory.server.core.integ.IntegrationUtils;
 import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
-import org.apache.directory.shared.ldap.model.entry.DefaultModification;
 import org.apache.directory.shared.ldap.model.entry.Entry;
-import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -119,31 +117,4 @@ public class RenamePerfIT extends Abstra
         System.out.println( "Delta : " + deltaWarmed + "( " + ( ( ( nbIterations - 5000 )
* 1000 ) / deltaWarmed ) + " per s ) /" + ( t1 - t0 ) );
         connection.close();
     }
-
-    
-    @Test
-    public void testRenameUperCase() throws Exception
-    {
-        LdapConnection connection = IntegrationUtils.getAdminConnection( getService() );
-
-        String oldDn = "cn=test,ou=system";
-
-        Dn dn = new Dn( oldDn );
-        Entry entry = new DefaultEntry( getService().getSchemaManager(), dn );
-        entry.add( "ObjectClass", "top", "person" );
-        entry.add( "sn", "TEST" );
-        entry.add( "cn", "test0" );
-
-        connection.add( entry );
-        
-        Entry original = connection.lookup( oldDn );
-        
-        System.out.println( "Original : " + original );
-
-        connection.modify( oldDn, new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
"cn", "TEST" ) );
-        
-        Entry renamed = connection.lookup( oldDn );
-        
-        System.out.println( "Renamed : " + renamed );
-    }
 }

Modified: directory/apacheds/trunk/interceptors/exception/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/exception/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java?rev=1292307&r1=1292306&r2=1292307&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/exception/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
(original)
+++ directory/apacheds/trunk/interceptors/exception/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
Wed Feb 22 14:26:22 2012
@@ -370,10 +370,16 @@ public class ExceptionInterceptor extend
 
         if ( nexus.hasEntry( new HasEntryOperationContext( renameContext.getSession(), newDn
) ) )
         {
-            LdapEntryAlreadyExistsException e;
-            e = new LdapEntryAlreadyExistsException( I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS,
newDn.getName() ) );
-            //e.setResolvedName( DNFactory.create( newDn.getName() ) );
-            throw e;
+            // Ok, the target entry already exists.
+            // If the target entry has the same name than the modified entry, it's a rename
on itself,
+            // we want to allow this.
+            if ( !newDn.equals( dn ) )
+            {
+                LdapEntryAlreadyExistsException e;
+                e = new LdapEntryAlreadyExistsException( I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS,
newDn.getName() ) );
+                //e.setResolvedName( DNFactory.create( newDn.getName() ) );
+                throw e;
+            }
         }
 
         // Remove the previous entry from the notAnAlias cache

Modified: directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java?rev=1292307&r1=1292306&r2=1292307&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
(original)
+++ directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
Wed Feb 22 14:26:22 2012
@@ -1438,10 +1438,7 @@ public class SchemaInterceptor extends B
         {
             AttributeType type = schemaManager.lookupAttributeTypeRegistry( atav.getType()
);
 
-            if ( !entry.contains( type, atav.getNormValue() ) )
-            {
-                entry.add( new DefaultAttribute( type, atav.getValue() ) );
-            }
+            entry.add( new DefaultAttribute( type, atav.getValue() ) );
         }
 
         // Substitute the Rdn and check if the new entry is correct

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java?rev=1292307&r1=1292306&r2=1292307&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
Wed Feb 22 14:26:22 2012
@@ -62,7 +62,7 @@ public class DefaultAttribute implements
     /** The normalized ID (will be the OID if we have a AttributeType) */
     private String id;
 
-    /** Tells if the attribute is Human Readable or not. When not set, 
+    /** Tells if the attribute is Human Readable or not. When not set,
      * this flag is null. */
     private Boolean isHR;
 
@@ -425,12 +425,12 @@ public class DefaultAttribute implements
      * If the initial Attribute is not schema aware, the copy will be if the attributeType
      * argument is not null.
      *
-     * @param attributeType The attribute's type 
+     * @param attributeType The attribute's type
      * @param attribute The attribute to be copied
      */
     public DefaultAttribute( AttributeType attributeType, Attribute attribute ) throws LdapException
     {
-        // Copy the common values. isHR is only available on a ServerAttribute 
+        // Copy the common values. isHR is only available on a ServerAttribute
         this.attributeType = attributeType;
         this.id = attribute.getId();
         this.upId = attribute.getUpId();
@@ -767,7 +767,13 @@ public class DefaultAttribute implements
                                 stringValue.apply( attributeType );
                             }
 
-                            if ( values.add( val ) )
+                            if ( values.contains( val ) )
+                            {
+                                // Replace the value
+                                values.remove( val );
+                                values.add( val );
+                            }
+                            else if ( values.add( val ) )
                             {
                                 nbAdded++;
                             }
@@ -847,11 +853,11 @@ public class DefaultAttribute implements
             {
                 if ( val == null )
                 {
-                    // We have a null value. If the HR flag is not set, we will consider

+                    // We have a null value. If the HR flag is not set, we will consider
                     // that the attribute is not HR. We may change this later
                     if ( isHR == null )
                     {
-                        // This is the first value. Add both types, as we 
+                        // This is the first value. Add both types, as we
                         // don't know yet the attribute type's, but we may
                         // know later if we add some new value.
                         // We have to do that because we are using a Set,
@@ -869,7 +875,7 @@ public class DefaultAttribute implements
                         // The attribute type is binary.
                         nullBinaryValue = new BinaryValue( ( byte[] ) null );
 
-                        // Don't add a value if it already exists. 
+                        // Don't add a value if it already exists.
                         if ( !values.contains( nullBinaryValue ) )
                         {
                             values.add( nullBinaryValue );
@@ -882,7 +888,7 @@ public class DefaultAttribute implements
                         // The attribute is HR
                         nullStringValue = new StringValue( ( String ) null );
 
-                        // Don't add a value if it already exists. 
+                        // Don't add a value if it already exists.
                         if ( !values.contains( nullStringValue ) )
                         {
                             values.add( nullStringValue );
@@ -891,7 +897,7 @@ public class DefaultAttribute implements
                 }
                 else
                 {
-                    // Let's check the value type. 
+                    // Let's check the value type.
                     if ( val instanceof StringValue )
                     {
                         // We have a String value
@@ -960,7 +966,7 @@ public class DefaultAttribute implements
             }
         }
 
-        // Last, not least, if a nullValue has been added, and if other 
+        // Last, not least, if a nullValue has been added, and if other
         // values are all String, we have to keep the correct nullValue,
         // and to remove the other
         if ( nullValueAdded )
@@ -1244,7 +1250,7 @@ public class DefaultAttribute implements
         }
         else
         {
-            // Iterate through all the values, and quit if we 
+            // Iterate through all the values, and quit if we
             // don't find one in the values. We have to separate the check
             // depending on the isHR flag value.
             if ( isHR )
@@ -1335,9 +1341,9 @@ public class DefaultAttribute implements
             }
             else
             {
-                // As the attribute type is binary, we have to convert 
+                // As the attribute type is binary, we have to convert
                 // the values before checking for them in the values
-                // Iterate through all the values, and quit if we 
+                // Iterate through all the values, and quit if we
                 // don't find one in the values
                 for ( String val : vals )
                 {
@@ -1354,7 +1360,7 @@ public class DefaultAttribute implements
         {
             if ( isHR )
             {
-                // Iterate through all the values, and quit if we 
+                // Iterate through all the values, and quit if we
                 // don't find one in the values
                 for ( String val : vals )
                 {
@@ -1400,7 +1406,7 @@ public class DefaultAttribute implements
         {
             if ( !isHR )
             {
-                // Iterate through all the values, and quit if we 
+                // Iterate through all the values, and quit if we
                 // don't find one in the values
                 for ( byte[] val : vals )
                 {
@@ -1412,9 +1418,9 @@ public class DefaultAttribute implements
             }
             else
             {
-                // As the attribute type is String, we have to convert 
+                // As the attribute type is String, we have to convert
                 // the values before checking for them in the values
-                // Iterate through all the values, and quit if we 
+                // Iterate through all the values, and quit if we
                 // don't find one in the values
                 for ( byte[] val : vals )
                 {
@@ -1431,7 +1437,7 @@ public class DefaultAttribute implements
         {
             if ( !isHR )
             {
-                // Iterate through all the values, and quit if we 
+                // Iterate through all the values, and quit if we
                 // don't find one in the values
                 for ( byte[] val : vals )
                 {
@@ -1819,11 +1825,11 @@ public class DefaultAttribute implements
 
 
     /**
-     * The hashCode is based on the id, the isHR flag and 
+     * The hashCode is based on the id, the isHR flag and
      * on the internal values.
-     *  
+     * 
      * @see Object#hashCode()
-     * @return the instance's hashcode 
+     * @return the instance's hashcode
      */
     public int hashCode()
     {
@@ -1936,7 +1942,7 @@ public class DefaultAttribute implements
 
 
     /**
-     * @see Object#toString() 
+     * @see Object#toString()
      */
     public String toString()
     {
@@ -1971,7 +1977,7 @@ public class DefaultAttribute implements
 
     /**
      * This is the place where we serialize attributes, and all theirs
-     * elements. 
+     * elements.
      * 
      * {@inheritDoc}
      */

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifRevertor.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifRevertor.java?rev=1292307&r1=1292306&r2=1292307&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifRevertor.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifRevertor.java
Wed Feb 22 14:26:22 2012
@@ -475,14 +475,6 @@ public final class LdifRevertor
         if ( newRdn.size() == 1 )
         {
             // We have a simple new Rdn, something like A=a
-            if ( ( oldRdn.size() == 1 ) && ( oldRdn.equals( newRdn ) ) )
-            {
-                // We have a simple old Rdn, something like A=a
-                // If the values overlap, we can't rename the entry, just get out
-                // with an error
-                throw new LdapInvalidDnException( I18n.err( I18n.ERR_12080 ) );
-            }
-
             reverted = revertEntry( entry, newDn, newSuperior, oldRdn, newRdn );
 
             entries.add( reverted );



Mime
View raw message