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

View File

@ -15,6 +15,8 @@ public class Task {
private final LocalDate startDate; private final LocalDate startDate;
private Integer interval; private Integer interval;
private LocalDate endDate; private LocalDate endDate;
private LocalDate nextExecution;
private LocalDate nextNotification;
private long cropId; private long cropId;
/** /**
@ -25,12 +27,14 @@ public class Task {
name= ""; name= "";
description= ""; description= "";
startDate = LocalDate.now(); startDate = LocalDate.now();
nextExecution = startDate;
} }
public Task(String name, String description, LocalDate startDate, long cropId) { public Task(String name, String description, LocalDate startDate, long cropId) {
this.name = name; this.name = name;
this.description = description; this.description = description;
this.startDate = startDate; this.startDate = startDate;
nextExecution = startDate;
this.cropId = cropId; this.cropId = cropId;
} }
@ -38,6 +42,7 @@ public class Task {
this.name = name; this.name = name;
this.description = description; this.description = description;
this.startDate = startDate; this.startDate = startDate;
nextExecution = startDate;
this.endDate = endDate; this.endDate = endDate;
this.interval = interval; this.interval = interval;
this.cropId = cropId; this.cropId = cropId;
@ -61,7 +66,29 @@ public class Task {
return startDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate); 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 // Getters
public LocalDate getNextNotification() { return nextNotification; }
public LocalDate getNextExecution() { return nextExecution; }
public Optional<Long> getId() { return Optional.ofNullable(id); } public Optional<Long> getId() { return Optional.ofNullable(id); }
public String getName() { return name; } public String getName() { return name; }
public String getDescription() { return description; } public String getDescription() { return description; }

View File

@ -16,10 +16,6 @@ public class TaskTemplate {
@JsonProperty @JsonProperty
private Integer interval; private Integer interval;
// TODO: reconsider if we need this
@JsonProperty
private boolean isOptional = false;
/** /**
* Default constructor * Default constructor
* (Used by deserializer) * (Used by deserializer)

View File

@ -32,8 +32,7 @@
"relativeStartDate": -14, "relativeStartDate": -14,
"relativeEndDate": null, "relativeEndDate": null,
"description": "Take an egg carton and fill it with soil. Put the seedling deep enough so its half covered with soil. Keep it in 10-15 * Celsius with lots of light.", "description": "Take an egg carton and fill it with soil. Put the seedling deep enough so its half covered with soil. Keep it in 10-15 * Celsius with lots of light.",
"interval": null, "interval": null
"isOptional": false
} }
] ]
}, },
@ -54,8 +53,7 @@
"relativeStartDate": 0, "relativeStartDate": 0,
"relativeEndDate": null, "relativeEndDate": null,
"description": "When the plants are 20 cm tall, begin hilling the potatoes by gently mounding the soil from the center of your rows around the stems of the plant. Mound up the soil around the plant until just the top few leaves show above the soil. Two weeks later, hill up the soil again when the plants grow another 20 cm.", "description": "When the plants are 20 cm tall, begin hilling the potatoes by gently mounding the soil from the center of your rows around the stems of the plant. Mound up the soil around the plant until just the top few leaves show above the soil. Two weeks later, hill up the soil again when the plants grow another 20 cm.",
"interval": 21, "interval": 21
"isOptional": false
} }
] ]
}, },
@ -76,8 +74,7 @@
"relativeStartDate": 0, "relativeStartDate": 0,
"relativeEndDate": null, "relativeEndDate": null,
"description": "Once the foliage has wilted and dried completely, harvest on a dry day. Store in a dark and cool location.", "description": "Once the foliage has wilted and dried completely, harvest on a dry day. Store in a dark and cool location.",
"interval": null, "interval": null
"isOptional": false
} }
] ]
} }
@ -106,8 +103,7 @@
"relativeStartDate": 0, "relativeStartDate": 0,
"relativeEndDate": 0, "relativeEndDate": 0,
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
"interval": null, "interval": null
"isOptional": false
} }
] ]
}, },
@ -130,8 +126,7 @@
"relativeStartDate": 0, "relativeStartDate": 0,
"relativeEndDate": null, "relativeEndDate": null,
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
"interval": 15, "interval": 15
"isOptional": true
} }
] ]
}, },
@ -152,8 +147,7 @@
"relativeStartDate": 0, "relativeStartDate": 0,
"relativeEndDate": 14, "relativeEndDate": 14,
"description": "When the leaves turn to a yellowish brown. Do not harvest earlier. The plant will show when it's ready.", "description": "When the leaves turn to a yellowish brown. Do not harvest earlier. The plant will show when it's ready.",
"interval": null, "interval": null
"isOptional": false
} }
] ]
} }
@ -192,8 +186,7 @@
"relativeStartDate": 0, "relativeStartDate": 0,
"relativeEndDate": 0, "relativeEndDate": 0,
"description": "Plant the sets about 5cm deep into the soil.", "description": "Plant the sets about 5cm deep into the soil.",
"interval": null, "interval": null
"isOptional": false
} }
] ]
}, },
@ -216,8 +209,7 @@
"relativeStartDate": 0, "relativeStartDate": 0,
"relativeEndDate": null, "relativeEndDate": null,
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
"interval": 15, "interval": 15
"isOptional": true
} }
] ]
}, },
@ -239,8 +231,7 @@
"relativeStartDate": 0, "relativeStartDate": 0,
"relativeEndDate": 14, "relativeEndDate": 14,
"description": "When ready for harvest, the leaves on your onion plants will start to flop over. This happens at the \"neck\" of the onion and it signals that the plant has stopped growing and is ready for storage. Onions should be harvested soon thereafter", "description": "When ready for harvest, the leaves on your onion plants will start to flop over. This happens at the \"neck\" of the onion and it signals that the plant has stopped growing and is ready for storage. Onions should be harvested soon thereafter",
"interval": null, "interval": null
"isOptional": false
} }
] ]
} }