updating/creating markets
This commit is contained in:
@@ -11,6 +11,7 @@ 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.Market;
|
||||
import io.dietz.ed.companion.models.eddb.Station;
|
||||
import io.dietz.ed.companion.models.eddb.StationType;
|
||||
import io.dietz.ed.companion.models.eddb.System;
|
||||
@@ -24,6 +25,7 @@ public class StationDeserializer extends JsonDeserializer<Station> {
|
||||
System system = new System(jsonStation.systemId);
|
||||
|
||||
Station station = new Station(jsonStation.id, jsonStation.name, system);
|
||||
station.setMarket(new Market(jsonStation.marketId));
|
||||
station.setType(new StationType(jsonStation.typeId, jsonStation.typeName));
|
||||
station.setMaxLandingPadSize(jsonStation.maxLandingPadSize);
|
||||
station.setDistanceToStar(jsonStation.distanceToStar);
|
||||
@@ -42,6 +44,9 @@ public class StationDeserializer extends JsonDeserializer<Station> {
|
||||
@JsonProperty("updated_at")
|
||||
public long updatedAt;
|
||||
|
||||
@JsonProperty("ed_market_id")
|
||||
public long marketId;
|
||||
|
||||
@JsonProperty("system_id")
|
||||
public long systemId;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.dietz.ed.companion.component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
@@ -13,6 +14,9 @@ import org.zeromq.ZContext;
|
||||
import org.zeromq.ZMQ;
|
||||
|
||||
import io.dietz.ed.companion.domain.MarketWithRoot;
|
||||
import io.dietz.ed.companion.models.eddb.Market;
|
||||
import io.dietz.ed.companion.repositories.MarketRepository;
|
||||
import io.dietz.ed.companion.repositories.StationRepository;
|
||||
|
||||
public class ZeroMqHandler implements Runnable {
|
||||
|
||||
@@ -28,6 +32,12 @@ public class ZeroMqHandler implements Runnable {
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Autowired
|
||||
private MarketRepository marketRepository;
|
||||
|
||||
@Autowired
|
||||
private StationRepository stationRepository;
|
||||
|
||||
public void msg(String msg) {
|
||||
System.out.println(msg);
|
||||
}
|
||||
@@ -66,9 +76,24 @@ public class ZeroMqHandler implements Runnable {
|
||||
|
||||
// outputString contains a json message
|
||||
if (outputString.contains(filterSchema)) {
|
||||
msg(outputString);
|
||||
var test = objectMapper.readValue(outputString, MarketWithRoot.class);
|
||||
msg(test.getMarket().toString());
|
||||
//msg(outputString);
|
||||
|
||||
MarketWithRoot marketContainer = objectMapper.readValue(outputString, MarketWithRoot.class);
|
||||
|
||||
msg(marketContainer.getMarket().toString());
|
||||
|
||||
var test = marketRepository.findById(marketContainer.getMarket().marketId).orElseGet(() -> {
|
||||
msg("Market created!");
|
||||
Market market = new Market(marketContainer.getMarket().marketId);
|
||||
marketRepository.saveAndFlush(market);
|
||||
return market;
|
||||
});
|
||||
|
||||
if(test.getStation() != null) {
|
||||
test.getStation().setUpdatedAt(LocalDateTime.now());
|
||||
stationRepository.saveAndFlush(test.getStation());
|
||||
msg(test.getStation().getName() + " updated!");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (DataFormatException | IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user