atg.search.query.filters
Class RepositoryItemResultCollectionFilter

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.service.collections.filter.CachedCollectionFilter
              extended by atg.search.query.filters.RepositoryItemResultCollectionFilter
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, atg.nucleus.logging.VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener
Direct Known Subclasses:
SampleRepositoryItemCollectionFilter

public abstract class RepositoryItemResultCollectionFilter
extends atg.service.collections.filter.CachedCollectionFilter

An abstract base class for search result collection filtering with support for repository items associated with the search result. A minimal implementation implements the accept method:

   protected boolean accept( Result pResult, RepositoryItem pUserProfile )
 

The following is a sample implementation of this method that retrieves the repository item from a Result object. This assumes that the Result object's url property contains an atgrep:/ url:

 protected boolean accept( Result pResult, RepositoryItem pUserProfile )
 {
   RepositoryItem item = null;

   try {
     repositoryItem = getRepositoryItem( pResult );
   }
   catch ( NamingException ne ) {
     if ( isLoggingDebug() )
       logDebug( "Error looking up: " + pResult, ne );
     throw new FilterException( "Error looking up: " + pResult, ne );
   }

   ...
 
   return <true to accept Result object>;
 }
 
This implementation attempts to retrieve a repository item with an atgrep:/ style URL, associated with the "someKey.$url" entry in the result object's properties map.
 protected boolean accept( Result pResult, RepositoryItem pUserProfile )
 {
   RepositoryItem item = null;

   try {
     String url = (String) pResult.getProperties().get( "someKey.$url" );
     repositoryItem = getRepositoryItem( url );
   }
   catch ( NamingException ne ) {
     if ( isLoggingDebug() )
       logDebug( "Error looking up: " + pResult, ne );
     throw new FilterException( "Error looking up: " + pResult, ne );
   }

   ...
 
   return <true to accept Result object>;
 }
 


Field Summary
static java.lang.String CLASS_VERSION
           
 
Fields inherited from class atg.service.collections.filter.CachedCollectionFilter
FILTER_CACHE_COMPONENT, mCache, mCacheEnabled
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
RepositoryItemResultCollectionFilter()
           
 
Method Summary
protected abstract  boolean accept(Result pResult, RepositoryItem pProfile)
          Override this method to filter individual result/repository items.
 java.lang.Object generateContextKey(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile)
          Generates a context key
protected  java.util.Collection generateFilteredCollection(java.util.Collection pUnfiltered, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile)
          Called by the filterCollection method to generate the filtered collection.
 JNDIInitialContextPool getInitialContextPool()
          Get the JNDI initial context pool
protected  RepositoryItem getRepositoryItem(java.lang.String pRepositoryUrl)
          Get a repository item from the Result object.
 void setInitialContextPool(JNDIInitialContextPool pInitialContextPool)
          Set the JNDI initial context pool.
 boolean shouldApplyFilter(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile)
          This method is called by filterCollection prior to looking up the filtered collection in the cache or generating a new filtered collection.
 
Methods inherited from class atg.service.collections.filter.CachedCollectionFilter
dumpCache, filterCollection, filterCollection, flushCache, generateCacheKey, generateNewCollectionObject, getCache, getDefaultProfile, isCacheEnabled, setCache, setCacheEnabled, stringIt
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static final java.lang.String CLASS_VERSION
See Also:
Constant Field Values
Constructor Detail

RepositoryItemResultCollectionFilter

public RepositoryItemResultCollectionFilter()
Method Detail

setInitialContextPool

public void setInitialContextPool(JNDIInitialContextPool pInitialContextPool)
Set the JNDI initial context pool. This pool is consulted when looking up repository items

Parameters:
pInitialContextPool - the JNDI initial context pool

getInitialContextPool

public JNDIInitialContextPool getInitialContextPool()
Get the JNDI initial context pool

Returns:
the context pool

generateContextKey

public java.lang.Object generateContextKey(java.util.Collection pUnfilteredCollection,
                                           java.lang.String pCollectionIdentifierKey,
                                           RepositoryItem pProfile)
Generates a context key

Specified by:
generateContextKey in class atg.service.collections.filter.CachedCollectionFilter
Parameters:
pUnfilteredCollection - the unfiltered collection
pCollectionIdentifierKey -
pProfile -
Returns:
a useless key

generateFilteredCollection

protected java.util.Collection generateFilteredCollection(java.util.Collection pUnfiltered,
                                                          java.lang.String pCollectionIdentifierKey,
                                                          RepositoryItem pProfile)
                                                   throws atg.service.collections.filter.FilterException
Called by the filterCollection method to generate the filtered collection.

Specified by:
generateFilteredCollection in class atg.service.collections.filter.CachedCollectionFilter
Parameters:
pUnfilteredCollection - the unfiltered collection, a collection of
pCollectionIdentifierKey - the key that was passed to the filterCollection method.
Returns:
the filtered collection. If null is returned from this method, the filterCollection method will return the original unfiltered collection as the filtered results. If all items are filtered from the collection, an empty collection should be returned.
Throws:
atg.service.collections.filter.FilterException

shouldApplyFilter

public boolean shouldApplyFilter(java.util.Collection pUnfilteredCollection,
                                 java.lang.String pCollectionIdentifierKey,
                                 RepositoryItem pProfile)
This method is called by filterCollection prior to looking up the filtered collection in the cache or generating a new filtered collection. Implementations should use this method to bypass the filter when it doesn't apply to the current execution context. (e.g. a profile attribute has the wrong value etc.)

Specified by:
shouldApplyFilter in class atg.service.collections.filter.CachedCollectionFilter
Parameters:
pUnfilteredCollection - the unfiltered collection
pCollectionIdentifierKey - the key param as passed to filterCollection
pProfile - the user profile
Returns:
false to bypass the filter prior to generating the filteredCollection, including cache lookup.
See Also:
CachedCollectionFilter.filterCollection(java.util.Collection, java.lang.String, atg.repository.RepositoryItem, boolean, boolean)

getRepositoryItem

protected RepositoryItem getRepositoryItem(java.lang.String pRepositoryUrl)
                                    throws javax.naming.NamingException
Get a repository item from the Result object. This method a repository item identified by the 'url' property of Result, or null if that property does not specify a repository item or if the repository item cannot be located.

Parameters:
pResult - the search result object
Returns:
a repository item or null
Throws:
javax.naming.NamingException - if repository item cannot be found

accept

protected abstract boolean accept(Result pResult,
                                  RepositoryItem pProfile)
                           throws atg.service.collections.filter.FilterException
Override this method to filter individual result/repository items. Return true to add item to results, false otherwise.

Parameters:
pResult - the search result object
pProfile - the user profile repository item
Returns:
true to accept this item, false otherwise
Throws:
atg.service.collections.filter.FilterException