new Structure of Task

This commit is contained in:
schrom01
2022-11-24 22:18:08 +01:00
parent d7b9095050
commit 775e35a70b
3 changed files with 36 additions and 22 deletions
@@ -15,6 +15,8 @@ public class Task {
private final LocalDate startDate;
private Integer interval;
private LocalDate endDate;
private LocalDate nextExecution;
private LocalDate nextNotification;
private long cropId;
/**
@@ -25,12 +27,14 @@ public class Task {
name= "";
description= "";
startDate = LocalDate.now();
nextExecution = startDate;
}
public Task(String name, String description, LocalDate startDate, long cropId) {
this.name = name;
this.description = description;
this.startDate = startDate;
nextExecution = startDate;
this.cropId = cropId;
}
@@ -38,6 +42,7 @@ public class Task {
this.name = name;
this.description = description;
this.startDate = startDate;
nextExecution = startDate;
this.endDate = endDate;
this.interval = interval;
this.cropId = cropId;
@@ -61,7 +66,29 @@ public class Task {
return startDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
}
public void done(){
if(interval != null && !nextExecution.plusDays(interval).isAfter(endDate)){
nextExecution = nextExecution.plusDays(interval);
} else {
nextExecution = null;
}
}
public boolean isDone(){
return nextExecution == null;
}
public void setNextExecution(LocalDate nextExecution) {
this.nextExecution = nextExecution;
}
public void setNextNotification(LocalDate nextNotification) {
this.nextNotification = nextNotification;
}
// Getters
public LocalDate getNextNotification() { return nextNotification; }
public LocalDate getNextExecution() { return nextExecution; }
public Optional<Long> getId() { return Optional.ofNullable(id); }
public String getName() { return name; }
public String getDescription() { return description; }
@@ -16,10 +16,6 @@ public class TaskTemplate {
@JsonProperty
private Integer interval;
// TODO: reconsider if we need this
@JsonProperty
private boolean isOptional = false;
/**
* Default constructor
* (Used by deserializer)