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 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; }

View File

@ -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)

View File

@ -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
}
]
}