CampaignExecutionService
CampaignExecutionService
The CampaignExecutionService is responsible for all aspects of campaign execution, including:
Creating
CampaignExecutionentitiesFiltering clients using an
ExpressionExecuting the campaign
Handling exceptions
Saving execution results
This service integrates with ScriptManager, ClientRepository, and ExceptionEntityService.
🔧 CampaignExecution createExecution(Campaign campaign)
CampaignExecution createExecution(Campaign campaign)Creates a new CampaignExecution linked to the provided campaign.
@Transactional(propagation = Propagation.MANDATORY)
public CampaignExecution createExecution(Campaign campaign) {
CampaignExecution execution = new CampaignExecution();
execution.setCampaign(campaign);
return executionRepository.saveAndFlush(execution);
}Called both manually (via
CampaignService) and automatically (viaCampaignExecutionProducer)Saves the execution to the DB with
status = NEW
🔐 _runExecution(CampaignExecution execution)
_runExecution(CampaignExecution execution)Private method containing the main business logic for campaign execution.
What it does:
Retrieves a list of clients matching the
ExpressionClears the exception if successful
On error, stores an
ExceptionEntityand marks the execution asEXCEPTION_OCCURREDSets the final status to
FINISHED
🔍 Set<Client> getSuitedBorrowers(...)
Set<Client> getSuitedBorrowers(...)Filters clients based on the campaign expression.
🔍 Optional<Client> evaluateClient(...)
Optional<Client> evaluateClient(...)Evaluates a single client using the script.
The script must return
trueorfalseOnly matching clients are included
🧰 Script getClientMatchingScript(...)
Script getClientMatchingScript(...)Compiles the Expression into a Script.
Throws a
RuntimeExceptionon compilation failure
💡 Object evaluateExpression(UUID clientId, Expression expression)
Object evaluateExpression(UUID clientId, Expression expression)Allows manual evaluation of an expression for a single client — useful in the UI.
Used by
CampaignControllerfor real-time filtering checks in the UI
Example service
Last updated
Was this helpful?