#11 Very basic implementation with dummy data

This commit is contained in:
David Guler
2022-10-17 17:01:50 +02:00
parent 9a29499c39
commit 5f53bb86c6
10 changed files with 159 additions and 7 deletions
@@ -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;
}