LogoLogo
timvero.comMaven Repository
  • timveroOS SDK guide
  • timveroOS how-to
  • timveroOS admin-side setup
  • Campaigns in timveroOS
    • 7.11
      • Business Context
      • Introduction
      • Core Concept
        • Entity Diagram
        • Lifecycle Diagram
        • Expression
      • Design and Development of the Campaign Model
        • Campaign model
        • Campaign repository
        • Campaign forms
        • Campaign сontroller
        • UI elements
        • Campaign actions
      • Design and Development of the CampaignExecution Model
        • CampaignExecution model
        • CampaignExecution repository
        • CampaignExecution controller
        • UI elements
      • Expression
      • Services
        • CampaignService
        • CampaignExecutionService
      • Campaign Processing
        • Producer
        • Consumer
      • Post-processing
        • Checker
Powered by GitBook
On this page

Was this helpful?

  1. Campaigns in timveroOS
  2. 7.11
  3. Post-processing

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

@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 monitor

    • isAvailable(...) β€” to define when the checker should trigger

    • perform(...) β€” to define the actions to perform upon trigger


πŸ”” Reacting to 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;
}
  • registerListeners subscribes the checker to changes in the status field

  • isAvailable ensures perform(...) is only called when the status becomes FINISHED


πŸ› οΈ Core Logic in 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 @Transactional

  • Application creation: For each selected client, it triggers createApplicationService.create(...) with a reference to the current campaign execution


πŸ“¦ Components and Dependencies

@Autowired
private CreateApplicationService createApplicationService;
  • CreateApplicationService is the internal service responsible for creating applications


πŸ”„ How It Works in the System

  1. A campaign finishes execution β†’ CampaignExecution.status becomes FINISHED

  2. The EntityChecker detects the status change

  3. perform(...) is triggered after the transaction ends

  4. Applications are created for each selected client


πŸ§ͺ Example Usage

  • Campaign A has a filter like client.score > 800 and selects 3 clients

  • After execution completes:

    • CampaignExecution.status β†’ FINISHED

    • CreateApplicationExecutionChecker is triggered

    • 3 applications are created β€” one for each selected client, linked to the campaign


πŸ“Œ Summary

  • Inherits from EntityChecker<CampaignExecution, Long>

  • Monitors changes to the status field

  • Trigger condition: status == FINISHED

  • Executes after transaction completes

  • Main logic: notifying on completion and creating applications for clients

  • Depends on: CreateApplicationService

PreviousPost-processing

Last updated 18 days ago

Was this helpful?