atg.projects.store.profile.recentlyviewed
Class RecentlyViewedTools

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.projects.store.profile.recentlyviewed.RecentlyViewedTools
All Implemented Interfaces:
atg.naming.AbsoluteNameable, atg.naming.NameContextBindingListener, atg.naming.NameContextElement, atg.naming.NameContextParentable, atg.naming.NameResolver, atg.nucleus.AdminableService, atg.nucleus.Configured, atg.nucleus.logging.ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, atg.nucleus.logging.VariableArgumentApplicationLogging, atg.nucleus.naming.ComponentNameResolver, atg.nucleus.Service, atg.nucleus.ServiceListener, java.util.EventListener

public class RecentlyViewedTools
extends atg.nucleus.GenericService

This class provides the low level functionality for recently viewed item creation/manipulation. It performs the calls required to read and write information to and from the userProfile repository.

There are also some convenience methods for general recently viewed functionality.

Version:
$Id: //hosting-blueprint/B2CBlueprint/version/10.2.1/EStore/src/atg/projects/store/profile/recentlyviewed/RecentlyViewedTools.java#4 $$Change: 796027 $
Author:
David Stewart

Field Summary
static java.lang.String ALL_SITE_SCOPE
           
static java.lang.String CLASS_VERSION
          Class version string
static java.lang.String CURRENT_SITE_SCOPE
           
protected  atg.multisite.SiteGroupManager mSiteGroupManager
           
 
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
RecentlyViewedTools()
           
 
Method Summary
 void addProduct(atg.repository.RepositoryItem pItem, atg.repository.RepositoryItem pProfile, java.lang.String pSiteId)
          Puts product into the list of recently viewed products for the current profile.
 void addProductsToList(java.util.List<atg.repository.RepositoryItem> pProducts, atg.repository.RepositoryItem pProfile)
          This method takes a List of recentlyViewedProduct items and adds them a user's recentlyViewedProducts list.
 void addRecentlyViewedProduct(atg.repository.MutableRepositoryItem pRecentlyViewedProduct)
          This method adds a transient recentlyViewedProduct item to the repository.
 atg.repository.MutableRepositoryItem createRecentlyViewedProduct(atg.repository.RepositoryItem pProduct, atg.repository.RepositoryItem pProfile, java.lang.String pSiteId)
          Create a new 'recentlyViewedProduct' item and add it to the repository if the user is logged in.
 atg.service.util.CurrentDate getCurrentDate()
           
 atg.repository.RepositoryItem getDuplicateRecentlyViewedProduct(atg.repository.RepositoryItem pProduct, java.util.List<atg.repository.RepositoryItem> pRecentlyViewed, java.lang.String pSiteId)
          Check a recentlyViewed list for a duplicate product.
 int getExpiryPeriod()
           
 StartEndDateValidator getItemDateValidator()
           
 java.util.List<atg.repository.RepositoryItem> getProducts(atg.repository.RepositoryItem pProfile)
          Get the specified user's (immutable) recentlyViewedProduct list.
 java.util.List<atg.repository.RepositoryItem> getProductsForUpdate(atg.repository.RepositoryItem pProfile)
          Gets a user's recentlyViewedProducts property list that can be written to.
 StoreProfileTools getProfileTools()
           
 int getRecentlyViewedSize()
           
protected  atg.multisite.SiteGroupManager getSiteGroupManager()
           
 java.lang.String getSiteScope()
           
 boolean isListSizeInfinite()
           
 boolean isProductExpired(atg.repository.RepositoryItem pProduct)
          This method checks if an recentlyViewedProduct item's timestamp property exceeds the expiryPeriod.
 boolean isSiteInScope(java.lang.String pRecentlyViewedProductSiteId, java.lang.String pSiteId)
          This method checks if a site is valid for a particular siteScope and the current site context.
 boolean removeExpiredProducts(java.util.List<atg.repository.RepositoryItem> pRecentlyViewed, atg.repository.RepositoryItem pProfile)
          This method removes any products from a user's recently viewed products repository list that exceed this components expiryPeriod.
 boolean removeNonExistentProducts(java.util.List<atg.repository.RepositoryItem> pRecentlyViewed, atg.repository.RepositoryItem pProfile)
          This method removes any recentlyViewedProduct items from the recentlyViewedProducts list if a product item doesn't exist any more in the productCatalog repository.
 void setCurrentDate(atg.service.util.CurrentDate pCurrentDate)
           
 void setExpiryPeriod(int pExpiryPeriod)
           
 void setItemDateValidator(StartEndDateValidator pItemDateValidator)
           
 void setListSizeInfinite(boolean pListSizeInfinite)
           
 void setProfileTools(StoreProfileTools pProfileTools)
           
 void setRecentlyViewedSize(int pRecentlyViewedSize)
           
 void setSiteGroupManager(atg.multisite.SiteGroupManager pSiteGroupManager)
           
 void setSiteScope(java.lang.String pSiteScope)
           
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, 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, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, 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
Class version string

See Also:
Constant Field Values

CURRENT_SITE_SCOPE

public static final java.lang.String CURRENT_SITE_SCOPE
See Also:
Constant Field Values

ALL_SITE_SCOPE

public static final java.lang.String ALL_SITE_SCOPE
See Also:
Constant Field Values

mSiteGroupManager

protected atg.multisite.SiteGroupManager mSiteGroupManager
Constructor Detail

RecentlyViewedTools

public RecentlyViewedTools()
Method Detail

getSiteGroupManager

protected atg.multisite.SiteGroupManager getSiteGroupManager()
Returns:
A SiteGroupManager instance.

setSiteGroupManager

public void setSiteGroupManager(atg.multisite.SiteGroupManager pSiteGroupManager)
Parameters:
pSiteGroupManager - A SiteGroupManager instance.

getProfileTools

public StoreProfileTools getProfileTools()
Returns:
A StoreProfileTools instance.

setProfileTools

public void setProfileTools(StoreProfileTools pProfileTools)
Parameters:
pProfileTools - A StoreProfileTools instance.

getRecentlyViewedSize

public int getRecentlyViewedSize()
Returns:
The maximum size of a user's recently viewed list.

setRecentlyViewedSize

public void setRecentlyViewedSize(int pRecentlyViewedSize)
Parameters:
pRecentlyViewedSize - The maximum size of a user's recently viewed list.

setListSizeInfinite

public void setListSizeInfinite(boolean pListSizeInfinite)
Parameters:
pListSizeInfinite - A flag determining whether the recently viewed list size should be infinite or not.

isListSizeInfinite

public boolean isListSizeInfinite()
Returns:
A flag determining whether the recently viewed list size should be infinite or not.

setExpiryPeriod

public void setExpiryPeriod(int pExpiryPeriod)
Parameters:
pExpiryPeriod - The expiry period for a recentlyViewedItem. '0' means that there is no expiry period.

getExpiryPeriod

public int getExpiryPeriod()
Returns:
The expiry period for a recentlyViewedItem. 0 means that there is no expiry period.

setSiteScope

public void setSiteScope(java.lang.String pSiteScope)
Parameters:
pSiteScope - The site scope (all/current/shareableId).

getSiteScope

public java.lang.String getSiteScope()
Returns:
The site scope (all/current/shareableId).

setItemDateValidator

public void setItemDateValidator(StartEndDateValidator pItemDateValidator)
Parameters:
pItemDateValidator - The ItemDateValidator component.

getItemDateValidator

public StartEndDateValidator getItemDateValidator()
Returns:
The ItemDateValidator component.

setCurrentDate

public void setCurrentDate(atg.service.util.CurrentDate pCurrentDate)
Parameters:
pCurrentDate - The CurrentDate component.

getCurrentDate

public atg.service.util.CurrentDate getCurrentDate()
Returns:
The CurrentDate component.

addProduct

public void addProduct(atg.repository.RepositoryItem pItem,
                       atg.repository.RepositoryItem pProfile,
                       java.lang.String pSiteId)
                throws atg.repository.RepositoryException
Puts product into the list of recently viewed products for the current profile. This method also takes care of removing duplicate and expired products and maintains 'virtual' lists of products based on siteScope.

The term 'virtual' list is used because each user's recently viewed list will contain every product browsed no matter what site it was viewed on. The siteScope property is then taken into account and a conceptual list is maintained for products in that particular siteScope and currently viewed site. This is needed to determine how many products from each site should be held in the list.

So for example, if the maximum number of products that can be held in a list is 10. If storeA and storeB both share a ShoppingCart shareableType and storeC doesn't share anything; storeA and storeB will share a conceptual list of 10 products and storeC will hold a conceptual list of 10 products. This means that the recently viewed user profile list for a a user can hold a total of 20 products.

Parameters:
pItem - A repository item to add to the list of recently viewed items.
pProfile - A user profile repository item.
pSiteId - The site id associated with the product to be added.
Throws:
atg.repository.RepositoryException

removeNonExistentProducts

public boolean removeNonExistentProducts(java.util.List<atg.repository.RepositoryItem> pRecentlyViewed,
                                         atg.repository.RepositoryItem pProfile)
                                  throws atg.repository.RepositoryException
This method removes any recentlyViewedProduct items from the recentlyViewedProducts list if a product item doesn't exist any more in the productCatalog repository.

Parameters:
pRecentlyViewed - The recentlyViewedProducts list that will be examined for expired products.
pProfile - The user who owns the recently viewed list.
Returns:
true if any recently viewed products were removed, otherwise false.
Throws:
atg.repository.RepositoryException - If there was a problem removing a product from the repository.

isSiteInScope

public boolean isSiteInScope(java.lang.String pRecentlyViewedProductSiteId,
                             java.lang.String pSiteId)
This method checks if a site is valid for a particular siteScope and the current site context.

Parameters:
pRecentlyViewedProductSiteId - The site id of a recentlyViewedProduct.
pSiteId - The id of the site currently in context.
Returns:
true if the recentlyViewedProduct site is valid for this component's siteScope and current site context, otherwise false.

createRecentlyViewedProduct

public atg.repository.MutableRepositoryItem createRecentlyViewedProduct(atg.repository.RepositoryItem pProduct,
                                                                        atg.repository.RepositoryItem pProfile,
                                                                        java.lang.String pSiteId)
                                                                 throws atg.repository.RepositoryException
Create a new 'recentlyViewedProduct' item and add it to the repository if the user is logged in.

Parameters:
pProduct - The product that will be set in the recentlyViewedItem 'product' property.
pProfile - The profile item of the user that the recentlyViewedProduct is being created for.
pSiteId - The site id of the site that is currently in context.
Returns:
The newly created recentlyViewedProduct or else null.
Throws:
atg.repository.RepositoryException - If there's a problem creating/adding the item.

addRecentlyViewedProduct

public void addRecentlyViewedProduct(atg.repository.MutableRepositoryItem pRecentlyViewedProduct)
                              throws atg.repository.RepositoryException
This method adds a transient recentlyViewedProduct item to the repository.

Parameters:
pRecentlyViewedProduct - The transient recentlyViewedProduct to be added.
Throws:
atg.repository.RepositoryException - If there's a problem adding the recentlyViewedProduct to the repository.

addProductsToList

public void addProductsToList(java.util.List<atg.repository.RepositoryItem> pProducts,
                              atg.repository.RepositoryItem pProfile)
                       throws atg.repository.RepositoryException
This method takes a List of recentlyViewedProduct items and adds them a user's recentlyViewedProducts list.

Parameters:
pProducts - The list of recentlyViewedProducts that are to be added to the list.
pProfile - The profile of the user whose recently viewed list is to be updated.
Throws:
atg.repository.RepositoryException

getProductsForUpdate

public java.util.List<atg.repository.RepositoryItem> getProductsForUpdate(atg.repository.RepositoryItem pProfile)
                                                                   throws atg.repository.RepositoryException
Gets a user's recentlyViewedProducts property list that can be written to.

Parameters:
pProfile - The user's profile whose recentlyViewedProducts property is to be modified.
Returns:
A recentlyViewedProducts list property that is ready to be modified.
Throws:
atg.repository.RepositoryException - If there's a problem retrieving the recently viewed list.

getProducts

public java.util.List<atg.repository.RepositoryItem> getProducts(atg.repository.RepositoryItem pProfile)
Get the specified user's (immutable) recentlyViewedProduct list.

Parameters:
pProfile - The user whose recentlyViewedProduct list will be retrieved.
Returns:
The list of recentlyViewedItem RepositoryItems associated with the user in pProfile.

getDuplicateRecentlyViewedProduct

public atg.repository.RepositoryItem getDuplicateRecentlyViewedProduct(atg.repository.RepositoryItem pProduct,
                                                                       java.util.List<atg.repository.RepositoryItem> pRecentlyViewed,
                                                                       java.lang.String pSiteId)
Check a recentlyViewed list for a duplicate product.

Parameters:
pProduct - The actual 'product' item to be added to the list.
pRecentlyViewed - The current list of recentlyViewedProduct items.
pSiteId - The site id of the site that is currently in context.
Returns:
A duplicate recentlyViewedProduct item (if any), otherwise null.

removeExpiredProducts

public boolean removeExpiredProducts(java.util.List<atg.repository.RepositoryItem> pRecentlyViewed,
                                     atg.repository.RepositoryItem pProfile)
                              throws atg.repository.RepositoryException
This method removes any products from a user's recently viewed products repository list that exceed this components expiryPeriod.

Parameters:
pRecentlyViewed - The recentlyViewedProducts list that will be examined for expired products.
Returns:
true if any recently viewed products were removed, otherwise false.
Throws:
atg.repository.RepositoryException - If there was a problem removing a product from the repository.

isProductExpired

public boolean isProductExpired(atg.repository.RepositoryItem pProduct)
This method checks if an recentlyViewedProduct item's timestamp property exceeds the expiryPeriod.

Parameters:
pProduct - The recentlyViewedProduct item we want to run the expiry check against.
Returns:
true if product has exceeded expiryPeriod, otherwise false.