Checker
📌 Purpose
CreateApplicationExecutionChecker is a component that automatically reacts to the completion of a campaign execution (CampaignExecution) and creates applications for the clients who were selected.
It implements the observer pattern for entity changes using the EntityChecker abstraction provided by the timveroOS framework.
🏗️ Inheritance from EntityChecker
EntityChecker@Component
public class CreateApplicationExecutionChecker extends EntityChecker<CampaignExecution, Long> {
@Autowired
private CreateApplicationService createApplicationService;
@Autowired
private TransactionTemplateBuilder ttb;
@Override
protected void registerListeners(CheckerListenerRegistry<CampaignExecution> registry) {
registry.entityChange().updated(CampaignExecution_.STATUS);
}
@Override
protected boolean isAvailable(CampaignExecution execution) {
return execution.getStatus() == CampaignExecutionStatus.FINISHED;
}
@Override
protected void perform(CampaignExecution execution) {
final Long executionId = execution.getId();
TransactionUtils.afterTransaction(() -> {
execution.getClients().forEach(borrower ->
createApplicationService.create(borrower.getId(), executionId)
);
});
}
}EntityChecker<E, ID>is a base class in the platform used to observe changes to entity fields.The implementation must override:
registerListeners(...)— to specify which fields to monitorisAvailable(...)— to define when the checker should triggerperform(...)— to define the actions to perform upon trigger
🔔 Reacting to FINISHED Status
FINISHED Status@Override
protected void registerListeners(CheckerListenerRegistry<CampaignExecution> registry) {
registry.entityChange().updated(CampaignExecution_.STATUS);
}
@Override
protected boolean isAvailable(CampaignExecution execution) {
return execution.getStatus() == CampaignExecutionStatus.FINISHED;
}registerListenerssubscribes the checker to changes in thestatusfieldisAvailableensuresperform(...)is only called when the status becomesFINISHED
🛠️ Core Logic in perform(...)
perform(...)@Override
protected void perform(CampaignExecution execution) {
final Long executionId = execution.getId();
TransactionUtils.afterTransaction(() -> {
execution.getClients().forEach(borrower ->
createApplicationService.create(borrower.getId(), executionId)
);
});
}✅ What happens here:
Transaction-safe execution: Uses
TransactionUtils.afterTransaction(...)to defer logic until after the current transaction completes — important for compatibility with Spring@TransactionalApplication creation: For each selected client, it triggers
createApplicationService.create(...)with a reference to the current campaign execution
📦 Components and Dependencies
@Autowired
private CreateApplicationService createApplicationService;CreateApplicationServiceis the internal service responsible for creating applications
🔄 How It Works in the System
A campaign finishes execution →
CampaignExecution.statusbecomesFINISHEDThe
EntityCheckerdetects the status changeperform(...)is triggered after the transaction endsApplications are created for each selected client
🧪 Example Usage
Campaign A has a filter like
client.score > 800and selects 3 clientsAfter execution completes:
CampaignExecution.status→FINISHEDCreateApplicationExecutionCheckeris triggered3 applications are created — one for each selected client, linked to the campaign
📌 Summary
Inherits from
EntityChecker<CampaignExecution, Long>Monitors changes to the
statusfieldTrigger condition:
status == FINISHEDExecutes after transaction completes
Main logic: notifying on completion and creating applications for clients
Depends on:
CreateApplicationService
Last updated
Was this helpful?