atg.commerce.collections.filter
Class PriceAndStateFilter

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.service.collections.filter.CachedCollectionFilter
              extended by atg.commerce.collections.filter.PriceAndStateFilter
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener

public class PriceAndStateFilter
extends CachedCollectionFilter

This filter demonstrates how someone might implement a filter based on profile attributes.

The objective of this filter is to create a filtered collection of products for users with a registered home state of X, that includes only the products with a price less than or equal to Y. X and Y are configurable values of the filter.

This filter assumes that a standard catalog configuration is being used which has the list price maintained as a property of the sku item. A product qualifies for the filtered collection if any of its skus pass the price test, or if the product does not have a sku.


Field Summary
static java.lang.String CLASS_VERSION
           
protected  CatalogServices mCatalogServices
           
protected  CatalogTools mCatalogTools
           
protected  java.lang.String mListPricePropertyName
           
protected  java.lang.Double mPrice
           
protected  java.lang.String mState
           
protected  java.lang.String mStatePropertyName
           
 
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
PriceAndStateFilter()
           
 
Method Summary
 java.lang.Object generateContextKey(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile)
          Generates a context key for this filter.
protected  java.util.Collection generateFilteredCollection(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile)
          Generates a filtered collection based on the registered home state of the user and the price of each product in the collection.
 CatalogServices getCatalogServices()
          Returns the CatalogServices
 CatalogTools getCatalogTools()
          Returns the CatalogTools
 java.lang.String getListPricePropertyName()
          Returns the property name used to store the list price on the sku
 java.lang.Double getPrice()
          Returns the threshold price
 java.lang.String getState()
          Returns the home state that applies to this filter
 java.lang.String getStatePropertyName()
          Returns the property name used to get the user's home state
 void setCatalogServices(CatalogServices pCatalogServices)
          Sets the CatalogServices
 void setCatalogTools(CatalogTools pCatalogTools)
          Sets the CatalogTools
 void setListPricePropertyName(java.lang.String pListPricePropertyName)
          Sets the property name used to store the list price on the sku
 void setPrice(java.lang.Double pPrice)
          Sets the threshold price
 void setState(java.lang.String pState)
          Sets the home state that applies to this filter
 void setStatePropertyName(java.lang.String pStatePropertyName)
          Sets the property name used to get the user's home state
 boolean shouldApplyFilter(java.util.Collection pUnfilteredCollection, java.lang.String pKey, RepositoryItem pProfile)
          If the filter is executed for a user that is not registered in the same home state as the filter's configured home state, then this method will return false.
 
Methods inherited from class atg.service.collections.filter.CachedCollectionFilter
dumpCache, filterCollection, filterCollection, filterCollection, filterCollection, flushCache, generateCacheKey, generateCacheKey, generateContextKey, generateFilteredCollection, generateNewCollectionObject, getCache, getDefaultProfile, isCacheEnabled, setCache, setCacheEnabled, shouldApplyFilter, 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, reResolveThis, 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

mCatalogServices

protected CatalogServices mCatalogServices

mListPricePropertyName

protected java.lang.String mListPricePropertyName

mStatePropertyName

protected java.lang.String mStatePropertyName

mState

protected java.lang.String mState

mPrice

protected java.lang.Double mPrice

mCatalogTools

protected CatalogTools mCatalogTools
Constructor Detail

PriceAndStateFilter

public PriceAndStateFilter()
Method Detail

setCatalogServices

public void setCatalogServices(CatalogServices pCatalogServices)
Sets the CatalogServices


getCatalogServices

public CatalogServices getCatalogServices()
Returns the CatalogServices


setListPricePropertyName

public void setListPricePropertyName(java.lang.String pListPricePropertyName)
Sets the property name used to store the list price on the sku


getListPricePropertyName

public java.lang.String getListPricePropertyName()
Returns the property name used to store the list price on the sku


setStatePropertyName

public void setStatePropertyName(java.lang.String pStatePropertyName)
Sets the property name used to get the user's home state


getStatePropertyName

public java.lang.String getStatePropertyName()
Returns the property name used to get the user's home state


setState

public void setState(java.lang.String pState)
Sets the home state that applies to this filter


getState

public java.lang.String getState()
Returns the home state that applies to this filter


setPrice

public void setPrice(java.lang.Double pPrice)
Sets the threshold price


getPrice

public java.lang.Double getPrice()
Returns the threshold price


setCatalogTools

public void setCatalogTools(CatalogTools pCatalogTools)
Sets the CatalogTools


getCatalogTools

public CatalogTools getCatalogTools()
Returns the CatalogTools


generateContextKey

public java.lang.Object generateContextKey(java.util.Collection pUnfilteredCollection,
                                           java.lang.String pCollectionIdentifierKey,
                                           RepositoryItem pProfile)
Generates a context key for this filter. The configured home state is the appropriate context key because this filter creates filtered results specific to a user that is registered in the configured home state. Therefore, having the state as the context key will enable all subsequent executions of the filter, for users in the same home state, to correctly identify results in the cache.

Overrides:
generateContextKey in class CachedCollectionFilter
Parameters:
pUnfilteredCollection - the collection to be filtered
pCollectionIdentifierKey - the key that uniquely identifies the unfiltered collection.
Returns:
the filter's configured home state.

shouldApplyFilter

public boolean shouldApplyFilter(java.util.Collection pUnfilteredCollection,
                                 java.lang.String pKey,
                                 RepositoryItem pProfile)
If the filter is executed for a user that is not registered in the same home state as the filter's configured home state, then this method will return false. In other words, the filter does not apply in that context. It only applies when the current user, represented by the pProfile parameter, is registered in the same home state as the filter's configured home state.

Overrides:
shouldApplyFilter in class CachedCollectionFilter
Parameters:
pUnfilteredCollection - the unfiltered collection
pKey - 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.shouldApplyFilter(java.util.Collection, java.lang.String, atg.repository.RepositoryItem)

generateFilteredCollection

protected java.util.Collection generateFilteredCollection(java.util.Collection pUnfilteredCollection,
                                                          java.lang.String pCollectionIdentifierKey,
                                                          RepositoryItem pProfile)
                                                   throws FilterException
Generates a filtered collection based on the registered home state of the user and the price of each product in the collection.

If the new filtered collection is the same size as the unfiltered collection, the filtered collection is disgarded and the unfiltered collection is returned.

Overrides:
generateFilteredCollection in class CachedCollectionFilter
Parameters:
pUnfilteredCollection - the unfiltered collection
pCollectionIdentifierKey - the key the uniquely identifies the unfiltered collection.
pProfile - Repository item
Returns:
the filtered collection
Throws:
FilterException