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 nameexecutionType
—MANUAL
orAUTOMATIC
, determining whether the campaign is launched manually or on a scheduleexpression
— a script (as anExpression
object) that defines which clients are included in the campaigncreditProductCodes
— a list of product codes (e.g., for loans) to which the campaign appliesrestartable
— indicates whether the campaign can be restarted at intervalsrestartableUnit
,restartableUnitType
— a numeric value and time unit (hours or days) for cyclic restartsdateTimeExecution
— the date and time of the next scheduled automatic launchexecutions
— a list of allCampaignExecution
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 executionIDLE
means the automatic launch is paused
RestartableUnitType
(e.g.,HOURS
,DAYS
) defines howrestartableUnit
is interpreted for recurring launches. These fields are heavily used by theCampaignExecutionProducer
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?