Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e228b9019d | ||
|
|
a2008450e6 | ||
|
|
96b5dba36c |
@@ -37,6 +37,8 @@ dependencies {
|
||||
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
|
||||
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.13.4'
|
||||
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.4'
|
||||
}
|
||||
|
||||
test {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package ch.zhaw.gartenverwaltung.io;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.MonthDayDeserializer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.time.MonthDay;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class JsonTaskDatabase implements TaskDatabase{
|
||||
private final URL dataSource = getClass().getResource("taskdb.json");
|
||||
|
||||
private final static JavaTimeModule timeModule = new JavaTimeModule();
|
||||
static {
|
||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("MM-dd");
|
||||
MonthDayDeserializer dateDeserializer = new MonthDayDeserializer(dateFormat);
|
||||
timeModule.addDeserializer(MonthDay.class, dateDeserializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> getTaskList(Date start, Date end) throws IOException{
|
||||
List<Task> taskList = Collections.emptyList();
|
||||
|
||||
if (dataSource != null) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(timeModule);
|
||||
|
||||
taskList = mapper.readerForListOf(Task.class).readValue(dataSource);
|
||||
}
|
||||
|
||||
return taskList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveTask(Task task) throws IOException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
if(dataSource != null) {
|
||||
mapper.writeValue(new File(dataSource.getFile()), task);
|
||||
} else {
|
||||
mapper.writeValue(new File("taskdb.json"),task);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTask(Task task) throws IOException {
|
||||
List<Task> taskList;
|
||||
|
||||
if(dataSource != null) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
taskList = mapper.readerForListOf(Task.class).readValue(dataSource);
|
||||
for (int index = 0; index < taskList.size(); index++){
|
||||
if(task.equals(taskList.get(index))){
|
||||
taskList.remove(task);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface TaskDatabase {
|
||||
List<Task> getTaskList(Date start, Date end);
|
||||
List<Task> getTaskList(Date start, Date end) throws IOException;
|
||||
void saveTask(Task task) throws IOException;
|
||||
void removeTask(Task task) throws IOException;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
[
|
||||
{
|
||||
"id" : "1",
|
||||
"name" : "sow plant",
|
||||
"description": "Plant the seeds/ crops in de bed.",
|
||||
"startDate" : "01.05.2022",
|
||||
"endDate" : "01.05.2022",
|
||||
"interval" : "null"
|
||||
},
|
||||
{
|
||||
"id" : "2",
|
||||
"name" : "water plant",
|
||||
"description": "water the plant, so that the soil is wet around the plant.",
|
||||
"startDate" : "01.05.2022",
|
||||
"endDate" : "01.09.2022",
|
||||
"interval" : "2"
|
||||
},
|
||||
{
|
||||
"id" : "3",
|
||||
"name" : "fertilize plant",
|
||||
"description": "The fertilizer has to be mixed with water. Then fertilize the plant's soil with the mixture",
|
||||
"startDate" : "01.06.2022",
|
||||
"endDate" : "01.08.2022",
|
||||
"interval" : "28"
|
||||
},
|
||||
{
|
||||
"id" : "4",
|
||||
"name" : "covering plant",
|
||||
"description": "Take a big enough coverage for the plants. Cover the whole plant with a bit space between the plant and the coverage",
|
||||
"startDate" : "15.07.2022",
|
||||
"endDate" : "15.07.2022",
|
||||
"interval" : "null"
|
||||
},
|
||||
{
|
||||
"id" : "5",
|
||||
"name" : "look after plant",
|
||||
"description": "Look for pest or illness at the leaves of the plant. Check the soil around the plant, if the roots are enough covered with soil",
|
||||
"startDate" : "01.05.2022",
|
||||
"endDate" : "01.09.2022",
|
||||
"interval" : "5"
|
||||
},
|
||||
{
|
||||
"id" : "6",
|
||||
"name" : "harvest plant",
|
||||
"description": "Pull the ripe vegetables out from the soil. Clean them with clear, fresh water. ",
|
||||
"startDate" : "01.09.2022",
|
||||
"endDate" : "01.09.2022",
|
||||
"interval" : "null"
|
||||
}
|
||||
]
|
||||
@@ -1,6 +1,8 @@
|
||||
module ch.zhaw.gartenverwaltung {
|
||||
requires javafx.controls;
|
||||
requires javafx.fxml;
|
||||
requires com.fasterxml.jackson.databind;
|
||||
requires com.fasterxml.jackson.datatype.jsr310;
|
||||
|
||||
|
||||
opens ch.zhaw.gartenverwaltung to javafx.fxml;
|
||||
|
||||
Reference in New Issue
Block a user