diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java index df15fc4..dab4d39 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java @@ -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 getId() { return Optional.ofNullable(id); } public String getName() { return name; } public String getDescription() { return description; } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java b/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java index 2e471cb..d094665 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java @@ -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) diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/io/plantdb.json b/src/main/resources/ch/zhaw/gartenverwaltung/io/plantdb.json index 8cacaeb..fac9a5b 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/io/plantdb.json +++ b/src/main/resources/ch/zhaw/gartenverwaltung/io/plantdb.json @@ -32,8 +32,7 @@ "relativeStartDate": -14, "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.", - "interval": null, - "isOptional": false + "interval": null } ] }, @@ -54,8 +53,7 @@ "relativeStartDate": 0, "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.", - "interval": 21, - "isOptional": false + "interval": 21 } ] }, @@ -76,8 +74,7 @@ "relativeStartDate": 0, "relativeEndDate": null, "description": "Once the foliage has wilted and dried completely, harvest on a dry day. Store in a dark and cool location.", - "interval": null, - "isOptional": false + "interval": null } ] } @@ -106,8 +103,7 @@ "relativeStartDate": 0, "relativeEndDate": 0, "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", - "interval": null, - "isOptional": false + "interval": null } ] }, @@ -130,8 +126,7 @@ "relativeStartDate": 0, "relativeEndDate": null, "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", - "interval": 15, - "isOptional": true + "interval": 15 } ] }, @@ -152,8 +147,7 @@ "relativeStartDate": 0, "relativeEndDate": 14, "description": "When the leaves turn to a yellowish brown. Do not harvest earlier. The plant will show when it's ready.", - "interval": null, - "isOptional": false + "interval": null } ] } @@ -192,8 +186,7 @@ "relativeStartDate": 0, "relativeEndDate": 0, "description": "Plant the sets about 5cm deep into the soil.", - "interval": null, - "isOptional": false + "interval": null } ] }, @@ -216,8 +209,7 @@ "relativeStartDate": 0, "relativeEndDate": null, "description": "Mound up the soil around the plant until just the top few leaves show above the soil. ", - "interval": 15, - "isOptional": true + "interval": 15 } ] }, @@ -239,8 +231,7 @@ "relativeStartDate": 0, "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", - "interval": null, - "isOptional": false + "interval": null } ] }