directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r593866 - in /directory/shared/branches/bigbang/ldap/src: main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
Date Sun, 11 Nov 2007 11:31:26 GMT
Author: elecharny
Date: Sun Nov 11 03:31:24 2007
New Revision: 593866

URL: http://svn.apache.org/viewvc?rev=593866&view=rev
Log:
Fixed the issue with deleteOldRdn the correct way.
Added a test to check the missing case (simple Move operation)

Modified:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java?rev=593866&r1=593865&r2=593866&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
Sun Nov 11 03:31:24 2007
@@ -23,6 +23,7 @@
 import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.Base64;
 import org.apache.directory.shared.ldap.util.StringTools;
 
@@ -512,6 +513,7 @@
     {
         Entry entry = new Entry();
         LdapDN newDN = null;
+        Rdn oldRdn = modifiedDn.getRdn();
 
         if ( newSuperiorDn != null )
         {
@@ -529,13 +531,23 @@
         
         entry.setDn( newDN.getUpName() );
         entry.setChangeType( ChangeType.ModDn );
-        entry.setDeleteOldRdn( deleteOldRdn );
+        
+        if ( newRdn.equals( oldRdn ) )
+        {
+            // This is a move operation : no need to delete the oldRdn
+            entry.setDeleteOldRdn( false );
+        }
+        else
+        {
+            entry.setDeleteOldRdn( true );
+        }
+        
         entry.setNewRdn( modifiedDn.getRdn().getUpName() );
         
         return entry;
     }
     
-    
+
     /**
      * 
      * Compute the reversed LDIF for a modify request. We will deal with the 
@@ -557,6 +569,9 @@
     public static Entry reverseModify( LdapDN dn, List<ModificationItemImpl> forwardModifications,
                                        Attributes modifiedEntry ) throws NamingException
     {
+        // First, protect the original entry by cloning it : we will modify it
+        Attributes clonedEntry = (Attributes)modifiedEntry.clone();
+        
         Entry entry = new Entry();
         entry.setChangeType( ChangeType.Modify );
         
@@ -566,9 +581,13 @@
         // we create a list to temporarily store the modifications.
         List<ModificationItemImpl> reverseModifications = new ArrayList<ModificationItemImpl>();
         
-        // Loop through all the modifications
+        // Loop through all the modifications. For each modification, we will
+        // have to apply it to the modified entry in order to be able to generate
+        // the reversed modification
         for ( ModificationItem modification : forwardModifications )
         {
+            AttributeUtils.applyModification( clonedEntry, modification );
+
             switch ( modification.getModificationOp() )
             {
                 case DirContext.ADD_ATTRIBUTE :

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java?rev=593866&r1=593865&r2=593866&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
Sun Nov 11 03:31:24 2007
@@ -483,6 +483,28 @@
 
 
     /**
+     * Test a reversed move ModifyDN
+     */
+    @Test
+    public void testReverseModifyDNMove() throws NamingException
+    {
+        LdapDN dnModified = new LdapDN( "cn=test,ou=system" );
+        LdapDN dn = new LdapDN( "cn=test, dc=example, dc=com" );
+
+        Entry reversed = LdifUtils.reverseModifyDN( new LdapDN( "ou=system" ), dn, new Rdn(
"cn=test" ), false );
+
+        assertNotNull( reversed );
+        assertEquals( dnModified.getUpName(), reversed.getDn() );
+        assertEquals( ChangeType.ModDn, reversed.getChangeType() );
+        assertNull( reversed.getAttributes() );
+        assertFalse( reversed.isDeleteOldRdn() );
+        assertEquals( new Rdn( "cn=test" ).getUpName(), reversed.getNewRdn() );
+        assertNotNull( reversed.getNewSuperior() );
+        assertEquals( new LdapDN( "dc=example, dc=com" ).getUpName(), reversed.getNewSuperior()
);
+    }
+
+
+    /**
      * Test a reversed ModifyDN with a deleteOldRdn and a superior
      */
     @Test
@@ -873,5 +895,91 @@
         assertEquals( "ou", attr.getID() );
         
         assertEquals( ou, attr );
+    }
+    
+    
+    /**
+     * Test a multiple modifications reverse.
+     * 
+     * On the following entry :
+     *  dn: cn=test, ou=system
+     *  objectclass: top
+     *  objectclass: person
+     *  cn: test
+     *  sn: joe doe
+     *  l: USA
+     *  ou: apache
+     *  ou: acme corp
+     * 
+     * We will :
+     *  - add an 'ou' value 'BigCompany inc.'
+     *  - delete the 'l' attribute
+     *  - add the 'l=FR' attribute
+     *  - replace the 'l=FR' by a 'l=USA' attribute
+     *  - replace the 'ou' attribute with 'apache' value.
+     *  
+     * The modify ldif will be :
+     * 
+     *  dn: cn=test, ou=system
+     *  changetype: modify
+     *  add: ou
+     *  ou: BigCompany inc.
+     *  -
+     *  delete: l
+     *  -
+     *  add: l
+     *  l: FR
+     *  -
+     *  replace: l
+     *  l: USA
+     *  -
+     *  replace: ou
+     *  ou: apache
+     *  -
+     *  
+     * At the end, the entry will looks like :
+     *  dn: cn=test, ou=system
+     *  objectclass: top
+     *  objectclass: person
+     *  cn: test
+     *  sn: joe doe
+     *  l: USA
+     *  ou: apache
+     *  
+     * and the reversed LDIF will be :
+     * 
+     *  dn: cn=test, ou=system
+     *  changetype: modify
+     *  replace: ou
+     *  ou: BigCompany
+     *  -
+     *  replace: l
+     *  l: USA
+     *  -
+     *  delete: l
+     *  l: FR
+     *  -
+     *  add: l
+     *  l: USA
+     *  -
+     *  delete: ou 
+     *  ou: BigCompany inc.
+     *  -
+     * 
+     */
+    @Test
+    public void testReverseMultipleModifications() throws NamingException
+    {
+        // Create a 
+        ModifyRequest modify = new ModifyRequestImpl( 1 );
+        
+        LdapDN dn = new LdapDN( "cn=test, ou=system" );
+        
+        ModificationItem mod = new ModificationItemImpl( 
+            DirContext.REPLACE_ATTRIBUTE, new AttributeImpl( "ou" ) );
+
+        modify.setName( dn );
+        modify.addModification( mod );
+        
     }
 }



Mime
View raw message