Compare commits
No commits in common. "5b860e0ff426ebfcb4c6803b2519d0883d1536da" and "f5fcfa78f63860dbcee04934313ae44cf6c81a47" have entirely different histories.
5b860e0ff4
...
f5fcfa78f6
Binary file not shown.
Before Width: | Height: | Size: 25 KiB |
|
@ -1,7 +0,0 @@
|
|||
<diagram program="umletino" version="15.0.0"><zoom_level>10</zoom_level><element><id>UMLPackage</id><coordinates><x>390</x><y>60</y><w>340</w><h>100</h></coordinates><panel_attributes>UI</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLPackage</id><coordinates><x>390</x><y>180</y><w>460</w><h>120</h></coordinates><panel_attributes>Domain</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLPackage</id><coordinates><x>390</x><y>330</y><w>460</w><h>120</h></coordinates><panel_attributes>Technical Services</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLPackage</id><coordinates><x>400</x><y>90</y><w>100</w><h>60</h></coordinates><panel_attributes>Views (JFX)</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLPackage</id><coordinates><x>400</x><y>220</y><w>100</w><h>60</h></coordinates><panel_attributes>IO</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLPackage</id><coordinates><x>400</x><y>370</y><w>100</w><h>60</h></coordinates><panel_attributes>Jackson</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLPackage</id><coordinates><x>510</x><y>220</y><w>100</w><h>60</h></coordinates><panel_attributes>Types</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLPackage</id><coordinates><x>620</x><y>220</y><w>100</w><h>60</h></coordinates><panel_attributes>Models</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLPackage</id><coordinates><x>510</x><y>90</y><w>110</w><h>60</h></coordinates><panel_attributes>Controllers (JFX)</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLPackage</id><coordinates><x>510</x><y>370</y><w>100</w><h>60</h></coordinates><panel_attributes>Logging</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLPackage</id><coordinates><x>620</x><y>370</y><w>100</w><h>60</h></coordinates><panel_attributes>JavaFX</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLPackage</id><coordinates><x>730</x><y>220</y><w>110</w><h>60</h></coordinates><panel_attributes>Services</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLPackage</id><coordinates><x>730</x><y>370</y><w>110</w><h>60</h></coordinates><panel_attributes>HTTP/API</panel_attributes><additional_attributes></additional_attributes></element><element><id>Relation</id><coordinates><x>570</x><y>150</y><w>90</w><h>70</h></coordinates><panel_attributes>lt=.>
|
||||
</panel_attributes><additional_attributes>70;10;10;50</additional_attributes></element><element><id>Relation</id><coordinates><x>570</x><y>290</y><w>110</w><h>80</h></coordinates><panel_attributes>lt=.>
|
||||
</panel_attributes><additional_attributes>90;10;10;60</additional_attributes></element><element><id>Relation</id><coordinates><x>340</x><y>120</y><w>350</w><h>400</h></coordinates><panel_attributes>lt=.>
|
||||
</panel_attributes><additional_attributes>60;10;10;10;10;380;330;380;330;310</additional_attributes></element><element><id>Relation</id><coordinates><x>770</x><y>270</y><w>30</w><h>120</h></coordinates><panel_attributes>lt=.>
|
||||
</panel_attributes><additional_attributes>10;10;10;100</additional_attributes></element><element><id>Relation</id><coordinates><x>360</x><y>250</y><w>60</w><h>180</h></coordinates><panel_attributes>lt=.>
|
||||
</panel_attributes><additional_attributes>40;10;10;10;10;160;40;160</additional_attributes></element><element><id>Relation</id><coordinates><x>610</x><y>120</y><w>70</w><h>120</h></coordinates><panel_attributes>lt=.>
|
||||
</panel_attributes><additional_attributes>10;10;50;10;50;100</additional_attributes></element></diagram>
|
|
@ -1,8 +0,0 @@
|
|||
package ch.zhaw.gartenverwaltung.gardenplan;
|
||||
|
||||
public class Gardenplanmodel {
|
||||
// private JasonGardenplan gardenplan;
|
||||
// liste von crops
|
||||
//task generieren
|
||||
//plant holen, task template mit tasktemplateklasse tasks erstellen
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
package ch.zhaw.gartenverwaltung.io;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Implements the {@link TaskDatabase} interface for loading and writing {@link Task} objects
|
||||
* from and to a JSON file.
|
||||
* The reads are cached to minimize file-io operations.
|
||||
*/
|
||||
public class JsonTaskDatabase implements TaskDatabase{
|
||||
IdProvider idProvider;
|
||||
private final URL dataSource = getClass().getResource("taskdb.json");
|
||||
|
||||
private Map<Long, Task> taskMap = Collections.emptyMap();
|
||||
|
||||
/**
|
||||
* Creating constant objects required to deserialize the {@link LocalDate} classes
|
||||
*/
|
||||
private final static JavaTimeModule timeModule = new JavaTimeModule();
|
||||
static {
|
||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
LocalDateDeserializer dateDeserializer = new LocalDateDeserializer(dateFormat);
|
||||
timeModule.addDeserializer(LocalDate.class, dateDeserializer);
|
||||
}
|
||||
|
||||
/**
|
||||
* If no data is currently loaded, data is loaded from {@link #dataSource}.
|
||||
* In any case, the values of {@link #taskMap} are returned.
|
||||
*
|
||||
* @see TaskDatabase#getTaskList(LocalDate, LocalDate)
|
||||
*/
|
||||
@Override
|
||||
public List<Task> getTaskList(LocalDate start, LocalDate end) throws IOException{
|
||||
if(taskMap.isEmpty()) {
|
||||
loadTaskListFromFile();
|
||||
}
|
||||
return taskMap.values().stream().filter(task -> task.isInTimePeriode(start, end)).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* If no data is currently loaded, data is loaded from {@link #dataSource}.
|
||||
* If the {@link Task} has an id than the task is added to the {@link #taskMap}
|
||||
* otherwise the id is generated with the {@link IdProvider} before adding
|
||||
* it to the {@link #taskMap}. In any case, the {@link #taskMap} is written
|
||||
* to the {@link #dataSource}.
|
||||
*
|
||||
* @see TaskDatabase#saveTask(Task)
|
||||
*/
|
||||
@Override
|
||||
public void saveTask(Task task) throws IOException {
|
||||
if(taskMap.isEmpty()) {
|
||||
loadTaskListFromFile();
|
||||
}
|
||||
if(task.getId() == 0) {
|
||||
task.withId(idProvider.incrementAndGet());
|
||||
}
|
||||
writeTaskListToFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* If no data is currently loaded, data is loaded from {@link #dataSource}.
|
||||
* If the {@link Task}s id is found in the {@link #taskMap}, the Task is removed
|
||||
* from the {@link #taskMap}. Then the Task are written to the {@link #dataSource}.
|
||||
*
|
||||
* @see TaskDatabase#removeTask(Task)
|
||||
*/
|
||||
@Override
|
||||
public void removeTask(Task task) throws IOException {
|
||||
if(taskMap.isEmpty()) {
|
||||
loadTaskListFromFile();
|
||||
}
|
||||
if(taskMap.containsKey(task.getId())){
|
||||
taskMap.remove(task.getId());
|
||||
writeTaskListToFile();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes cached data to the {@link #dataSource}.
|
||||
*
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
private void writeTaskListToFile() throws IOException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(timeModule)
|
||||
.registerModule(new Jdk8Module());
|
||||
|
||||
if(dataSource != null) {
|
||||
mapper.writeValue(new File(dataSource.getFile()), taskMap);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the database from {@link #dataSource} and updates the cached data.
|
||||
*
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
private void loadTaskListFromFile() throws IOException {
|
||||
if (dataSource != null) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(timeModule);
|
||||
|
||||
List<Task> result;
|
||||
result = mapper.readerForListOf(Task.class).readValue(dataSource);
|
||||
|
||||
taskMap = result.stream()
|
||||
.collect(HashMap::new,
|
||||
(res, task) -> res.put(task.getId(), task),
|
||||
(existing, replacement) -> {});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +1,13 @@
|
|||
package ch.zhaw.gartenverwaltung.io;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A database of {@link Task}s.
|
||||
* The interface specifies the minimal required operations.
|
||||
*/
|
||||
public interface TaskDatabase {
|
||||
/**
|
||||
* Yields a list of all {@link Task}s in the database with the start and end date of a period of time.
|
||||
*
|
||||
* @param start The start date of the wanted time period
|
||||
* @param end The end date of the wanted time period
|
||||
* @return A list of {@link Task}s planned in the specified time period
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
List<Task> getTaskList(LocalDate start, LocalDate end) throws IOException;
|
||||
|
||||
/**
|
||||
* Saves the {@link Task} in the Cache.
|
||||
*
|
||||
* @param task The {@link Task} which is wanted to be saved in the TaskList
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
List<Task> getTaskList(Date start, Date end);
|
||||
void saveTask(Task task) throws IOException;
|
||||
|
||||
/**
|
||||
* Removes the {@link Task}from the Cache.
|
||||
*
|
||||
* @param task The {@link Task} which has to be removed from the {@link Task} list.
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
void removeTask(Task task) throws IOException;
|
||||
}
|
||||
|
|
|
@ -16,22 +16,11 @@ public class Task {
|
|||
private Integer interval;
|
||||
private LocalDate endDate;
|
||||
|
||||
/**
|
||||
* default constructor
|
||||
* (used by Json deserializer)
|
||||
*/
|
||||
public Task(){
|
||||
name= "";
|
||||
description= "";
|
||||
startDate = LocalDate.now();
|
||||
}
|
||||
|
||||
public Task(String name, String description, LocalDate startDate) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public Task(String name, String description, LocalDate startDate, LocalDate endDate, int interval) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
|
@ -54,13 +43,6 @@ public class Task {
|
|||
return this;
|
||||
}
|
||||
|
||||
public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){
|
||||
if(startDate.isAfter(searchStartDate) &&startDate.isBefore(searchEndDate)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Getters
|
||||
public long getId() { return id; }
|
||||
public String getName() { return name; }
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
[
|
||||
{
|
||||
"id" : 1,
|
||||
"name" : "sow plant",
|
||||
"description": "Plant the seeds, crops in de bed.",
|
||||
"startDate" : "2022-05-01",
|
||||
"endDate" : "2022-05-01",
|
||||
"interval" : 0
|
||||
},
|
||||
{
|
||||
"id" : 2,
|
||||
"name" : "water plant",
|
||||
"description": "water the plant, so that the soil is wet around the plant.",
|
||||
"startDate" : "2022-05-01",
|
||||
"endDate" : "2022-09-01",
|
||||
"interval" : 2
|
||||
},
|
||||
{
|
||||
"id" : 3,
|
||||
"name" : "fertilize plant",
|
||||
"description": "The fertilizer has to be mixed with water. Then fertilize the plants soil with the mixture",
|
||||
"startDate" : "2022-06-01",
|
||||
"endDate" : "2022-08-01",
|
||||
"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" : "2022-07-01",
|
||||
"endDate" : "2022-07-01",
|
||||
"interval" : 0
|
||||
},
|
||||
{
|
||||
"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" : "2022-05-01",
|
||||
"endDate" : "2022-09-01",
|
||||
"interval" : 5
|
||||
},
|
||||
{
|
||||
"id" : 6,
|
||||
"name" : "harvest plant",
|
||||
"description": "Pull the ripe vegetables out from the soil. Clean them with clear, fresh water. ",
|
||||
"startDate" : "2022-09-01",
|
||||
"endDate" : "2022-09-01",
|
||||
"interval" : 0
|
||||
}
|
||||
]
|
|
@ -1,37 +0,0 @@
|
|||
package ch.zhaw.gartenverwaltung.io;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
public class JsonTaskDatabaseTest {
|
||||
|
||||
TaskDatabase testDatabase;
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
|
||||
@BeforeEach
|
||||
void connectToDb() {
|
||||
// testDatabase = new JsonTaskDatabase();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("Check if results are retrieved completely")
|
||||
void getTasks(){
|
||||
/*
|
||||
List<Task> taskList=null;
|
||||
try {
|
||||
taskList = testDatabase.getTaskList(formatter.parse("01.05.2022"), formatter.parse("01.08.2022"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Assertions.assertTrue(taskList.size()>0);
|
||||
*/
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
[
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue