mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
23.03.2013 c98ff3c33fac394c1077a709af7958bc4199da04
Simple fix for OPENDJ-1082: Order attributes according to search request attribute list order

Use LinkedHashMap when filter entries before returning them in search results. This ensures that attributes are mostly returned in the same order that they were requested. I use the word "mostly" because user attributes will still be grouped together ahead of operational attributes.

Verbally reviewed by Ludo.

1 files modified
24 ■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/types/Entry.java 24 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/types/Entry.java
@@ -4857,24 +4857,26 @@
    if (attrNameList == null || attrNameList.isEmpty())
    {
      // Common case: return filtered user attributes.
      userAttrsCopy =
          new HashMap<AttributeType, List<Attribute>>(userAttributes.size());
      operationalAttrsCopy = new HashMap<AttributeType, List<Attribute>>(0);
      userAttrsCopy = new LinkedHashMap<AttributeType, List<Attribute>>(
          userAttributes.size());
      operationalAttrsCopy =
          new LinkedHashMap<AttributeType, List<Attribute>>(0);
      if (omitReal)
      {
        objectClassesCopy = new HashMap<ObjectClass, String>(0);
        objectClassesCopy = new LinkedHashMap<ObjectClass, String>(0);
      }
      else if (omitValues)
      {
        objectClassesCopy = new HashMap<ObjectClass, String>(0);
        objectClassesCopy = new LinkedHashMap<ObjectClass, String>(0);
        // Add empty object class attribute.
        userAttrsCopy.put(ocType, newList(Attributes.empty(ocType)));
      }
      else
      {
        objectClassesCopy = new HashMap<ObjectClass, String>(objectClasses);
        objectClassesCopy =
            new LinkedHashMap<ObjectClass, String>(objectClasses);
        // First, add the objectclass attribute.
        Attribute ocAttr = getObjectClassAttribute();
@@ -4893,18 +4895,18 @@
      // Incrementally build table of attributes.
      if (omitReal || omitValues)
      {
        objectClassesCopy = new HashMap<ObjectClass, String>(0);
        objectClassesCopy = new LinkedHashMap<ObjectClass, String>(0);
      }
      else
      {
        objectClassesCopy =
            new HashMap<ObjectClass, String>(objectClasses.size());
            new LinkedHashMap<ObjectClass, String>(objectClasses.size());
      }
      userAttrsCopy =
          new HashMap<AttributeType, List<Attribute>>(userAttributes.size());
      userAttrsCopy = new LinkedHashMap<AttributeType, List<Attribute>>(
          userAttributes.size());
      operationalAttrsCopy =
          new HashMap<AttributeType, List<Attribute>>(
          new LinkedHashMap<AttributeType, List<Attribute>>(
              operationalAttributes.size());
      for (String attrName : attrNameList)