directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r721240 - in /directory: apacheds/branches/apacheds-mina2/core/src/main/java/org/apache/directory/server/core/changelog/ shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/ shared/branches/shared-mina2/lda...
Date Thu, 27 Nov 2008 16:46:15 GMT
Author: elecharny
Date: Thu Nov 27 08:46:14 2008
New Revision: 721240

URL: http://svn.apache.org/viewvc?rev=721240&view=rev
Log:
Last fix for DIRSERVER-1231 !

Modified:
    directory/apacheds/branches/apacheds-mina2/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java
    directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java
    directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
    directory/shared/branches/shared-mina2/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java

Modified: directory/apacheds/branches/apacheds-mina2/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mina2/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java?rev=721240&r1=721239&r2=721240&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-mina2/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java
(original)
+++ directory/apacheds/branches/apacheds-mina2/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java
Thu Nov 27 08:46:14 2008
@@ -48,7 +48,6 @@
 import org.apache.directory.shared.ldap.ldif.ChangeType;
 import org.apache.directory.shared.ldap.ldif.LdifEntry;
 import org.apache.directory.shared.ldap.ldif.LdifRevertor;
-import org.apache.directory.shared.ldap.ldif.LdifUtils;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.AttributeType;
@@ -333,8 +332,8 @@
         forward.setNewRdn( opCtx.getNewRdn().getUpName() );
         forward.setNewSuperior( opCtx.getParent().getUpName() );
 
-        List<LdifEntry> reverses = LdifUtils.reverseModifyRdn( ServerEntryUtils.toBasicAttributes(
serverEntry ), 
-            opCtx.getParent(), opCtx.getDn(), new Rdn( opCtx.getNewRdn() ) );
+        List<LdifEntry> reverses = LdifRevertor.reverseMoveAndRename(  
+            serverEntry, opCtx.getParent(), new Rdn( opCtx.getNewRdn() ), false );
         opCtx.setChangeLogEvent( changeLog.log( getPrincipal(), forward, reverses ) );
     }
 

Modified: directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java?rev=721240&r1=721239&r2=721240&view=diff
==============================================================================
--- directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java
(original)
+++ directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java
Thu Nov 27 08:46:14 2008
@@ -297,7 +297,17 @@
         // We have a composite old RDN, something like A=a+B=b
         // It does not matter if the RDNs overlap
         reverted.setChangeType( ChangeType.ModRdn );
-        reverted.setDn( newDn );
+        
+        if ( newSuperior != null )
+        {
+            LdapDN restoredDn = (LdapDN)((LdapDN)newSuperior.clone()).add( newRdn ); 
+            reverted.setDn( restoredDn );
+        }
+        else
+        {
+            reverted.setDn( newDn );
+        }
+        
         reverted.setNewRdn( oldRdn.getUpName() );
 
         // Is the newRdn's value present in the entry ?
@@ -355,13 +365,32 @@
     /**
      * A helper method which generates a reverted entry
      */
-    private static LdifEntry generateReverted( LdapDN newDn, Rdn oldRdn, boolean deleteOldRdn
)
+    private static LdifEntry generateReverted( LdapDN newSuperior, Rdn newRdn, LdapDN newDn,

+        Rdn oldRdn, boolean deleteOldRdn ) throws InvalidNameException
     {
         LdifEntry reverted = new LdifEntry();
         reverted.setChangeType( ChangeType.ModRdn );
-        reverted.setDn( newDn );
+
+        if ( newSuperior != null )
+        {
+            LdapDN restoredDn = (LdapDN)((LdapDN)newSuperior.clone()).add( newRdn ); 
+            reverted.setDn( restoredDn );
+        }
+        else
+        {
+            reverted.setDn( newDn );
+        }
+        
         reverted.setNewRdn( oldRdn.getUpName() );
         
+        if ( newSuperior != null )
+        {
+            LdapDN oldSuperior = ( LdapDN ) newDn.clone();
+
+            oldSuperior.remove( oldSuperior.size() - 1 );
+            reverted.setNewSuperior( oldSuperior.getUpName() );
+        }
+        
         // Delete the newRDN values
         reverted.setDeleteOldRdn( deleteOldRdn );
         
@@ -480,7 +509,7 @@
                         // Some of the new RDN AVAs existed in the entry
                         // We have to restore them, but we also have to remove
                         // the new values
-                        reverted = generateReverted( newDn, oldRdn, KEEP_OLD_RDN );
+                        reverted = generateReverted( newSuperior, newRdn, newDn, oldRdn,
KEEP_OLD_RDN );
                         
                         entries.add( reverted );
                         
@@ -493,7 +522,7 @@
                     {
                         // This is the simplest case, we don't have to restore
                         // some existing values (case 8.1 and 9.1)
-                        reverted = generateReverted( newDn, oldRdn, DELETE_OLD_RDN );
+                        reverted = generateReverted( newSuperior, newRdn, newDn, oldRdn,
DELETE_OLD_RDN );
                         
                         entries.add( reverted );
                     }
@@ -505,7 +534,7 @@
                         // Some of the new RDN AVAs existed in the entry
                         // We have to restore them, but we also have to remove
                         // the new values
-                        reverted = generateReverted( newDn, oldRdn, KEEP_OLD_RDN );
+                        reverted = generateReverted( newSuperior, newRdn, newDn, oldRdn,
KEEP_OLD_RDN );
                         
                         entries.add( reverted );
                         
@@ -516,7 +545,7 @@
                     else
                     {
                         // A much simpler case, as we just have to remove the newRDN
-                        reverted = generateReverted( newDn, oldRdn, DELETE_OLD_RDN );
+                        reverted = generateReverted( newSuperior, newRdn, newDn, oldRdn,
DELETE_OLD_RDN );
 
                         entries.add( reverted );
                     }
@@ -558,7 +587,7 @@
                     {
                         // In this case, we have to reestablish the removed ATAVs
                         // (Cases 12.2 and 13.2)
-                        reverted = generateReverted( newDn, oldRdn, KEEP_OLD_RDN );
+                        reverted = generateReverted( newSuperior, newRdn, newDn, oldRdn,
KEEP_OLD_RDN );
     
                         entries.add( reverted );
                     }
@@ -567,7 +596,7 @@
                         // We can simply remove all the new RDN atavs, as the
                         // overlapping values will be re-created.
                         // (Cases 12.1 and 13.1)
-                        reverted = generateReverted( newDn, oldRdn, DELETE_OLD_RDN );
+                        reverted = generateReverted( newSuperior, newRdn, newDn, oldRdn,
DELETE_OLD_RDN );
     
                         entries.add( reverted );
                     }
@@ -579,7 +608,7 @@
                     {
                         // In this case, we have to reestablish the removed ATAVs
                         // (Cases 10.2 and 11.2)
-                        reverted = generateReverted( newDn, oldRdn, KEEP_OLD_RDN );
+                        reverted = generateReverted( newSuperior, newRdn, newDn, oldRdn,
KEEP_OLD_RDN );
     
                         entries.add( reverted );
                         
@@ -591,7 +620,7 @@
                     {
                         // We are safe ! We can delete all the new Rdn ATAVs
                         // (Cases 10.1 and 11.1)
-                        reverted = generateReverted( newDn, oldRdn, DELETE_OLD_RDN );
+                        reverted = generateReverted( newSuperior, newRdn, newDn, oldRdn,
DELETE_OLD_RDN );
     
                         entries.add( reverted );
                     }

Modified: directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java?rev=721240&r1=721239&r2=721240&view=diff
==============================================================================
--- directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
(original)
+++ directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
Thu Nov 27 08:46:14 2008
@@ -20,11 +20,8 @@
 package org.apache.directory.shared.ldap.ldif;
 
 import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.List;
 
 import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 
 import org.apache.directory.shared.ldap.entry.Entry;
@@ -35,7 +32,6 @@
 import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
 import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
 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;
@@ -525,108 +521,5 @@
         
         return new String( buffer );
     }
-    
-    
-    /**
-     * Compute a reverse LDIF for a forward change which if in LDIF format
-     * would represent a modrdn operation.
-     *
-     * @param t0 the entry the way it was before changes were made
-     * @param t1_parentDn the new superior dn if this is a move, otherwise null
-     * @param t0_dn the dn of the entry being modified
-     * @param t1_rdn the new rdn to use
-     * @return A reverse LDIF, with potentially more than one reverse operation 
-     * @throws NamingException If something went wrong
-     */
-    public static List<LdifEntry> reverseModifyRdn( Attributes t0, LdapDN t1_parentDn,
LdapDN t0_dn, Rdn t1_rdn )
-            throws NamingException
-    {
-        if ( t0_dn == null )
-        {
-            throw new NullPointerException( "t0_dn must not be null" );
-        }
-
-        if ( t0_dn.size() == 0 )
-        {
-            throw new IllegalArgumentException( "Don't think about a move op on the rootDSE."
);
-        }
-
-        // if there is no rdn change then this is a raw move operation without
-        // a name change, we can delegate this to a simpler method
-        if ( t1_rdn == null )
-        {
-            List<LdifEntry> entries = new ArrayList<LdifEntry>(1);
-            LdifEntry entry = LdifRevertor.reverseMove( t1_parentDn, t0_dn );
-            entries.add( entry );
-            
-            return entries;
-        }
-
-        // -------------------------------------------------------------------
-        // Below here we do a move and change the name of the rdn all in one
-        // -------------------------------------------------------------------
-
-        // the reverse LDIF we will create
-        LdifEntry reverse = new LdifEntry();
-
-        // take the dn before the forward change was applied, and get it's
-        // parent, this parent will be the newSuperiorDn to be used for the
-        // reverse LDIF.  This is the same as t0_parentDn.
-        LdapDN reverseNewSuperiorDn = ( LdapDN ) t0_dn.clone();
-        reverseNewSuperiorDn.remove( reverseNewSuperiorDn.size() - 1 );
-
-        // take the rdn before the forward change, this will be the newRdn
-        // of the reverse LDIF, this is the same as a t0_rdn.
-        Rdn reverseNewRdn = t0_dn.getRdn();
-
-        // take the newSuperiorDn of the forward operation and append to it
-        // the new rdn of the forward operation to get the new dn after the
-        // change.  This will be the dn of the reverse ldif.  And this is just
-        // the same as t1_dn.
-        LdapDN reverseDn = ( LdapDN ) t1_parentDn.clone();
-        reverseDn.add( t1_rdn );
-
-        reverse.setDn( reverseDn );
-        reverse.setNewSuperior( reverseNewSuperiorDn.getUpName() );
-        reverse.setNewRdn( reverseNewRdn.getUpName() );
-        reverse.setChangeType( ChangeType.ModRdn );
-        reverse.setDeleteOldRdn( reverseDoDeleteOldRdn( t0, t1_rdn ) );
-
-        List<LdifEntry> entries = new ArrayList<LdifEntry>(1);
-        entries.add( reverse );
-        return entries;
-    }
-
-
-    private static boolean reverseDoDeleteOldRdn( Attributes t0_entry, Rdn t1_rdn )
-    {
-        // Consider simple example changes (rename or move does not matter)
-        // -------------------------------------------------------------------
-        // Example A:  t0 (ou=foo) => t1 (ou=bar)
-        //
-        // If at t0 ou=foo contained an ou value of 'bar' then the reverse
-        // LDIF must not delete the old rdn which would be bar.  Otherwise
-        // we must delete the old rdn.
-        //
-        // Example B:  t0 (cn=foo) => t1 (ou=bar)
-        //
-        // Here it's similar to example (A) except because the rdn attribute
-        // is different which shifts basically changes how we check for the
-        // presence of the rdn.  If cn=foo at t0 contains the ou attribute
-        // with a 'bar' value then we cannot delete the oldRdn in the reverse
-        // LDAP.  The logic below expresses this.
-        //
-        // @TODO this code stinks because it does not consider whitespace and
-        // case varience which requires schema awareness.  This must change.
-
-        // look up attribute in t0 using t1's rdn attribute type
-        Attribute t0_attr = t0_entry.get( t1_rdn.getUpType() );
-
-        // if we don't have that attribute in t0 then we need to make sure the
-        // reverse LDIF deletes the t1 rdn of 'bar', if we do have that attribute
-        // then we check if the value 'bar' is in it, if not there we delete
-        // if there we do not
-        return t0_attr == null || ! t0_attr.contains( t1_rdn.getUpValue() );
-    }
 }
 

Modified: directory/shared/branches/shared-mina2/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-mina2/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java?rev=721240&r1=721239&r2=721240&view=diff
==============================================================================
--- directory/shared/branches/shared-mina2/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
(original)
+++ directory/shared/branches/shared-mina2/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
Thu Nov 27 08:46:14 2008
@@ -19,8 +19,10 @@
  */
 package org.apache.directory.shared.ldap.ldif;
 
+import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -407,20 +409,13 @@
         LdapDN dn = new LdapDN( "cn=john doe, dc=example, dc=com" );
         LdapDN newSuperior = new LdapDN( "ou=system" );
 
-        Attributes attrs = new BasicAttributes( "objectClass", "person", true );
-        attrs.get( "objectClass" ).add( "uidObject" );
-                
-        Attribute attr = new BasicAttribute( "cn" );
-        
-        attr.add( "john doe" );
-        attr.add( "jack doe" );
-        
-        attrs.put( attr );
-        
-        attrs.put( "sn", "doe" );
-        attrs.put( "uid", "jdoe" );
+        Entry entry = new DefaultClientEntry( dn );
+        entry.add( "objectClass", "person", "uidObject" );
+        entry.add( "cn", "john doe", "jack doe" );
+        entry.add( "sn", "doe" );
+        entry.add( "uid", "jdoe" );
 
-        List<LdifEntry> reverseds = LdifUtils.reverseModifyRdn( attrs, newSuperior,
dn, new Rdn( "cn=jack doe" ) );
+        List<LdifEntry> reverseds = LdifRevertor.reverseMoveAndRename( entry, newSuperior,
new Rdn( "cn=jack doe" ), false );
 
         assertNotNull( reverseds );
         assertEquals( 1, reverseds.size() );
@@ -446,13 +441,13 @@
         LdapDN dn = new LdapDN( "cn=john doe, dc=example, dc=com" );
         LdapDN newSuperior = new LdapDN( "ou=system" );
 
-        Attributes attrs = new BasicAttributes( "objectClass", "person", true );
-        attrs.get( "objectClass" ).add( "uidObject" );
-        attrs.put( "cn", "john doe" );
-        attrs.put( "sn", "doe" );
-        attrs.put( "uid", "jdoe" );
+        Entry entry = new DefaultClientEntry( dn );
+        entry.add( "objectClass", "person", "uidObject" );
+        entry.add( "cn", "john doe" );
+        entry.add( "sn", "doe" );
+        entry.add( "uid", "jdoe" );
 
-        List<LdifEntry> reverseds = LdifUtils.reverseModifyRdn( attrs, newSuperior,
dn, new Rdn( "cn=jack doe" ) );
+        List<LdifEntry> reverseds = LdifRevertor.reverseMoveAndRename( entry, newSuperior,
new Rdn( "cn=jack doe" ), false );
 
         assertNotNull( reverseds );
         assertEquals( 1, reverseds.size() );



Mime
View raw message