You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2005/08/10 11:42:26 UTC

svn commit: r231203 - in /directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree: BTreeContextPartition.java BTreeSearchResultEnumeration.java

Author: akarasulu
Date: Wed Aug 10 02:42:23 2005
New Revision: 231203

URL: http://svn.apache.org/viewcvs?rev=231203&view=rev
Log:
changes ...

 o Added the ability to list all user attributes using the '*' operator as an
   attribute.  Hence the '*' can be used with any number of operational 
   attributes in the attribute list to control the returned attributes.
 o Added the ability to list all operational attributes using the '+' operator
   as an attribute.  Hence the '+' can be used with any number of user 
   attributes in the attribute list to control the returned attributes.
 o Enabled the use of '*' and '+' together to list all attributes within an 
   entry whether they are operational or user attributes.

notes ...

 o This fixes the issue posted by Kirill Kovalenko here:

     http://issues.apache.org/jira/browse/DIREVE-210


Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/BTreeContextPartition.java
    directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/BTreeSearchResultEnumeration.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/BTreeContextPartition.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/BTreeContextPartition.java?rev=231203&r1=231202&r2=231203&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/BTreeContextPartition.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/BTreeContextPartition.java Wed Aug 10 02:42:23 2005
@@ -96,7 +96,7 @@
      * the search engine used to search the database
      */
     private SearchEngine searchEngine = null;
-
+    private AttributeTypeRegistry attributeTypeRegistry = null;
 
     // ------------------------------------------------------------------------
     // C O N S T R U C T O R S
@@ -112,7 +112,7 @@
 
     public void init( ContextFactoryConfiguration factoryCfg, ContextPartitionConfiguration cfg ) throws NamingException
     {
-        AttributeTypeRegistry attributeTypeRegistry = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry();
+        attributeTypeRegistry = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry();
         OidRegistry oidRegistry = factoryCfg.getGlobalRegistries().getOidRegistry();
         ExpressionEvaluator evaluator = new ExpressionEvaluator( this, oidRegistry, attributeTypeRegistry );
         ExpressionEnumerator enumerator = new ExpressionEnumerator( this, attributeTypeRegistry, evaluator );
@@ -236,7 +236,7 @@
     {
         SearchResultEnumeration list;
         list = new BTreeSearchResultEnumeration( ArrayUtils.EMPTY_STRING_ARRAY,
-                list( getEntryId( base.toString() ) ), this );
+                list( getEntryId( base.toString() ) ), this, attributeTypeRegistry );
         return list;
     }
     
@@ -250,7 +250,7 @@
         
         underlying = searchEngine.search( base, env, filter, searchCtls );
         
-        return new BTreeSearchResultEnumeration( attrIds, underlying, this );
+        return new BTreeSearchResultEnumeration( attrIds, underlying, this, attributeTypeRegistry );
     }
 
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/BTreeSearchResultEnumeration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/BTreeSearchResultEnumeration.java?rev=231203&r1=231202&r2=231203&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/BTreeSearchResultEnumeration.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/BTreeSearchResultEnumeration.java Wed Aug 10 02:42:23 2005
@@ -23,7 +23,10 @@
 import javax.naming.directory.Attributes;
 
 import org.apache.ldap.common.message.LockableAttributesImpl;
+import org.apache.ldap.common.schema.AttributeType;
+import org.apache.ldap.common.schema.UsageEnum;
 import org.apache.ldap.server.enumeration.SearchResultEnumeration;
+import org.apache.ldap.server.schema.AttributeTypeRegistry;
 
 
 /**
@@ -41,12 +44,14 @@
 {
     /** Database used to lookup entries from */
     private BTreeContextPartition partition = null;
-    /** base of search for relative names */
     /** the attributes to return */
     private final String [] attrIds;
     /** underlying enumeration over IndexRecords */
     private final NamingEnumeration underlying;
 
+    private boolean attrIdsHasStar = false;
+    private boolean attrIdsHasPlus = false;
+    private AttributeTypeRegistry registry = null;
 
     /**
      * Creates an enumeration that returns entries packaged within SearchResults
@@ -57,11 +62,15 @@
      */
     public BTreeSearchResultEnumeration( String [] attrIds, 
                                     NamingEnumeration underlying,
-                                    BTreeContextPartition db )
+                                    BTreeContextPartition db,
+                                    AttributeTypeRegistry registry )
     {
         this.partition = db;
         this.attrIds = attrIds;
         this.underlying = underlying;
+        this.attrIdsHasStar = containsStar( attrIds );
+        this.attrIdsHasPlus = containsPlus( attrIds );
+        this.registry = registry;
     }
     
     
@@ -91,7 +100,7 @@
         IndexRecord rec = ( IndexRecord ) underlying.next();
         Attributes entry;
         String name = partition.getEntryUpdn( rec.getEntryId() );
-        
+
         if ( null == rec.getAttributes() )
         {
             rec.setAttributes( partition.lookup( rec.getEntryId() ) );
@@ -101,6 +110,82 @@
         {
             entry = ( Attributes ) rec.getAttributes().clone();
         }
+        else if ( attrIdsHasPlus && attrIdsHasStar )
+        {
+            entry = ( Attributes ) rec.getAttributes().clone();
+        }
+        else if ( attrIdsHasPlus )
+        {
+            entry = new LockableAttributesImpl();
+
+            // add all listed attributes
+            for ( int ii = 0; ii < attrIds.length; ii++ )
+            {
+                if ( attrIds[ii].equals( "+") )
+                {
+                    continue;
+                }
+                // there is no attribute by that name in the entry so we continue
+                if ( null == rec.getAttributes().get( attrIds[ii] ) )
+                {
+                    continue;
+                }
+
+                // clone attribute to stuff into the new resultant entry
+                Attribute attr = ( Attribute ) rec.getAttributes().get( attrIds[ii] ).clone();
+                entry.put( attr );
+            }
+
+            // add all operational attributes
+            NamingEnumeration list = rec.getAttributes().getIDs();
+            while ( list.hasMore() )
+            {
+                String attrId = ( String ) list.next();
+                AttributeType attrType = registry.lookup( attrId );
+                if ( attrType.getUsage() == UsageEnum.USERAPPLICATIONS )
+                {
+                    continue;
+                }
+
+                Attribute attr = ( Attribute ) rec.getAttributes().get( attrId ).clone();
+                entry.put( attr );
+            }
+        }
+        else if ( attrIdsHasStar )
+        {
+            entry = new LockableAttributesImpl();
+
+            // add all listed operational attributes
+            for ( int ii = 0; ii < attrIds.length; ii++ )
+            {
+                if ( attrIds[ii].equals( "*") )
+                {
+                    continue;
+                }
+                // there is no attribute by that name in the entry so we continue
+                if ( null == rec.getAttributes().get( attrIds[ii] ) )
+                {
+                    continue;
+                }
+
+                // clone attribute to stuff into the new resultant entry
+                Attribute attr = ( Attribute ) rec.getAttributes().get( attrIds[ii] ).clone();
+                entry.put( attr );
+            }
+
+            // add all user attributes
+            NamingEnumeration list = rec.getAttributes().getIDs();
+            while ( list.hasMore() )
+            {
+                String attrId = ( String ) list.next();
+                AttributeType attrType = registry.lookup( attrId );
+                if ( attrType.getUsage() == UsageEnum.USERAPPLICATIONS )
+                {
+                    Attribute attr = ( Attribute ) rec.getAttributes().get( attrId ).clone();
+                    entry.put( attr );
+                }
+            }
+        }
         else
         {
             entry = new LockableAttributesImpl();
@@ -122,7 +207,45 @@
         return new BTreeSearchResult( rec.getEntryId(), name, null, entry );
     }
 
-    
+
+    private boolean containsStar( String[] ids )
+    {
+        if ( ids == null )
+        {
+            return false;
+        }
+
+        for ( int ii = ids.length - 1; ii >= 0; ii-- )
+        {
+            if ( ids[ii].trim().equals( "*" ) )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+
+    private boolean containsPlus( String[] ids )
+    {
+        if ( ids == null )
+        {
+            return false;
+        }
+
+        for ( int ii = ids.length - 1; ii >= 0; ii-- )
+        {
+            if ( ids[ii].trim().equals( "+" ) )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+
     /**
      * @see java.util.Enumeration#hasMoreElements()
      */