Campaign model

Campaign

The Campaign class represents the definition of a campaign and extends HistoryEntity<Long>. This means every change to a campaign is stored as a new version, while the previous one is automatically deactivated. Versioning is managed by the HistoryEntityFormService, so the developer does not need to manually call setActive(false) for the previous version.

Key Fields:

  • name — a string representing the campaign’s display name

  • executionTypeMANUAL or AUTOMATIC, determining whether the campaign is launched manually or on a schedule

  • expression — a script (as an Expression object) that defines which clients are included in the campaign

  • creditProductCodes — a list of product codes (e.g., for loans) to which the campaign applies

  • restartable — indicates whether the campaign can be restarted at intervals

  • restartableUnit, restartableUnitType — a numeric value and time unit (hours or days) for cyclic restarts

  • dateTimeExecution — the date and time of the next scheduled automatic launch

  • executions — a list of all CampaignExecution instances associated with the campaign

Impact of AutomaticCampaignStatus and RestartableUnitType Fields:

  • AutomaticCampaignStatus controls the current state of an automatic campaign:

    • SCHEDULED means the campaign is active and ready for execution

    • IDLE means the automatic launch is paused

  • RestartableUnitType (e.g., HOURS, DAYS) defines how restartableUnit is interpreted for recurring launches. These fields are heavily used by the CampaignExecutionProducer component to calculate scheduling.

Model Example:

@Entity
@Table(name = "campaign")
public class Campaign extends HistoryEntity<Long> {

    @Column(nullable = false)
    private String name;

    @Column(nullable = false)
    @Enumerated(EnumType.STRING)
    private CampaignExecutionType executionType;

    @Column
    @Enumerated(EnumType.STRING)
    private AutomaticCampaignStatus automaticCampaignStatus;

    @Embedded
    private Expression expression;

    @ElementCollection
    private Set<String> creditProductCodes;

    private boolean restartable;
    private Integer restartableUnit;

    @Enumerated(EnumType.STRING)
    private RestartableUnitType restartableUnitType;

    private LocalDateTime dateTimeExecution;

    @ManyToOne
    private ProcessSpecification processSpecification;

    @OneToMany(mappedBy = "campaign")
    private List<CampaignExecution> executions;
    
    // getters and setters

    @Transient
    public Optional<CampaignExecution> getLatestExecution() {
       return getExecutions().stream()
           .max(Comparator.comparing(CampaignExecution::getCreatedAt));
    }

    @Transient
    public boolean isNotInExecution() {
       CampaignExecution execution = getLatestExecution();
       return execution == null || execution.getStatus() != CampaignExecutionStatus.IN_PROGRESS;
    }

    @Transient
    public Duration getRestartableDuration() {
       return getRestartableUnitType().getChronoUnit().getDuration().multipliedBy(getRestartableUnit());
    }
}

Last updated

Was this helpful?