directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From malder...@apache.org
Subject svn commit: r562916 - in /directory/apacheds/trunk/mitosis/src: main/java/org/apache/directory/mitosis/operation/OperationFactory.java test/java/org/apache/directory/mitosis/service/ReplicationServiceITest.java
Date Sun, 05 Aug 2007 17:30:04 GMT
Author: malderson
Date: Sun Aug  5 10:30:02 2007
New Revision: 562916

URL: http://svn.apache.org/viewvc?view=rev&rev=562916
Log:
Fix for DIRSERVER-778, where an OperationNotSupportedException would occur when renaming an
entry with java.naming.ldap.deleteRDN set to false.

Modified:
    directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/operation/OperationFactory.java
    directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceITest.java

Modified: directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/operation/OperationFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/operation/OperationFactory.java?view=diff&rev=562916&r1=562915&r2=562916
==============================================================================
--- directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/operation/OperationFactory.java
(original)
+++ directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/operation/OperationFactory.java
Sun Aug  5 10:30:02 2007
@@ -25,19 +25,25 @@
 import javax.naming.NameAlreadyBoundException;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
-import javax.naming.OperationNotSupportedException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
+import org.apache.directory.mitosis.common.CSN;
+import org.apache.directory.mitosis.common.CSNFactory;
+import org.apache.directory.mitosis.common.Constants;
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.common.UUIDFactory;
+import org.apache.directory.mitosis.configuration.ReplicationConfiguration;
 import org.apache.directory.server.core.DirectoryServiceConfiguration;
 import org.apache.directory.server.core.interceptor.context.EntryOperationContext;
 import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
 import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
 import org.apache.directory.server.core.interceptor.context.OperationContext;
 import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.partition.Partition;
 import org.apache.directory.server.core.partition.PartitionNexus;
 import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
@@ -46,12 +52,6 @@
 import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.NamespaceTools;
-import org.apache.directory.mitosis.common.CSN;
-import org.apache.directory.mitosis.common.CSNFactory;
-import org.apache.directory.mitosis.common.Constants;
-import org.apache.directory.mitosis.common.ReplicaId;
-import org.apache.directory.mitosis.common.UUIDFactory;
-import org.apache.directory.mitosis.configuration.ReplicationConfiguration;
 
 
 /**
@@ -239,18 +239,11 @@
     /**
      * Returns a new {@link Operation} that performs "move" operation.
      * Please note this operation is the most fragile operation I've written
-     * so it should be reviewed completely again.  This methods
-     * doesn't allow you to specify <tt>deleteOldRn</tt> as <tt>false</tt>
-     * for now.  This limitation should be removed too.
+     * so it should be reviewed completely again.
      */
     public Operation newMove( LdapDN oldName, LdapDN newParentName, String newRdn, boolean
deleteOldRn )
         throws NamingException
     {
-        if ( !deleteOldRn )
-        {
-            throw new OperationNotSupportedException( "deleteOldRn must be true." );
-        }
-
         // Prepare to create composite operations
         CSN csn = newCSN();
         CompositeOperation result = new CompositeOperation( csn );
@@ -277,8 +270,33 @@
             Attributes entry = sr.getAttributes();
             if ( oldEntryName.size() == oldName.size() )
             {
-                entry.remove( NamespaceTools.getRdnAttribute( oldName.get( oldName.size()
- 1 ) ) );
-                entry.put( NamespaceTools.getRdnAttribute( newRdn ), NamespaceTools.getRdnValue(
newRdn ) );
+                if ( deleteOldRn )
+                {
+                    // Delete the old RDN attribute value
+                    String oldRDNAttributeID = oldName.getRdn().getUpType();
+                    Attribute oldRDNAttribute = entry.get( oldRDNAttributeID );
+                    if ( oldRDNAttribute != null )
+                    {
+                        boolean removed = oldRDNAttribute.remove( oldName.getRdn().getUpValue()
);
+                        if ( removed && oldRDNAttribute.size() == 0 )
+                        {
+                            // Now an empty attribute, remove it.
+                            entry.remove( oldRDNAttributeID );
+                        }
+                    }
+                }
+                // Add the new RDN attribute value.
+                String newRDNAttributeID = NamespaceTools.getRdnAttribute( newRdn );
+                String newRDNAttributeValue = NamespaceTools.getRdnValue( newRdn );
+                Attribute newRDNAttribute = entry.get( newRDNAttributeID );
+                if ( newRDNAttribute != null )
+                {
+                    newRDNAttribute.add( newRDNAttributeValue );
+                }
+                else
+                {
+                    entry.put( newRDNAttributeID, newRDNAttributeValue );
+                }
             }
 
             // Calculate new name from newParentName, oldEntryName, and newRdn.

Modified: directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceITest.java?view=diff&rev=562916&r1=562915&r2=562916
==============================================================================
--- directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceITest.java
(original)
+++ directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceITest.java
Sun Aug  5 10:30:02 2007
@@ -30,6 +30,7 @@
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
+import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
@@ -55,6 +56,7 @@
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.mina.util.AvailablePortFinder;
 
 /**
@@ -84,8 +86,9 @@
         String dn2 = "cn=test2,ou=system";
         testOneWayBind( dn1 );
         testOneWayModify( dn1 );
-        testOneWayRename( dn1, dn2 );
-        testOneWayUnbind( dn2 );
+        testOneWayRename( dn1, dn2, true );
+        testOneWayRename( dn2, dn1, false );
+        testOneWayUnbind( dn1 );
     }
     
     /**
@@ -171,12 +174,15 @@
         Assert.assertEquals( newValue, getAttributeValue( ctxC, dn, "ou" ) );
     }
 
-    private void testOneWayRename( String dn1, String dn2 ) throws Exception
+    private void testOneWayRename( String dn1, String dn2, boolean deleteRDN ) throws Exception
     {
         LdapContext ctxA = getReplicaContext( "A" );
         LdapContext ctxB = getReplicaContext( "B" );
         LdapContext ctxC = getReplicaContext( "C" );
         
+        String oldRDNValue = (String) new LdapDN(dn1).getRdn().getUpValue();
+        
+        ctxA.addToEnvironment( "java.naming.ldap.deleteRDN", Boolean.toString( deleteRDN
) );
         ctxA.rename( dn1, dn2 );
         
         replicationServices.get( "A" ).replicate();
@@ -189,6 +195,26 @@
         Assert.assertNotNull( ctxA.lookup( dn2 ) );
         Assert.assertNotNull( ctxB.lookup( dn2 ) );
         Assert.assertNotNull( ctxC.lookup( dn2 ) );
+
+        Attribute oldRDNAttributeA = ctxA.getAttributes( dn2 ).get( new LdapDN(dn1).getRdn().getUpType()
);
+        Attribute oldRDNAttributeB = ctxB.getAttributes( dn2 ).get( new LdapDN(dn1).getRdn().getUpType()
);
+        Attribute oldRDNAttributeC = ctxC.getAttributes( dn2 ).get( new LdapDN(dn1).getRdn().getUpType()
);
+        boolean oldRDNExistsA = attributeContainsValue( oldRDNAttributeA, oldRDNValue );
+        boolean oldRDNExistsB = attributeContainsValue( oldRDNAttributeB, oldRDNValue );
+        boolean oldRDNExistsC = attributeContainsValue( oldRDNAttributeC, oldRDNValue );
+        
+        if ( deleteRDN )
+        {
+            Assert.assertFalse( oldRDNExistsA );
+            Assert.assertFalse( oldRDNExistsB );
+            Assert.assertFalse( oldRDNExistsC );
+        }
+        else
+        {
+            Assert.assertTrue( oldRDNExistsA );
+            Assert.assertTrue( oldRDNExistsB );
+            Assert.assertTrue( oldRDNExistsC );
+        }
     }
     
     private void testOneWayUnbind( String dn ) throws Exception
@@ -226,6 +252,19 @@
     {
         Attribute attr = ctx.getAttributes( name ).get( attrName );
         return ( String ) attr.get();
+    }
+    
+    private boolean attributeContainsValue( Attribute attribute, Object value ) throws NamingException
+    {
+        boolean foundValue = false;
+        for ( NamingEnumeration ne = attribute.getAll(); ne.hasMore(); )
+        {
+            if ( value.equals( ne.next() ) )
+            {
+                foundValue = true;
+            }
+        }
+        return foundValue;
     }
 
     @SuppressWarnings("unchecked")



Mime
View raw message