Campaign Model
Campaign
@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?