Class RecursiveResultHandler

All Implemented Interfaces:
Function<SearchResponse,SearchResponse>, SearchResultHandler

public class RecursiveResultHandler extends AbstractEntryHandler<SearchResponse> implements SearchResultHandler
This recursively searches based on a supplied attribute and merges those results into the original entry. For the following LDIF:
   dn: uugid=group1,ou=groups,dc=ldaptive,dc=org
   uugid: group1
   member: uugid=group2,ou=groups,dc=ldaptive,dc=org

   dn: uugid=group2,ou=groups,dc=ldaptive,dc=org
   uugid: group2
 

With the following code:

   RecursiveResultHandler reh = new RecursiveResultHandler("member", "uugid");
 

Will produce this result for the query (uugid=group1):

   dn: uugid=group1,ou=groups,dc=ldaptive,dc=org
   uugid: group1
   uugid: group2
   member: uugid=group2,ou=groups,dc=ldaptive,dc=org
 
This handler should only be used with the SearchOperation.execute() method since it leverages the connection to make further searches.
  • Field Details

    • HASH_CODE_SEED

      private static final int HASH_CODE_SEED
      hash code seed.
      See Also:
    • searchAttribute

      private String searchAttribute
      Attribute to recursively search on.
    • mergeAttributes

      private String[] mergeAttributes
      Attribute(s) to merge.
    • retAttrs

      private String[] retAttrs
      Attributes to return when searching, mergeAttributes + searchAttribute.
  • Constructor Details

    • RecursiveResultHandler

      public RecursiveResultHandler()
      Default constructor.
    • RecursiveResultHandler

      public RecursiveResultHandler(String searchAttr, String... mergeAttrs)
      Creates a new recursive entry handler.
      Parameters:
      searchAttr - attribute to search on
      mergeAttrs - attribute names to merge
  • Method Details

    • getSearchAttribute

      public String getSearchAttribute()
      Returns the attribute name that will be recursively searched on.
      Returns:
      attribute name
    • setSearchAttribute

      public void setSearchAttribute(String name)
      Sets the attribute name that will be recursively searched on.
      Parameters:
      name - of the search attribute
    • getMergeAttributes

      public String[] getMergeAttributes()
      Returns the attribute names that will be merged by the recursive search.
      Returns:
      attribute names
    • setMergeAttributes

      public void setMergeAttributes(String... mergeAttrs)
      Sets the attribute name that will be merged by the recursive search.
      Parameters:
      mergeAttrs - attribute names to merge
    • initializeReturnAttributes

      protected void initializeReturnAttributes()
      Initializes the return attributes array. Must be called after both searchAttribute and mergeAttributes have been set.
    • apply

      public SearchResponse apply(SearchResponse response)
      Specified by:
      apply in interface Function<SearchResponse,SearchResponse>
    • handleEntry

      public void handleEntry(LdapEntry entry)
      Description copied from class: AbstractEntryHandler
      Handle the entry.
      Overrides:
      handleEntry in class AbstractEntryHandler<SearchResponse>
      Parameters:
      entry - to handle
    • readSearchAttribute

      private void readSearchAttribute(LdapEntry entry, List<String> searchedDns)
      Parameters:
      entry - to read
      searchedDns - list of DNs whose attributes have been read
    • recursiveSearch

      private void recursiveSearch(String dn, LdapEntry entry, List<String> searchedDns)
      Recursively gets the attribute(s) mergeAttributes for the supplied dn and adds the values to the supplied attributes.
      Parameters:
      dn - to get attribute(s) for
      entry - to merge with
      searchedDns - list of DNs that have been searched for
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class AbstractEntryHandler<SearchResponse>
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in class AbstractEntryHandler<SearchResponse>
    • toString

      public String toString()
      Overrides:
      toString in class Object