implement import helped classes, refactoring EDDN message parse
This commit is contained in:
@@ -4,11 +4,14 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.trader.controllers.MainController;
|
import ru.trader.controllers.MainController;
|
||||||
import ru.trader.emdn.EMDN;
|
import ru.trader.emdn.EMDN;
|
||||||
import ru.trader.emdn.entities.Item;
|
|
||||||
import ru.trader.emdn.entities.Message;
|
import ru.trader.emdn.entities.Message;
|
||||||
import ru.trader.model.*;
|
import ru.trader.model.*;
|
||||||
import ru.trader.model.support.StationUpdater;
|
import ru.trader.model.support.StationUpdater;
|
||||||
|
import ru.trader.store.imp.entities.ItemData;
|
||||||
|
import ru.trader.store.imp.entities.StarSystemData;
|
||||||
|
import ru.trader.store.imp.entities.StationData;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@@ -64,12 +67,18 @@ public class EMDNUpdater {
|
|||||||
public void accept(Message message) {
|
public void accept(Message message) {
|
||||||
if (world == null || message == null) return;
|
if (world == null || message == null) return;
|
||||||
LOG.trace("Update station from EDDN: {}", message);
|
LOG.trace("Update station from EDDN: {}", message);
|
||||||
SystemModel system = world.get(message.getBody().getSystem().getName());
|
StarSystemData data = message.getImportData();
|
||||||
|
SystemModel system = world.get(data.getName());
|
||||||
if (!ModelFabric.isFake(system)) {
|
if (!ModelFabric.isFake(system)) {
|
||||||
StationModel station = system.get(message.getBody().getStation().getName());
|
Collection<StationData> stations = data.getStations();
|
||||||
|
if (stations == null) return;
|
||||||
|
for (StationData stationData : stations) {
|
||||||
|
StationModel station = system.get(stationData.getName());
|
||||||
if (!ModelFabric.isFake(station)){
|
if (!ModelFabric.isFake(station)){
|
||||||
|
Collection<ItemData> commodities = stationData.getCommodities();
|
||||||
|
if (commodities == null) return;
|
||||||
updater.edit(station);
|
updater.edit(station);
|
||||||
for (Item commodity : message.getBody().getCommodities()) {
|
for (ItemData commodity : commodities) {
|
||||||
String id = commodity.getName().toLowerCase().replace(" ","_");
|
String id = commodity.getName().toLowerCase().replace(" ","_");
|
||||||
Optional<ItemModel> item = world.getItem(id);
|
Optional<ItemModel> item = world.getItem(id);
|
||||||
if (item.isPresent()) {
|
if (item.isPresent()) {
|
||||||
@@ -88,15 +97,16 @@ public class EMDNUpdater {
|
|||||||
} else {
|
} else {
|
||||||
LOG.trace("Station not found");
|
LOG.trace("Station not found");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.trace("System not found");
|
LOG.trace("System not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillOffers(StationUpdater.FakeOffer offer, Item commodity) {
|
private void fillOffers(StationUpdater.FakeOffer offer, ItemData commodity) {
|
||||||
offer.setSprice(commodity.getBuyPrice());
|
offer.setSprice(commodity.getSellOfferPrice());
|
||||||
offer.setSupply(commodity.getSupply());
|
offer.setSupply(commodity.getSupply());
|
||||||
offer.setBprice(commodity.getSellPrice());
|
offer.setBprice(commodity.getBuyOfferPrice());
|
||||||
offer.setDemand(commodity.getDemand());
|
offer.setDemand(commodity.getDemand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,6 @@ import ru.trader.emdn.entities.*;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
public class EMDNParser {
|
public class EMDNParser {
|
||||||
private final static Logger LOG = LoggerFactory.getLogger(EMDNParser.class);
|
private final static Logger LOG = LoggerFactory.getLogger(EMDNParser.class);
|
||||||
@@ -34,133 +30,20 @@ public class EMDNParser {
|
|||||||
public Message parse(String json) throws IOException {
|
public Message parse(String json) throws IOException {
|
||||||
JsonParser parser = mapper.getFactory().createParser(json);
|
JsonParser parser = mapper.getFactory().createParser(json);
|
||||||
JsonNode node = parser.readValueAsTree();
|
JsonNode node = parser.readValueAsTree();
|
||||||
String schema = node.get("$schemaRef").asText();
|
String schema = node.get("$schemaRef").asText("");
|
||||||
PARSERS p = PARSERS.getParser(schema);
|
SUPPORT_VERSIONS version = SUPPORT_VERSIONS.getVersion(schema);
|
||||||
if (p == null){
|
if (version == null){
|
||||||
LOG.warn("Unknown EDDN message schema {}", schema);
|
LOG.warn("Unknown EDDN message schema {}", schema);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return p.parse(node);
|
return parse(node, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum PARSERS {
|
protected Message parse(JsonNode node, SUPPORT_VERSIONS version){
|
||||||
V1_SHIPYARD("http://schemas.elite-markets.net/eddn/shipyard/1"),
|
|
||||||
V2_SHIPYARD("http://schemas.elite-markets.net/eddn/shipyard/2"),
|
|
||||||
V1("http://schemas.elite-markets.net/eddn/commodity/1"){
|
|
||||||
@Override
|
|
||||||
protected Body parseBody(JsonNode node) {
|
|
||||||
if (node == null){
|
|
||||||
LOG.warn("Not found message body on parse EDDN message");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
JsonNode systemName = node.get("systemName");
|
|
||||||
JsonNode stationName = node.get("stationName");
|
|
||||||
JsonNode timestamp = node.get("timestamp");
|
|
||||||
if (systemName == null || stationName == null || timestamp == null){
|
|
||||||
LOG.warn("Body EDDN message don't have required fields");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
StarSystem starSystem = new StarSystem(systemName.asText());
|
|
||||||
Station station = new Station(stationName.asText());
|
|
||||||
LocalDateTime dt = LocalDateTime.parse(timestamp.asText(), DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
|
||||||
Body body = new Body(starSystem, station);
|
|
||||||
body.setTimestamp(dt);
|
|
||||||
body.addAll(parseCommodities(node));
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Collection<Item> parseCommodities(JsonNode node) {
|
|
||||||
JsonNode name = node.get("itemName");
|
|
||||||
JsonNode buyPrice = node.get("buyPrice");
|
|
||||||
JsonNode supply = node.get("stationStock");
|
|
||||||
JsonNode supplyLevel = node.get("supplyLevel");
|
|
||||||
JsonNode sellPrice = node.get("sellPrice");
|
|
||||||
JsonNode demand = node.get("demand");
|
|
||||||
JsonNode demandLevel = node.get("demandLevel");
|
|
||||||
if (name == null || buyPrice == null || supply == null || sellPrice == null || demand == null){
|
|
||||||
LOG.warn("Commodity of EDDN message don't have required fields");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Item item = new Item(name.asText(), buyPrice.asLong(), supply.asLong(), sellPrice.asLong(), demand.asLong());
|
|
||||||
if (supplyLevel != null){
|
|
||||||
item.setSupplyLevel(LEVEL_TYPE.fromJSON(supplyLevel.asText()));
|
|
||||||
}
|
|
||||||
if (demandLevel != null){
|
|
||||||
item.setDemandLevel(LEVEL_TYPE.fromJSON(demandLevel.asText()));
|
|
||||||
}
|
|
||||||
return Collections.singleton(item);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
V2("http://schemas.elite-markets.net/eddn/commodity/2"),
|
|
||||||
|
|
||||||
V3("http://schemas.elite-markets.net/eddn/commodity/3"){
|
|
||||||
@Override
|
|
||||||
protected Body parseBody(JsonNode node) {
|
|
||||||
if (node == null){
|
|
||||||
LOG.warn("Not found message body on parse EDDN message");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
JsonNode systemNode = node.get("system");
|
|
||||||
JsonNode stationNode = node.get("station");
|
|
||||||
JsonNode timestamp = node.get("timestamp");
|
|
||||||
JsonNode commodities = node.get("commodities");
|
|
||||||
if (systemNode == null || stationNode == null || timestamp == null || commodities == null){
|
|
||||||
LOG.warn("Body EDDN message don't have required fields");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
StarSystem starSystem = parseSystem(systemNode);
|
|
||||||
Station station = parseStation(stationNode);
|
|
||||||
LocalDateTime dt = LocalDateTime.parse(timestamp.asText(), DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
|
||||||
Body body = new Body(starSystem, station);
|
|
||||||
body.setTimestamp(dt);
|
|
||||||
body.addAll(parseCommodities(commodities));
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Station parseStation(JsonNode node) {
|
|
||||||
JsonNode name = node.get("name");
|
|
||||||
JsonNode id = node.get("id");
|
|
||||||
if (name == null){
|
|
||||||
LOG.warn("Station in EDDN message don't have required fields");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Station station = new Station(name.asText());
|
|
||||||
if (id != null){
|
|
||||||
station.setId(id.asLong());
|
|
||||||
}
|
|
||||||
return station;
|
|
||||||
}
|
|
||||||
|
|
||||||
private StarSystem parseSystem(JsonNode node) {
|
|
||||||
JsonNode name = node.get("name");
|
|
||||||
JsonNode id = node.get("id");
|
|
||||||
JsonNode address = node.get("address");
|
|
||||||
if (name == null){
|
|
||||||
LOG.warn("System in EDDN message don't have required fields");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
StarSystem system = new StarSystem(name.asText());
|
|
||||||
if (id != null){
|
|
||||||
system.setId(id.asLong());
|
|
||||||
}
|
|
||||||
if (address != null){
|
|
||||||
system.setAddress(address.asLong());
|
|
||||||
}
|
|
||||||
return system;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
private final String schema;
|
|
||||||
|
|
||||||
public Message parse(JsonNode node){
|
|
||||||
Header header = parseHeader(node.get("header"));
|
Header header = parseHeader(node.get("header"));
|
||||||
Body body = parseBody(node.get("message"));
|
JsonNode body = node.get("message");
|
||||||
if (header == null || body == null) return null;
|
if (header == null || body == null) return null;
|
||||||
return new Message(schema, header, body);
|
return new Message(version, header, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Header parseHeader(JsonNode node){
|
protected Header parseHeader(JsonNode node){
|
||||||
@@ -184,86 +67,4 @@ public class EMDNParser {
|
|||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Body parseBody(JsonNode node){
|
|
||||||
if (node == null){
|
|
||||||
LOG.warn("Not found message body on parse EDDN message");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
JsonNode systemName = node.get("systemName");
|
|
||||||
JsonNode stationName = node.get("stationName");
|
|
||||||
JsonNode timestamp = node.get("timestamp");
|
|
||||||
JsonNode commodities = node.get("commodities");
|
|
||||||
JsonNode ships = node.get("ships");
|
|
||||||
if (systemName == null || stationName == null || timestamp == null || (commodities == null && ships == null)){
|
|
||||||
LOG.warn("Body EDDN message don't have required fields");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
StarSystem starSystem = new StarSystem(systemName.asText());
|
|
||||||
Station station = new Station(stationName.asText());
|
|
||||||
LocalDateTime dt = LocalDateTime.parse(timestamp.asText(), DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
|
||||||
Body body = new Body(starSystem, station);
|
|
||||||
body.setTimestamp(dt);
|
|
||||||
if (commodities != null){
|
|
||||||
body.addAll(parseCommodities(commodities));
|
|
||||||
}
|
|
||||||
if (ships != null){
|
|
||||||
body.addShips(parseShips(ships));
|
|
||||||
}
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Collection<Item> parseCommodities(JsonNode commodities) {
|
|
||||||
Collection<Item> res = new ArrayList<>();
|
|
||||||
for (Iterator<JsonNode> iterator = commodities.elements(); iterator.hasNext(); ) {
|
|
||||||
JsonNode node = iterator.next();
|
|
||||||
JsonNode name = node.get("name");
|
|
||||||
JsonNode id = node.get("id");
|
|
||||||
JsonNode buyPrice = node.get("buyPrice");
|
|
||||||
JsonNode supply = node.get("supply");
|
|
||||||
JsonNode supplyLevel = node.get("supplyLevel");
|
|
||||||
JsonNode sellPrice = node.get("sellPrice");
|
|
||||||
JsonNode demand = node.get("demand");
|
|
||||||
JsonNode demandLevel = node.get("demandLevel");
|
|
||||||
if (name == null || buyPrice == null || supply == null || sellPrice == null || demand == null){
|
|
||||||
LOG.warn("Commodity of EDDN message don't have required fields");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Item item = new Item(name.asText(), buyPrice.asLong(), supply.asLong(), sellPrice.asLong(), demand.asLong());
|
|
||||||
if (id != null){
|
|
||||||
item.setId(id.asLong());
|
|
||||||
}
|
|
||||||
if (supplyLevel != null){
|
|
||||||
item.setSupplyLevel(LEVEL_TYPE.fromJSON(supplyLevel.asText()));
|
|
||||||
}
|
|
||||||
if (demandLevel != null){
|
|
||||||
item.setDemandLevel(LEVEL_TYPE.fromJSON(demandLevel.asText()));
|
|
||||||
}
|
|
||||||
res.add(item);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Collection<Ship> parseShips(JsonNode ships) {
|
|
||||||
Collection<Ship> res = new ArrayList<>();
|
|
||||||
for (Iterator<JsonNode> iterator = ships.elements(); iterator.hasNext(); ) {
|
|
||||||
JsonNode node = iterator.next();
|
|
||||||
String name = node.asText();
|
|
||||||
Ship ship = new Ship(name);
|
|
||||||
res.add(ship);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PARSERS(String schema) {
|
|
||||||
this.schema = schema;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PARSERS getParser(String schema){
|
|
||||||
for (PARSERS parser : PARSERS.values()) {
|
|
||||||
if (parser.schema.equals(schema)) return parser;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
package ru.trader.emdn;
|
|
||||||
|
|
||||||
public class ItemData {
|
|
||||||
private final String name;
|
|
||||||
private double buy;
|
|
||||||
private double sell;
|
|
||||||
private long demand;
|
|
||||||
private long stock;
|
|
||||||
|
|
||||||
|
|
||||||
public ItemData(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSell(double price, long count){
|
|
||||||
sell = price;
|
|
||||||
demand = count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBuy(double price, long count){
|
|
||||||
buy = price;
|
|
||||||
stock = count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getBuy() {
|
|
||||||
return buy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getSell() {
|
|
||||||
return sell;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDemand() {
|
|
||||||
return demand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getStock() {
|
|
||||||
return stock;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (!(o instanceof ItemData)) return false;
|
|
||||||
ItemData itemData = (ItemData) o;
|
|
||||||
return !(name != null ? !name.equals(itemData.name) : itemData.name != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return name != null ? name.hashCode() : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
final StringBuilder sb = new StringBuilder("{");
|
|
||||||
sb.append(name);
|
|
||||||
sb.append(" buy=").append(buy);
|
|
||||||
sb.append(" (").append(stock).append(")");
|
|
||||||
sb.append(" sell=").append(sell);
|
|
||||||
sb.append(" (").append(demand).append(")");
|
|
||||||
sb.append('}');
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
package ru.trader.emdn.entities;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
public class Body {
|
|
||||||
private final StarSystem system;
|
|
||||||
private final Station station;
|
|
||||||
private LocalDateTime timestamp;
|
|
||||||
private final Collection<Item> commodities;
|
|
||||||
private final Collection<Ship> ships;
|
|
||||||
|
|
||||||
public Body(StarSystem system, Station station) {
|
|
||||||
this.system = system;
|
|
||||||
this.station = station;
|
|
||||||
commodities = new ArrayList<>();
|
|
||||||
ships = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public StarSystem getSystem() {
|
|
||||||
return system;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Station getStation() {
|
|
||||||
return station;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDateTime getTimestamp() {
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimestamp(LocalDateTime timestamp) {
|
|
||||||
this.timestamp = timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<Item> getCommodities() {
|
|
||||||
return commodities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Item item){
|
|
||||||
commodities.add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAll(Collection<Item> items){
|
|
||||||
commodities.addAll(items);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<Ship> getShips() {
|
|
||||||
return ships;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Ship ship){
|
|
||||||
ships.add(ship);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addShips(Collection<Ship> ships){
|
|
||||||
this.ships.addAll(ships);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Body{" +
|
|
||||||
"system=" + system +
|
|
||||||
", station=" + station +
|
|
||||||
", timestamp=" + timestamp +
|
|
||||||
", commodities=" + commodities +
|
|
||||||
", ships=" + ships +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package ru.trader.emdn.entities;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import ru.trader.store.imp.ImportDataError;
|
||||||
|
import ru.trader.store.imp.entities.ItemDataBase;
|
||||||
|
|
||||||
|
public class EDDNItemData extends ItemDataBase {
|
||||||
|
private final JsonNode node;
|
||||||
|
private final SUPPORT_VERSIONS version;
|
||||||
|
|
||||||
|
public EDDNItemData(JsonNode node, SUPPORT_VERSIONS version) {
|
||||||
|
this.node = node;
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getId() {
|
||||||
|
JsonNode n = node.get("id");
|
||||||
|
if (n != null && n.isNumber()){
|
||||||
|
return n.asLong();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
String name = null;
|
||||||
|
JsonNode n;
|
||||||
|
switch (version) {
|
||||||
|
case V1:
|
||||||
|
n = node.get("itemName");
|
||||||
|
if (n != null) name = n.asText();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
n = node.get("name");
|
||||||
|
if (n != null) name = n.asText();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (name == null){
|
||||||
|
throw new ImportDataError("EDDN message don't have commodity name");
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getBuyOfferPrice() {
|
||||||
|
// buy offer price in trader = sell price in EDCE
|
||||||
|
JsonNode n = node.get("sellPrice");
|
||||||
|
if (n != null && n.isNumber()){
|
||||||
|
return n.asLong();
|
||||||
|
} else {
|
||||||
|
throw new ImportDataError("EDDN message don't have commodity sell price");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSellOfferPrice() {
|
||||||
|
// sell offer price in trader = buy price in EDCE
|
||||||
|
JsonNode n = node.get("buyPrice");
|
||||||
|
if (n != null && n.isNumber()){
|
||||||
|
return n.asLong();
|
||||||
|
} else {
|
||||||
|
throw new ImportDataError("EDDN message don't have commodity buy price");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSupply() {
|
||||||
|
JsonNode n;
|
||||||
|
switch (version) {
|
||||||
|
case V1:
|
||||||
|
n = node.get("stationStock");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
n = node.get("supply");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (n != null && n.isNumber()){
|
||||||
|
return n.asLong();
|
||||||
|
} else {
|
||||||
|
throw new ImportDataError("EDDN message don't have commodity supply");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getDemand() {
|
||||||
|
JsonNode n = node.get("demand");
|
||||||
|
if (n != null && n.isNumber()){
|
||||||
|
return n.asLong();
|
||||||
|
} else {
|
||||||
|
throw new ImportDataError("EDDN message don't have commodity demand");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package ru.trader.emdn.entities;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import ru.trader.store.imp.ImportDataError;
|
||||||
|
import ru.trader.store.imp.entities.ShipDataBase;
|
||||||
|
|
||||||
|
public class EDDNShipData extends ShipDataBase {
|
||||||
|
private final JsonNode node;
|
||||||
|
private final SUPPORT_VERSIONS version;
|
||||||
|
|
||||||
|
public EDDNShipData(JsonNode node, SUPPORT_VERSIONS version) {
|
||||||
|
this.node = node;
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getId() {
|
||||||
|
JsonNode n = node.get("id");
|
||||||
|
if (n != null && n.isNumber()){
|
||||||
|
return n.asLong();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
if (node != null && node.isTextual()){
|
||||||
|
return node.asText();
|
||||||
|
} else {
|
||||||
|
throw new ImportDataError("EDDN message don't have ship name");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getPrice() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
106
utils/src/main/java/ru/trader/emdn/entities/EDDNStationData.java
Normal file
106
utils/src/main/java/ru/trader/emdn/entities/EDDNStationData.java
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
package ru.trader.emdn.entities;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import ru.trader.store.imp.ImportDataError;
|
||||||
|
import ru.trader.store.imp.entities.ItemData;
|
||||||
|
import ru.trader.store.imp.entities.ShipData;
|
||||||
|
import ru.trader.store.imp.entities.StationDataBase;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
public class EDDNStationData extends StationDataBase {
|
||||||
|
private final JsonNode node;
|
||||||
|
private final SUPPORT_VERSIONS version;
|
||||||
|
|
||||||
|
|
||||||
|
public EDDNStationData(JsonNode node, SUPPORT_VERSIONS version) {
|
||||||
|
this.node = node;
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getId() {
|
||||||
|
JsonNode n = node.get("id");
|
||||||
|
if (n != null && n.isNumber()){
|
||||||
|
return n.asLong();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
String name = null;
|
||||||
|
JsonNode n = node.get("stationName");
|
||||||
|
if (n != null) name = n.asText();
|
||||||
|
if (name == null){
|
||||||
|
throw new ImportDataError("EDDN message don't have station name");
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Collection<ItemData> getCommodities() {
|
||||||
|
JsonNode n;
|
||||||
|
switch (version) {
|
||||||
|
case V1_SHIPYARD:
|
||||||
|
case V2_SHIPYARD:
|
||||||
|
return null;
|
||||||
|
case V1:
|
||||||
|
Collection<ItemData> items = new ArrayList<>();
|
||||||
|
items.add(new EDDNItemData(node, version));
|
||||||
|
return items;
|
||||||
|
default:
|
||||||
|
n = node.get("commodities");
|
||||||
|
if (n != null && n.isArray()){
|
||||||
|
items = new ArrayList<>();
|
||||||
|
for (Iterator<JsonNode> iterator = n.elements(); iterator.hasNext(); ) {
|
||||||
|
JsonNode itemNode = iterator.next();
|
||||||
|
items.add(new EDDNItemData(itemNode, version));
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
} else {
|
||||||
|
throw new ImportDataError("EDDN message don't have commodities field");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Collection<ShipData> getShips() {
|
||||||
|
JsonNode n;
|
||||||
|
switch (version) {
|
||||||
|
case V1_SHIPYARD:
|
||||||
|
case V2_SHIPYARD:
|
||||||
|
n = node.get("ships");
|
||||||
|
if (n != null && n.isArray()){
|
||||||
|
Collection<ShipData> ships = new ArrayList<>();
|
||||||
|
for (Iterator<JsonNode> iterator = n.elements(); iterator.hasNext(); ) {
|
||||||
|
JsonNode shipNode = iterator.next();
|
||||||
|
ships.add(new EDDNShipData(shipNode, version));
|
||||||
|
}
|
||||||
|
return ships;
|
||||||
|
} else {
|
||||||
|
throw new ImportDataError("EDDN message don't have ships field");
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public LocalDateTime getModifiedTime() {
|
||||||
|
JsonNode n = node.get("timestamp");
|
||||||
|
if (n != null && n.isTextual()){
|
||||||
|
return LocalDateTime.parse(n.asText(), DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||||
|
} else {
|
||||||
|
throw new ImportDataError("EDDN message don't have timestamp field");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package ru.trader.emdn.entities;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import ru.trader.store.imp.ImportDataError;
|
||||||
|
import ru.trader.store.imp.entities.StarSystemDataBase;
|
||||||
|
import ru.trader.store.imp.entities.StationData;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class EDDNSystemData extends StarSystemDataBase {
|
||||||
|
private final JsonNode node;
|
||||||
|
private final SUPPORT_VERSIONS version;
|
||||||
|
|
||||||
|
public EDDNSystemData(JsonNode node, SUPPORT_VERSIONS version) {
|
||||||
|
this.node = node;
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getId() {
|
||||||
|
JsonNode n = node.get("id");
|
||||||
|
if (n != null && n.isNumber()){
|
||||||
|
return n.asLong();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
String name = null;
|
||||||
|
JsonNode n = node.get("systemName");
|
||||||
|
if (n != null) name = n.asText();
|
||||||
|
if (name == null){
|
||||||
|
throw new ImportDataError("EDDN message don't have system name");
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Collection<StationData> getStations() {
|
||||||
|
Collection<StationData> stations = new ArrayList<>();
|
||||||
|
stations.add(new EDDNStationData(node, version));
|
||||||
|
return stations;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
package ru.trader.emdn.entities;
|
|
||||||
|
|
||||||
public class Item {
|
|
||||||
private final String name;
|
|
||||||
private Long id;
|
|
||||||
private final long buyPrice;
|
|
||||||
private final long supply;
|
|
||||||
private LEVEL_TYPE supplyLevel;
|
|
||||||
private final long sellPrice;
|
|
||||||
private final long demand;
|
|
||||||
private LEVEL_TYPE demandLevel;
|
|
||||||
|
|
||||||
public Item(String name, long buyPrice, long supply, long sellPrice, long demand) {
|
|
||||||
this.name = name;
|
|
||||||
this.buyPrice = buyPrice;
|
|
||||||
this.supply = supply;
|
|
||||||
this.sellPrice = sellPrice;
|
|
||||||
this.demand = demand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getBuyPrice() {
|
|
||||||
return buyPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSupply() {
|
|
||||||
return supply;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LEVEL_TYPE getSupplyLevel() {
|
|
||||||
return supplyLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSupplyLevel(LEVEL_TYPE supplyLevel) {
|
|
||||||
this.supplyLevel = supplyLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSellPrice() {
|
|
||||||
return sellPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDemand() {
|
|
||||||
return demand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LEVEL_TYPE getDemandLevel() {
|
|
||||||
return demandLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDemandLevel(LEVEL_TYPE demandLevel) {
|
|
||||||
this.demandLevel = demandLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Item{" +
|
|
||||||
"name='" + name + '\'' +
|
|
||||||
", id=" + id +
|
|
||||||
", buyPrice=" + buyPrice +
|
|
||||||
", supply=" + supply +
|
|
||||||
", supplyLevel=" + supplyLevel +
|
|
||||||
", sellPrice=" + sellPrice +
|
|
||||||
", demand=" + demand +
|
|
||||||
", demandLevel=" + demandLevel +
|
|
||||||
"} ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package ru.trader.emdn.entities;
|
|
||||||
|
|
||||||
public enum LEVEL_TYPE {
|
|
||||||
LOW("Low"), MEDIUM("Med"), HIGH("High");
|
|
||||||
|
|
||||||
private final String jsonText;
|
|
||||||
|
|
||||||
private LEVEL_TYPE(String jsonText) {
|
|
||||||
this.jsonText = jsonText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toJSON(){
|
|
||||||
return jsonText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LEVEL_TYPE fromJSON(String text){
|
|
||||||
for (LEVEL_TYPE level : LEVEL_TYPE.values()) {
|
|
||||||
if (level.jsonText.equals(text)) return level;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,37 +1,37 @@
|
|||||||
package ru.trader.emdn.entities;
|
package ru.trader.emdn.entities;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import ru.trader.store.imp.entities.StarSystemData;
|
||||||
|
|
||||||
public class Message {
|
public class Message {
|
||||||
@JsonProperty("$schemaRef")
|
private SUPPORT_VERSIONS version;
|
||||||
private String schemaRef;
|
|
||||||
|
|
||||||
private Header header;
|
private Header header;
|
||||||
|
private JsonNode body;
|
||||||
|
|
||||||
private Body body;
|
public Message(SUPPORT_VERSIONS version, Header header, JsonNode body) {
|
||||||
|
this.version = version;
|
||||||
public Message(String schemaRef, Header header, Body body) {
|
|
||||||
this.schemaRef = schemaRef;
|
|
||||||
this.header = header;
|
this.header = header;
|
||||||
this.body = body;
|
this.body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSchemaRef() {
|
public SUPPORT_VERSIONS getVersion() {
|
||||||
return schemaRef;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Header getHeader() {
|
public Header getHeader() {
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Body getBody() {
|
public StarSystemData getImportData(){
|
||||||
return body;
|
return new EDDNSystemData(body, version);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Message{" +
|
return "Message{" +
|
||||||
"schemaRef='" + schemaRef + '\'' +
|
"version='" + version + '\'' +
|
||||||
", header=" + header +
|
", header=" + header +
|
||||||
", body=" + body +
|
", body=" + body +
|
||||||
"} ";
|
"} ";
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package ru.trader.emdn.entities;
|
||||||
|
|
||||||
|
public enum SUPPORT_VERSIONS {
|
||||||
|
V1_SHIPYARD("http://schemas.elite-markets.net/eddn/shipyard/1"),
|
||||||
|
V2_SHIPYARD("http://schemas.elite-markets.net/eddn/shipyard/2"),
|
||||||
|
V1("http://schemas.elite-markets.net/eddn/commodity/1"),
|
||||||
|
V2("http://schemas.elite-markets.net/eddn/commodity/2"),
|
||||||
|
V3("http://schemas.elite-markets.net/eddn/commodity/3");
|
||||||
|
|
||||||
|
private final String schema;
|
||||||
|
|
||||||
|
private SUPPORT_VERSIONS(String schema) {
|
||||||
|
this.schema = schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SUPPORT_VERSIONS getVersion(String schema){
|
||||||
|
for (SUPPORT_VERSIONS parser : SUPPORT_VERSIONS.values()) {
|
||||||
|
if (parser.schema.equals(schema)) return parser;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package ru.trader.emdn.entities;
|
|
||||||
|
|
||||||
public class Ship {
|
|
||||||
private final String name;
|
|
||||||
private Long price;
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
public Ship(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getPrice() {
|
|
||||||
return price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrice(Long price) {
|
|
||||||
this.price = price;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Ship{" +
|
|
||||||
"name='" + name + '\'' +
|
|
||||||
", id=" + id +
|
|
||||||
", price=" + price +
|
|
||||||
"} ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package ru.trader.emdn.entities;
|
|
||||||
|
|
||||||
public class StarSystem {
|
|
||||||
private final String name;
|
|
||||||
private Long id;
|
|
||||||
private Long address;
|
|
||||||
|
|
||||||
public StarSystem(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getAddress() {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAddress(Long address) {
|
|
||||||
this.address = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "StarSystem{" +
|
|
||||||
"name='" + name + '\'' +
|
|
||||||
", id=" + id +
|
|
||||||
", address=" + address +
|
|
||||||
"} ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package ru.trader.emdn.entities;
|
|
||||||
|
|
||||||
public class Station {
|
|
||||||
private final String name;
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
public Station(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Station{" +
|
|
||||||
"name='" + name + '\'' +
|
|
||||||
", id=" + id +
|
|
||||||
"} ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
318
utils/src/main/java/ru/trader/store/imp/AbstractImporter.java
Normal file
318
utils/src/main/java/ru/trader/store/imp/AbstractImporter.java
Normal file
@@ -0,0 +1,318 @@
|
|||||||
|
package ru.trader.store.imp;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import ru.trader.core.*;
|
||||||
|
import ru.trader.store.imp.entities.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public abstract class AbstractImporter implements Importer {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(AbstractImporter.class);
|
||||||
|
private final EnumSet<IMPORT_FLAG> flags;
|
||||||
|
|
||||||
|
protected AbstractImporter() {
|
||||||
|
this.flags = EnumSet.copyOf(IMPORT_FLAG.ADD_AND_UPDATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addFlag(IMPORT_FLAG flag) {
|
||||||
|
flags.add(flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeFlag(IMPORT_FLAG flag) {
|
||||||
|
flags.remove(flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFlags(EnumSet<IMPORT_FLAG> flags) {
|
||||||
|
this.flags.clear();
|
||||||
|
this.flags.addAll(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void imp(Market market){
|
||||||
|
while (next()){
|
||||||
|
StarSystemData systemData = getSystem();
|
||||||
|
Place system = impSystem(market, systemData);
|
||||||
|
if (system != null){
|
||||||
|
Collection<StationData> stations = systemData.getStations();
|
||||||
|
impStations(market, system, stations);
|
||||||
|
} else {
|
||||||
|
LOG.warn("System {} not found", systemData.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Place impSystem(Market market, StarSystemData data){
|
||||||
|
Place system = market.get(data.getName());
|
||||||
|
if (system == null){
|
||||||
|
if (flags.contains(IMPORT_FLAG.ADD_STARSYSTEMS)){
|
||||||
|
LOG.debug("{} - is new system, adding", data.getName());
|
||||||
|
system = market.addPlace(data.getName(), data.getX(), data.getY(), data.getZ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (flags.contains(IMPORT_FLAG.STARSYSTEMS)){
|
||||||
|
updateSystem(system, data);
|
||||||
|
}
|
||||||
|
return system;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateSystem(Place system, StarSystemData data){
|
||||||
|
if (!Double.isNaN(data.getX()) && !Double.isNaN(data.getY()) && !Double.isNaN(data.getZ()) &&
|
||||||
|
(data.getX() != system.getX() || data.getY() != system.getY() || data.getZ() != system.getZ())){
|
||||||
|
system.setPosition(data.getX(), data.getY(), data.getZ());
|
||||||
|
}
|
||||||
|
if (data.getFaction() != null){
|
||||||
|
system.setFaction(data.getFaction());
|
||||||
|
}
|
||||||
|
if (data.getGovernment() != null){
|
||||||
|
system.setGovernment(data.getGovernment());
|
||||||
|
}
|
||||||
|
if (data.getPower() != null && data.getPowerState() != null){
|
||||||
|
system.setPower(data.getPower(), data.getPowerState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void impStations(Market market, Place system, Collection<StationData> stations){
|
||||||
|
if (stations == null) return;
|
||||||
|
Set<String> stationsList = new HashSet<>();
|
||||||
|
if (flags.contains(IMPORT_FLAG.REMOVE_STATIONS)){
|
||||||
|
stationsList.addAll(system.getVendorNames());
|
||||||
|
}
|
||||||
|
for (StationData s : stations) {
|
||||||
|
Vendor station = impStation(system, s);
|
||||||
|
if (station != null){
|
||||||
|
stationsList.remove(station.getName());
|
||||||
|
impItems(market, station, s.getCommodities(), s.getModules(), s.getShips());
|
||||||
|
} else {
|
||||||
|
LOG.warn("Station {} not found", s.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (flags.contains(IMPORT_FLAG.REMOVE_STATIONS)){
|
||||||
|
for (String s : stationsList) {
|
||||||
|
LOG.debug("{} - is old station, remove", s);
|
||||||
|
Vendor station = system.get(s);
|
||||||
|
if (station != null){
|
||||||
|
system.remove(station);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Vendor impStation(Place system, StationData data){
|
||||||
|
Vendor station = system.get(data.getName());
|
||||||
|
if (station == null){
|
||||||
|
if (flags.contains(IMPORT_FLAG.ADD_STATIONS)){
|
||||||
|
LOG.debug("{} - is new station, adding", data.getName());
|
||||||
|
station = system.addVendor(data.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (flags.contains(IMPORT_FLAG.STATIONS)){
|
||||||
|
updateStation(station, data);
|
||||||
|
}
|
||||||
|
return station;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateStation(Vendor station, StationData data) {
|
||||||
|
if (!Double.isNaN(data.getDistance())){
|
||||||
|
station.setDistance(data.getDistance());
|
||||||
|
}
|
||||||
|
if (data.getType() != null){
|
||||||
|
station.setType(data.getType());
|
||||||
|
}
|
||||||
|
if (data.getFaction() != null){
|
||||||
|
station.setFaction(data.getFaction());
|
||||||
|
}
|
||||||
|
if (data.getGovernment() != null){
|
||||||
|
station.setGovernment(data.getGovernment());
|
||||||
|
}
|
||||||
|
if (data.getEconomic() != null){
|
||||||
|
station.setEconomic(data.getEconomic());
|
||||||
|
}
|
||||||
|
if (data.getSubEconomic() != null){
|
||||||
|
station.setSubEconomic(data.getSubEconomic());
|
||||||
|
}
|
||||||
|
if (data.getServices() != null){
|
||||||
|
Collection<SERVICE_TYPE> services = new ArrayList<>(station.getServices());
|
||||||
|
services.removeAll(data.getServices());
|
||||||
|
services.forEach(station::remove);
|
||||||
|
data.getServices().forEach(station::add);
|
||||||
|
}
|
||||||
|
if (data.getModifiedTime() != null){
|
||||||
|
station.setModifiedTime(data.getModifiedTime());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void impItems(Market market, Vendor station, Collection<ItemData> commodities, Collection<ModuleData> modules, Collection<ShipData> ships){
|
||||||
|
Set<Item> itemsList = new HashSet<>();
|
||||||
|
if (flags.contains(IMPORT_FLAG.REMOVE_COMMODITY) || flags.contains(IMPORT_FLAG.REMOVE_MODULE) || flags.contains(IMPORT_FLAG.REMOVE_SHIP)){
|
||||||
|
Predicate<Offer> isCanRemove = o ->
|
||||||
|
ships != null && o.getItem().getGroup().isShip() && flags.contains(IMPORT_FLAG.REMOVE_SHIP) ||
|
||||||
|
modules != null && o.getItem().getGroup().isOutfit() && flags.contains(IMPORT_FLAG.REMOVE_MODULE) ||
|
||||||
|
commodities != null && o.getItem().getGroup().isMarket() && flags.contains(IMPORT_FLAG.REMOVE_COMMODITY);
|
||||||
|
station.getAllSellOffers().stream().filter(isCanRemove).map(Offer::getItem).forEach(itemsList::add);
|
||||||
|
station.getAllBuyOffers().stream().filter(isCanRemove).map(Offer::getItem).forEach(itemsList::add);
|
||||||
|
}
|
||||||
|
if (commodities != null){
|
||||||
|
for (ItemData c : commodities) {
|
||||||
|
Item item = impItem(market, station, c);
|
||||||
|
if (item != null){
|
||||||
|
itemsList.remove(item);
|
||||||
|
} else {
|
||||||
|
LOG.warn("Item {}({}) not found", c.getId(), c.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (modules != null){
|
||||||
|
for (ModuleData m : modules) {
|
||||||
|
Item item = impModule(market, station, m);
|
||||||
|
if (item != null){
|
||||||
|
itemsList.remove(item);
|
||||||
|
} else {
|
||||||
|
LOG.warn("Item {}({}) not found", m.getId(), m.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ships != null){
|
||||||
|
for (ShipData s : ships) {
|
||||||
|
Item item = impShip(market, station, s);
|
||||||
|
if (item != null){
|
||||||
|
itemsList.remove(item);
|
||||||
|
} else {
|
||||||
|
LOG.warn("Item {}({}) not found", s.getId(), s.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags.contains(IMPORT_FLAG.REMOVE_COMMODITY) || flags.contains(IMPORT_FLAG.REMOVE_MODULE) || flags.contains(IMPORT_FLAG.REMOVE_SHIP)){
|
||||||
|
for (Item i : itemsList) {
|
||||||
|
Offer o = station.get(OFFER_TYPE.SELL, i);
|
||||||
|
if (o != null){
|
||||||
|
LOG.debug("{} - is old offer, remove", o);
|
||||||
|
station.remove(o);
|
||||||
|
}
|
||||||
|
o = station.get(OFFER_TYPE.BUY, i);
|
||||||
|
if (o != null){
|
||||||
|
LOG.debug("{} - is old offer, remove", o);
|
||||||
|
station.remove(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Item impItem(Market market, Vendor station, ItemData data) {
|
||||||
|
Item item = market.getItem(data.getName());
|
||||||
|
if (item == null){
|
||||||
|
if (data.getGroup() != null && flags.contains(IMPORT_FLAG.ADD_COMMODITY)){
|
||||||
|
LOG.debug("{} - is new commodity, adding", data.getName());
|
||||||
|
Optional<Group> group = market.getGroups().stream().filter(g -> g.getName().equals(data.getGroup())).findAny();
|
||||||
|
if (group.isPresent()) {
|
||||||
|
item = market.addItem(data.getName(), group.get());
|
||||||
|
} else {
|
||||||
|
LOG.warn("Not found group, id={}, skip item", data.getGroup());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item != null && flags.contains(IMPORT_FLAG.ITEMS)){
|
||||||
|
updateOffers(station, item, data);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateOffers(Vendor station, Item item, ItemData data){
|
||||||
|
Offer sellOffer = station.getSell(item);
|
||||||
|
if (data.getBuyOfferPrice() > 0){
|
||||||
|
if (sellOffer != null){
|
||||||
|
sellOffer.setPrice(data.getSellOfferPrice());
|
||||||
|
sellOffer.setCount(data.getSupply());
|
||||||
|
} else {
|
||||||
|
station.addOffer(OFFER_TYPE.SELL, item, data.getBuyOfferPrice(), data.getSupply());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (sellOffer != null) station.remove(sellOffer);
|
||||||
|
}
|
||||||
|
Offer buyOffer = station.getBuy(item);
|
||||||
|
if (data.getSellOfferPrice() > 0){
|
||||||
|
if (buyOffer != null){
|
||||||
|
buyOffer.setPrice(data.getBuyOfferPrice());
|
||||||
|
buyOffer.setCount(data.getDemand());
|
||||||
|
} else {
|
||||||
|
station.addOffer(OFFER_TYPE.BUY, item, data.getSellOfferPrice(), data.getDemand());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (buyOffer != null) station.remove(buyOffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Item impShip(Market market, Vendor station, ShipData data) {
|
||||||
|
Item item = market.getItem(data.getName());
|
||||||
|
if (item == null){
|
||||||
|
if (flags.contains(IMPORT_FLAG.ADD_SHIP)){
|
||||||
|
LOG.debug("{} - is new ship, adding", data.getName());
|
||||||
|
Optional<Group> group = market.getGroups().stream().filter(Group::isShip).findAny();
|
||||||
|
if (group.isPresent()) {
|
||||||
|
item = market.addItem(data.getName(), group.get());
|
||||||
|
} else {
|
||||||
|
LOG.warn("Not found ship group, skip");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item != null && flags.contains(IMPORT_FLAG.ITEMS)){
|
||||||
|
updateOffers(station, item, data);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateOffers(Vendor station, Item item, ShipData data){
|
||||||
|
if (data.getPrice() == null) return;
|
||||||
|
Offer sellOffer = station.getSell(item);
|
||||||
|
if (data.getPrice() > 0){
|
||||||
|
if (sellOffer != null){
|
||||||
|
sellOffer.setPrice(data.getPrice());
|
||||||
|
sellOffer.setCount(1);
|
||||||
|
} else {
|
||||||
|
station.addOffer(OFFER_TYPE.SELL, item, data.getPrice(), 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (sellOffer != null) station.remove(sellOffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Item impModule(Market market, Vendor station, ModuleData data) {
|
||||||
|
Item item = market.getItem(data.getName());
|
||||||
|
if (item == null){
|
||||||
|
if (data.getGroup() != null && flags.contains(IMPORT_FLAG.ADD_MODULE)){
|
||||||
|
LOG.debug("{} - is new module, adding", data.getName());
|
||||||
|
Optional<Group> group = market.getGroups().stream().filter(g -> g.getName().equals(data.getGroup())).findAny();
|
||||||
|
if (group.isPresent()) {
|
||||||
|
item = market.addItem(data.getName(), group.get());
|
||||||
|
} else {
|
||||||
|
LOG.warn("Not found outfit group, id={}, skip item", data.getGroup());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item != null && flags.contains(IMPORT_FLAG.ITEMS)){
|
||||||
|
updateOffers(station, item, data);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateOffers(Vendor station, Item item, ModuleData data){
|
||||||
|
Offer sellOffer = station.getSell(item);
|
||||||
|
if (data.getPrice() > 0){
|
||||||
|
if (sellOffer != null){
|
||||||
|
sellOffer.setPrice(data.getPrice());
|
||||||
|
sellOffer.setCount(1);
|
||||||
|
} else {
|
||||||
|
station.addOffer(OFFER_TYPE.SELL, item, data.getPrice(), 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (sellOffer != null) station.remove(sellOffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
21
utils/src/main/java/ru/trader/store/imp/IMPORT_FLAG.java
Normal file
21
utils/src/main/java/ru/trader/store/imp/IMPORT_FLAG.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package ru.trader.store.imp;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public enum IMPORT_FLAG {
|
||||||
|
STARSYSTEMS, STATIONS, ITEMS,
|
||||||
|
ADD_STARSYSTEMS,
|
||||||
|
REMOVE_STATIONS, ADD_STATIONS,
|
||||||
|
REMOVE_COMMODITY, ADD_COMMODITY,
|
||||||
|
REMOVE_MODULE, ADD_MODULE,
|
||||||
|
REMOVE_SHIP, ADD_SHIP;
|
||||||
|
|
||||||
|
public static final Set<IMPORT_FLAG> UPDATE_ONLY = Collections.unmodifiableSet(EnumSet.of(STARSYSTEMS, STATIONS, ITEMS));
|
||||||
|
public static final Set<IMPORT_FLAG> ADD_AND_UPDATE = Collections.unmodifiableSet(EnumSet.of(STARSYSTEMS, STATIONS, ITEMS, ADD_STARSYSTEMS, ADD_STATIONS, ADD_COMMODITY, ADD_SHIP, ADD_MODULE));
|
||||||
|
public static final Set<IMPORT_FLAG> ADD_AND_REMOVE = Collections.unmodifiableSet(EnumSet.of(ADD_STATIONS, ADD_COMMODITY, ADD_SHIP, ADD_MODULE, REMOVE_STATIONS, REMOVE_COMMODITY, REMOVE_MODULE, REMOVE_SHIP));
|
||||||
|
public static final Set<IMPORT_FLAG> UPDATE_MARKET = Collections.unmodifiableSet(EnumSet.of(ITEMS, ADD_STARSYSTEMS, ADD_STATIONS, ADD_COMMODITY, ADD_SHIP, ADD_MODULE));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
19
utils/src/main/java/ru/trader/store/imp/ImportDataError.java
Normal file
19
utils/src/main/java/ru/trader/store/imp/ImportDataError.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package ru.trader.store.imp;
|
||||||
|
|
||||||
|
public class ImportDataError extends Error {
|
||||||
|
public ImportDataError() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImportDataError(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImportDataError(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImportDataError(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
utils/src/main/java/ru/trader/store/imp/Importer.java
Normal file
22
utils/src/main/java/ru/trader/store/imp/Importer.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package ru.trader.store.imp;
|
||||||
|
|
||||||
|
import ru.trader.core.Market;
|
||||||
|
import ru.trader.store.imp.entities.StarSystemData;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
public interface Importer {
|
||||||
|
|
||||||
|
|
||||||
|
void addFlag(IMPORT_FLAG flag);
|
||||||
|
void removeFlag(IMPORT_FLAG flag);
|
||||||
|
void setFlags(EnumSet<IMPORT_FLAG> flags);
|
||||||
|
|
||||||
|
|
||||||
|
boolean next();
|
||||||
|
StarSystemData getSystem();
|
||||||
|
|
||||||
|
void imp(Market market);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package ru.trader.store.imp.entities;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public interface ItemData {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
Long getId();
|
||||||
|
String getName();
|
||||||
|
@Nullable
|
||||||
|
String getGroup();
|
||||||
|
long getBuyOfferPrice();
|
||||||
|
long getSellOfferPrice();
|
||||||
|
long getSupply();
|
||||||
|
long getDemand();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package ru.trader.store.imp.entities;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public abstract class ItemDataBase implements ItemData {
|
||||||
|
@Override
|
||||||
|
public Long getId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getGroup() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package ru.trader.store.imp.entities;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public interface ModuleData {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
Long getId();
|
||||||
|
String getName();
|
||||||
|
@Nullable
|
||||||
|
String getGroup();
|
||||||
|
long getPrice();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package ru.trader.store.imp.entities;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public abstract class ModuleDataBase implements ModuleData {
|
||||||
|
@Override
|
||||||
|
public Long getId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getGroup() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package ru.trader.store.imp.entities;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public interface ShipData {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
Long getId();
|
||||||
|
String getName();
|
||||||
|
@Nullable
|
||||||
|
Long getPrice();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package ru.trader.store.imp.entities;
|
||||||
|
|
||||||
|
public abstract class ShipDataBase implements ShipData {
|
||||||
|
@Override
|
||||||
|
public Long getId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getPrice() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package ru.trader.store.imp.entities;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import ru.trader.core.FACTION;
|
||||||
|
import ru.trader.core.GOVERNMENT;
|
||||||
|
import ru.trader.core.POWER;
|
||||||
|
import ru.trader.core.POWER_STATE;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public interface StarSystemData {
|
||||||
|
@Nullable
|
||||||
|
Long getId();
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
double getX();
|
||||||
|
double getY();
|
||||||
|
double getZ();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
FACTION getFaction();
|
||||||
|
@Nullable
|
||||||
|
GOVERNMENT getGovernment();
|
||||||
|
@Nullable
|
||||||
|
POWER getPower();
|
||||||
|
@Nullable
|
||||||
|
POWER_STATE getPowerState();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
Collection<StationData> getStations();
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package ru.trader.store.imp.entities;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import ru.trader.core.FACTION;
|
||||||
|
import ru.trader.core.GOVERNMENT;
|
||||||
|
import ru.trader.core.POWER;
|
||||||
|
import ru.trader.core.POWER_STATE;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public abstract class StarSystemDataBase implements StarSystemData {
|
||||||
|
@Override
|
||||||
|
public Long getId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getX() {
|
||||||
|
return Double.NaN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getY() {
|
||||||
|
return Double.NaN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getZ() {
|
||||||
|
return Double.NaN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public FACTION getFaction() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public GOVERNMENT getGovernment() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public POWER getPower() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public POWER_STATE getPowerState() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Collection<StationData> getStations() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package ru.trader.store.imp.entities;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import ru.trader.core.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public interface StationData {
|
||||||
|
@Nullable
|
||||||
|
Long getId();
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
double getDistance();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
STATION_TYPE getType();
|
||||||
|
@Nullable
|
||||||
|
FACTION getFaction();
|
||||||
|
@Nullable
|
||||||
|
GOVERNMENT getGovernment();
|
||||||
|
@Nullable
|
||||||
|
ECONOMIC_TYPE getEconomic();
|
||||||
|
@Nullable
|
||||||
|
ECONOMIC_TYPE getSubEconomic();
|
||||||
|
@Nullable
|
||||||
|
Collection<SERVICE_TYPE> getServices();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
Collection<ItemData> getCommodities();
|
||||||
|
@Nullable
|
||||||
|
Collection<ModuleData> getModules();
|
||||||
|
@Nullable
|
||||||
|
Collection<ShipData> getShips();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
LocalDateTime getModifiedTime();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package ru.trader.store.imp.entities;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import ru.trader.core.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public abstract class StationDataBase implements StationData {
|
||||||
|
@Override
|
||||||
|
public Long getId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getDistance() {
|
||||||
|
return Double.NaN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public STATION_TYPE getType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public FACTION getFaction() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public GOVERNMENT getGovernment() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ECONOMIC_TYPE getEconomic() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ECONOMIC_TYPE getSubEconomic() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Collection<SERVICE_TYPE> getServices() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Collection<ItemData> getCommodities() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Collection<ModuleData> getModules() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Collection<ShipData> getShips() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public LocalDateTime getModifiedTime() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,11 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.trader.TestUtils;
|
import ru.trader.TestUtils;
|
||||||
import ru.trader.emdn.entities.*;
|
import ru.trader.emdn.entities.*;
|
||||||
|
import ru.trader.store.imp.ImportDataError;
|
||||||
|
import ru.trader.store.imp.entities.ItemData;
|
||||||
|
import ru.trader.store.imp.entities.ShipData;
|
||||||
|
import ru.trader.store.imp.entities.StarSystemData;
|
||||||
|
import ru.trader.store.imp.entities.StationData;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -28,38 +33,50 @@ public class ParserTest extends Assert {
|
|||||||
String json = TestUtils.read(is);
|
String json = TestUtils.read(is);
|
||||||
Message message = parser.parse(json);
|
Message message = parser.parse(json);
|
||||||
assertNotNull(message);
|
assertNotNull(message);
|
||||||
assertEquals("http://schemas.elite-markets.net/eddn/commodity/1", message.getSchemaRef());
|
assertEquals(SUPPORT_VERSIONS.V1, message.getVersion());
|
||||||
Header header = message.getHeader();
|
Header header = message.getHeader();
|
||||||
assertNotNull(header);
|
assertNotNull(header);
|
||||||
assertEquals("abcdef0123456789", header.getUploaderId());
|
assertEquals("abcdef0123456789", header.getUploaderId());
|
||||||
assertEquals("My Awesome Market Uploader", header.getSoftwareName());
|
assertEquals("My Awesome Market Uploader", header.getSoftwareName());
|
||||||
assertEquals("v3.14", header.getSoftwareVersion());
|
assertEquals("v3.14", header.getSoftwareVersion());
|
||||||
assertEquals(LocalDateTime.of(2014, 11, 17, 13, 35), header.getGatewayTimestamp());
|
assertEquals(LocalDateTime.of(2014, 11, 17, 13, 35), header.getGatewayTimestamp());
|
||||||
Body body = message.getBody();
|
StarSystemData data = message.getImportData();
|
||||||
assertNotNull(body);
|
assertNotNull(data);
|
||||||
assertEquals(LocalDateTime.of(2014, 11, 17, 12, 34, 56), body.getTimestamp());
|
assertEquals("Eranin", data.getName());
|
||||||
StarSystem system = body.getSystem();
|
Collection<StationData> stations = data.getStations();
|
||||||
assertNotNull(system);
|
assertNotNull(stations);
|
||||||
assertEquals("Eranin", system.getName());
|
assertEquals(1, stations.size());
|
||||||
assertNull(system.getId());
|
StationData station = stations.iterator().next();
|
||||||
assertNull(system.getAddress());
|
|
||||||
Station station = body.getStation();
|
|
||||||
assertNotNull(station);
|
assertNotNull(station);
|
||||||
assertEquals("Azeban Orbital", station.getName());
|
assertEquals("Azeban Orbital", station.getName());
|
||||||
assertNull(station.getId());
|
assertEquals(LocalDateTime.of(2014, 11, 17, 12, 34, 56), station.getModifiedTime());
|
||||||
Collection<Item> items = body.getCommodities();
|
Collection<ItemData> items = station.getCommodities();
|
||||||
assertNotNull(items);
|
assertNotNull(items);
|
||||||
assertEquals(1, items.size());
|
assertEquals(1, items.size());
|
||||||
Item item = items.iterator().next();
|
ItemData item = items.iterator().next();
|
||||||
assertNotNull(item);
|
assertNotNull(item);
|
||||||
assertEquals("Gold", item.getName());
|
assertEquals("Gold", item.getName());
|
||||||
assertNull(item.getId());
|
assertEquals(1024, item.getSellOfferPrice());
|
||||||
assertEquals(1024, item.getBuyPrice());
|
|
||||||
assertEquals(7, item.getSupply());
|
assertEquals(7, item.getSupply());
|
||||||
assertEquals(LEVEL_TYPE.LOW, item.getSupplyLevel());
|
assertEquals(1138, item.getBuyOfferPrice());
|
||||||
assertEquals(1138, item.getSellPrice());
|
|
||||||
assertEquals(42, item.getDemand());
|
assertEquals(42, item.getDemand());
|
||||||
assertEquals(LEVEL_TYPE.MEDIUM, item.getDemandLevel());
|
|
||||||
|
assertNull(data.getId());
|
||||||
|
assertNull(data.getFaction());
|
||||||
|
assertNull(data.getGovernment());
|
||||||
|
assertNull(data.getPower());
|
||||||
|
assertNull(data.getPowerState());
|
||||||
|
assertNull(station.getId());
|
||||||
|
assertNull(station.getType());
|
||||||
|
assertNull(station.getFaction());
|
||||||
|
assertNull(station.getGovernment());
|
||||||
|
assertNull(station.getEconomic());
|
||||||
|
assertNull(station.getSubEconomic());
|
||||||
|
assertNull(station.getServices());
|
||||||
|
assertNull(station.getShips());
|
||||||
|
assertNull(station.getModules());
|
||||||
|
assertNull(item.getId());
|
||||||
|
assertNull(item.getGroup());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,53 +89,64 @@ public class ParserTest extends Assert {
|
|||||||
String json = TestUtils.read(is);
|
String json = TestUtils.read(is);
|
||||||
Message message = parser.parse(json);
|
Message message = parser.parse(json);
|
||||||
assertNotNull(message);
|
assertNotNull(message);
|
||||||
assertEquals("http://schemas.elite-markets.net/eddn/commodity/2", message.getSchemaRef());
|
assertEquals(SUPPORT_VERSIONS.V2, message.getVersion());
|
||||||
Header header = message.getHeader();
|
Header header = message.getHeader();
|
||||||
assertNotNull(header);
|
assertNotNull(header);
|
||||||
assertEquals("abcdef0123456789", header.getUploaderId());
|
assertEquals("abcdef0123456789", header.getUploaderId());
|
||||||
assertEquals("My Awesome Market Uploader", header.getSoftwareName());
|
assertEquals("My Awesome Market Uploader", header.getSoftwareName());
|
||||||
assertEquals("v3.14", header.getSoftwareVersion());
|
assertEquals("v3.14", header.getSoftwareVersion());
|
||||||
assertEquals(LocalDateTime.of(2014, 11, 17, 13, 35), header.getGatewayTimestamp());
|
assertEquals(LocalDateTime.of(2014, 11, 17, 13, 35), header.getGatewayTimestamp());
|
||||||
Body body = message.getBody();
|
StarSystemData data = message.getImportData();
|
||||||
assertNotNull(body);
|
assertNotNull(data);
|
||||||
assertEquals(LocalDateTime.of(2014, 11, 17, 12, 34, 56), body.getTimestamp());
|
assertEquals("Eranin", data.getName());
|
||||||
StarSystem system = body.getSystem();
|
Collection<StationData> stations = data.getStations();
|
||||||
assertNotNull(system);
|
assertNotNull(stations);
|
||||||
assertEquals("Eranin", system.getName());
|
assertEquals(1, stations.size());
|
||||||
assertNull(system.getId());
|
StationData station = stations.iterator().next();
|
||||||
assertNull(system.getAddress());
|
|
||||||
Station station = body.getStation();
|
|
||||||
assertNotNull(station);
|
assertNotNull(station);
|
||||||
assertEquals("Azeban Orbital", station.getName());
|
assertEquals("Azeban Orbital", station.getName());
|
||||||
assertNull(station.getId());
|
assertEquals(LocalDateTime.of(2014, 11, 17, 12, 34, 56), station.getModifiedTime());
|
||||||
Collection<Item> items = body.getCommodities();
|
Collection<ItemData> items = station.getCommodities();
|
||||||
assertNotNull(items);
|
assertNotNull(items);
|
||||||
assertEquals(2, items.size());
|
assertEquals(2, items.size());
|
||||||
int found = 0;
|
int found = 0;
|
||||||
for (Item item : items) {
|
for (ItemData item : items) {
|
||||||
assertNotNull(item);
|
assertNotNull(item);
|
||||||
if ("Gold".equals(item.getName())){
|
if ("Gold".equals(item.getName())){
|
||||||
found++;
|
found++;
|
||||||
assertNull(item.getId());
|
assertEquals(1024, item.getSellOfferPrice());
|
||||||
assertEquals(1024, item.getBuyPrice());
|
|
||||||
assertEquals(7, item.getSupply());
|
assertEquals(7, item.getSupply());
|
||||||
assertEquals(LEVEL_TYPE.LOW, item.getSupplyLevel());
|
assertEquals(1138, item.getBuyOfferPrice());
|
||||||
assertEquals(1138, item.getSellPrice());
|
|
||||||
assertEquals(42, item.getDemand());
|
assertEquals(42, item.getDemand());
|
||||||
assertEquals(LEVEL_TYPE.MEDIUM, item.getDemandLevel());
|
assertNull(item.getId());
|
||||||
|
assertNull(item.getGroup());
|
||||||
} else
|
} else
|
||||||
if ("Explosives".equals(item.getName())){
|
if ("Explosives".equals(item.getName())){
|
||||||
found++;
|
found++;
|
||||||
assertNull(item.getId());
|
assertEquals(999, item.getSellOfferPrice());
|
||||||
assertEquals(999, item.getBuyPrice());
|
|
||||||
assertEquals(1500, item.getSupply());
|
assertEquals(1500, item.getSupply());
|
||||||
assertEquals(LEVEL_TYPE.LOW, item.getSupplyLevel());
|
assertEquals(0, item.getBuyOfferPrice());
|
||||||
assertEquals(0, item.getSellPrice());
|
|
||||||
assertEquals(0, item.getDemand());
|
assertEquals(0, item.getDemand());
|
||||||
assertNull(item.getDemandLevel());
|
assertNull(item.getId());
|
||||||
|
assertNull(item.getGroup());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals("Expected items not found", 2, found);
|
assertEquals("Expected items not found", 2, found);
|
||||||
|
|
||||||
|
assertNull(data.getId());
|
||||||
|
assertNull(data.getFaction());
|
||||||
|
assertNull(data.getGovernment());
|
||||||
|
assertNull(data.getPower());
|
||||||
|
assertNull(data.getPowerState());
|
||||||
|
assertNull(station.getId());
|
||||||
|
assertNull(station.getType());
|
||||||
|
assertNull(station.getFaction());
|
||||||
|
assertNull(station.getGovernment());
|
||||||
|
assertNull(station.getEconomic());
|
||||||
|
assertNull(station.getSubEconomic());
|
||||||
|
assertNull(station.getServices());
|
||||||
|
assertNull(station.getShips());
|
||||||
|
assertNull(station.getModules());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,38 +158,51 @@ public class ParserTest extends Assert {
|
|||||||
String json = TestUtils.read(is);
|
String json = TestUtils.read(is);
|
||||||
Message message = parser.parse(json);
|
Message message = parser.parse(json);
|
||||||
assertNotNull(message);
|
assertNotNull(message);
|
||||||
assertEquals("http://schemas.elite-markets.net/eddn/commodity/1", message.getSchemaRef());
|
assertEquals(SUPPORT_VERSIONS.V1, message.getVersion());
|
||||||
Header header = message.getHeader();
|
Header header = message.getHeader();
|
||||||
assertNotNull(header);
|
assertNotNull(header);
|
||||||
assertEquals("abcdef0123456789", header.getUploaderId());
|
assertEquals("abcdef0123456789", header.getUploaderId());
|
||||||
assertEquals("My Awesome Market Uploader", header.getSoftwareName());
|
assertEquals("My Awesome Market Uploader", header.getSoftwareName());
|
||||||
assertEquals("v3.14", header.getSoftwareVersion());
|
assertEquals("v3.14", header.getSoftwareVersion());
|
||||||
assertNull(header.getGatewayTimestamp());
|
assertNull(header.getGatewayTimestamp());
|
||||||
Body body = message.getBody();
|
StarSystemData data = message.getImportData();
|
||||||
assertNotNull(body);
|
assertNotNull(data);
|
||||||
assertEquals(LocalDateTime.of(2014, 11, 17, 12, 34, 56), body.getTimestamp());
|
assertEquals("Eranin", data.getName());
|
||||||
StarSystem system = body.getSystem();
|
Collection<StationData> stations = data.getStations();
|
||||||
assertNotNull(system);
|
assertNotNull(stations);
|
||||||
assertEquals("Eranin", system.getName());
|
assertEquals(1, stations.size());
|
||||||
assertNull(system.getId());
|
StationData station = stations.iterator().next();
|
||||||
assertNull(system.getAddress());
|
|
||||||
Station station = body.getStation();
|
|
||||||
assertNotNull(station);
|
assertNotNull(station);
|
||||||
assertEquals("Azeban Orbital", station.getName());
|
assertEquals("Azeban Orbital", station.getName());
|
||||||
assertNull(station.getId());
|
assertEquals(LocalDateTime.of(2014, 11, 17, 12, 34, 56), station.getModifiedTime());
|
||||||
Collection<Item> items = body.getCommodities();
|
Collection<ItemData> items = station.getCommodities();
|
||||||
assertNotNull(items);
|
assertNotNull(items);
|
||||||
assertEquals(1, items.size());
|
assertEquals(1, items.size());
|
||||||
Item item = items.iterator().next();
|
ItemData item = items.iterator().next();
|
||||||
assertNotNull(item);
|
assertNotNull(item);
|
||||||
assertEquals("Gold", item.getName());
|
assertEquals("Gold", item.getName());
|
||||||
assertNull(item.getId());
|
assertNull(item.getId());
|
||||||
assertEquals(1024, item.getBuyPrice());
|
assertEquals(1024, item.getSellOfferPrice());
|
||||||
assertEquals(7, item.getSupply());
|
assertEquals(7, item.getSupply());
|
||||||
assertNull(item.getSupplyLevel());
|
assertEquals(1138, item.getBuyOfferPrice());
|
||||||
assertEquals(1138, item.getSellPrice());
|
|
||||||
assertEquals(42, item.getDemand());
|
assertEquals(42, item.getDemand());
|
||||||
assertNull(item.getDemandLevel());
|
|
||||||
|
assertNull(data.getId());
|
||||||
|
assertNull(data.getFaction());
|
||||||
|
assertNull(data.getGovernment());
|
||||||
|
assertNull(data.getPower());
|
||||||
|
assertNull(data.getPowerState());
|
||||||
|
assertNull(station.getId());
|
||||||
|
assertNull(station.getType());
|
||||||
|
assertNull(station.getFaction());
|
||||||
|
assertNull(station.getGovernment());
|
||||||
|
assertNull(station.getEconomic());
|
||||||
|
assertNull(station.getSubEconomic());
|
||||||
|
assertNull(station.getServices());
|
||||||
|
assertNull(station.getShips());
|
||||||
|
assertNull(station.getModules());
|
||||||
|
assertNull(item.getId());
|
||||||
|
assertNull(item.getGroup());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,39 +215,52 @@ public class ParserTest extends Assert {
|
|||||||
String json = TestUtils.read(is);
|
String json = TestUtils.read(is);
|
||||||
Message message = parser.parse(json);
|
Message message = parser.parse(json);
|
||||||
assertNotNull(message);
|
assertNotNull(message);
|
||||||
assertEquals("http://schemas.elite-markets.net/eddn/commodity/2", message.getSchemaRef());
|
assertEquals(SUPPORT_VERSIONS.V2, message.getVersion());
|
||||||
Header header = message.getHeader();
|
Header header = message.getHeader();
|
||||||
assertNotNull(header);
|
assertNotNull(header);
|
||||||
assertEquals("abcdef0123456789", header.getUploaderId());
|
assertEquals("abcdef0123456789", header.getUploaderId());
|
||||||
assertEquals("My Awesome Market Uploader", header.getSoftwareName());
|
assertEquals("My Awesome Market Uploader", header.getSoftwareName());
|
||||||
assertEquals("v3.14", header.getSoftwareVersion());
|
assertEquals("v3.14", header.getSoftwareVersion());
|
||||||
assertNull(header.getGatewayTimestamp());
|
assertNull(header.getGatewayTimestamp());
|
||||||
Body body = message.getBody();
|
StarSystemData data = message.getImportData();
|
||||||
assertNotNull(body);
|
assertNotNull(data);
|
||||||
assertEquals(LocalDateTime.of(2014, 11, 17, 12, 34, 56), body.getTimestamp());
|
assertEquals("Eranin", data.getName());
|
||||||
StarSystem system = body.getSystem();
|
Collection<StationData> stations = data.getStations();
|
||||||
assertNotNull(system);
|
assertNotNull(stations);
|
||||||
assertEquals("Eranin", system.getName());
|
assertEquals(1, stations.size());
|
||||||
assertNull(system.getId());
|
StationData station = stations.iterator().next();
|
||||||
assertNull(system.getAddress());
|
|
||||||
Station station = body.getStation();
|
|
||||||
assertNotNull(station);
|
assertNotNull(station);
|
||||||
assertEquals("Azeban Orbital", station.getName());
|
assertEquals("Azeban Orbital", station.getName());
|
||||||
assertNull(station.getId());
|
assertEquals(LocalDateTime.of(2014, 11, 17, 12, 34, 56), station.getModifiedTime());
|
||||||
Collection<Item> items = body.getCommodities();
|
Collection<ItemData> items = station.getCommodities();
|
||||||
assertNotNull(items);
|
assertNotNull(items);
|
||||||
assertEquals(1, items.size());
|
assertEquals(1, items.size());
|
||||||
for (Item item : items) {
|
for (ItemData item : items) {
|
||||||
assertNotNull(item);
|
assertNotNull(item);
|
||||||
assertEquals("Gold", item.getName());
|
assertEquals("Gold", item.getName());
|
||||||
assertNull(item.getId());
|
assertNull(item.getId());
|
||||||
assertEquals(1024, item.getBuyPrice());
|
assertEquals(1024, item.getSellOfferPrice());
|
||||||
assertEquals(7, item.getSupply());
|
assertEquals(7, item.getSupply());
|
||||||
assertNull(item.getSupplyLevel());
|
assertEquals(1138, item.getBuyOfferPrice());
|
||||||
assertEquals(1138, item.getSellPrice());
|
|
||||||
assertEquals(42, item.getDemand());
|
assertEquals(42, item.getDemand());
|
||||||
assertNull(item.getDemandLevel());
|
assertNull(item.getId());
|
||||||
|
assertNull(item.getGroup());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertNull(data.getId());
|
||||||
|
assertNull(data.getFaction());
|
||||||
|
assertNull(data.getGovernment());
|
||||||
|
assertNull(data.getPower());
|
||||||
|
assertNull(data.getPowerState());
|
||||||
|
assertNull(station.getId());
|
||||||
|
assertNull(station.getType());
|
||||||
|
assertNull(station.getFaction());
|
||||||
|
assertNull(station.getGovernment());
|
||||||
|
assertNull(station.getEconomic());
|
||||||
|
assertNull(station.getSubEconomic());
|
||||||
|
assertNull(station.getServices());
|
||||||
|
assertNull(station.getShips());
|
||||||
|
assertNull(station.getModules());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +280,18 @@ public class ParserTest extends Assert {
|
|||||||
try (InputStream is = getClass().getResourceAsStream("/emdn/v2e.json")) {
|
try (InputStream is = getClass().getResourceAsStream("/emdn/v2e.json")) {
|
||||||
String json = TestUtils.read(is);
|
String json = TestUtils.read(is);
|
||||||
Message message = parser.parse(json);
|
Message message = parser.parse(json);
|
||||||
assertNull(message);
|
assertNotNull(message);
|
||||||
|
StarSystemData data = message.getImportData();
|
||||||
|
assertNotNull(data);
|
||||||
|
assertEquals("Eranin", data.getName());
|
||||||
|
Collection<StationData> stations = data.getStations();
|
||||||
|
assertNotNull(stations);
|
||||||
|
assertEquals(1, stations.size());
|
||||||
|
StationData station = stations.iterator().next();
|
||||||
|
assertNotNull(station);
|
||||||
|
assertEquals("Azeban Orbital", station.getName());
|
||||||
|
exception.expect(ImportDataError.class);
|
||||||
|
station.getCommodities();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,33 +328,28 @@ public class ParserTest extends Assert {
|
|||||||
String json = TestUtils.read(is);
|
String json = TestUtils.read(is);
|
||||||
Message message = parser.parse(json);
|
Message message = parser.parse(json);
|
||||||
assertNotNull(message);
|
assertNotNull(message);
|
||||||
assertEquals("http://schemas.elite-markets.net/eddn/shipyard/1", message.getSchemaRef());
|
assertEquals(SUPPORT_VERSIONS.V1_SHIPYARD, message.getVersion());
|
||||||
Header header = message.getHeader();
|
Header header = message.getHeader();
|
||||||
assertNotNull(header);
|
assertNotNull(header);
|
||||||
assertEquals("Marek Ce'ex", header.getUploaderId());
|
assertEquals("Marek Ce'ex", header.getUploaderId());
|
||||||
assertEquals("E:D Market Connector [Mac OS]", header.getSoftwareName());
|
assertEquals("E:D Market Connector [Mac OS]", header.getSoftwareName());
|
||||||
assertEquals("2.1.6.1", header.getSoftwareVersion());
|
assertEquals("2.1.6.1", header.getSoftwareVersion());
|
||||||
assertEquals(LocalDateTime.of(2016, 10, 5, 13, 53, 33, 930428000), header.getGatewayTimestamp());
|
assertEquals(LocalDateTime.of(2016, 10, 5, 13, 53, 33, 930428000), header.getGatewayTimestamp());
|
||||||
Body body = message.getBody();
|
StarSystemData data = message.getImportData();
|
||||||
assertNotNull(body);
|
assertNotNull(data);
|
||||||
assertEquals(LocalDateTime.of(2016, 10, 5, 13, 53, 25), body.getTimestamp());
|
assertEquals("Venegana", data.getName());
|
||||||
StarSystem system = body.getSystem();
|
Collection<StationData> stations = data.getStations();
|
||||||
assertNotNull(system);
|
assertNotNull(stations);
|
||||||
assertEquals("Venegana", system.getName());
|
assertEquals(1, stations.size());
|
||||||
assertNull(system.getId());
|
StationData station = stations.iterator().next();
|
||||||
assertNull(system.getAddress());
|
|
||||||
Station station = body.getStation();
|
|
||||||
assertNotNull(station);
|
assertNotNull(station);
|
||||||
assertEquals("Shull Ring", station.getName());
|
assertEquals("Shull Ring", station.getName());
|
||||||
assertNull(station.getId());
|
assertEquals(LocalDateTime.of(2016, 10, 5, 13, 53, 25), station.getModifiedTime());
|
||||||
Collection<Item> items = body.getCommodities();
|
Collection<ShipData> ships = station.getShips();
|
||||||
assertNotNull(items);
|
|
||||||
assertEquals(0, items.size());
|
|
||||||
Collection<Ship> ships = body.getShips();
|
|
||||||
assertNotNull(ships);
|
assertNotNull(ships);
|
||||||
assertEquals(8, ships.size());
|
assertEquals(8, ships.size());
|
||||||
int found = 0;
|
int found = 0;
|
||||||
for (Ship ship : ships) {
|
for (ShipData ship : ships) {
|
||||||
assertNotNull(ship);
|
assertNotNull(ship);
|
||||||
if ("Sidewinder".equals(ship.getName())){
|
if ("Sidewinder".equals(ship.getName())){
|
||||||
found++;
|
found++;
|
||||||
@@ -303,6 +363,21 @@ public class ParserTest extends Assert {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals("Expected ships not found", 2, found);
|
assertEquals("Expected ships not found", 2, found);
|
||||||
|
|
||||||
|
assertNull(data.getId());
|
||||||
|
assertNull(data.getFaction());
|
||||||
|
assertNull(data.getGovernment());
|
||||||
|
assertNull(data.getPower());
|
||||||
|
assertNull(data.getPowerState());
|
||||||
|
assertNull(station.getId());
|
||||||
|
assertNull(station.getType());
|
||||||
|
assertNull(station.getFaction());
|
||||||
|
assertNull(station.getGovernment());
|
||||||
|
assertNull(station.getEconomic());
|
||||||
|
assertNull(station.getSubEconomic());
|
||||||
|
assertNull(station.getServices());
|
||||||
|
assertNull(station.getCommodities());
|
||||||
|
assertNull(station.getModules());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,33 +390,30 @@ public class ParserTest extends Assert {
|
|||||||
String json = TestUtils.read(is);
|
String json = TestUtils.read(is);
|
||||||
Message message = parser.parse(json);
|
Message message = parser.parse(json);
|
||||||
assertNotNull(message);
|
assertNotNull(message);
|
||||||
assertEquals("http://schemas.elite-markets.net/eddn/shipyard/2", message.getSchemaRef());
|
assertEquals(SUPPORT_VERSIONS.V2_SHIPYARD, message.getVersion());
|
||||||
Header header = message.getHeader();
|
Header header = message.getHeader();
|
||||||
assertNotNull(header);
|
assertNotNull(header);
|
||||||
assertEquals("Amadeus Sheperd", header.getUploaderId());
|
assertEquals("Amadeus Sheperd", header.getUploaderId());
|
||||||
assertEquals("E:D Market Connector [Windows]", header.getSoftwareName());
|
assertEquals("E:D Market Connector [Windows]", header.getSoftwareName());
|
||||||
assertEquals("2.1.7.2", header.getSoftwareVersion());
|
assertEquals("2.1.7.2", header.getSoftwareVersion());
|
||||||
assertEquals(LocalDateTime.of(2016, 10, 5, 13, 16, 12, 490637000), header.getGatewayTimestamp());
|
assertEquals(LocalDateTime.of(2016, 10, 5, 13, 16, 12, 490637000), header.getGatewayTimestamp());
|
||||||
Body body = message.getBody();
|
StarSystemData data = message.getImportData();
|
||||||
assertNotNull(body);
|
assertNotNull(data);
|
||||||
assertEquals(LocalDateTime.of(2016, 10, 5, 13, 15, 51), body.getTimestamp());
|
assertEquals("Sothis", data.getName());
|
||||||
StarSystem system = body.getSystem();
|
assertNull(data.getId());
|
||||||
assertNotNull(system);
|
Collection<StationData> stations = data.getStations();
|
||||||
assertEquals("Sothis", system.getName());
|
assertNotNull(stations);
|
||||||
assertNull(system.getId());
|
assertEquals(1, stations.size());
|
||||||
assertNull(system.getAddress());
|
StationData station = stations.iterator().next();
|
||||||
Station station = body.getStation();
|
|
||||||
assertNotNull(station);
|
assertNotNull(station);
|
||||||
assertEquals("Newholm Station", station.getName());
|
assertEquals("Newholm Station", station.getName());
|
||||||
assertNull(station.getId());
|
assertNull(station.getId());
|
||||||
Collection<Item> items = body.getCommodities();
|
assertEquals(LocalDateTime.of(2016, 10, 5, 13, 15, 51), station.getModifiedTime());
|
||||||
assertNotNull(items);
|
Collection<ShipData> ships = station.getShips();
|
||||||
assertEquals(0, items.size());
|
|
||||||
Collection<Ship> ships = body.getShips();
|
|
||||||
assertNotNull(ships);
|
assertNotNull(ships);
|
||||||
assertEquals(5, ships.size());
|
assertEquals(5, ships.size());
|
||||||
int found = 0;
|
int found = 0;
|
||||||
for (Ship ship : ships) {
|
for (ShipData ship : ships) {
|
||||||
assertNotNull(ship);
|
assertNotNull(ship);
|
||||||
if ("SideWinder".equals(ship.getName())){
|
if ("SideWinder".equals(ship.getName())){
|
||||||
found++;
|
found++;
|
||||||
@@ -355,6 +427,21 @@ public class ParserTest extends Assert {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals("Expected ships not found", 2, found);
|
assertEquals("Expected ships not found", 2, found);
|
||||||
|
|
||||||
|
assertNull(data.getId());
|
||||||
|
assertNull(data.getFaction());
|
||||||
|
assertNull(data.getGovernment());
|
||||||
|
assertNull(data.getPower());
|
||||||
|
assertNull(data.getPowerState());
|
||||||
|
assertNull(station.getId());
|
||||||
|
assertNull(station.getType());
|
||||||
|
assertNull(station.getFaction());
|
||||||
|
assertNull(station.getGovernment());
|
||||||
|
assertNull(station.getEconomic());
|
||||||
|
assertNull(station.getSubEconomic());
|
||||||
|
assertNull(station.getServices());
|
||||||
|
assertNull(station.getCommodities());
|
||||||
|
assertNull(station.getModules());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user