You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2010/12/20 18:16:30 UTC

svn commit: r1051212 - /directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/PartitionsDiffComputer.java

Author: pamarcelot
Date: Mon Dec 20 17:16:30 2010
New Revision: 1051212

URL: http://svn.apache.org/viewvc?rev=1051212&view=rev
Log:
Fixed the search operation context creation for returning attributes.

Modified:
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/PartitionsDiffComputer.java

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/PartitionsDiffComputer.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/PartitionsDiffComputer.java?rev=1051212&r1=1051211&r2=1051212&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/PartitionsDiffComputer.java (original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/PartitionsDiffComputer.java Mon Dec 20 17:16:30 2010
@@ -25,11 +25,11 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
 import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
 import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
 import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
 import org.apache.directory.shared.ldap.entry.DefaultModification;
 import org.apache.directory.shared.ldap.entry.Entry;
@@ -37,6 +37,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.filter.FilterParser;
 import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.ldif.ChangeType;
@@ -46,6 +47,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.AttributeTypeOptions;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.SchemaUtils;
 import org.apache.directory.shared.ldap.schema.UsageEnum;
 
 
@@ -210,25 +212,21 @@ public class PartitionsDiffComputer
                     }
                 }
 
-                // TODO add doc
+                // Creating a search operation context to get the children of the current entry
                 SearchOperationContext soc = new SearchOperationContext( null );
-                //                soc.setReturningAttributes( convertReturningAttributes( originalPartition.getSchemaManager(),
-                //                    attributeIds ) );
-                soc.setAllUserAttributes( true );
+                setReturningAttributes( originalPartition.getSchemaManager(), attributeIds, soc );
                 soc.setDn( originalEntry.getDn() );
                 soc.setScope( SearchScope.ONELEVEL );
                 soc.setFilter( FilterParser.parse( originalPartition.getSchemaManager(), "(objectClass=*)" ) );
                 soc.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
 
-                // TODO add doc
+                // Looking for the children of the current entry
                 EntryFilteringCursor cursor = originalPartition.search( soc );
                 while ( cursor.next() )
                 {
-                    ClonedServerEntry entry = cursor.get();
-                    originalEntries.add( entry.getClonedEntry() );
+                    originalEntries.add( cursor.get().getClonedEntry() );
                 }
             }
-
         }
         catch ( Exception e )
         {
@@ -239,20 +237,62 @@ public class PartitionsDiffComputer
     }
 
 
-    private Set<AttributeTypeOptions> convertReturningAttributes( SchemaManager schemaManager, String[] attributeIds )
+    /**
+     * Sets the returning attributes to the search operation context.
+     *
+     * @param schemaManager
+     *      the schema manager
+     * @param attributeIds
+     *      the attribute IDs
+     * @param soc
+     *      the search operation context
+     * @throws LdapException
+     */
+    private void setReturningAttributes( SchemaManager schemaManager, String[] attributeIds,
+        SearchOperationContext soc ) throws LdapException
     {
-        Set<AttributeTypeOptions> set = new HashSet<AttributeTypeOptions>();
-
-        for ( String attributeId : attributeIds )
+        if ( attributeIds != null && attributeIds.length != 0 )
         {
-            AttributeType attributeType = schemaManager.getAttributeType( attributeId );
-            if ( attributeType != null )
+            Set<AttributeTypeOptions> returningAttributes = new HashSet<AttributeTypeOptions>();
+
+            for ( String returnAttribute : attributeIds )
             {
-                set.add( new AttributeTypeOptions( attributeType ) );
+                if ( returnAttribute.equals( SchemaConstants.NO_ATTRIBUTE ) )
+                {
+                    soc.setNoAttributes( true );
+                    continue;
+                }
+
+                if ( returnAttribute.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
+                {
+                    soc.setAllOperationalAttributes( true );
+                    continue;
+                }
+
+                if ( returnAttribute.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) )
+                {
+                    soc.setAllUserAttributes( true );
+                    continue;
+                }
+
+                String id = SchemaUtils.stripOptions( returnAttribute );
+                Set<String> options = SchemaUtils.getOptions( returnAttribute );
+
+                AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
+                AttributeTypeOptions attrOptions = new AttributeTypeOptions( attributeType, options );
+
+                returningAttributes.add( attrOptions );
             }
-        }
 
-        return set;
+            // reset the noAttrubte flag if it is already set cause that will be ignored if any other AT is requested
+            if ( soc.isNoAttributes()
+                && ( soc.isAllUserAttributes() || soc.isAllOperationalAttributes() || ( !returningAttributes.isEmpty() ) ) )
+            {
+                soc.setNoAttributes( false );
+            }
+
+            soc.setReturningAttributes( returningAttributes );
+        }
     }