Class AbstractPromotion
- java.lang.Object
-
- de.hybris.platform.util.BridgeAbstraction
-
- de.hybris.platform.jalo.Item
-
- de.hybris.platform.jalo.ExtensibleItem
-
- de.hybris.platform.jalo.c2l.LocalizableItem
-
- de.hybris.platform.jalo.GenericItem
-
- de.hybris.platform.promotions.jalo.GeneratedAbstractPromotion
-
- de.hybris.platform.promotions.jalo.AbstractPromotion
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable
- Direct Known Subclasses:
GeneratedOrderPromotion
,GeneratedProductPromotion
,GeneratedRuleBasedPromotion
public abstract class AbstractPromotion extends GeneratedAbstractPromotion
AbstractPromotion. The base class for all promotions.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.GenericItem
GenericItem.GenericItemImpl
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
LocalizableItem.LocalizableItemImpl
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.ExtensibleItem
ExtensibleItem.ExtensibleItemImpl
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.Item
Item.AttributeFilter, Item.AttributeMode, Item.CachedGetter, Item.CachedSetter, Item.ItemAttributeMap, Item.ItemConstraint, Item.ItemImpl, Item.JaloCachedComputationException
-
-
Field Summary
-
Fields inherited from class de.hybris.platform.promotions.jalo.GeneratedAbstractPromotion
CODE, DEFAULT_INITIAL_ATTRIBUTES, DESCRIPTION, DETAILSURL, ENABLED, ENDDATE, IMMUTABLEKEY, IMMUTABLEKEYHASH, PRIORITY, PROMOTIONGROUP, PROMOTIONGROUPHANDLER, PROMOTIONTYPE, RESTRICTIONS, STARTDATE, TITLE
-
Fields inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
LANGUAGE_FALLBACK_ENABLED
-
Fields inherited from class de.hybris.platform.jalo.Item
_CREATION_TIME_INTERNAL, _MODIFIED_TIME_INTERNAL, accessorLog, CREATION_TIME, DISABLE_ATTRIBUTE_CHECK, DISABLE_ITEMCHECK_BEFORE_REMOVABLE, EVEN, FEATURE_ACCESSMAP_QUALIFIER, HJMPTS, INITIAL_CREATION_FLAG, isJaloOnly, MODIFIED_TIME, NEGATIVE, NOT_FOUND, OWNER, PK, POSITIVE, SAVE_FROM_SERVICE_LAYER, staticTransientObjects, TYPE
-
Fields inherited from class de.hybris.platform.util.BridgeAbstraction
impl, tenant
-
-
Constructor Summary
Constructors Constructor Description AbstractPromotion()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
buildDataUniqueKey(SessionContext ctx, java.lang.StringBuilder builder)
Build a unique data driven key.protected static void
buildDataUniqueKeyForCategories(SessionContext ctx, java.lang.StringBuilder builder, java.util.Collection<Category> categories)
protected static void
buildDataUniqueKeyForPriceRows(SessionContext ctx, java.lang.StringBuilder builder, java.util.Collection<PromotionPriceRow> priceRows)
protected static void
buildDataUniqueKeyForProducts(SessionContext ctx, java.lang.StringBuilder builder, java.util.Collection<Product> products)
protected static java.lang.String
buildMD5Hash(java.lang.String message)
protected void
buildPromotionResultDataUnigueKey(SessionContext ctx, PromotionResult promotionResult, java.lang.StringBuilder builder)
Build a unique identifier for a PromotionResult.protected AbstractPromotion
createImmutableDeepClone(SessionContext ctx, java.lang.String immutableKeyHash, java.lang.String immutableKey)
protected Item
createItem(SessionContext ctx, ComposedType type, Item.ItemAttributeMap allAttributes)
Create the item.protected void
deepCloneAttributes(SessionContext ctx, java.util.Map values)
Called to deep clone attributes of this instance.protected static java.util.Collection<PromotionPriceRow>
deepClonePriceRows(SessionContext ctx, java.util.Collection<PromotionPriceRow> priceRows)
static void
deletePromotionPriceRows(SessionContext ctx, java.util.Collection<PromotionPriceRow> prices)
Helper method to delete promotion price rows from the database.abstract java.util.List<PromotionResult>
evaluate(SessionContext ctx, PromotionEvaluationContext promoContext)
Evaluate whether a promotion can fire or not.protected static AbstractPromotion
findImmutablePromotionByUniqueKey(JaloSession jaloSession, SessionContext ctx, java.lang.String immutableKeyHash, java.lang.String immutableKey)
protected AbstractPromotion
findOrCreateImmutableClone(SessionContext ctx)
Find or create an immutable clone of this promotion.protected static java.lang.String
formatMessage(java.lang.String pattern, java.lang.Object[] arguments, java.util.Locale locale)
Format a message pattern using the MessageFormatjava.util.Map
getAllPromotionType(SessionContext ctx)
Get promotionType for all supported languages.protected java.lang.String
getDataUniqueKey(SessionContext ctx)
Build a unique data driven key.protected java.lang.Double
getPriceForOrder(SessionContext ctx, java.util.Collection<PromotionPriceRow> prices, AbstractOrder order, java.lang.String fieldLabel)
Lookup the price for an order.protected java.lang.String
getPromotionResultDataUnigueKey(SessionContext ctx, PromotionResult promotionResult)
Generate a string identifier that can be used to establish if 2 PromotionResults are the same.java.lang.String
getPromotionType(SessionContext ctx)
Return the type name for this promotion instance.java.util.Collection
getRestrictions(SessionContext ctx)
Get the collection ofAbstractPromotionRestriction
instances.abstract java.lang.String
getResultDescription(SessionContext ctx, PromotionResult promotionResult, java.util.Locale locale)
Get a localized user presentable description for the result of this promotion.void
remove(SessionContext ctx)
Remove the item.void
setPromotionGroup(SessionContext ctx, PromotionGroup promotionGroup)
Override the default behaviour to prevent PromotionGroup from being set to null.void
setRestrictions(SessionContext ctx, java.util.Collection restrictions)
Set the collection ofAbstractPromotionRestriction
instance.java.lang.String
toString()
Get a simple description of promotion object.-
Methods inherited from class de.hybris.platform.promotions.jalo.GeneratedAbstractPromotion
getAllPromotionType, getCode, getCode, getDefaultAttributeModes, getDescription, getDescription, getDetailsURL, getDetailsURL, getEndDate, getEndDate, getImmutableKey, getImmutableKey, getImmutableKeyHash, getImmutableKeyHash, getPriority, getPriority, getPriorityAsPrimitive, getPriorityAsPrimitive, getPromotionGroup, getPromotionGroup, getPromotionType, getRestrictions, getStartDate, getStartDate, getTitle, getTitle, isEnabled, isEnabled, isEnabledAsPrimitive, isEnabledAsPrimitive, setCode, setCode, setDescription, setDescription, setDetailsURL, setDetailsURL, setEnabled, setEnabled, setEnabled, setEnabled, setEndDate, setEndDate, setImmutableKey, setImmutableKey, setImmutableKeyHash, setImmutableKeyHash, setPriority, setPriority, setPriority, setPriority, setPromotionGroup, setRestrictions, setStartDate, setStartDate, setTitle, setTitle
-
Methods inherited from class de.hybris.platform.jalo.GenericItem
getImplementation, getInitialProperties, getNonInitialAttributes, getRelatedItems, setRelatedItems
-
Methods inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
getAllLocalizedProperties, getAllLocalizedProperties, getAllLocalizedProperties, getAllLocalizedProperties, getAllValuesSessionContext, getLocalizedProperty, getLocalizedProperty, getLocalizedPropertyInternal, getLocalizedPropertyNames, getLocalizedPropertyNames, hasLanguage, isEmptyValue, isFallbackEnabled, removeLocalizedProperty, removeLocalizedProperty, setAllLocalizedProperties, setAllLocalizedProperties, setLocalizedProperty, setLocalizedProperty
-
Methods inherited from class de.hybris.platform.jalo.ExtensibleItem
createNonClassAccessor, getAllProperties, getAllProperties, getProperty, getProperty, getPropertyNames, getPropertyNames, removeProperty, removeProperty, setAllProperties, setAllProperties, setProperty, setProperty
-
Methods inherited from class de.hybris.platform.jalo.Item
addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addNegativePermission, addPermission, addPositivePermission, assureExtensionsLoaded, changeTypeAfterCreation, checkConstraint, checkItemPermission, checkMandatoryAttribute, checkMandatoryAttribute, checkPermission, checkPermission, checkRemovable, clearPermission, compareTo, ctx, doAfterRemove, doBeforeRemove, equals, getAccessorFor, getAllAttributes, getAllAttributes, getAllAttributes, getAllAttributes, getAllAttributesInternal, getAllLinkedItems, getAndCheckCacheBoundItem, getAttribute, getAttribute, getCacheBoundItem, getComposedType, getComposedTypePK, getCreationTime, getCurrentlyRemovingCount, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItemsCount, getLinkedItemsCount, getLinkedItemsCount, getModificationTime, getNegativePermissions, getOwner, getPermissionMap, getPermissions, getPersistenceVersion, getPK, getPositivePermissions, getRestrictedPrincipals, getSession, getSyncObject, getTenant, getTransientObject, getTransientObjectMap, hashCode, hasRegisteredClassAccessorFor, internal_registerClassAccessorFor, internal_registerNonClassAccessorFor, invalidateLocalCaches, isAlive, isCacheBound, isCurrentlyRemoving, isCurrentlyRemoving, isEmptyRelationValue, isInCreate, isInstanceOf, isItemCheckBeforeRemoveableDisabled, isMarkModifiedDisabled, isRelationLocalizationFallbackEnabled, newInstance, notifyExtensionsAfterItemCreation, notifyExtensionsBeforeItemCreation, notifyItemRemoval, notifyManagerAboutItemRemoval, readResolve, registerAccessFor, registerAccessFor, registerJaloInvalidationListeners, remove, removeItemCollection, removeItemCollection, removeLinkedItems, removeLinkedItems, removeLinkedItems, removeLinkedItems, removeLinks, removePartOfItems, removePartOfItems, setAllAttributes, setAllAttributes, setAllAttributesInternal, setAllLinkedItems, setAllLinkedItems, setAllLinkedItems, setAllLinkedItems, setAttribute, setAttribute, setAttributeFromString, setAttributeFromString, setCacheBound, setComposedType, setCreationTime, setImplementation, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setModificationTime, setNonInitialAttributes, setOwner, setPermissionsByMap, setTransientObject, setUseTA, useTA, writeReplace
-
Methods inherited from class de.hybris.platform.util.BridgeAbstraction
setTenant
-
-
-
-
Method Detail
-
createItem
protected Item createItem(SessionContext ctx, ComposedType type, Item.ItemAttributeMap allAttributes) throws JaloBusinessException
Create the item.- Overrides:
createItem
in classGeneratedAbstractPromotion
- Parameters:
ctx
- the current session context which this item is created withintype
- the actual item type ( since subtypes may not provide a own jalo class this may be different from the type which this method was implemented for )- Returns:
- the new item instance
- Throws:
JaloBusinessException
- indicates an error during creation - any changes will be rollbacked
-
remove
public void remove(SessionContext ctx) throws ConsistencyCheckException
Remove the item. When the promotion is removed any associated restriction items are also removed.- Overrides:
remove
in classItem
- Parameters:
ctx
- A SessionContext object- Throws:
ConsistencyCheckException
- if this item could not be removed for some reason
-
toString
public java.lang.String toString()
Get a simple description of promotion object.
-
getPromotionType
public java.lang.String getPromotionType(SessionContext ctx)
Return the type name for this promotion instance.- Specified by:
getPromotionType
in classGeneratedAbstractPromotion
- Parameters:
ctx
- The hybris context- Returns:
- the type name for this instance.
-
getAllPromotionType
public java.util.Map getAllPromotionType(SessionContext ctx)
Get promotionType for all supported languages.- Specified by:
getAllPromotionType
in classGeneratedAbstractPromotion
- Parameters:
ctx
- The hybris context- Returns:
- a map of the type names keyed by language.
-
setPromotionGroup
public void setPromotionGroup(SessionContext ctx, PromotionGroup promotionGroup)
Override the default behaviour to prevent PromotionGroup from being set to null.- Overrides:
setPromotionGroup
in classGeneratedAbstractPromotion
- Parameters:
ctx
- The hybris contextpromotionGroup
- The promotion group to set
-
evaluate
public abstract java.util.List<PromotionResult> evaluate(SessionContext ctx, PromotionEvaluationContext promoContext)
Evaluate whether a promotion can fire or not.- Parameters:
ctx
- The context to run the operation inpromoContext
- The evaluation context- Returns:
- the list of promotion results that this promotions creates
-
getResultDescription
public abstract java.lang.String getResultDescription(SessionContext ctx, PromotionResult promotionResult, java.util.Locale locale)
Get a localized user presentable description for the result of this promotion.- Parameters:
ctx
- The contextpromotionResult
- The promotion result to be describedlocale
- The locale to use to generate the message- Returns:
- a string description
-
getPriceForOrder
protected final java.lang.Double getPriceForOrder(SessionContext ctx, java.util.Collection<PromotionPriceRow> prices, AbstractOrder order, java.lang.String fieldLabel)
Lookup the price for an order. Lookup the price for the currency specified on the order.- Parameters:
ctx
- The hybris contextprices
- The collection ofPromotionPriceRow
which is the set of pricesorder
- The order to lookup the price forfieldLabel
- A string label to use when generating error messages.- Returns:
- The price for the order's currency or null if not specified
-
formatMessage
protected static final java.lang.String formatMessage(java.lang.String pattern, java.lang.Object[] arguments, java.util.Locale locale)
Format a message pattern using the MessageFormat- Parameters:
pattern
- the message patternarguments
- the arguments to pass into the patternlocale
- the rendering locale- Returns:
- a formatted string
-
findOrCreateImmutableClone
protected final AbstractPromotion findOrCreateImmutableClone(SessionContext ctx)
Find or create an immutable clone of this promotion.- Parameters:
ctx
- the hybris context- Returns:
- the immutable version of this promotion
-
buildMD5Hash
protected static final java.lang.String buildMD5Hash(java.lang.String message)
-
createImmutableDeepClone
protected final AbstractPromotion createImmutableDeepClone(SessionContext ctx, java.lang.String immutableKeyHash, java.lang.String immutableKey)
-
findImmutablePromotionByUniqueKey
protected static final AbstractPromotion findImmutablePromotionByUniqueKey(JaloSession jaloSession, SessionContext ctx, java.lang.String immutableKeyHash, java.lang.String immutableKey)
-
getDataUniqueKey
protected final java.lang.String getDataUniqueKey(SessionContext ctx)
Build a unique data driven key. Build a unique key that is data driven. This will uniquely identify the rules used in this promotion and will form the immutable key for stored promotions.- Parameters:
ctx
- The hybris context- Returns:
- A
StringBuilder
used to build up the immutable key
-
buildDataUniqueKey
protected void buildDataUniqueKey(SessionContext ctx, java.lang.StringBuilder builder)
Build a unique data driven key. Build a unique key that is data driven. This will uniquely identify the rules used in this promotion and will form the immutable key for stored promotions. This method may be overridden in a subclass to customize the identifier.- Parameters:
ctx
- The hybris contextbuilder
- AStringBuilder
used to build up the immutable key
-
deepCloneAttributes
protected void deepCloneAttributes(SessionContext ctx, java.util.Map values)
Called to deep clone attributes of this instance. The values map contains all the attributes defined on this instance. The map will be used to initialize a new instance of the Action that is a clone of this instance. This method can remove, replace or add to the Map of attributes.- Parameters:
ctx
- The hybris contextvalues
- The map to write into
-
deepClonePriceRows
protected static final java.util.Collection<PromotionPriceRow> deepClonePriceRows(SessionContext ctx, java.util.Collection<PromotionPriceRow> priceRows)
-
buildDataUniqueKeyForPriceRows
protected static final void buildDataUniqueKeyForPriceRows(SessionContext ctx, java.lang.StringBuilder builder, java.util.Collection<PromotionPriceRow> priceRows)
-
buildDataUniqueKeyForProducts
protected static final void buildDataUniqueKeyForProducts(SessionContext ctx, java.lang.StringBuilder builder, java.util.Collection<Product> products)
-
buildDataUniqueKeyForCategories
protected static final void buildDataUniqueKeyForCategories(SessionContext ctx, java.lang.StringBuilder builder, java.util.Collection<Category> categories)
-
getRestrictions
public final java.util.Collection getRestrictions(SessionContext ctx)
Get the collection ofAbstractPromotionRestriction
instances.- Specified by:
getRestrictions
in classGeneratedAbstractPromotion
- Parameters:
ctx
- The hybris session context- Returns:
- A collection of
AbstractPromotionRestriction
instances attached to this promotion.
-
setRestrictions
public final void setRestrictions(SessionContext ctx, java.util.Collection restrictions)
Set the collection ofAbstractPromotionRestriction
instance. TheAbstractPromotionRestriction
instances associated with this promotion are owned (and part of) this promotion. They cannot belong to another instance, therefore when setting the collection anyAbstractPromotionRestriction
instances previously associated with this promotion, that are no longer associated are deleted from the database.- Specified by:
setRestrictions
in classGeneratedAbstractPromotion
- Parameters:
ctx
- The hybris session contextrestrictions
- the collection of restrictions
-
deletePromotionPriceRows
public static void deletePromotionPriceRows(SessionContext ctx, java.util.Collection<PromotionPriceRow> prices) throws ConsistencyCheckException
Helper method to delete promotion price rows from the database.- Parameters:
ctx
- The hybris contextprices
- The prices to delete- Throws:
ConsistencyCheckException
-
getPromotionResultDataUnigueKey
protected final java.lang.String getPromotionResultDataUnigueKey(SessionContext ctx, PromotionResult promotionResult)
Generate a string identifier that can be used to establish if 2 PromotionResults are the same. The identifier should be based on the data for the PromotionResult, e.g. the promotion that created it, the number and type of products consumed, the actions created. This method is final, but calls thebuildPromotionResultDataUnigueKey(de.hybris.platform.jalo.SessionContext, de.hybris.platform.promotions.jalo.PromotionResult, java.lang.StringBuilder)
method to allow subclasses to affect the way the identifier is built.- Parameters:
ctx
- The hybris contextpromotionResult
- The promotion result- Returns:
- a string that identifies this promotion result
-
buildPromotionResultDataUnigueKey
protected void buildPromotionResultDataUnigueKey(SessionContext ctx, PromotionResult promotionResult, java.lang.StringBuilder builder)
Build a unique identifier for a PromotionResult. This method is called fromgetPromotionResultDataUnigueKey(de.hybris.platform.jalo.SessionContext, de.hybris.platform.promotions.jalo.PromotionResult)
. This method may be overridden by a subclass to customize how the identifier is built.- Parameters:
ctx
- The hybris contextpromotionResult
- The promotion resultbuilder
- A StringBuilder used to build up the identifier
-
-