Manages promotions and points buckets, both modelled by the Reward entity, plus reward categories and reward entries awarded to participants. Provides find, create and update operations for promotions and points buckets, builders for constructing a promotion (PromotionBuilder), a reward category (RewardCategoryBuilder) and a reward entry (RewardEntryBuilder), and participant search helpers used to work out who is eligible for a given promotion. Registered as the Spring bean "promotions.manager" and normally reached via the request-scoped lookup RequestContext.C(PromotionsManager .class); several of the builder methods are also exported to GraalJS scripts via HostAccess.Export.

Group: Managers


Properties

PropertyReturnsDescription
allPromotionsPromotionsListLists every promotion (excluding points buckets) belonging to the current tenant organisation.
allRewardsList<Reward>Lists every promotion and points bucket belonging to the current tenant organisation.
pointsAllocationSourcesList<PointsAllocationSource>Looks up all points allocation sources configured for the current tenant organisation.
pointsBucketsList<Reward>Lists all points buckets belonging to the current tenant organisation.
promotionMechanicTypesList<PromotionMechanicType>Lists the promotion mechanic types registered with the ApplicationManager, for example the types of rewards apps installed on the account.
rewardCategoriesList<RewardCategory>Lists all reward categories belonging to the current tenant organisation.

Methods

duplicatePromotion(String name, Reward sourcePromo) · createPromotion(String promoId, String promoTitle, Website website, String promoType) · updatePromotion(Reward promotion) · updatePromotionContent(Reward promotion, String bodyContent, String termsContent) · updatePromotionProperties(Reward promotion, Map<String,String> propValues) · newPromotionBuilder(String id, String title, Website website, String promoType) · getPointsAllocationSources() · findPointsAllocationSource(String name) · getPromotionMechanicTypes() · findPromotionMechanicType(String name) · findRewardEntry(Long id) · findRewardEntries(Profile user, Reward promo) · deleteRewardEntry(RewardEntry re) · getAllRewards() · getAllPromotions() · findPromotions(String query, String sortField, String sortDir) · deletePromo(Reward reward) · findPromotionsAfter(Date dt) · matchesParticipantSelector(Reward promo, BaseEntity entity) · matchesParticipantSelector(List<KSelectorItem> sels, Organisation entity) · findPointsBucket(long id) · findPointsBucket(String name) · findPromotion(String name) · findPromotionById(long id) · getPointsBuckets() · promotions(Boolean open, Date now) · availablePromotions() · availablePromotions(Date now, Profile curUser) · availablePromotions(Date now, Profile curUser, Boolean open) · activePromotions() · isMatchingPromoCode(String code, Reward promotion) · isElligbleUser(Profile user, Reward promotion) · isElligbleParticipant(BaseEntity participant, Reward promotion) · isActive(Reward promotion) · isStarted(Reward promotion) · promotionDetails(Reward reward) · numEntries(Reward promo) · findAnswerKeys(Reward reward) · newRewardEntryBuilder(Reward reward, Profile enteredProfile) · submitEntry(RewardEntryBuilder b) · participantSelectors(Reward promo) · newParticipantSearch() · countParticipants(ParticipantSearchBuilder psb) · findParticipants(Reward promo) · findParticipants(Reward promo, Boolean orgs) · findParticipants(ParticipantSearchBuilder psb) · useParticipants(ParticipantSearchBuilder psb, Consumer<BaseEntity> callback) · findRewardEntriesForUser(Reward reward, Profile user) · findUserAttachmentHash(Reward reward, Profile user) · findRewardEntriesWithAttachment(Reward reward) · findPromotionTerm(Reward reward) · putPromotionImage(Reward reward, String hash, String name) · updatePromotionImage(Reward reward, String newHash) · addPromotionGroup(Reward reward, Group group) · removePromotionGroup(Reward reward, Group group) · countPromotionEntries(Reward reward) · findPromotionsByType(String promotionType) · rewardEntryStatus(String s) · updateWinningEntry(RewardEntry entry) · newRewardCategoryBuilder(String name, String title) · getRewardCategories() · findRewardCategoryByName(String name) · updateRewardCategory(RewardCategory category) · deleteRewardCategory(RewardCategory category)

duplicatePromotion(String name, Reward sourcePromo)

Returns: Reward

Creates a new Reward by copying the core fields (dates, points org types, image, title, url, status, website and group filters) from an existing promotion, then copies the source promotion's content directory (if any) across to the new promotion's rewards folder. Throws a RuntimeException if there is no current user or if saving the copied content fails.

ParameterDescription
namethe name to give the new promotion
sourcePromothe promotion to copy fields, groups and content from

createPromotion(String promoId, String promoTitle, Website website, String promoType)

Returns: Reward

Creates and persists a new promotion using the default builder settings, then records a "create-promotion" telemetry event for the account.

ParameterDescription
promoIdthe unique name to give the new promotion
promoTitlethe display title of the promotion
websitethe website the promotion belongs to
promoTypethe promotion mechanic type, as registered with the ApplicationManager

updatePromotion(Reward promotion)

Returns: void

Saves changes to an existing promotion or points bucket entity.

ParameterDescription
promotionthe promotion to save

updatePromotionContent(Reward promotion, String bodyContent, String termsContent)

Returns: void

Updates the promotion's body and terms content, stored as files in the promotion's directory in the rewards branch. The body is saved into the "details" property for historical reasons, and the terms are written to a terms.html file; either can be omitted by passing null to leave it unchanged.

ParameterDescription
promotionthe promotion whose content is being updated
bodyContentthe new body content, or null to leave the existing body unchanged
termsContentthe new terms content, or null to leave the existing terms unchanged

updatePromotionProperties(Reward promotion, Map<String,String> propValues)

Returns: void

Merges the given values into the promotion's stored properties file, in its directory in the rewards branch. Blank values are ignored, so existing properties are only overwritten when a non-blank replacement is supplied.

ParameterDescription
promotionthe promotion whose properties are being updated
propValuesa map of property name to new value; blank values are skipped

newPromotionBuilder(String id, String title, Website website, String promoType)

Returns: PromotionBuilder

Creates a builder for constructing and persisting a new promotion.

ParameterDescription
idthe unique name to give the new promotion
titlethe display title of the promotion
websitethe website the promotion belongs to
promoTypethe promotion mechanic type, as registered with the ApplicationManager

getPointsAllocationSources()

Returns: List<PointsAllocationSource>

Looks up all points allocation sources configured for the current tenant organisation.

findPointsAllocationSource(String name)

Returns: PointsAllocationSource

Looks up a points allocation source by name within the current tenant organisation.

ParameterDescription
namethe name of the points allocation source

getPromotionMechanicTypes()

Returns: List<PromotionMechanicType>

Lists the promotion mechanic types registered with the ApplicationManager, for example the types of rewards apps installed on the account.

findPromotionMechanicType(String name)

Returns: PromotionMechanicType

Looks up a registered promotion mechanic type by its name.

ParameterDescription
namethe name of the promotion mechanic type

findRewardEntry(Long id)

Returns: RewardEntry

Looks up a reward entry by its id within the current tenant organisation.

ParameterDescription
idthe id of the reward entry

findRewardEntries(Profile user, Reward promo)

Returns: List<RewardEntry>

Finds the reward entries a user has for a given promotion.

ParameterDescription
userthe profile to find entries for
promothe promotion to find entries for

deleteRewardEntry(RewardEntry re)

Returns: void

Deletes a reward entry. Does nothing if the given entry is null. Callers are responsible for ensuring no ModuleStatus, Referral or ReferralAcceptance still references the entry, as those relations prevent deletion.

ParameterDescription
rethe reward entry to delete, or null to do nothing

getAllRewards()

Returns: List<Reward>

Lists every promotion and points bucket belonging to the current tenant organisation.

getAllPromotions()

Returns: PromotionsList

Lists every promotion (excluding points buckets) belonging to the current tenant organisation.

findPromotions(String query, String sortField, String sortDir)

Returns: PromotionsList

Searches the current tenant organisation's promotions by a free-text query, with the results sorted.

ParameterDescription
queryfree-text search query, or null/blank to match all promotions
sortFieldthe field to sort results by
sortDirthe sort direction

deletePromo(Reward reward)

Returns: void

Soft-deletes a promotion or points bucket, recording the current user and time as the deleting user and date.

ParameterDescription
rewardthe promotion or points bucket to delete

findPromotionsAfter(Date dt)

Returns: PromotionsList

Finds all promotions in the current tenant organisation with a start date after the given date.

ParameterDescription
dtthe date to search after

matchesParticipantSelector(Reward promo, BaseEntity entity)

Returns: boolean

Checks whether an entity (a profile or organisation) matches a promotion's participant selectors.

ParameterDescription
promothe promotion whose selectors are checked
entitythe entity to check against the selectors

matchesParticipantSelector(List<KSelectorItem> sels, Organisation entity)

Returns: boolean

Checks whether an organisation matches the given list of participant selectors.

ParameterDescription
selsthe participant selectors to check against
entitythe organisation to check

findPointsBucket(long id)

Returns: Reward

Looks up a points bucket by id within the current tenant organisation.

ParameterDescription
idthe id of the points bucket

findPointsBucket(String name)

Returns: Reward

Looks up a points bucket by name within the current tenant organisation.

ParameterDescription
namethe name of the points bucket

findPromotion(String name)

Returns: Reward

Looks up a promotion or points bucket by name within the current tenant organisation.

ParameterDescription
namethe name of the promotion

findPromotionById(long id)

Returns: Reward

Looks up a promotion or points bucket by id within the current tenant organisation.

ParameterDescription
idthe id of the promotion

getPointsBuckets()

Returns: List<Reward>

Lists all points buckets belonging to the current tenant organisation.

promotions(Boolean open, Date now)

Returns: PromotionsList

Finds promotions for the current tenant organisation, filtered by whether they have finished as at the given date. Passing null for open returns every promotion regardless of status.

ParameterDescription
opentrue to return only unfinished promotions, false to return only finished ones, or null for all
nowthe date to evaluate finished status against

availablePromotions()

Returns: PromotionsList

Finds the open promotions currently available to the current user, evaluated as at now.

availablePromotions(Date now, Profile curUser)

Returns: PromotionsList

Finds the open promotions available to a given user as at a given date.

ParameterDescription
nowthe date to evaluate availability against
curUserthe profile to find available promotions for

availablePromotions(Date now, Profile curUser, Boolean open)

Returns: PromotionsList

Finds the promotions available to a given user as at a given date, optionally filtered to only open ones.

ParameterDescription
nowthe date to evaluate availability against
curUserthe profile to find available promotions for
opentrue to return only currently open promotions; false or null includes closed ones too

activePromotions()

Returns: PromotionsList

Finds the promotions that are currently open, as at now.

isMatchingPromoCode(String code, Reward promotion)

Returns: boolean

Checks whether the given code matches one of the promotion's configured entry codes.

ParameterDescription
codethe code to check
promotionthe promotion whose entry codes are checked

isElligbleUser(Profile user, Reward promotion)

Returns: boolean

Checks whether a user is eligible for a promotion, based on the promotion's participant selectors. Returns false if the promotion is null.

ParameterDescription
userthe user to check eligibility for
promotionthe promotion to check, or null

isElligbleParticipant(BaseEntity participant, Reward promotion)

Returns: boolean

Checks whether a participant, either a profile or an organisation, is eligible for a promotion, based on the promotion's participant selectors and, for profiles, org criteria.

ParameterDescription
participantthe profile or organisation to check eligibility for
promotionthe promotion to check

isActive(Reward promotion)

Returns: boolean

Checks whether a promotion is currently active, meaning it has started (or has no start date), has not finished (or has no end date), and is not null.

ParameterDescription
promotionthe promotion to check, or null

isStarted(Reward promotion)

Returns: boolean

Checks whether a promotion is viewable, meaning it has passed its start date. Unlike isActive, this remains true after the finish date. Equivalent to calling promotion.isViewable(now). Returns false if the promotion is null.

ParameterDescription
promotionthe promotion to check, or null

promotionDetails(Reward reward)

Returns: PromotionBean

Loads the promotion's stored content properties (as saved by updatePromotionContent and updatePromotionProperties) into a PromotionBean. Returns null if the reward is null.

ParameterDescription
rewardthe promotion to load details for, or null

numEntries(Reward promo)

Returns: long

Counts the reward entries recorded against a promotion. Returns 0 if the promotion is null.

ParameterDescription
promothe promotion to count entries for, or null

findAnswerKeys(Reward reward)

Returns: List<String>

Finds the distinct quiz answer keys that have been submitted for a promotion, sorted in natural order.

ParameterDescription
rewardthe promotion to find answer keys for

newRewardEntryBuilder(Reward reward, Profile enteredProfile)

Returns: RewardEntryBuilder

Creates a builder for constructing and submitting a new reward entry, recording that a profile has entered or been awarded a promotion.

ParameterDescription
rewardthe promotion the entry is for
enteredProfilethe profile being awarded the entry

submitEntry(RewardEntryBuilder b)

Returns: RewardEntry

Builds and persists a RewardEntry from a configured RewardEntryBuilder. If quiz answers were added to the builder, also creates the RewardQuizSubmission, QuizAttempt and QuizAnswer records, uploading any answered files via the FileStorageManager. The entry's approval status defaults to pending or accepted depending on whether the reward requires approval, unless an explicit status was set on the builder. Fires a reward entry status updated event once the entry is saved.

ParameterDescription
bthe configured builder to create the reward entry from

participantSelectors(Reward promo)

Returns: List<KSelectorItem>

Parses and returns the participant selectors configured on a promotion.

ParameterDescription
promothe promotion to read participant selectors from

newParticipantSearch()

Returns: ParticipantSearchBuilder

Creates a builder for searching for the profiles or organisations eligible to participate in a promotion.

countParticipants(ParticipantSearchBuilder psb)

Returns: int

Counts the profiles or organisations matching a participant search, without loading the full result set.

ParameterDescription
psbthe configured participant search to count matches for

findParticipants(Reward promo)

Returns: Collection<BaseEntity>

Finds the profiles eligible to participate in a promotion, based on its group and organisation type filters.

ParameterDescription
promothe promotion to find participants for

findParticipants(Reward promo, Boolean orgs)

Returns: Collection<BaseEntity>

Finds the profiles or organisations eligible to participate in a promotion, based on its group and organisation type filters.

ParameterDescription
promothe promotion to find participants for
orgstrue to find matching organisations instead of profiles

findParticipants(ParticipantSearchBuilder psb)

Returns: Collection<BaseEntity>

Finds the profiles or organisations matching a configured participant search, including any paging limits set on the builder.

ParameterDescription
psbthe configured participant search to run

useParticipants(ParticipantSearchBuilder psb, Consumer<BaseEntity> callback)

Returns: void

Streams the profiles or organisations matching a configured participant search to a callback, rather than loading them all into memory at once. Does nothing if the search has no criteria.

ParameterDescription
psbthe configured participant search to run
callbackinvoked once for each matching profile or organisation

findRewardEntriesForUser(Reward reward, Profile user)

Returns: List<RewardEntry>

Finds the reward entries a user has for a given promotion.

ParameterDescription
rewardthe promotion to find entries for
userthe profile to find entries for

findUserAttachmentHash(Reward reward, Profile user)

Returns: String

Finds the attachment hash from the first of the user's reward entries for this promotion that has an attachment. The hash can be used with /_hashes/files/{hash} to display the file. Returns null if the promotion or user is null, or no matching entry has an attachment.

ParameterDescription
rewardthe promotion to look up entries for, or null
userthe profile to look up entries for, or null

findRewardEntriesWithAttachment(Reward reward)

Returns: List<RewardEntry>

Finds the reward entries for a promotion that have a non-blank attachment hash.

ParameterDescription
rewardthe promotion to find entries for

findPromotionTerm(Reward reward)

Returns: String

Reads the terms and conditions content stored for a promotion. Returns null if the terms cannot be loaded, for example if none have been saved yet.

ParameterDescription
rewardthe promotion to read terms for

putPromotionImage(Reward reward, String hash, String name)

Returns: ItemImage

Sets the promotion's image from an already-uploaded file.

ParameterDescription
rewardthe promotion to set the image on
hashthe content hash of the uploaded image file
namethe file name of the image

updatePromotionImage(Reward reward, String newHash)

Returns: ItemImage

Replaces the promotion's existing image with a new version, for example after the image has been cropped.

ParameterDescription
rewardthe promotion whose image is being replaced
newHashthe content hash of the new image file

addPromotionGroup(Reward reward, Group group)

Returns: void

Adds a group to a promotion's group filter.

ParameterDescription
rewardthe promotion to add the group to
groupthe group to add

removePromotionGroup(Reward reward, Group group)

Returns: void

Removes a group from a promotion's group filter.

ParameterDescription
rewardthe promotion to remove the group from
groupthe group to remove

countPromotionEntries(Reward reward)

Returns: long

Counts the reward entries recorded against a promotion.

ParameterDescription
rewardthe promotion to count entries for

findPromotionsByType(String promotionType)

Returns: List<Reward>

Finds the promotions in the current tenant organisation with the given promotion mechanic type.

ParameterDescription
promotionTypethe promotion mechanic type to match

rewardEntryStatus(String s)

Returns: RewardEntryStatus

Parses a reward entry status name into its RewardEntryStatus enum value.

ParameterDescription
sthe status name to parse

updateWinningEntry(RewardEntry entry)

Returns: void

Marks a reward entry as the winner, setting its approval status to WINNER and saving it.

ParameterDescription
entrythe reward entry to mark as the winner

newRewardCategoryBuilder(String name, String title)

Returns: RewardCategoryBuilder

Creates a builder for constructing and persisting a new reward category.

ParameterDescription
namethe unique name to give the new reward category
titlethe display title of the reward category

getRewardCategories()

Returns: List<RewardCategory>

Lists all reward categories belonging to the current tenant organisation.

findRewardCategoryByName(String name)

Returns: RewardCategory

Looks up a reward category by name within the current tenant organisation.

ParameterDescription
namethe name of the reward category

updateRewardCategory(RewardCategory category)

Returns: void

Saves changes to an existing reward category.

ParameterDescription
categorythe reward category to save

deleteRewardCategory(RewardCategory category)

Returns: void

Deletes a reward category.

ParameterDescription
categorythe reward category to delete
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.