#11 Very basic implementation with dummy data
This commit is contained in:
parent
9a29499c39
commit
5f53bb86c6
|
@ -5,7 +5,7 @@ plugins {
|
|||
id 'org.beryx.jlink' version '2.25.0'
|
||||
}
|
||||
|
||||
group 'ch.zhaw.pm3'
|
||||
group 'ch.zhaw.gartenverwaltung'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
|
@ -37,6 +37,7 @@ 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'
|
||||
}
|
||||
|
||||
test {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.JsonPlantDatabase;
|
||||
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
|
@ -18,6 +21,12 @@ public class HelloApplication extends Application {
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
PlantDatabase db = new JsonPlantDatabase();
|
||||
try {
|
||||
System.out.println(db.getPlantList(HardinessZone.ZONE_8A));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
launch();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package ch.zhaw.gartenverwaltung.io;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
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");
|
||||
|
||||
@Override
|
||||
public List<Plant> getPlantList(HardinessZone zone) throws IOException {
|
||||
List<Plant> result = Collections.emptyList();
|
||||
|
||||
if (dataSource != null) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
DateFormat dateFormat = new SimpleDateFormat("MM-dd");
|
||||
mapper.setDateFormat(dateFormat);
|
||||
|
||||
result = mapper.readerForListOf(Plant.class).readValue(dataSource);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Plant> getPlantById(long id) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
|
@ -3,10 +3,11 @@ package ch.zhaw.gartenverwaltung.io;
|
|||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface PlantDatabase {
|
||||
List<Plant> getPlantList(HardinessZone zone);
|
||||
Optional<Plant> getPlantById(long id);
|
||||
List<Plant> getPlantList(HardinessZone zone) throws IOException;
|
||||
Optional<Plant> getPlantById(long id) throws IOException;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
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,9 +1,15 @@
|
|||
package ch.zhaw.gartenverwaltung.types;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.json.GrowthPhaseTypeDeserializer;
|
||||
import ch.zhaw.gartenverwaltung.json.HardinessZoneDeserializer;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public record GrowthPhase(Date startDate,
|
||||
Date endDate,
|
||||
GrowthPhaseType type,
|
||||
HardinessZone zone) {
|
||||
|
||||
public record GrowthPhase(
|
||||
Date startDate,
|
||||
Date endDate,
|
||||
@JsonDeserialize(using = GrowthPhaseTypeDeserializer.class) GrowthPhaseType type,
|
||||
@JsonDeserialize(using = HardinessZoneDeserializer.class) HardinessZone zone) {
|
||||
}
|
||||
|
|
|
@ -7,5 +7,10 @@ public record Plant(
|
|||
String name,
|
||||
String description,
|
||||
int spacing,
|
||||
Object water,
|
||||
int light,
|
||||
List<String> maintenance,
|
||||
List<String> specialTasks,
|
||||
List<String> pests,
|
||||
List<GrowthPhase> lifecycle) {
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
module ch.zhaw.gartenverwaltung {
|
||||
requires javafx.controls;
|
||||
requires javafx.fxml;
|
||||
requires com.fasterxml.jackson.databind;
|
||||
|
||||
|
||||
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.types;
|
||||
exports ch.zhaw.gartenverwaltung.json;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
[
|
||||
{
|
||||
"name": "Potato",
|
||||
"description": "Tasty tubers.",
|
||||
"water": {
|
||||
"amount": "27-55",
|
||||
"interval": 7
|
||||
},
|
||||
"light": 6,
|
||||
"maintenance": [],
|
||||
"specialTasks": [],
|
||||
"lifecycle": [
|
||||
{
|
||||
"startDate": "04-01",
|
||||
"endDate": "05-31",
|
||||
"type": "SOW",
|
||||
"zone": "ZONE_8A"
|
||||
},
|
||||
{
|
||||
"startDate": "07-01",
|
||||
"endDate": "08-31",
|
||||
"type": "HARVEST",
|
||||
"zone": "ZONE_8A"
|
||||
}
|
||||
],
|
||||
"spacing": 35,
|
||||
"pests": [
|
||||
"Potato beetle"
|
||||
]
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue