Package org.ldaptive.handler
Class RecursiveResultHandler
- java.lang.Object
-
- org.ldaptive.AbstractFreezable
-
- org.ldaptive.transport.MessageFunctional<Q,S>
-
- org.ldaptive.transport.MessageFunctional.Function<SearchRequest,SearchResponse,T,T>
-
- org.ldaptive.transport.AbstractMessageFunctionalEntryHandler<SearchResponse>
-
- org.ldaptive.handler.RecursiveResultHandler
-
- All Implemented Interfaces:
Function<SearchResponse,SearchResponse>
,Freezable
,SearchResultHandler
public class RecursiveResultHandler extends AbstractMessageFunctionalEntryHandler<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 theSearchOperation.execute()
method since it leverages the connection to make further searches.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
HASH_CODE_SEED
hash code seed.private String[]
mergeAttributes
Attribute(s) to merge.private String[]
retAttrs
Attributes to return when searching, mergeAttributes + searchAttribute.private String
searchAttribute
Attribute to recursively search on.-
Fields inherited from class org.ldaptive.transport.AbstractMessageFunctionalEntryHandler
logger
-
-
Constructor Summary
Constructors Constructor Description RecursiveResultHandler()
Default constructor.RecursiveResultHandler(String searchAttr, String... mergeAttrs)
Creates a new recursive entry handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SearchResponse
apply(SearchResponse response)
boolean
equals(Object o)
String[]
getMergeAttributes()
Returns the attribute names that will be merged by the recursive search.String
getSearchAttribute()
Returns the attribute name that will be recursively searched on.void
handleEntry(LdapEntry entry)
Handle the entry.int
hashCode()
protected void
initializeReturnAttributes()
Initializes the return attributes array.RecursiveResultHandler
newInstance()
Create a new instance of this message functional.protected SearchResponse
performSearch(String baseDn, String[] attrs)
Perform an object scope search on the supplied baseDN and retrieve the supplied return attributes.private void
readSearchAttribute(LdapEntry entry, List<String> searchedDns)
Reads the values ofsearchAttribute
from the supplied attributes and callsrecursiveSearch(java.lang.String, org.ldaptive.LdapEntry, java.util.List<java.lang.String>)
for each.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.void
setMergeAttributes(String... mergeAttrs)
Sets the attribute name that will be merged by the recursive search.void
setSearchAttribute(String name)
Sets the attribute name that will be recursively searched on.String
toString()
-
Methods inherited from class org.ldaptive.transport.AbstractMessageFunctionalEntryHandler
handleAttribute, handleAttributeName, handleAttributes, handleAttributeValue, handleAttributeValue, handleDn
-
Methods inherited from class org.ldaptive.transport.MessageFunctional
getConnection, getHandle, getRequest, setConnection, setHandle, setRequest
-
Methods inherited from class org.ldaptive.AbstractFreezable
assertMutable, freeze, freeze, freeze, isFrozen
-
-
-
-
Field Detail
-
HASH_CODE_SEED
private static final int HASH_CODE_SEED
hash code seed.- See Also:
- Constant Field Values
-
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.
-
-
Method Detail
-
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 interfaceFunction<SearchResponse,SearchResponse>
-
handleEntry
public void handleEntry(LdapEntry entry)
Description copied from class:AbstractMessageFunctionalEntryHandler
Handle the entry.- Overrides:
handleEntry
in classAbstractMessageFunctionalEntryHandler<SearchResponse>
- Parameters:
entry
- to handle
-
readSearchAttribute
private void readSearchAttribute(LdapEntry entry, List<String> searchedDns) throws LdapException
Reads the values ofsearchAttribute
from the supplied attributes and callsrecursiveSearch(java.lang.String, org.ldaptive.LdapEntry, java.util.List<java.lang.String>)
for each.- Parameters:
entry
- to readsearchedDns
- list of DNs whose attributes have been read- Throws:
LdapException
- if an error occurs performing a search
-
recursiveSearch
private void recursiveSearch(String dn, LdapEntry entry, List<String> searchedDns) throws LdapException
Recursively gets the attribute(s)mergeAttributes
for the supplied dn and adds the values to the supplied attributes.- Parameters:
dn
- to get attribute(s) forentry
- to merge withsearchedDns
- list of DNs that have been searched for- Throws:
LdapException
- if an error occurs performing a search
-
performSearch
protected SearchResponse performSearch(String baseDn, String[] attrs) throws LdapException
Perform an object scope search on the supplied baseDN and retrieve the supplied return attributes.- Parameters:
baseDn
- to search onattrs
- attributes to return- Returns:
- search response
- Throws:
LdapException
- if the search operation fails
-
newInstance
public RecursiveResultHandler newInstance()
Description copied from class:MessageFunctional
Create a new instance of this message functional.- Specified by:
newInstance
in classMessageFunctional<SearchRequest,SearchResponse>
- Returns:
- new instance of this message functional
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classAbstractMessageFunctionalEntryHandler<SearchResponse>
-
hashCode
public int hashCode()
- Specified by:
hashCode
in classAbstractMessageFunctionalEntryHandler<SearchResponse>
-
-