#11 Very basic implementation with dummy data
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user