Voters

The voter mechanism allows determining when and how the recalculation is triggered. The logic of handling votes is in the CxPersonalizationFilter.

Voters have access to httpRequest and httpResponse to create a vote. Based on provided input, a voter decides if customer experience recalculation in form of a vote is required or not.

For each vote, you can set the following properties:
  • recalculateActions: a set of recalculation actions to be executed (the values of RecalculateAction enum).
  • conclusive: a vote is final, no other vote is taken into account.

The execution of CxPersonalizationFilter results in evaluating voters according to their order. For each voter, a corresponding vote is checked. If a conclusive vote is encountered, the first vote is the only one considered. If there is no conclusive vote, the actions returned by each voter are merged into one set of actions to execute.

Actions can be ordered in DefaultCxRecalculationService. The default action order is as follows: UPDATE, RECALCULATE, LOAD, ASYNC_PROCESS. The voters are executed one after another depending on the action order.

PreviewVoter

A PreviewVoter triggers recalculation if a preview ticket exists. This vote is conclusive by default.

PeriodicVoter

A PeriodicVoter triggers the periodic recalculation. The configuration for the PerodicVoter is stored in the database in the CxPeriodicVoterConfigModel. The configurations for base sites are gathered in the periodicVoterConfigs attribute of the CxConfigModel.

A single CxPeriodicVoterConfigModel contains the following attributes:

  • userType: a user type for which the configuration is valid (ALL, REGISTERED, ANONYMOUS).
  • actions: a set of actions to be executed on subsequent requests if userMinRequestNumber and userMinTime conditions are met.
  • userMinRequestNumber: the minimal number of requests that need to pass between executing actions.
  • userMinTime: minimal time (in milliseconds) that needs to pass between executing actions.
The table shows a sample PeriodicVoter configuration and its meaning:
userMinRequestNumber userMinTime Meaning
0 0 actions will be executed on every request
1 0 actions will be executed on every request
0 1 actions will be executed on every request if at least 1 ms passed from last execution
10 0 actions will be executed on every tenth request
0 60000 actions will be executed if one minute passed from last execution
10 60000 actions will be executed if one minute passed and there were at least 10 requests from last execution

ConfigurableUrlVoter

ConfigurableUrlVoter triggers the recalculation if the request url contains one of configured patterns. It can be configured in the Backoffice Administration Cockpit using the CxUrlVoterConfig model.

You need to define the following attributes:
  • userType: user type for which the configuration is valid (ALL, REGISTERED, ANONYMOUS).
  • urlRegexp: regular expression to be evaluated against the HttpServletRequest.getRequestURI.
  • actions: a set of actions to be executed when the request's url matches the urlRegexp pattern.
If a requested url matches more than one configuration, the actions will be merged. For example, the following url: https://electronics.local:9002/yacceleratorstorefront/electronics/en/ matches both the following configurations:
userType=ALL
URL regexp=.*
actions=RECALCULATE,LOAD
userType=ALL
URL regexp=electronics/en/$
actions=UPDATE

This is why the action set returned by the ConfigurableUrlVoter includes the following actions: RECALCULATE, LOAD, UPDATE.

UrlVoter(deprecated)

The UrlVoter triggers recalculation if the request url contains one of configured patterns. The UrlVoter reads configuration from properties of the following format:
personalizationservices.calculate.<configId>.url = <regex_for_url>
personalizationservices.calculate.<configId>.actions=<comma_separated_actions>
where:
  • <regex_for_url>: regexp expression, which will be evaluated against the HttpServletRequest.getRequestURI
  • <comma_separated_actions>: comma separated values of RecalculateAction enum.
An example:
#Loading recalculation result on each request
personalizationservices.calculate.default.load.url=.*
personalizationservices.calculate.default.load.actions=LOAD
 
#Synchronous recalculation on homepage request
personalizationservices.calculate.homepage.url=electronics/en/$
personalizationservices.calculate.homepage.actions=RECALCULATE
 
#Synchronous update user segments and recalculation on checkout
personalizationservices.calculate.checkout.url=checkout
personalizationservices.calculate.checkout.actions=UPDATE,RECALCULATE
 
#Starting asynchronous recalculation process
personalizationservices.calculate.checkout.url=.*/cart
personalizationservices.calculate.checkout.actions=ASYNC_PROCESS

If a requested url matches more than one configuration, the actions will be merged. For example the following url: https://electronics.local:9002/yacceleratorstorefront/electronics/en/ matches both the following configuration:

  • personalizationservices.calculate.default.load.url=.*
  • personalizationservices.calculate.default.load.actions=RECALCULATE

and this one:

  • personalizationservices.calculate.homepage.url=electronics/en/$
  • personalizationservices.calculate.homepage.actions=ASYNC_PROCESS

That is why the action set returned by the UrlVoter will be RECALCULATE, ASYNC_PROCESS. The value of the property is a normal regexp expression, which is evaluated against HttpServletRequest.getRequestURI.

Custom Voters

A custom voter can be created by performing the following actions:
  • creating class that implements de.hybris.platform.personalizationservices.voters.Voter,
  • defining this class as a bean in Spring context - it is automatically used by CxPersonalizationFilter.