atg.commerce.promotion.template
Class PromotionTemplateManager

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.commerce.promotion.template.PromotionTemplateManager
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, Schedulable, java.util.EventListener

public class PromotionTemplateManager
extends GenericService
implements Schedulable

Manages operations involving the template registry used in promotions. The template registry stores the templates used in promotions.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
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
PromotionTemplateManager()
           
 
Method Summary
protected  boolean canDisplay(java.lang.String pPath, java.lang.String pType)
           Determines if the template can be displayed in the promotions ui.
 void doStartService()
          Adds the update job to the scheduler
 java.util.Map<java.lang.String,java.lang.Object> getAllProperties(java.lang.String pPath, java.util.Map<java.lang.String,java.lang.String> pPlaceholderReplacements)
           Gets all the properties in the template pPath.
 java.util.Map<java.lang.String,java.lang.Object> getAllProperties(java.lang.String pPath, java.util.Map<java.lang.String,java.lang.String> pPlaceholderReplacements, java.util.List<java.lang.String> pExclusionList)
           Calls getAllProperties(String, Map) but removes the properties whose name appears in the pExclusionList
protected  java.util.Map<java.lang.String,java.lang.String> getAttributesMap(java.lang.String pPath, java.lang.String pTag)
           Gets the attributes of a node and returns them in a Map where the keys are the attribute names and the values are the attribute values.
protected  org.w3c.dom.Document getDocument(java.lang.String pPath)
           Gets a document from the registry
 java.lang.Object getProperty(java.lang.String pPropertyName, java.lang.String pPath, java.util.Map<java.lang.String,java.lang.String> pPlaceholderReplacements, boolean pReplaceEmtpyPlaceholders)
           Gets the property specified by pPropertyName from the template pPath.
 java.util.Map<java.lang.String,java.lang.Object> getPropertyPlaceholdersMap(java.lang.String pPath)
           Returns a Map containing a template property name and either a List of place holders associated with this template property, or a List of Maps associated with this property if the property has sub properties.
 atg.repository.editingtemplate.RepositoryItemEditingTemplateParser getRepositoryItemEditingTemplateParser()
          Gets the RepositoryItemEditingTemplateParser
 Schedule getSchedule()
          Gets the schedule
 Scheduler getScheduler()
          Gets the scheduler
 java.util.Map<java.lang.String,java.util.Map> getTemplateInfoForUI(java.lang.String pType)
           Filters a map of templates with a specified type for the templates which firstly, have a ui-description section and secondly whose display-in-ui attribute is set to true.
 java.lang.String getTemplateItemType(java.lang.String pPath)
           Returns the item-type (e.g "Shipping Discount") attribute of the promotion template at pPath.
 atg.commerce.service.registry.TemplateRegistry getTemplateRegistry()
          Gets the template registry
 java.lang.String getTemplateUIDescription(java.lang.String pPath)
           Returns the section of the template pPath.
protected  boolean isDisplayAttributeTrue(org.w3c.dom.Document pDocument)
           Determines whether or not the available-in-ui attribute is set
protected  boolean isPromotionTypeCorrect(org.w3c.dom.Document pDocument, java.lang.String pType)
           Determines if the current template has the requested promotion type
 void performScheduledTask(Scheduler pScheduler, ScheduledJob pJob)
           Update the cache of templates on a configurable basis as defined by the schedule.
 void setRepositoryItemEditingTemplateParser(atg.repository.editingtemplate.RepositoryItemEditingTemplateParser pRepositoryItemEditingTemplateParser)
          Sets the RepositoryItemEditingTemplateParser
 void setSchedule(Schedule pSchedule)
          Sets the schedule
 void setScheduler(Scheduler pScheduler)
          Sets the scheduler
 void setTemplateRegistry(atg.commerce.service.registry.TemplateRegistry pTemplateRegistry)
          Sets the template registry
 void updateTemplateCache()
           Updates the template registrys cache to reflect the templates stored in the registry.
protected  boolean validRoot(org.w3c.dom.Element pRoot)
           Determines if this document has a valid generic template root
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, 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

PromotionTemplateManager

public PromotionTemplateManager()
Method Detail

getScheduler

public Scheduler getScheduler()
Gets the scheduler


setScheduler

public void setScheduler(Scheduler pScheduler)
Sets the scheduler


getSchedule

public Schedule getSchedule()
Gets the schedule


setSchedule

public void setSchedule(Schedule pSchedule)
Sets the schedule


getRepositoryItemEditingTemplateParser

public atg.repository.editingtemplate.RepositoryItemEditingTemplateParser getRepositoryItemEditingTemplateParser()
Gets the RepositoryItemEditingTemplateParser


setRepositoryItemEditingTemplateParser

public void setRepositoryItemEditingTemplateParser(atg.repository.editingtemplate.RepositoryItemEditingTemplateParser pRepositoryItemEditingTemplateParser)
Sets the RepositoryItemEditingTemplateParser


getTemplateRegistry

public atg.commerce.service.registry.TemplateRegistry getTemplateRegistry()
Gets the template registry


setTemplateRegistry

public void setTemplateRegistry(atg.commerce.service.registry.TemplateRegistry pTemplateRegistry)
Sets the template registry


doStartService

public void doStartService()
                    throws ServiceException
Adds the update job to the scheduler

Overrides:
doStartService in class GenericService
Throws:
ServiceException - if the Service had a problem starting up

performScheduledTask

public void performScheduledTask(Scheduler pScheduler,
                                 ScheduledJob pJob)

Update the cache of templates on a configurable basis as defined by the schedule.

Specified by:
performScheduledTask in interface Schedulable
Parameters:
pScheduler - calling the job
pJob - the ScheduledJob

getTemplateInfoForUI

public java.util.Map<java.lang.String,java.util.Map> getTemplateInfoForUI(java.lang.String pType)
                                                                   throws atg.repository.editingtemplate.TemplateException

Filters a map of templates with a specified type for the templates which firstly, have a ui-description section and secondly whose display-in-ui attribute is set to true. This means the template author intended them to be displayed in the UI.

If there are no templates matching pType or there are no templates which are displayable in the ui then an empty map will be returned.

Returns:
A map whose key is the template path and whose value is a Map of the template and ui-description attributes.
Throws:
atg.repository.editingtemplate.TemplateException - if an error occurred parsing the template or if the required pType is null.

updateTemplateCache

public void updateTemplateCache()
                         throws atg.service.registry.RegistryException

Updates the template registrys cache to reflect the templates stored in the registry. Any changes to templates will be picked up by this action.

Throws:
atg.service.registry.RegistryException - if an error occurred reading a template in the registry

getTemplateUIDescription

public java.lang.String getTemplateUIDescription(java.lang.String pPath)
                                          throws atg.repository.editingtemplate.TemplateException

Returns the section of the template pPath. If the template does not exist null is returned, or if the template does not have a section null is returned.

Parameters:
pPath - The full path to a template
Returns:
The section of a template as a string.
Throws:
atg.repository.editingtemplate.TemplateException - If the required argument pPath is null or there is a problem parsing the template

getProperty

public java.lang.Object getProperty(java.lang.String pPropertyName,
                                    java.lang.String pPath,
                                    java.util.Map<java.lang.String,java.lang.String> pPlaceholderReplacements,
                                    boolean pReplaceEmtpyPlaceholders)
                             throws atg.repository.editingtemplate.TemplateException

Gets the property specified by pPropertyName from the template pPath. If there are place holders in the property value then the Map pPlaceholderReplacements will be used to replace them.

A property will be returned as a string, unless the property has itself has properties (name=value pairs), in this case a List of Maps will be returned. Each Map in the list represents a sub tag of a . They key will be the sub property name and the value the sub property value (either a String or a List of Maps)

Parameters:
pPath - The full path to a template
pPropertyName - The name of a template property
pPlaceholderReplacements - A map of key=value pairs representing place holder names and place holder values
pReplaceEmtpyPlaceholders - Flag to indicate whether to replace empty placeholders with empty strings
Returns:
Either a String if the property only has one value, or a List of Maps if the property has sub properties.
Throws:
atg.repository.editingtemplate.TemplateException - If the required argument pPath is null or there is a problem parsing the template

getAllProperties

public java.util.Map<java.lang.String,java.lang.Object> getAllProperties(java.lang.String pPath,
                                                                         java.util.Map<java.lang.String,java.lang.String> pPlaceholderReplacements)
                                                                  throws atg.repository.editingtemplate.TemplateException

Gets all the properties in the template pPath. Any place holders in the property values will be replaced by the replacement values specified in pPlaceholderReplacements Map.

Parameters:
pPath - The full template path
pPlaceholderReplacements - A map of key=value pairs representing place holder names and place holder values
Returns:
A Map whose keys are the property names and whose values are Objects, a String object value represents a simple property (e.g just a value) a List object of Map is returned when a property has sub properties. Each Map in the List represents a sub element under the . Within these Maps the object may again be a String for a simple property or a List containing Map.
Throws:
atg.repository.editingtemplate.TemplateException - If the required argument pPath is null or there is a problem parsing the template

getAllProperties

public java.util.Map<java.lang.String,java.lang.Object> getAllProperties(java.lang.String pPath,
                                                                         java.util.Map<java.lang.String,java.lang.String> pPlaceholderReplacements,
                                                                         java.util.List<java.lang.String> pExclusionList)
                                                                  throws atg.repository.editingtemplate.TemplateException

Calls getAllProperties(String, Map) but removes the properties whose name appears in the pExclusionList

Parameters:
pPath - The full template path
pExclusionList - A list of properties which will not appear in the returned Map.
pPlaceholderReplacements - A map of key=value pairs representing place holder names and place holder values
Returns:
A Map whose keys are the property names and whose values are Objects, a String object value represents a simple property (e.g just a value) a List object of Map is returned when a property has sub properties. Each Map in the List represents a sub element under the . Within these Maps the object may again be a String for a simple property or a List containing Map.
Throws:
atg.repository.editingtemplate.TemplateException - If the required argument pPath is null or there is a problem parsing the template

getPropertyPlaceholdersMap

public java.util.Map<java.lang.String,java.lang.Object> getPropertyPlaceholdersMap(java.lang.String pPath)
                                                                            throws atg.repository.editingtemplate.TemplateException

Returns a Map containing a template property name and either a List of place holders associated with this template property, or a List of Maps associated with this property if the property has sub properties.

Parameters:
pPath - The path to a template
Returns:
Map where keys are the property names and the values are either Lists of place holders associated with the property or a List of Maps if the property has sub properties.
Throws:
atg.repository.editingtemplate.TemplateException - If the required argument pPath is null or there is a problem parsing the template

getTemplateItemType

public java.lang.String getTemplateItemType(java.lang.String pPath)
                                     throws atg.repository.editingtemplate.TemplateException

Returns the item-type (e.g "Shipping Discount") attribute of the promotion template at pPath. If the template at pPath does not exist then null is returned.

Parameters:
pPath - A path to a promotions template
Returns:
The item type of the promotion
Throws:
atg.repository.editingtemplate.TemplateException - If the required argument pPath is null or the promotions template at pPath does not have the required attributes.

canDisplay

protected boolean canDisplay(java.lang.String pPath,
                             java.lang.String pType)
                      throws atg.repository.editingtemplate.TemplateException

Determines if the template can be displayed in the promotions ui. The "available-in-ui" ui-description attribute must be true and the promotion type must be of the requested type

Parameters:
pPath - A path to a template
pType - The type of template
Returns:
A boolean indicating if the template can be displayed or not
Throws:
atg.repository.editingtemplate.TemplateException - if either of the required parameters are null or there is a problem getting the template from the registry

isDisplayAttributeTrue

protected boolean isDisplayAttributeTrue(org.w3c.dom.Document pDocument)
                                  throws atg.repository.editingtemplate.TemplateException

Determines whether or not the available-in-ui attribute is set

Parameters:
pDocument - A Document representation of a template
Returns:
A boolean indicating whether or not the available-in-ui attribute is set or not
Throws:
atg.repository.editingtemplate.TemplateException - If the template is not a promotions template

isPromotionTypeCorrect

protected boolean isPromotionTypeCorrect(org.w3c.dom.Document pDocument,
                                         java.lang.String pType)
                                  throws atg.repository.editingtemplate.TemplateException

Determines if the current template has the requested promotion type

Parameters:
pDocument - A Document representation of a template
pType - The template type
Returns:
A boolean indicating whether or not the template type is correct
Throws:
atg.repository.editingtemplate.TemplateException - If the template is not a promotions template

getAttributesMap

protected java.util.Map<java.lang.String,java.lang.String> getAttributesMap(java.lang.String pPath,
                                                                            java.lang.String pTag)
                                                                     throws atg.service.registry.RegistryException,
                                                                            atg.repository.editingtemplate.TemplateException

Gets the attributes of a node and returns them in a Map where the keys are the attribute names and the values are the attribute values. If the node has no attributes null is returned.

Parameters:
pPath - the path to the template
pTag - the element whose attributes to get
Returns:
A map whose keys are the attribute names and values are the attribute values of the node pTag
Throws:
atg.repository.editingtemplate.TemplateException - if an error occurred parsing a template or the required arguments are null
atg.service.registry.RegistryException - if an error occurred reading the template in the registry

getDocument

protected org.w3c.dom.Document getDocument(java.lang.String pPath)
                                    throws atg.repository.editingtemplate.TemplateException

Gets a document from the registry

Parameters:
pPath - The full path to a template
Returns:
A DOM Document
Throws:
atg.repository.editingtemplate.TemplateException - If a problem occurred retrieving the template from the registry

validRoot

protected boolean validRoot(org.w3c.dom.Element pRoot)

Determines if this document has a valid generic template root

Parameters:
pRoot - The document element of the template
Returns:
A boolean indicating a valid root element.