automated download of systems and stations
used to populate database if empty
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package io.dietz.ed.companion.component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import io.dietz.ed.companion.models.eddb.Station;
|
||||
import io.dietz.ed.companion.models.eddb.StationType;
|
||||
import io.dietz.ed.companion.models.eddb.System;
|
||||
|
||||
public class StationDeserializer extends JsonDeserializer<Station> {
|
||||
|
||||
@Override
|
||||
public Station deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
StationJson jsonStation = p.readValueAs(StationJson.class);
|
||||
|
||||
System system = new System(jsonStation.systemId);
|
||||
|
||||
Station station = new Station(jsonStation.id, jsonStation.name, system);
|
||||
station.setType(new StationType(jsonStation.typeId, jsonStation.typeName));
|
||||
station.setMaxLandingPadSize(jsonStation.maxLandingPadSize);
|
||||
station.setDistanceToStar(jsonStation.distanceToStar);
|
||||
station.setPlanetary(jsonStation.isPlanetary);
|
||||
station.setUpdatedAt(LocalDateTime.ofInstant(Instant.ofEpochSecond(jsonStation.updatedAt), TimeZone.getDefault().toZoneId()));
|
||||
|
||||
return station;
|
||||
}
|
||||
|
||||
private static class StationJson {
|
||||
|
||||
public long id;
|
||||
|
||||
public String name;
|
||||
|
||||
@JsonProperty("updated_at")
|
||||
public long updatedAt;
|
||||
|
||||
@JsonProperty("system_id")
|
||||
public long systemId;
|
||||
|
||||
@JsonProperty("type_id")
|
||||
public long typeId;
|
||||
|
||||
@JsonProperty("type")
|
||||
public String typeName;
|
||||
|
||||
@JsonProperty("max_landing_pad_size")
|
||||
public String maxLandingPadSize;
|
||||
|
||||
@JsonProperty("distance_to_star")
|
||||
public long distanceToStar;
|
||||
|
||||
@JsonProperty("is_planetary")
|
||||
public boolean isPlanetary;
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,9 @@ public class SystemDeserializer extends JsonDeserializer<System> {
|
||||
SystemJson jsonSystem = p.readValueAs(SystemJson.class);
|
||||
|
||||
GeometryFactory gf = new GeometryFactory();
|
||||
Point test = gf.createPoint(new Coordinate(jsonSystem.x, jsonSystem.y, jsonSystem.z));
|
||||
Point systemPointInGalaxy = gf.createPoint(new Coordinate(jsonSystem.x, jsonSystem.y, jsonSystem.z));
|
||||
|
||||
return new System(jsonSystem.id, jsonSystem.name, test);
|
||||
return new System(jsonSystem.id, jsonSystem.name, systemPointInGalaxy);
|
||||
}
|
||||
|
||||
private static class SystemJson {
|
||||
|
||||
Reference in New Issue
Block a user