adapted GardenSchedule and GardenScheduleTest to new Structure of Task
This commit is contained in:
parent
b2c0886e46
commit
f389cfcdfd
|
@ -9,6 +9,7 @@ import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class GardenSchedule {
|
public class GardenSchedule {
|
||||||
|
@ -136,10 +137,22 @@ public class GardenSchedule {
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public List<List<Task>> getTasksUpcomingWeek() throws IOException {
|
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<>();
|
List<List<Task>> dayTaskList = new ArrayList<>();
|
||||||
for(int i = 0; i < 7; i++) {
|
for(int i = 0; i < listLength; i++) {
|
||||||
LocalDate date = LocalDate.now().plusDays(i);
|
LocalDate date = LocalDate.now().plusDays(i);
|
||||||
dayTaskList.add(taskList.getTaskList(date, date));
|
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)));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return dayTaskList;
|
return dayTaskList;
|
||||||
}
|
}
|
||||||
|
@ -150,11 +163,8 @@ public class GardenSchedule {
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public List<List<Task>> getTasksUpcomingWeekForCrop(Long cropId) throws IOException {
|
public List<List<Task>> getTasksUpcomingWeekForCrop(Long cropId) throws IOException {
|
||||||
List<List<Task>> dayTaskList = new ArrayList<>();
|
List<List<Task>> dayTaskList = getTasksUpcomingWeek();
|
||||||
for(int i = 0; i < 7; i++) {
|
dayTaskList.forEach(taskList -> taskList.removeIf(task -> task.getCropId() != cropId));
|
||||||
LocalDate date = LocalDate.now().plusDays(i);
|
|
||||||
dayTaskList.add(filterListByCrop(taskList.getTaskList(date, date), cropId));
|
|
||||||
}
|
|
||||||
return dayTaskList;
|
return dayTaskList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ public class Task {
|
||||||
name= "";
|
name= "";
|
||||||
description= "";
|
description= "";
|
||||||
startDate = LocalDate.now();
|
startDate = LocalDate.now();
|
||||||
|
endDate = startDate;
|
||||||
nextExecution = startDate;
|
nextExecution = startDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ public class Task {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.startDate = startDate;
|
this.startDate = startDate;
|
||||||
|
this.endDate = startDate;
|
||||||
nextExecution = startDate;
|
nextExecution = startDate;
|
||||||
this.cropId = cropId;
|
this.cropId = cropId;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +65,7 @@ public class Task {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){
|
public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){
|
||||||
return startDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
|
return endDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void done(){
|
public void done(){
|
||||||
|
|
|
@ -15,7 +15,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
class GardenScheduleTest {
|
class GardenScheduleTest {
|
||||||
LocalDate exampleStartDate = LocalDate.of(2020, 02, 02);
|
LocalDate exampleStartDate = LocalDate.of(2020, 2, 2);
|
||||||
TaskList taskList;
|
TaskList taskList;
|
||||||
PlantList plantList;
|
PlantList plantList;
|
||||||
List<Plant> examplePlantList;
|
List<Plant> examplePlantList;
|
||||||
|
@ -43,6 +43,7 @@ class GardenScheduleTest {
|
||||||
private TaskList mockTaskDatabase(List<Task> exampleTaskList) throws IOException {
|
private TaskList mockTaskDatabase(List<Task> exampleTaskList) throws IOException {
|
||||||
TaskList taskList = mock(JsonTaskList.class);
|
TaskList taskList = mock(JsonTaskList.class);
|
||||||
when(taskList.getTaskList(LocalDate.MIN, LocalDate.MAX)).thenReturn(exampleTaskList);
|
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)));
|
when(taskList.getTaskList(LocalDate.now(), LocalDate.MAX)).thenReturn((exampleTaskList.subList(1, 4)));
|
||||||
|
|
||||||
|
@ -105,7 +106,7 @@ class GardenScheduleTest {
|
||||||
exampleTaskList.add(new Task("name", "description", LocalDate.now().plusDays(1), 2L));
|
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.now(), 1L));
|
||||||
exampleTaskList.add(new Task("name", "description", LocalDate.of(9019, 5, 5), 1L));
|
exampleTaskList.add(new Task("name", "description", LocalDate.of(9019, 5, 5), 1L));
|
||||||
exampleTaskList.add(new Task("name", "description", LocalDate.of(2019, 5, 5), 2L));
|
exampleTaskList.add(new Task("name", "description", LocalDate.now().minusDays(10), LocalDate.now().plusDays(4),2, 2L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -157,19 +158,22 @@ class GardenScheduleTest {
|
||||||
assertEquals(7, dayList.size());
|
assertEquals(7, dayList.size());
|
||||||
|
|
||||||
//Check day 0
|
//Check day 0
|
||||||
assertEquals(1, dayList.get(0).size());
|
assertEquals(2, dayList.get(0).size());
|
||||||
assertEquals(exampleTaskList.get(2), dayList.get(0).get(0));
|
assertTrue(dayList.get(0).contains(exampleTaskList.get(2)));
|
||||||
|
assertTrue(dayList.get(0).contains(exampleTaskList.get(4)));
|
||||||
|
|
||||||
//Check day 1
|
//Check day 1
|
||||||
assertEquals(1, dayList.get(1).size());
|
assertEquals(1, dayList.get(1).size());
|
||||||
assertEquals(exampleTaskList.get(1), dayList.get(1).get(0));
|
assertTrue(dayList.get(1).contains(exampleTaskList.get(1)));
|
||||||
|
|
||||||
//Check day 2
|
//Check day 2
|
||||||
assertEquals(0, dayList.get(2).size());
|
assertEquals(1, dayList.get(2).size());
|
||||||
|
assertTrue(dayList.get(2).contains(exampleTaskList.get(4)));
|
||||||
//Check day 3
|
//Check day 3
|
||||||
assertEquals(0, dayList.get(3).size());
|
assertEquals(0, dayList.get(3).size());
|
||||||
//Check day 4
|
//Check day 4
|
||||||
assertEquals(0, dayList.get(4).size());
|
assertEquals(1, dayList.get(4).size());
|
||||||
|
assertTrue(dayList.get(4).contains(exampleTaskList.get(4)));
|
||||||
//Check day 5
|
//Check day 5
|
||||||
assertEquals(0, dayList.get(5).size());
|
assertEquals(0, dayList.get(5).size());
|
||||||
//Check day 6
|
//Check day 6
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -193,8 +187,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
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -217,8 +210,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
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -241,8 +233,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
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue