From 421e89ed67043e6d978f39418ef7002e7c160cba Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Thu, 29 Jan 2009 16:22:43 +0000
Subject: [PATCH] Fix issue 3561: aliased attributes not returned properly

---
 opends/src/server/org/opends/server/core/SearchOperationBasis.java |  269 -----------------------------------------------------
 1 files changed, 3 insertions(+), 266 deletions(-)

diff --git a/opends/src/server/org/opends/server/core/SearchOperationBasis.java b/opends/src/server/org/opends/server/core/SearchOperationBasis.java
index 456aa04..2285719 100644
--- a/opends/src/server/org/opends/server/core/SearchOperationBasis.java
+++ b/opends/src/server/org/opends/server/core/SearchOperationBasis.java
@@ -30,12 +30,10 @@
 import org.opends.messages.Message;
 
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 import org.opends.server.api.ClientConnection;
 import org.opends.server.api.plugin.PluginResult;
@@ -714,183 +712,10 @@
 
     // Make a copy of the entry and pare it down to only include the set
     // of requested attributes.
-    Entry entryToReturn;
-    boolean omitReal = isVirtualAttributesOnly();
-    boolean omitVirtual = isRealAttributesOnly();
-    if ((getAttributes() == null) || getAttributes().isEmpty())
-    {
-      entryToReturn =
-          entry.duplicateWithoutOperationalAttributes(typesOnly,
-              omitReal, omitVirtual);
-    }
-    else
-    {
-      entryToReturn = entry.duplicateWithoutAttributes();
+    Entry entryToReturn =
+        entry.filterEntry(getAttributes(), typesOnly,
+            isVirtualAttributesOnly(), isRealAttributesOnly());
 
-      for (String attrName : getAttributes())
-      {
-        if (attrName.equals("*"))
-        {
-          // This is a special placeholder indicating that all user attributes
-          // should be returned.
-          if (!omitReal)
-          {
-            if (typesOnly)
-            {
-              // First, add the placeholder for the objectclass
-              // attribute.
-              AttributeType ocType =
-                  DirectoryServer.getObjectClassAttributeType();
-              List<Attribute> ocList = new ArrayList<Attribute>(1);
-              ocList.add(Attributes.empty(ocType));
-              entryToReturn.putAttribute(ocType, ocList);
-            }
-            else
-            {
-              // First, add the objectclass attribute.
-              Attribute ocAttr = entry.getObjectClassAttribute();
-              if (ocAttr != null)
-              {
-                entryToReturn.replaceAttribute(ocAttr);
-              }
-            }
-          }
-
-          // Next iterate through all the user attributes and include them.
-          for (AttributeType t : entry.getUserAttributes().keySet())
-          {
-            List<Attribute> attrList =
-                duplicateUserAttribute(entry, t, null, typesOnly,
-                    omitReal, omitVirtual);
-            if (attrList != null)
-            {
-              entryToReturn.putAttribute(t, attrList);
-            }
-          }
-
-          continue;
-        }
-        else if (attrName.equals("+"))
-        {
-          // This is a special placeholder indicating that all operational
-          // attributes should be returned.
-          for (AttributeType t : entry.getOperationalAttributes().keySet())
-          {
-            List<Attribute> attrList =
-                duplicateOperationalAttribute(entry, t, null,
-                    typesOnly, omitReal, omitVirtual);
-            if (attrList != null)
-            {
-              entryToReturn.putAttribute(t, attrList);
-            }
-          }
-
-          continue;
-        }
-
-        String lowerName;
-        HashSet<String> options;
-        int semicolonPos = attrName.indexOf(';');
-        if (semicolonPos > 0)
-        {
-          lowerName = toLowerCase(attrName.substring(0, semicolonPos));
-          int nextPos = attrName.indexOf(';', semicolonPos+1);
-          options = new HashSet<String>();
-          while (nextPos > 0)
-          {
-            options.add(attrName.substring(semicolonPos+1, nextPos));
-
-            semicolonPos = nextPos;
-            nextPos = attrName.indexOf(';', semicolonPos+1);
-          }
-          options.add(attrName.substring(semicolonPos+1));
-        }
-        else
-        {
-          lowerName = toLowerCase(attrName);
-          options = null;
-        }
-
-        AttributeType attrType = DirectoryServer.getAttributeType(lowerName);
-        if (attrType == null)
-        {
-          boolean added = false;
-          for (AttributeType t : entry.getUserAttributes().keySet())
-          {
-            if (t.hasNameOrOID(lowerName))
-            {
-              List<Attribute> attrList =
-                  duplicateUserAttribute(entry, t, options, typesOnly,
-                      omitReal, omitVirtual);
-              if (attrList != null)
-              {
-                entryToReturn.putAttribute(t, attrList);
-                added = true;
-                break;
-              }
-            }
-          }
-
-          if (added)
-          {
-            continue;
-          }
-
-          for (AttributeType t : entry.getOperationalAttributes().keySet())
-          {
-            if (t.hasNameOrOID(lowerName))
-            {
-              List<Attribute> attrList =
-                  duplicateOperationalAttribute(entry, t, options,
-                      typesOnly, omitReal, omitVirtual);
-              if (attrList != null)
-              {
-                entryToReturn.putAttribute(t, attrList);
-                break;
-              }
-            }
-          }
-        }
-        else
-        {
-          if (attrType.isObjectClassType()) {
-            if (!omitReal)
-            {
-              if (typesOnly)
-              {
-                AttributeType ocType =
-                    DirectoryServer.getObjectClassAttributeType();
-                List<Attribute> ocList = new ArrayList<Attribute>(1);
-                ocList.add(Attributes.empty(ocType));
-                entryToReturn.putAttribute(ocType, ocList);
-              }
-              else
-              {
-                List<Attribute> attrList = new ArrayList<Attribute>(1);
-                attrList.add(entry.getObjectClassAttribute());
-                entryToReturn.putAttribute(attrType, attrList);
-              }
-            }
-          }
-          else
-          {
-            List<Attribute> attrList =
-                duplicateOperationalAttribute(entry, attrType, options,
-                    typesOnly, omitReal, omitVirtual);
-            if (attrList == null)
-            {
-              attrList =
-                  duplicateUserAttribute(entry, attrType, options,
-                      typesOnly, omitReal, omitVirtual);
-            }
-            if (attrList != null)
-            {
-              entryToReturn.putAttribute(attrType, attrList);
-            }
-          }
-        }
-      }
-    }
 
     // If there is a matched values control, then further pare down the entry
     // based on the filters that it contains.
@@ -1626,92 +1451,4 @@
             ERR_SEARCH_BASE_DOESNT_EXIST.get(String.valueOf(getBaseDN()));
     appendErrorMessage(message);
   }
-
-
-  // Copies non-empty attributes.
-  private List<Attribute> duplicateAttribute(
-       List<Attribute> attrList,
-       Set<String> options,
-       boolean omitValues,
-       boolean omitReal,
-       boolean omitVirtual)
-  {
-    if (attrList == null)
-    {
-      return null;
-    }
-
-    ArrayList<Attribute> duplicateList =
-         new ArrayList<Attribute>(attrList.size());
-    for (Attribute a : attrList)
-    {
-      if (a.hasAllOptions(options))
-      {
-        if (omitReal && !a.isVirtual())
-        {
-          continue;
-        }
-        else if (omitVirtual && a.isVirtual())
-        {
-          continue;
-        }
-        else if (a.isEmpty())
-        {
-          continue;
-        }
-        else if (omitValues)
-        {
-          duplicateList.add(Attributes.empty(a));
-        }
-        else
-        {
-          duplicateList.add(a);
-        }
-      }
-    }
-
-    if (duplicateList.isEmpty())
-    {
-      return null;
-    }
-    else
-    {
-      return duplicateList;
-    }
-  }
-
-
-
-  // Copy a user attribute - may return null if the attribute was
-  // not found or if it was empty.
-  private List<Attribute> duplicateUserAttribute(
-       Entry entry,
-       AttributeType attributeType,
-       Set<String> options,
-       boolean omitValues,
-       boolean omitReal,
-       boolean omitVirtual)
-  {
-    List<Attribute> currentList = entry.getUserAttribute(attributeType);
-    return duplicateAttribute(currentList, options, omitValues,
-        omitReal, omitVirtual);
-  }
-
-
-
-  // Copy an operational attribute - may return null if the
-  // attribute was not found or if it was empty.
-  private List<Attribute> duplicateOperationalAttribute(
-       Entry entry,
-       AttributeType attributeType,
-       Set<String> options,
-       boolean omitValues,
-       boolean omitReal,
-       boolean omitVirtual)
-  {
-    List<Attribute> currentList =
-         entry.getOperationalAttribute(attributeType);
-    return duplicateAttribute(currentList, options, omitValues,
-        omitReal, omitVirtual);
-  }
 }

--
Gitblit v1.10.0