atg.commerce.catalog.custom
Class CatalogItemLookupDroplet

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.nucleus.TimedOperationService
              extended by atg.nucleus.servlet.ServletService
                  extended by atg.nucleus.servlet.HttpServletService
                      extended by atg.servlet.DynamoServlet
                          extended by atg.repository.servlet.ItemLookupDroplet
                              extended by atg.commerce.catalog.custom.CatalogItemLookupDroplet
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, ParameterServlet, java.util.EventListener, javax.servlet.Servlet

public class CatalogItemLookupDroplet
extends ItemLookupDroplet

This servlet looks for a RepositoryItem by its id from within a Repository. If the item is found, then it will check whether the item belongs to the user's catalog in his current Profile and if the item belongs to the current site. If it does, output is rendered. If the item is not found, empty is rendered. If it is not found on the current site then wrongSite is rendered. If it does not belong to the user's catalog, wrongCatalog is rendered. It checks this by looking at the item's "catalogs" property and "sites" property. If the item has no "catalogs" and no "sites" property then this class behaves the same as the superclass.

The repository and item descriptor type can be configured through properties. If the useParams property is true, then the repository and item descriptor can be resolved through input parameters.

One can configure this droplet to define a mapping from a key to an alternate set of repositories.
For example: ProductLookup.properties

 $class=atg.commerce.catalog.custom.CatalogItemLookupDroplet
 
 repository=/atg/commerce/catalog/ProductCatalog
 itemDescriptor=product
 
 alternateRepositories=\
      fr_FR=/atg/commerce/catalog/FrenchProductCatalog
      ja_JP=/atg/commerce/catalog/JapaneseProductCatalog
      de_DE=/atg/commerce/catalog/GermanProductCatalog
 
The invocation of the droplet can then be invoked with the following parameters:
 <DROPLET bean="ProductLookup">
 <PARAM NAME="id" VALUE="param:productId">
 <PARAM NAME="repositoryKey" value="bean:/OriginatingRequest.requestLocale.localeString">
 <PARAM name="elementName" value="product">
 <OPARAM NAME="output">
   <a href="param:product.template.url">
     <param name="prod_id" value="param:product.repositoryId">
     <valueof param="product.displayName"></valueof>
   </a>
 </OPARAM>
 </DROPLET>
 
If the mapping for the provided key is found that repository will be used, otherwise the system will fall back to the default repository and search for the item.

If the item cannot be found in the repository searched (e.g. the french product catalog), then the droplet will once again fall back to the default repository and attempt to find the item using the same id. Obviously this is only useful if the items have the exact same id in each repository.

In this example if you are french and attempt to look at product 1234, and product 1234 is defined in the french product catalog you will see that item. However if 1234 is not defined then you will see the default english version of 1234.

This behavior can be modified with use of the useDefaultRepository and getDefaultItem properties. If useDefaultRepository is false and an alternate repository cannot be found, then no repository is searched and empty is serviced. Like wise, if an alternative repository is selected, but the item cannot be found, and if getDefaultItem is false, then the default repository will not be searched and empty will be serviced.

The required input paramters for this servlet are:

id
The id of the item to lookup
The following parameters are optional:
repositoryKey
If specified this parameter will be used as a key to map to a secondary set of repositories.
elementName
This parameter can be used to change the default name of the element which is bound into the scope of the output oparam.
repository
The repository within which to look for the item. It is recommended to not use this parameter and to define different instances of the CatalogItemLookupDroplet for each set of repositories you wish to use.
itemDescriptor
The name of the Item Descriptor to use to load the item. It is recommended to not use this parameter and to setup the item descriptor through property configuration.
catalog
The catalog to look for the item in. This is normally not needed since the catalog that is in the current user's profile will be used. If however, you want to search in a catalog other than the current catalog, or there is no current session (for example within the context of an email template) then you may want to explicitly provide the catalog. This must be a repository item.
catalogs
The set of catalogs to look for the item in. The item must be a memeber of at least one of the catalogs. This parameter supercedes the catalog parameter.
sites
The sites to look for the item in. This is normally not needed since the current site will be used. If however, you want to search in a site other than the current site, or there is no current session (for example within the context of an email template) then you may want to explicitly provide the site. If you provide more than one site, the item must be a member of at least one of the sites. This must be a Collection of Site objects.
filterByCatalog
Whether or not the item should match the specified catalog(s). If set to false then the item will not be checked against any catalog.
filterBySite
Whether or not the item should match the specified site(s). If set to false then the item will not be checked against any site.

The output parameters for this servlet are:

output
Rendered if the item was found in the repository
element
Set to the RepositoryItem corresponding to the id supplied
wrongSite
This gets rendered if the item being looked up is not accessible through the current user's site. The item is still accessible if you need it.
wrongCatalog
This gets rendered if the item being looked up is not accessible through the current user's catalog. The item is still accessible if you need it.
noCatalog
This gets rendered if the current user does not have a catalog and the catalog input parameter was not specified.
error
Any exception that may have occurred while looking up the item
empty
Rendered in all other cases, e.g. item not found, user did not specify a required parameter.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.servlet.DynamoServlet
mAllowCleanupRequest, mParameters
 
Fields inherited from class atg.nucleus.servlet.ServletService
SERVLET_INFO_KEY
 
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
CatalogItemLookupDroplet()
           
 
Method Summary
protected  RepositoryItem findItem(java.lang.String pId, java.lang.String pItemDescriptorName, Repository pRepository)
          Attempts to find an item in the given repository based on Id and Item descriptor.
protected  java.util.Collection<RepositoryItem> getCatalogs(DynamoHttpServletRequest pRequest)
          Returns catalogs from request parameters.
 RepositoryItem getProfile()
          Returns property Profile
protected  Repository getRepository(DynamoHttpServletRequest pRequest)
          Returns repository.
protected  Repository getRepositoryForCatalogItemLookup(java.lang.String pRepositoryKey)
          Gets the specified alternate repository if available, otherwise returns the defaults repository.
protected  java.util.Collection<Site> getSites(DynamoHttpServletRequest pRequest)
          If we have collection of sites in request parameter, then returns them, otherwise returns null.
 java.lang.String getSitesPropertyName()
          Returns property SitesPropertyName
 boolean isFilterByCatalog()
          Returns property FilterByCatalog
protected  boolean isFilterByCatalog(DynamoHttpServletRequest pRequest)
          Returns true if item should filter by catalog.
 boolean isFilterBySite()
          Returns property FilterBySite
protected  boolean isFilterBySite(DynamoHttpServletRequest pRequest)
          Determines if we are filtering by sites.
protected  boolean isItemInCatalogs(RepositoryItem pItem, java.util.Collection<RepositoryItem> pCatalogs)
          Determines if a given item is part of any catalog in the given collection.
protected  boolean isItemInSites(RepositoryItem pItem, java.util.Collection<Site> pSites)
          Determines if a given item is a part of any sites from the given set or the current site.
 void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Look for the RepositoryItem and if found render the output oparam by binding the item as a parameter.
 void setFilterByCatalog(boolean pFilterByCatalogs)
          Sets property FilterByCatalog
 void setFilterBySite(boolean pFilterBySite)
          Sets property FilterBySite
 void setSitesPropertyName(java.lang.String pSitesPropertyName)
          Sets property SitesPropertyName
 
Methods inherited from class atg.repository.servlet.ItemLookupDroplet
commitTransaction, ensureTransaction, getAlternateRepositories, getItemDescriptor, getRepository, getTransactionManager, isEnsureTransaction, isGetDefaultItem, isUseDefaultRepository, isUseParams, setAlternateRepositories, setEnsureTransaction, setGetDefaultItem, setItemDescriptor, setRepository, setTransactionManager, setUseDefaultRepository, setUseParams
 
Methods inherited from class atg.servlet.DynamoServlet
doDelete, doGet, doPost, doPut, getParameter, getParameters, getServletContext, service, service, setParameter
 
Methods inherited from class atg.nucleus.servlet.ServletService
destroy, getServletConfig, getServletInfo, init, setServletInfo
 
Methods inherited from class atg.nucleus.TimedOperationService
getAverageRequestHandlingTime, getHandledRequestCount, getRequestStartTime, getTotalRequestHandlingTime, isKeepingStatistics, notifyHandledRequest, resetStatistics, setKeepingStatistics
 
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 java.lang.String CLASS_VERSION
Class version string

Constructor Detail

CatalogItemLookupDroplet

public CatalogItemLookupDroplet()
Method Detail

getProfile

public RepositoryItem getProfile()
Returns property Profile


setFilterByCatalog

public void setFilterByCatalog(boolean pFilterByCatalogs)
Sets property FilterByCatalog


isFilterByCatalog

public boolean isFilterByCatalog()
Returns property FilterByCatalog


setFilterBySite

public void setFilterBySite(boolean pFilterBySite)
Sets property FilterBySite


isFilterBySite

public boolean isFilterBySite()
Returns property FilterBySite


setSitesPropertyName

public void setSitesPropertyName(java.lang.String pSitesPropertyName)
Sets property SitesPropertyName


getSitesPropertyName

public java.lang.String getSitesPropertyName()
Returns property SitesPropertyName


service

public void service(DynamoHttpServletRequest pRequest,
                    DynamoHttpServletResponse pResponse)
             throws javax.servlet.ServletException,
                    java.io.IOException
Look for the RepositoryItem and if found render the output oparam by binding the item as a parameter. If no item can be found render the empty oparam. If the RepositoryItem is found, but does not belong to the user's catalog, render the wrongCatalog oparam. If no catalog is provided, render the noCatalog oparam. If the item belongs to a site but it is not the current site render the wrongSite property.

Overrides:
service in class ItemLookupDroplet
Parameters:
pRequest - the request to be processed
pResponse - the response object for this request
Throws:
javax.servlet.ServletException - an application specific error occurred processing this request
java.io.IOException - an error occurred reading data from the request or writing data to the response.

findItem

protected RepositoryItem findItem(java.lang.String pId,
                                  java.lang.String pItemDescriptorName,
                                  Repository pRepository)
                           throws RepositoryException
Attempts to find an item in the given repository based on Id and Item descriptor. If the item can not be found in the given repository the default repository will be used to find the item.

Parameters:
pId - - Id of the item to find
pItemDescriptorName - ItemDescriptor for the item
pRepository - Repository to look for the item before using the default repository.
Returns:
The repository item matching the given id and item descriptor.
Throws:
RepositoryException

getRepositoryForCatalogItemLookup

protected Repository getRepositoryForCatalogItemLookup(java.lang.String pRepositoryKey)
Gets the specified alternate repository if available, otherwise returns the defaults repository.

Parameters:
pRepositoryKey - Alternate repository to get
Returns:
the repository to use for Catalog Item Lookup

isItemInCatalogs

protected boolean isItemInCatalogs(RepositoryItem pItem,
                                   java.util.Collection<RepositoryItem> pCatalogs)
Determines if a given item is part of any catalog in the given collection.

Parameters:
pItem - Repository Item to check for membership in a catalog
pCatalogs - Catalogs to check membership for
Returns:
True if the item is in any catalog

isItemInSites

protected boolean isItemInSites(RepositoryItem pItem,
                                java.util.Collection<Site> pSites)
Determines if a given item is a part of any sites from the given set or the current site. If there is no site to check or if the item has no sites property in its definition, return true.

Parameters:
pItem - repository item
pSites - set of sites
Returns:
true if item is a part of any site.

isFilterBySite

protected boolean isFilterBySite(DynamoHttpServletRequest pRequest)
Determines if we are filtering by sites. Acceptable parameters are Boolean and String.

Parameters:
pRequest - Dynamo http request
Returns:
true if we filter item by site

isFilterByCatalog

protected boolean isFilterByCatalog(DynamoHttpServletRequest pRequest)
Returns true if item should filter by catalog. Acceptable parameters are Boolean and String.

Parameters:
pRequest - Dynamo http request
Returns:
true if filter item by catalog

getRepository

protected Repository getRepository(DynamoHttpServletRequest pRequest)
Returns repository. If useParams is true, retrieves repository from request parameters, otherwise calls getRepositoryForCatalogItemLookup method

Parameters:
pRequest - Dynamo http request
Returns:
repository

getCatalogs

protected java.util.Collection<RepositoryItem> getCatalogs(DynamoHttpServletRequest pRequest)
Returns catalogs from request parameters. If no catalogs specified, returns null.

Parameters:
pRequest - Dynamo http request
Returns:
collection of catalog repository items or null

getSites

protected java.util.Collection<Site> getSites(DynamoHttpServletRequest pRequest)
If we have collection of sites in request parameter, then returns them, otherwise returns null.

Parameters:
pRequest - Dynamo http request
Returns:
collection of sites or null