Compare commits
No commits in common. "99e8f305e1b5b519fc08bc522cd261f2eeb48558" and "1e4dd07879a325383ebee2073dbb3247daadb387" have entirely different histories.
99e8f305e1
...
1e4dd07879
|
@ -5,7 +5,7 @@ plugins {
|
||||||
id 'org.beryx.jlink' version '2.25.0'
|
id 'org.beryx.jlink' version '2.25.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'ch.zhaw.gartenverwaltung'
|
group 'ch.zhaw.pm3'
|
||||||
version '1.0-SNAPSHOT'
|
version '1.0-SNAPSHOT'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -37,8 +37,6 @@ dependencies {
|
||||||
|
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
|
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
|
||||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${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 {
|
test {
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
package ch.zhaw.gartenverwaltung.io;
|
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
||||||
import com.fasterxml.jackson.datatype.jsr310.deser.MonthDayDeserializer;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.time.MonthDay;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class JsonPlantDatabase implements PlantDatabase {
|
|
||||||
private final URL dataSource = getClass().getResource("plantdb.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<Plant> getPlantList(HardinessZone zone) throws IOException {
|
|
||||||
List<Plant> result = Collections.emptyList();
|
|
||||||
|
|
||||||
if (dataSource != null) {
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
mapper.registerModule(timeModule);
|
|
||||||
|
|
||||||
result = mapper.readerForListOf(Plant.class).readValue(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<Plant> getPlantById(long id) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,11 +3,10 @@ package ch.zhaw.gartenverwaltung.io;
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface PlantDatabase {
|
public interface PlantDatabase {
|
||||||
List<Plant> getPlantList(HardinessZone zone) throws IOException;
|
List<Plant> getPlantList(HardinessZone zone);
|
||||||
Optional<Plant> getPlantById(long id) throws IOException;
|
Optional<Plant> getPlantById(long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
package ch.zhaw.gartenverwaltung.json;
|
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
|
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
||||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class GrowthPhaseTypeDeserializer extends StdDeserializer<GrowthPhaseType> {
|
|
||||||
public GrowthPhaseTypeDeserializer(Class<?> vc) {
|
|
||||||
super(vc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GrowthPhaseTypeDeserializer() { this(null); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GrowthPhaseType deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
|
||||||
GrowthPhaseType result = null;
|
|
||||||
try {
|
|
||||||
result = GrowthPhaseType.valueOf(parser.getText().toUpperCase());
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
// TODO: Log
|
|
||||||
System.err.println("bad growth phase type");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package ch.zhaw.gartenverwaltung.json;
|
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
||||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class HardinessZoneDeserializer extends StdDeserializer<HardinessZone> {
|
|
||||||
public HardinessZoneDeserializer(Class<?> vc) {
|
|
||||||
super(vc);
|
|
||||||
}
|
|
||||||
public HardinessZoneDeserializer() {
|
|
||||||
this(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HardinessZone deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
|
||||||
HardinessZone result = null;
|
|
||||||
try {
|
|
||||||
result = HardinessZone.valueOf(parser.getText().toUpperCase());
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
// TODO: Log
|
|
||||||
System.err.println("bad growth phase type");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +1,9 @@
|
||||||
package ch.zhaw.gartenverwaltung.types;
|
package ch.zhaw.gartenverwaltung.types;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.json.GrowthPhaseTypeDeserializer;
|
import java.util.Date;
|
||||||
import ch.zhaw.gartenverwaltung.json.HardinessZoneDeserializer;
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
||||||
|
|
||||||
import java.time.MonthDay;
|
public record GrowthPhase(Date startDate,
|
||||||
import java.util.List;
|
Date endDate,
|
||||||
|
GrowthPhaseType type,
|
||||||
|
HardinessZone zone) {
|
||||||
public record GrowthPhase(
|
|
||||||
MonthDay startDate,
|
|
||||||
MonthDay endDate,
|
|
||||||
int group,
|
|
||||||
Object wateringCycle,
|
|
||||||
@JsonDeserialize(using = GrowthPhaseTypeDeserializer.class) GrowthPhaseType type,
|
|
||||||
@JsonDeserialize(using = HardinessZoneDeserializer.class) HardinessZone zone,
|
|
||||||
List<TaskTemplate> taskTemplates) {
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package ch.zhaw.gartenverwaltung.types;
|
package ch.zhaw.gartenverwaltung.types;
|
||||||
|
|
||||||
public enum GrowthPhaseType {
|
public enum GrowthPhaseType {
|
||||||
SOW, PLANT, REPLANT, HARVEST
|
SOW, PLANT, HARVEST
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,5 @@ public record Plant(
|
||||||
String name,
|
String name,
|
||||||
String description,
|
String description,
|
||||||
int spacing,
|
int spacing,
|
||||||
int light,
|
|
||||||
String soil,
|
|
||||||
List<Object> pests,
|
|
||||||
List<GrowthPhase> lifecycle) {
|
List<GrowthPhase> lifecycle) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package ch.zhaw.gartenverwaltung.types;
|
package ch.zhaw.gartenverwaltung.types;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,21 +11,14 @@ public class Task {
|
||||||
private long id;
|
private long id;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String description;
|
private final String description;
|
||||||
private final LocalDate startDate;
|
private final Date startDate;
|
||||||
private Integer interval;
|
private Integer interval;
|
||||||
private LocalDate endDate;
|
private Date endDate;
|
||||||
|
|
||||||
public Task(String name, String description, LocalDate startDate) {
|
public Task(String name, String description, Date startDate) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.startDate = startDate;
|
this.startDate = endDate;
|
||||||
}
|
|
||||||
public Task(String name, String description, LocalDate startDate, LocalDate endDate, int interval) {
|
|
||||||
this.name = name;
|
|
||||||
this.description = description;
|
|
||||||
this.startDate = startDate;
|
|
||||||
this.endDate = endDate;
|
|
||||||
this.interval = interval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Builder-pattern-style setters
|
// Builder-pattern-style setters
|
||||||
|
@ -38,7 +30,7 @@ public class Task {
|
||||||
this.interval = interval;
|
this.interval = interval;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public Task withEndDate(LocalDate endDate) {
|
public Task withEndDate(Date endDate) {
|
||||||
this.endDate = endDate;
|
this.endDate = endDate;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -47,12 +39,12 @@ public class Task {
|
||||||
public long getId() { return id; }
|
public long getId() { return id; }
|
||||||
public String getName() { return name; }
|
public String getName() { return name; }
|
||||||
public String getDescription() { return description; }
|
public String getDescription() { return description; }
|
||||||
public LocalDate getStartDate() { return startDate; }
|
public Date getStartDate() { return startDate; }
|
||||||
|
|
||||||
public Optional<Integer> getInterval() {
|
public Optional<Integer> getInterval() {
|
||||||
return Optional.ofNullable(interval);
|
return Optional.ofNullable(interval);
|
||||||
}
|
}
|
||||||
public Optional<LocalDate> getEndDate() {
|
public Optional<Date> getEndDate() {
|
||||||
return Optional.ofNullable(endDate);
|
return Optional.ofNullable(endDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
package ch.zhaw.gartenverwaltung.types;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
public class TaskTemplate {
|
|
||||||
@JsonProperty
|
|
||||||
private final String name;
|
|
||||||
@JsonProperty
|
|
||||||
private final String description;
|
|
||||||
@JsonProperty
|
|
||||||
private final int relativeStartDate;
|
|
||||||
@JsonProperty
|
|
||||||
private Integer relativeEndDate;
|
|
||||||
@JsonProperty
|
|
||||||
private Integer interval;
|
|
||||||
|
|
||||||
// TODO: reconsider if we need this
|
|
||||||
@JsonProperty
|
|
||||||
private boolean isOptional = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default constructor
|
|
||||||
* (Used by deserializer)
|
|
||||||
*/
|
|
||||||
public TaskTemplate() {
|
|
||||||
this.name = "";
|
|
||||||
this.description = "";
|
|
||||||
this.relativeStartDate = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setters
|
|
||||||
public void setRelativeEndDate(Integer relativeEndDate) {
|
|
||||||
this.relativeEndDate = relativeEndDate;
|
|
||||||
}
|
|
||||||
public void setInterval(Integer interval) {
|
|
||||||
this.interval = interval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TaskTemplate(String name, String description, int relativeStartDate) {
|
|
||||||
this.name = name;
|
|
||||||
this.description = description;
|
|
||||||
this.relativeStartDate = relativeStartDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task generateTask(LocalDate realStartDate) {
|
|
||||||
Task task = new Task(name, description, realStartDate.plusDays(relativeStartDate));
|
|
||||||
if (relativeEndDate != null) {
|
|
||||||
task.withEndDate(realStartDate.plusDays(relativeEndDate));
|
|
||||||
}
|
|
||||||
if (interval != null) {
|
|
||||||
task.withInterval(interval);
|
|
||||||
}
|
|
||||||
return task;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,13 +1,8 @@
|
||||||
module ch.zhaw.gartenverwaltung {
|
module ch.zhaw.gartenverwaltung {
|
||||||
requires javafx.controls;
|
requires javafx.controls;
|
||||||
requires javafx.fxml;
|
requires javafx.fxml;
|
||||||
requires com.fasterxml.jackson.databind;
|
|
||||||
requires com.fasterxml.jackson.datatype.jsr310;
|
|
||||||
|
|
||||||
opens ch.zhaw.gartenverwaltung to javafx.fxml;
|
opens ch.zhaw.gartenverwaltung to javafx.fxml;
|
||||||
opens ch.zhaw.gartenverwaltung.types to com.fasterxml.jackson.databind;
|
|
||||||
// opens ch.zhaw.gartenverwaltung.types to com.fasterxml.jackson.databind;
|
|
||||||
exports ch.zhaw.gartenverwaltung;
|
exports ch.zhaw.gartenverwaltung;
|
||||||
exports ch.zhaw.gartenverwaltung.types;
|
|
||||||
exports ch.zhaw.gartenverwaltung.json;
|
|
||||||
}
|
}
|
|
@ -1,85 +0,0 @@
|
||||||
[
|
|
||||||
{
|
|
||||||
"id": 0,
|
|
||||||
"name": "Potato",
|
|
||||||
"description": "The potato is a tuber, round or oval, with small white roots called 'eyes', that are growth buds. The size varies depending on the variety; the colour of the skin can be white, yellow or even purple.",
|
|
||||||
"light": 6,
|
|
||||||
"spacing": "35",
|
|
||||||
"soil": "sandy",
|
|
||||||
"pests": [
|
|
||||||
{
|
|
||||||
"name": "Rot",
|
|
||||||
"description": "Rot, any of several plant diseases, caused by any of hundreds of species of soil-borne bacteria, fungi, and funguslike organisms (Oomycota). Rot diseases are characterized by plant decomposition and putrefaction. The decay may be hard, dry, spongy, watery, mushy, or slimy and may affect any plant part.",
|
|
||||||
"measures": "Less water."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"lifecycle": [
|
|
||||||
{
|
|
||||||
"startDate": "03-10",
|
|
||||||
"endDate": "04-10",
|
|
||||||
"type": "SOW",
|
|
||||||
"zone": "ZONE_8A",
|
|
||||||
"group": 0,
|
|
||||||
"wateringCycle": {
|
|
||||||
"litersPerSqM": 0,
|
|
||||||
"interval": null,
|
|
||||||
"notes": []
|
|
||||||
},
|
|
||||||
"taskTemplates": [
|
|
||||||
{
|
|
||||||
"name": "Germinate",
|
|
||||||
"relativeStartDate": -14,
|
|
||||||
"relativeEndDate": null,
|
|
||||||
"description": "\"Take an egg carton and fill it with soil. Put the seedling deep enaugh so its half covered with soil. Keep it in 10-15 * Celsius with lots of light.\"",
|
|
||||||
"interval": null,
|
|
||||||
"isOptional": false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"startDate": "04-10",
|
|
||||||
"endDate": "07-10",
|
|
||||||
"type": "PLANT",
|
|
||||||
"zone": "ZONE_8A",
|
|
||||||
"group": 0,
|
|
||||||
"wateringCycle": {
|
|
||||||
"litersPerSqM": 25,
|
|
||||||
"interval": 7,
|
|
||||||
"notes": []
|
|
||||||
},
|
|
||||||
"taskTemplates": [
|
|
||||||
{
|
|
||||||
"name": "hilling",
|
|
||||||
"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
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"startDate": "06-10",
|
|
||||||
"endDate": "08-10",
|
|
||||||
"type": "HARVEST",
|
|
||||||
"zone": "ZONE_8A",
|
|
||||||
"group": 0,
|
|
||||||
"wateringCycle": {
|
|
||||||
"litersPerSqM": 0,
|
|
||||||
"interval": null,
|
|
||||||
"notes": []
|
|
||||||
},
|
|
||||||
"taskTemplates": [
|
|
||||||
{
|
|
||||||
"name": "Harvest",
|
|
||||||
"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
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
Loading…
Reference in New Issue