Compare commits
No commits in common. "2d88c9ea9108449d3d60f60285cb5bfec54f2945" and "a437236788ccadc5fd3bd56b3fdb5d6e5acfb553" have entirely different histories.
2d88c9ea91
...
a437236788
|
@ -1,23 +1,16 @@
|
|||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
|
||||
import ch.zhaw.gartenverwaltung.notifier.Notifier;
|
||||
import javafx.application.Application;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HelloApplication extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
AppLoader appLoader = new AppLoader();
|
||||
|
||||
Notifier notifier = new Notifier(appLoader.getGardenSchedule());
|
||||
Thread notificationThread = new Thread(notifier);
|
||||
notificationThread.start();
|
||||
notificationThread.interrupt();
|
||||
|
||||
appLoader.loadSceneToStage("MainFXML.fxml", stage);
|
||||
|
||||
stage.setTitle("Gartenverwaltung");
|
||||
|
|
|
@ -10,7 +10,6 @@ import ch.zhaw.gartenverwaltung.io.TaskList;
|
|||
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
||||
import ch.zhaw.gartenverwaltung.notifier.Notifier;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.DialogPane;
|
||||
|
@ -42,7 +41,6 @@ public class AppLoader {
|
|||
|
||||
|
||||
public AppLoader() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -156,8 +154,4 @@ public class AppLoader {
|
|||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
public GardenSchedule getGardenSchedule() {
|
||||
return gardenSchedule;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,22 +136,10 @@ public class GardenSchedule {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public List<List<Task>> getTasksUpcomingWeek() throws IOException {
|
||||
final int listLength = 7;
|
||||
List<Task> weekTasks = taskList.getTaskList(LocalDate.now(), LocalDate.now().plusDays(listLength - 1));
|
||||
List<List<Task>> dayTaskList = new ArrayList<>();
|
||||
for(int i = 0; i < listLength; i++) {
|
||||
for(int i = 0; i < 7; i++) {
|
||||
LocalDate date = LocalDate.now().plusDays(i);
|
||||
dayTaskList.add(new ArrayList<>());
|
||||
final int finalI = i;
|
||||
weekTasks.forEach(task -> {
|
||||
LocalDate checkDate = task.getNextExecution();
|
||||
do {
|
||||
if (date.equals(checkDate) && !date.isAfter(task.getEndDate().orElse(LocalDate.MIN))) {
|
||||
dayTaskList.get(finalI).add(task);
|
||||
}
|
||||
checkDate = checkDate.plusDays(task.getInterval().orElse(0));
|
||||
} while (task.getInterval().isPresent() && checkDate.isBefore(LocalDate.now().plusDays(listLength)));
|
||||
});
|
||||
dayTaskList.add(taskList.getTaskList(date, date));
|
||||
}
|
||||
return dayTaskList;
|
||||
}
|
||||
|
@ -162,8 +150,11 @@ public class GardenSchedule {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public List<List<Task>> getTasksUpcomingWeekForCrop(Long cropId) throws IOException {
|
||||
List<List<Task>> dayTaskList = getTasksUpcomingWeek();
|
||||
dayTaskList.forEach(taskList -> taskList.removeIf(task -> task.getCropId() != cropId));
|
||||
List<List<Task>> dayTaskList = new ArrayList<>();
|
||||
for(int i = 0; i < 7; i++) {
|
||||
LocalDate date = LocalDate.now().plusDays(i);
|
||||
dayTaskList.add(filterListByCrop(taskList.getTaskList(date, date), cropId));
|
||||
}
|
||||
return dayTaskList;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import java.util.function.Consumer;
|
|||
|
||||
public class Notifier implements Runnable{
|
||||
private final GardenSchedule gardenSchedule;
|
||||
private boolean interrupted = false;
|
||||
|
||||
public Notifier(GardenSchedule gardenSchedule) {
|
||||
this.gardenSchedule = gardenSchedule;
|
||||
|
@ -19,13 +18,16 @@ public class Notifier implements Runnable{
|
|||
// TODO implement
|
||||
}
|
||||
|
||||
private void sendNotifications(){
|
||||
System.out.println("sending Notifications");
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
gardenSchedule.getTaskList().forEach(task -> {
|
||||
if(task.getNextNotification() != null && task.getNextNotification().isBefore(LocalDate.now().minusDays(1))){
|
||||
sendNotification(task);
|
||||
task.setNextNotification(task.getNextExecution());
|
||||
gardenSchedule.getTaskList().forEach(new Consumer<Task>() {
|
||||
@Override
|
||||
public void accept(Task task) {
|
||||
if(task.getNextNotification() != null && task.getNextNotification().isBefore(LocalDate.now().minusDays(1))){
|
||||
sendNotification(task);
|
||||
task.setNextNotification(task.getNextExecution());
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
|
@ -33,16 +35,4 @@ public class Notifier implements Runnable{
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(!interrupted){
|
||||
try {
|
||||
sendNotifications();
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
interrupted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ public class Task {
|
|||
name= "";
|
||||
description= "";
|
||||
startDate = LocalDate.now();
|
||||
endDate = startDate;
|
||||
nextExecution = startDate;
|
||||
}
|
||||
|
||||
|
@ -35,7 +34,6 @@ public class Task {
|
|||
this.name = name;
|
||||
this.description = description;
|
||||
this.startDate = startDate;
|
||||
this.endDate = startDate;
|
||||
nextExecution = startDate;
|
||||
this.cropId = cropId;
|
||||
}
|
||||
|
@ -65,7 +63,7 @@ public class Task {
|
|||
}
|
||||
|
||||
public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){
|
||||
return endDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
|
||||
return startDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
|
||||
}
|
||||
|
||||
public void done(){
|
||||
|
|
|
@ -15,7 +15,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||
import static org.mockito.Mockito.*;
|
||||
|
||||
class GardenScheduleTest {
|
||||
LocalDate exampleStartDate = LocalDate.of(2020, 2, 2);
|
||||
LocalDate exampleStartDate = LocalDate.of(2020, 02, 02);
|
||||
TaskList taskList;
|
||||
PlantList plantList;
|
||||
List<Plant> examplePlantList;
|
||||
|
@ -43,7 +43,6 @@ class GardenScheduleTest {
|
|||
private TaskList mockTaskDatabase(List<Task> exampleTaskList) throws IOException {
|
||||
TaskList taskList = mock(JsonTaskList.class);
|
||||
when(taskList.getTaskList(LocalDate.MIN, LocalDate.MAX)).thenReturn(exampleTaskList);
|
||||
when(taskList.getTaskList(LocalDate.now(), LocalDate.now().plusDays(7 - 1))).thenReturn(exampleTaskList);
|
||||
|
||||
when(taskList.getTaskList(LocalDate.now(), LocalDate.MAX)).thenReturn((exampleTaskList.subList(1, 4)));
|
||||
|
||||
|
@ -106,7 +105,7 @@ class GardenScheduleTest {
|
|||
exampleTaskList.add(new Task("name", "description", LocalDate.now().plusDays(1), 2L));
|
||||
exampleTaskList.add(new Task("name", "description", LocalDate.now(), 1L));
|
||||
exampleTaskList.add(new Task("name", "description", LocalDate.of(9019, 5, 5), 1L));
|
||||
exampleTaskList.add(new Task("name", "description", LocalDate.now().minusDays(10), LocalDate.now().plusDays(4),2, 2L));
|
||||
exampleTaskList.add(new Task("name", "description", LocalDate.of(2019, 5, 5), 2L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -158,22 +157,19 @@ class GardenScheduleTest {
|
|||
assertEquals(7, dayList.size());
|
||||
|
||||
//Check day 0
|
||||
assertEquals(2, dayList.get(0).size());
|
||||
assertTrue(dayList.get(0).contains(exampleTaskList.get(2)));
|
||||
assertTrue(dayList.get(0).contains(exampleTaskList.get(4)));
|
||||
assertEquals(1, dayList.get(0).size());
|
||||
assertEquals(exampleTaskList.get(2), dayList.get(0).get(0));
|
||||
|
||||
//Check day 1
|
||||
assertEquals(1, dayList.get(1).size());
|
||||
assertTrue(dayList.get(1).contains(exampleTaskList.get(1)));
|
||||
assertEquals(exampleTaskList.get(1), dayList.get(1).get(0));
|
||||
|
||||
//Check day 2
|
||||
assertEquals(1, dayList.get(2).size());
|
||||
assertTrue(dayList.get(2).contains(exampleTaskList.get(4)));
|
||||
assertEquals(0, dayList.get(2).size());
|
||||
//Check day 3
|
||||
assertEquals(0, dayList.get(3).size());
|
||||
//Check day 4
|
||||
assertEquals(1, dayList.get(4).size());
|
||||
assertTrue(dayList.get(4).contains(exampleTaskList.get(4)));
|
||||
assertEquals(0, dayList.get(4).size());
|
||||
//Check day 5
|
||||
assertEquals(0, dayList.get(5).size());
|
||||
//Check day 6
|
||||
|
|
Loading…
Reference in New Issue