directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1059081 - in /directory/apacheds/branches/apacheds-AP: core-api/src/main/java/org/apache/directory/server/core/administrative/ core-integ/src/test/java/org/apache/directory/server/core/subtree/ core/src/main/java/org/apache/directory/serve...
Date Fri, 14 Jan 2011 17:20:18 GMT
Author: elecharny
Date: Fri Jan 14 17:20:18 2011
New Revision: 1059081

URL: http://svn.apache.org/viewvc?rev=1059081&view=rev
Log:
o Added a toString() method to the subentryCache
o Added some test for the AP rename of an IAP
o Partially implemented the IAP rename

Modified:
    directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubentryCache.java
    directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryRenameOperationIT.java
    directory/apacheds/branches/apacheds-AP/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java

Modified: directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubentryCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubentryCache.java?rev=1059081&r1=1059080&r2=1059081&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubentryCache.java
(original)
+++ directory/apacheds/branches/apacheds-AP/core-api/src/main/java/org/apache/directory/server/core/administrative/SubentryCache.java
Fri Jan 14 17:20:18 2011
@@ -403,4 +403,37 @@ public class SubentryCache implements It
             unlock();
         }
     }
+    
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( "Subentry cache :\n" );
+        
+        lockRead();
+        sb.append( "  DN cache :\n" ).append( dnCache ).append( "\n" );
+        
+        sb.append( "  UUID cache :\n" );
+        
+        for ( String uuid : uuidCache.keySet() )
+        {
+            sb.append( uuid ).append( " -> " );
+            
+            for ( Subentry subentry : uuidCache.get( uuid ) )
+            {
+                if ( subentry != null )
+                {
+                    sb.append( subentry );
+                }
+            }
+        }
+        
+        unlock();
+        
+        return sb.toString();
+    }
 }

Modified: directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryRenameOperationIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryRenameOperationIT.java?rev=1059081&r1=1059080&r2=1059081&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryRenameOperationIT.java
(original)
+++ directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryRenameOperationIT.java
Fri Jan 14 17:20:18 2011
@@ -21,6 +21,7 @@ package org.apache.directory.server.core
 
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -59,7 +60,13 @@ import org.junit.runner.RunWith;
         "objectClass: person",
         "cn: testUser",
         "sn: test User",
-        "userpassword: test"
+        "userpassword: test",
+        "",
+        // An entry used as a root for tests
+        "dn: ou=test,ou=system",
+        "objectClass: top",
+        "objectClass: organizationalUnit",
+        "ou: test"
     })
 public class SubentryRenameOperationIT extends AbstractSubentryUnitTest
 {
@@ -116,6 +123,108 @@ public class SubentryRenameOperationIT e
     }
     
     
+    /**
+     * Test a rename of an IAP. We will use this data structure :
+     * <pre>
+     * ou=test,ou=system
+     *   |
+     *   +-- [ou=SAP]
+     *        |
+     *        +-- <cn=test1> base="ou=europe,ou=IAP2,ou=IAP1", will select europe,
france, paris
+     *        |
+     *        +-- ou=IAP1
+     *              |
+     *              +-- <cn=test2> base="ou=france,ou=europe,ou=IAP2" will select france,
paris
+     *              |
+     *              +-- ou=IAP2
+     *                    |
+     *                    +-- <cn=test3> base="ou=paris,ou=france,ou=europe" will select
paris
+     *                    |
+     *                    +-- ou=europe
+     *                          |
+     *                          +-- ou=france
+     *                                |
+     *                                +-- ou=paris 
+     * </pre>
+     * 
+     * We will rename ou=IAP2, and the cn=test1 or cn=test2 will now select nothing
+     */
+    @Test
+    public void testRenameIAP() throws Exception
+    {
+        // Create the APs
+        createCaSAP( "ou=SAP,ou=test,ou=system" );
+        createCaIAP( "ou=IAP1,ou=SAP,ou=test,ou=system" );
+        createCaIAP( "ou=IAP2,ou=IAP1,ou=SAP,ou=test,ou=system" );
+        
+        // Create the subentries
+        createCaSubentry( "cn=test1,ou=SAP,ou=test,ou=system", "{base \"ou=europe,ou=IAP2,ou=IAP1\"}"
);
+        createCaSubentry( "cn=test2,ou=IAP1,ou=SAP,ou=test,ou=system", "{base \"ou=france,ou=europe,ou=IAP2\"}"
);
+        createCaSubentry( "cn=test3,ou=IAP2,ou=IAP1,ou=SAP,ou=test,ou=system", "{base \"ou=paris,ou=france,ou=europe\"}"
);
+        
+        // Add entries
+        Entry e1 = LdifUtils.createEntry( 
+            "ou=europe,ou=IAP2,ou=IAP1,ou=SAP,ou=test,ou=system", 
+            "ObjectClass: top",
+            "ObjectClass: organizationalUnit", 
+            "ou: europe" );
+        
+        createEntryAdmin( e1 );
+
+        Entry e2 = LdifUtils.createEntry( 
+            "ou=france,ou=europe,ou=IAP2,ou=IAP1,ou=SAP,ou=test,ou=system", 
+            "ObjectClass: top",
+            "ObjectClass: organizationalUnit", 
+            "ou: france" );
+        
+        createEntryAdmin( e2 );
+
+        Entry e3 = LdifUtils.createEntry( 
+            "ou=paris,ou=france,ou=europe,ou=IAP2,ou=IAP1,ou=SAP,ou=test,ou=system", 
+            "ObjectClass: top",
+            "ObjectClass: organizationalUnit", 
+            "ou: paris" );
+        
+        createEntryAdmin( e3 );
+        
+        // Check that the entries are referring the subentries
+        String sapUuid = getEntryUuid( "cn=test1,ou=SAP,ou=test,ou=system" );
+        String iap1Uuid = getEntryUuid( "cn=test2,ou=IAP1,ou=SAP,ou=test,ou=system" );
+        String iap2Uuid = getEntryUuid( "cn=test3,ou=IAP2,ou=IAP1,ou=SAP,ou=test,ou=system"
);
+        
+        e1 = adminConnection.lookup( "ou=europe,ou=IAP2,ou=IAP1,ou=SAP,ou=test,ou=system",
"+" );
+        e2 = adminConnection.lookup( "ou=france,ou=europe,ou=IAP2,ou=IAP1,ou=SAP,ou=test,ou=system",
"+" );
+        e3 = adminConnection.lookup( "ou=paris,ou=france,ou=europe,ou=IAP2,ou=IAP1,ou=SAP,ou=test,ou=system",
"+" );
+        
+        assertTrue( e1.contains( "CollectiveAttributeSubentriesUUID", sapUuid ) );
+        assertTrue( e2.contains( "CollectiveAttributeSubentriesUUID", sapUuid, iap1Uuid )
);
+        assertTrue( e3.contains( "CollectiveAttributeSubentriesUUID", sapUuid, iap1Uuid,
iap2Uuid ) );
+        
+        dumpBase( "ou=test,ou=system" );
+        dumpSubentries( "ou=test,ou=system" );
+        dumpApCache();
+        dumpSubentryCache();
+        
+        // Now, rename IAP2
+        ModifyDnResponse response = adminConnection.rename( "ou=IAP2,ou=IAP1,ou=SAP,ou=test,ou=system",
"ou=IAPnew" );
+        
+        assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() );
+        
+        dumpBase( "ou=test,ou=system" );
+        dumpSubentries( "ou=test,ou=system" );
+        dumpApCache();
+        dumpSubentryCache();
+        
+        // Check the references
+        e1 = adminConnection.lookup( "ou=europe,ou=IAPnew,ou=IAP1,ou=SAP,ou=test,ou=system",
"+" );
+        e2 = adminConnection.lookup( "ou=france,ou=europe,ou=IAPnew,ou=IAP1,ou=SAP,ou=test,ou=system",
"+" );
+        e3 = adminConnection.lookup( "ou=paris,ou=france,ou=europe,ou=IAPnew,ou=IAP1,ou=SAP,ou=test,ou=system",
"+" );
+        
+        assertFalse( e1.containsAttribute( "CollectiveAttributeSubentriesUUID" ) );
+        assertFalse( e2.containsAttribute( "CollectiveAttributeSubentriesUUID" ) );
+        assertTrue( e3.contains( "CollectiveAttributeSubentriesUUID", iap2Uuid ) );
+        assertFalse( e3.contains( "CollectiveAttributeSubentriesUUID", iap1Uuid, sapUuid
) );
+    }
     
     
     // ===================================================================

Modified: directory/apacheds/branches/apacheds-AP/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java?rev=1059081&r1=1059080&r2=1059081&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
(original)
+++ directory/apacheds/branches/apacheds-AP/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
Fri Jan 14 17:20:18 2011
@@ -789,7 +789,7 @@ public class SubentryInterceptor extends
                     entrySeqNumber = adminPoint.getSeqNumber();
                 }
 
-                if ( initialSeqNumber < adminPoint.getSeqNumber() )
+                if ( ( initialSeqNumber < adminPoint.getSeqNumber() ) || seqNumberUpdated
)
                 {
                     // Evaluate the current AP on the entry for each subentry
                     for ( Subentry subentry : adminPoint.getSubentries() )
@@ -2780,11 +2780,13 @@ public class SubentryInterceptor extends
             switch ( adminPoint.getRole() )
             {
                 case AccessControlSpecificArea :
+                case AccessControlInnerArea :
                     directoryService.getAccessControlAPCache().remove( oldDn );
                     directoryService.getAccessControlAPCache().add( newDn, adminPoint );
                     break;
                     
                 case CollectiveAttributeSpecificArea :
+                case CollectiveAttributeInnerArea :
                     directoryService.getCollectiveAttributeAPCache().remove( oldDn );
                     directoryService.getCollectiveAttributeAPCache().add( newDn, adminPoint
);
                     break;
@@ -2795,6 +2797,7 @@ public class SubentryInterceptor extends
                     break;
                     
                 case TriggerExecutionSpecificArea :
+                case TriggerExecutionInnerArea :
                     directoryService.getTriggerExecutionAPCache().remove( oldDn );
                     directoryService.getTriggerExecutionAPCache().add( newDn, adminPoint
);
                     break;
@@ -2873,7 +2876,8 @@ public class SubentryInterceptor extends
                 applyRenameApCache( oldDn, newDn );
                 
                 // And check if we have to change the parent's AP seqNumbers
-                List<Modification> modifications = null;
+                List<Modification> modifications = new ArrayList<Modification>();
+                long newSeqNumber = -1L;
                 
                 for ( AdministrativeRoleEnum role : getRoles( adminPointAT ) )
                 {
@@ -2884,10 +2888,11 @@ public class SubentryInterceptor extends
                             
                         case CollectiveAttribute :
                             DnNode<AdministrativePoint> apCache = directoryService.getCollectiveAttributeAPCache();
-                            DnNode<AdministrativePoint> apNode = apCache.getParentWithElement(
newDn );
+                            DnNode<AdministrativePoint> apNode = apCache.getNode( newDn
);
 
                             // We have an AdministrativePoint for this entry, get its SeqNumber
                             AdministrativePoint adminPoint = apNode.getElement();
+                            AdministrativePoint currentAP = apNode.getElement();
                             EntryAttribute seqNumberAttribute = entry.get( COLLECTIVE_ATTRIBUTE_SEQ_NUMBER_AT
);
 
                             // We have to recurse : starting from the IAP, we go up the AP
tree
@@ -2901,12 +2906,12 @@ public class SubentryInterceptor extends
 
                             do
                             {
-                                if ( adminPoint.isSpecific() )
+                                if ( currentAP.isSpecific() )
                                 {
                                     sapFound = true;
                                 }
 
-                                Set<Subentry> subentries = adminPoint.getSubentries();
+                                Set<Subentry> subentries = currentAP.getSubentries();
                                 
                                 if ( ( subentries != null ) && ( subentries.size()
!= 0 ) )
                                 {
@@ -2945,50 +2950,44 @@ public class SubentryInterceptor extends
                                 
                                 // Go down one level
                                 apNode = apNode.getParentWithElement();
-                                adminPoint = apNode.getElement();
+                                currentAP = apNode.getElement();
                             } while ( !sapFound && !updateSN );
                             
+                            if ( updateSN )
+                            {
+                                if ( newSeqNumber == -1L )
+                                {
+                                    newSeqNumber = directoryService.getNewApSeqNumber();
+
+                                    adminPoint.setSeqNumber( newSeqNumber );
+                                    
+                                    EntryAttribute newSeqNumberAT = new DefaultEntryAttribute(
COLLECTIVE_ATTRIBUTE_SEQ_NUMBER_AT, Long.toString( newSeqNumber ) );
+                                    Modification seqNumberModification = new DefaultModification(
ModificationOperation.REPLACE_ATTRIBUTE, newSeqNumberAT );
+                                    
+                                    modifications.add( seqNumberModification );
+                                }
+                            }
                             break;
 
                         case SubSchema :
                         case TriggerExecution :
                     }
+                    
+                    // Update the AdminPoint
+                    
 
-                    // Now, update the seqNumber
-                    /*
+                    // Now, update the AP entry
                     // If we have updated the entry, create the list of modifications to
apply
-                    if ( updateSN )
+                    if ( modifications.size() > 0 )
                     {
-                        // Create the list of modifications : we will inject REPLACE operations.

-                        modifications = new ArrayList<Modification>();
-                        
-                        // The seqNubmer
-                        EntryAttribute newSeqNumberAT = new DefaultEntryAttribute( seqNumberAT,
Long.toString( entrySeqNumber ) );
-                        Modification seqNumberModification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
newSeqNumberAT );
-                        
-                        modifications.add( seqNumberModification );
-                        
-                        // The subentry UUID, if any
-                        if ( ( subentryUuids != null ) && ( subentryUuids.size()
!= 0 ) )
-                        {
-                            EntryAttribute newSubentryUuidAT = new DefaultEntryAttribute(
subentryUuidAT, subentryUuids.toArray( new String[]{} ) );
-                            Modification subentryUuiMod = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
newSubentryUuidAT );
-
-                            modifications.add( subentryUuiMod );
-                        }
-                        else
-                        {
-                            // We may have to remove UUID refs from the entry
-                            if ( entry.containsAttribute( subentryUuidAT ) )
-                            {
-                                EntryAttribute newSubentryUuidAT = new DefaultEntryAttribute(
subentryUuidAT );
-                                Modification subentryUuiMod = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE,
newSubentryUuidAT );
+                        ModifyOperationContext modCtx = new ModifyOperationContext( directoryService.getAdminSession()
);
+                        modCtx.setByPassed( BYPASS_INTERCEPTORS );
+                        modCtx.setDn( entry.getDn() );
+                        modCtx.setModItems( modifications );
+                        modCtx.setEntry( renameContext.getEntry() );
 
-                                modifications.add( subentryUuiMod );
-                            }
-                        }
+                        directoryService.getOperationManager().modify( modCtx );
                     }
-                    */
                 }
             }
             else



Mime
View raw message