You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/01/07 17:20:48 UTC

svn commit: r1056374 - /directory/apacheds/branches/apacheds-AP/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java

Author: elecharny
Date: Fri Jan  7 16:20:47 2011
New Revision: 1056374

URL: http://svn.apache.org/viewvc?rev=1056374&view=rev
Log:
Update the entry adding the entryUUID of subentries for the searchOperation

Modified:
    directory/apacheds/branches/apacheds-AP/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java

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=1056374&r1=1056373&r2=1056374&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  7 16:20:47 2011
@@ -302,8 +302,8 @@ public class SubentryInterceptor extends
         c.add( ExceptionInterceptor.class.getName() );
         c.add( OperationalAttributeInterceptor.class.getName() );
         c.add( SchemaInterceptor.class.getName() );
-        c.add( SubentryInterceptor.class.getName() );
         c.add( CollectiveAttributeInterceptor.class.getName() );
+        c.add( SubentryInterceptor.class.getName() );
         c.add( EventInterceptor.class.getName() );
         c.add( TriggerInterceptor.class.getName() );
         BYPASS_INTERCEPTORS = Collections.unmodifiableCollection( c );
@@ -349,7 +349,20 @@ public class SubentryInterceptor extends
     {
         public boolean accept( SearchingOperationContext searchContext, ClonedServerEntry entry ) throws Exception
         {
-            updateEntry( entry );
+            if ( entry.getOriginalEntry().containsAttribute( ADMINISTRATIVE_ROLE_AT ) ||
+                entry.getOriginalEntry().contains( OBJECT_CLASS_AT, SchemaConstants.SUBENTRY_OC ) )
+            {
+                // No need to update anything
+                return true;
+            }
+
+            List<Modification> modifications = updateEntry( entry );
+            
+            if ( modifications != null )
+            {
+                // The entry has been updated, we have to apply the modifications in the entry
+                applyModifications( entry, modifications );
+            }
 
             return true;
         }
@@ -357,6 +370,36 @@ public class SubentryInterceptor extends
     
     
     /**
+     * Apply the modifications done on an entry. We should just have REPLACE operations
+     * @param entry
+     * @param modifications
+     * @throws LdapException
+     */
+    private void applyModifications( Entry entry, List<Modification> modifications ) throws LdapException
+    {
+        for ( Modification modification : modifications )
+        {
+            switch ( modification.getOperation() )
+            {
+                case ADD_ATTRIBUTE :
+                    entry.add( modification.getAttribute() );
+                    break;
+                    
+                case REMOVE_ATTRIBUTE :
+                    entry.remove( modification.getAttribute() );
+                    break;
+                    
+                case REPLACE_ATTRIBUTE :
+                    entry.remove( modification.getAttribute() );
+                    entry.add( modification.getAttribute() );
+                    
+                    break;
+            }
+        }
+    }
+    
+    
+    /**
      * Creates a specific Subentry instances using the Auxiliary ObjectClasses stored into 
      * the Subentry Entry. We may have more than one instance created, if the entry is managing
      * more than one role.
@@ -642,16 +685,17 @@ public class SubentryInterceptor extends
      * Update the seqNumber for each kind of role. The entry will be updated in the backend only
      * if its seqNumbers are not up to date.
      */
-    private boolean updateEntry( Entry entry ) throws LdapException
+    private List<Modification> updateEntry( Entry entry ) throws LdapException
     {
         List<Modification> modificationAcs = updateEntry( entry, directoryService.getAccessControlAPCache(), ACCESS_CONTROL_SEQ_NUMBER_AT, ACCESS_CONTROL_SUBENTRIES_UUID_AT );
         List<Modification> modificationCas = updateEntry( entry, directoryService.getCollectiveAttributeAPCache(), COLLECTIVE_ATTRIBUTE_SEQ_NUMBER_AT, COLLECTIVE_ATTRIBUTE_SUBENTRIES_UUID_AT );
         List<Modification> modificationSss = updateEntry( entry, directoryService.getSubschemaAPCache(), SUB_SCHEMA_SEQ_NUMBER_AT, SUBSCHEMA_SUBENTRY_UUID_AT );
         List<Modification> modificationTes = updateEntry( entry, directoryService.getTriggerExecutionAPCache(), TRIGGER_EXECUTION_SEQ_NUMBER_AT, TRIGGER_EXECUTION_SUBENTRIES_UUID_AT );
+        List<Modification> modifications = null;
         
         if ( ( modificationAcs != null ) || ( modificationCas != null ) || ( modificationSss != null ) || (modificationTes != null ) )
         {
-            List<Modification> modifications = new ArrayList<Modification>();
+            modifications = new ArrayList<Modification>();
             
             if ( modificationAcs != null )
             {
@@ -680,11 +724,9 @@ public class SubentryInterceptor extends
             modCtx.setEntry( (ClonedServerEntry)entry );
 
             directoryService.getOperationManager().modify( modCtx );
-            
-            return true;
         }
         
-        return false;
+        return modifications;
     }
 
     
@@ -2291,11 +2333,13 @@ public class SubentryInterceptor extends
             return entry;
         }
         
-        // This is a normal entry, update its seqNumbers if neede
-        if ( updateEntry( entry ) )
+        // This is a normal entry, update its seqNumbers if needed
+        List<Modification> modifications = updateEntry( entry );
+        
+        if ( modifications != null )
         {
-            // Get the entry back again
-            entry = nextInterceptor.lookup( lookupContext );
+            // update the entry
+            applyModifications( entry, modifications );
         }
 
         return entry;