Skip to content

Commit

Permalink
178-Trade-Module-Fix-Consumed-Data (#184)
Browse files Browse the repository at this point in the history
* update ReceiveCommodityMessageService to include isPlanetary, requiresOdyssey, isFleetCarrier, and updateTimestamp

* add includeOdyssey option for single and loop trade

* update single and loop queries to implement filled in boolean data fields for planetary/fleet/odyssey

* update isPlanetary and isFleetCarrier to allow for null values
simplify requiresOdyssey boolean

* update tests to accommodate includeOdyssey boolean field

* update trade/loop queries to "include" results correctly
  • Loading branch information
Daniel-J-Mason authored Jul 7, 2024
1 parent a15e387 commit e073bd3
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ public class MybatisLocateLoopTradeFilter {
private Integer minSupply;
private Integer minDemand;
private Boolean includeSurfaceStations;
private Boolean includeOdyssey;
private Boolean includeFleetCarriers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ public class MybatisLocateSingleHopTradeFilter {
private Integer minSupply;
private Integer minDemand;
private Boolean includeSurfaceStations;
private Boolean includeOdyssey;
private Boolean includeFleetCarriers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public MybatisLocateLoopTradeFilter map(LocateLoopTradeFilter locateLoopTradeFil
.minSupply(locateLoopTradeFilter.getMinSupply())
.minDemand(locateLoopTradeFilter.getMinDemand())
.includeSurfaceStations(locateLoopTradeFilter.getIncludeSurfaceStations())
.includeOdyssey(locateLoopTradeFilter.getIncludeOdyssey())
.includeFleetCarriers(locateLoopTradeFilter.getIncludeFleetCarriers())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public MybatisLocateSingleHopTradeFilter map(LocateSingleHopTradeFilter locateSi
.minDemand(locateSingleHopTradeFilter.getMinDemand())
.minSupply(locateSingleHopTradeFilter.getMinSupply())
.includeSurfaceStations(locateSingleHopTradeFilter.getIncludeSurfaceStations())
.includeOdyssey(locateSingleHopTradeFilter.getIncludeOdyssey())
.includeFleetCarriers(locateSingleHopTradeFilter.getIncludeFleetCarriers())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ WITH stations_in_range AS (SELECT station.id,
FROM public.station
INNER JOIN system ON station.system_id = system.id
WHERE st_3ddwithin(st_makepoint(#{xCoordinate}, #{yCoordinate}, #{zCoordinate}), coordinates_geom, 300)
<if test='!includeFleetCarriers'>
AND station.name NOT SIMILAR TO '[A-Za-z0-9]{3}-[A-Za-z0-9]{3}'
`<if test='!includeFleetCarriers'>
AND station.fleet_carrier = #{includeFleetCarriers}
</if>
<if test='!includeOdyssey'>
AND station.require_odyssey = #{includeOdyssey}
</if>
<if test='!includeSurfaceStations'>
AND station.planetary = #{includeSurfaceStations}
</if>
<if test='maxLandingPadSize == "LARGE"'>AND max_landing_pad_size = 'LARGE'</if>
<if test='maxLandingPadSize == "MEDIUM"'>AND max_landing_pad_size IN ('MEDIUM', 'LARGE')</if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ WHERE st_3ddwithin((select coordinates_geom
from system
where system.name = #{sellToSystemName}), coordinates_geom, #{maxRouteDistance})
<if test='!includeFleetCarriers'>
AND station.name NOT SIMILAR TO '[A-Za-z0-9]{3}-[A-Za-z0-9]{3}'
AND station.fleet_carrier = #{includeFleetCarriers}
</if>
<if test='!includeOdyssey'>
AND station.require_odyssey = #{includeOdyssey}
</if>
<if test='!includeSurfaceStations'>
AND station.planetary = #{includeSurfaceStations}
</if>
<if test='maxLandingPadSize == "LARGE"'>AND max_landing_pad_size = 'LARGE'</if>
<if test='maxLandingPadSize == "MEDIUM"'>AND max_landing_pad_size IN ('MEDIUM', 'LARGE')</if>
Expand Down Expand Up @@ -129,7 +135,13 @@ WHERE st_3ddwithin((select coordinates_geom
from system
where system.name = #{sellToSystemName}), coordinates_geom, #{maxRouteDistance})
<if test='!includeFleetCarriers'>
AND station.name NOT SIMILAR TO '[A-Za-z0-9]{3}-[A-Za-z0-9]{3}'
AND station.fleet_carrier = #{includeFleetCarriers}
</if>
<if test='!includeOdyssey'>
AND station.require_odyssey = #{includeOdyssey}
</if>
<if test='!includeSurfaceStations'>
AND station.planetary = #{includeSurfaceStations}
</if>
<if test='maxLandingPadSize == "LARGE"'>AND max_landing_pad_size = 'LARGE'</if>
<if test='maxLandingPadSize == "MEDIUM"'>AND max_landing_pad_size IN ('MEDIUM', 'LARGE')</if>
Expand Down Expand Up @@ -222,7 +234,13 @@ WHERE st_3ddwithin((select coordinates_geom
from system
where system.name = #{buyFromSystemName}), coordinates_geom, #{maxRouteDistance})
<if test='!includeFleetCarriers'>
AND station.name NOT SIMILAR TO '[A-Za-z0-9]{3}-[A-Za-z0-9]{3}'
AND station.fleet_carrier = #{includeFleetCarriers}
</if>
<if test='!includeOdyssey'>
AND station.require_odyssey = #{includeOdyssey}
</if>
<if test='!includeSurfaceStations'>
AND station.planetary = #{includeSurfaceStations}
</if>
<if test='maxLandingPadSize == "LARGE"'>AND max_landing_pad_size = 'LARGE'</if>
<if test='maxLandingPadSize == "MEDIUM"'>AND max_landing_pad_size IN ('MEDIUM', 'LARGE')</if>
Expand Down Expand Up @@ -314,7 +332,13 @@ WHERE st_3ddwithin((select coordinates_geom
from system
where system.name = #{buyFromSystemName}), coordinates_geom, #{maxRouteDistance})
<if test='!includeFleetCarriers'>
AND station.name NOT SIMILAR TO '[A-Za-z0-9]{3}-[A-Za-z0-9]{3}'
AND station.fleet_carrier = #{includeFleetCarriers}
</if>
<if test='!includeOdyssey'>
AND station.require_odyssey = #{includeOdyssey}
</if>
<if test='!includeSurfaceStations'>
AND station.planetary = #{includeSurfaceStations}
</if>
<if test='maxLandingPadSize == "LARGE"'>AND max_landing_pad_size = 'LARGE'</if>
<if test='maxLandingPadSize == "MEDIUM"'>AND max_landing_pad_size IN ('MEDIUM', 'LARGE')</if>
Expand Down Expand Up @@ -404,9 +428,15 @@ WITH buy_system AS MATERIALIZED (SELECT station.id,
FROM station
INNER JOIN system ON station.system_id = system.id
WHERE system.name = #{buyFromSystemName}
<if test='!includeFleetCarriers'>
AND station.name NOT SIMILAR TO '[A-Za-z0-9]{3}-[A-Za-z0-9]{3}'
</if>
<if test='!includeFleetCarriers'>
AND station.fleet_carrier = #{includeFleetCarriers}
</if>
<if test='!includeOdyssey'>
AND station.require_odyssey = #{includeOdyssey}
</if>
<if test='!includeSurfaceStations'>
AND station.planetary = #{includeSurfaceStations}
</if>
<if test='maxLandingPadSize == "LARGE"'>AND max_landing_pad_size = 'LARGE'</if>
<if test='maxLandingPadSize == "MEDIUM"'>AND max_landing_pad_size IN ('MEDIUM', 'LARGE')</if>
AND #{maxArrivalDistance} >= arrival_distance),
Expand All @@ -417,9 +447,15 @@ sell_system AS (select station.id,
FROM station
INNER JOIN system ON station.system_id = system.id
WHERE system.name = #{sellToSystemName}
<if test='!includeFleetCarriers'>
AND station.name NOT SIMILAR TO '[A-Za-z0-9]{3}-[A-Za-z0-9]{3}'
</if>
<if test='!includeFleetCarriers'>
AND station.fleet_carrier = #{includeFleetCarriers}
</if>
<if test='!includeOdyssey'>
AND station.require_odyssey = #{includeOdyssey}
</if>
<if test='!includeSurfaceStations'>
AND station.planetary = #{includeSurfaceStations}
</if>
<if test='maxLandingPadSize == "LARGE"'>AND max_landing_pad_size = 'LARGE'</if>
<if test='maxLandingPadSize == "MEDIUM"'>AND max_landing_pad_size IN ('MEDIUM', 'LARGE')</if>
AND #{maxArrivalDistance} >= arrival_distance),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public record RestLocateLoopRouteFilterDto(
Integer minSupply,
Integer minDemand,
Boolean includeSurfaceStations,
Boolean includeOdyssey,
Boolean includeFleetCarriers) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public record RestLocateSingleHopRouteFilterDto(
@NotNull Integer maxArrivalDistance,
@NotNull Integer cargoCapacity,
@NotNull Boolean includeSurfaceStations,
@NotNull Boolean includeOdyssey,
@NotNull Boolean includeFleetCarriers) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public LocateLoopTradeFilter map(RestLocateLoopRouteFilterDto locateLoopRouteFil
.minSupply(locateLoopRouteFilterDto.minSupply())
.minDemand(locateLoopRouteFilterDto.minDemand())
.includeSurfaceStations(locateLoopRouteFilterDto.includeSurfaceStations())
.includeOdyssey(locateLoopRouteFilterDto.includeOdyssey())
.includeFleetCarriers(locateLoopRouteFilterDto.includeFleetCarriers())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public LocateSingleHopTradeFilter map(RestLocateSingleHopRouteFilterDto locateSi
.minDemand(locateSingleHopRouteFilterDto.cargoCapacity() * 4) // no loss on sale
.minSupply(locateSingleHopRouteFilterDto.cargoCapacity()) // enough supply for full cargo hold
.includeSurfaceStations(locateSingleHopRouteFilterDto.includeSurfaceStations())
.includeOdyssey(locateSingleHopRouteFilterDto.includeOdyssey())
.includeFleetCarriers(locateSingleHopRouteFilterDto.includeFleetCarriers())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ public class LocateLoopTradeFilter {
private Integer minSupply;
private Integer minDemand;
private Boolean includeSurfaceStations;
private Boolean includeOdyssey;
private Boolean includeFleetCarriers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class LocateSingleHopTradeFilter {
private Integer maxArrivalDistance; //default < 5000
private Integer minSupply;
private Integer minDemand;
private Boolean includeSurfaceStations; //TODO
private Boolean includeFleetCarriers; //TODO
private Boolean includeSurfaceStations;
private Boolean includeOdyssey;
private Boolean includeFleetCarriers;

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -57,7 +56,19 @@ public void receive(CommodityMessage.V3 message) {
String systemName = payload.systemName();
String stationName = payload.stationName();
String[] prohibitedCommodities = payload.prohibited();


var planetaryStationTypes = List.of("CraterOutpost", "CraterPort", "OnFootSettlement");
Boolean isPlanetary;
Boolean isFleetCarrier;
if (payload.stationType() != null) {
isPlanetary = planetaryStationTypes.contains(payload.stationType());
isFleetCarrier = "FleetCarrier".equals(payload.stationType());
} else {
isFleetCarrier = null;
isPlanetary = null;
}
boolean requiresOdyssey = payload.odyssey();

CompletableFuture<Station> stationCompletableFuture = CompletableFuture.supplyAsync(() -> createOrLoadSystemPort.createOrLoad(new System(
idGenerator.generateId(),
null,
Expand All @@ -74,15 +85,15 @@ public void receive(CommodityMessage.V3 message) {
}).thenCompose(loadedSystem -> CompletableFuture.supplyAsync(() -> {
Station station = new Station(
idGenerator.generateId(),
null,
marketId,
stationName,
null,
loadedSystem,
isPlanetary,
requiresOdyssey,
isFleetCarrier,
null,
null,
null,
null,
null,
updateTimestamp,
null
);
return createOrLoadStationPort.createOrLoad(station);
Expand All @@ -91,21 +102,9 @@ public void receive(CommodityMessage.V3 message) {
if (throwable != null) {
log.error("Exception occurred in retrieving station", throwable);
} else {
//if we get the message here, it always is NOT a fleet carrier
Station updatedStation = station.withFleetCarrier(false);

if (Objects.isNull(updatedStation.marketId())) {
updatedStation = updatedStation.withMarketId(marketId);
}

if (Objects.isNull(updatedStation.marketUpdatedAt()) || updateTimestamp.isAfter(station.marketUpdatedAt())) {
updatedStation = updatedStation.withMarketUpdatedAt(updateTimestamp);
}

final Station finalUpdatedStation = updatedStation;
stationRequestDataServices.stream()
.filter(useCase -> useCase.isApplicable(finalUpdatedStation))
.forEach(useCase -> useCase.request(finalUpdatedStation));
.filter(useCase -> useCase.isApplicable(station))
.forEach(useCase -> useCase.request(station));
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void testMap_givenDto_shouldReturnDomainObject() {
10000,
10000,
true,
false,
false);

LocateLoopTradeFilter domainObject = underTest.map(dto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void testMap_givenDto_shouldReturnDomainObject() {
5000,
720,
true,
false,
false);

LocateSingleHopTradeFilter domainObject = underTest.map(dto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
import io.edpn.backend.trade.application.port.outgoing.station.UpdateStationPort;
import io.edpn.backend.trade.application.port.outgoing.system.CreateOrLoadSystemPort;
import io.edpn.backend.util.IdGenerator;
import java.time.LocalDateTime;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.time.LocalDateTime;
import java.util.List;

import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -106,9 +107,6 @@ public void shouldReceiveMessage() {

Station station = mock(Station.class);
when(createOrLoadStationPort.createOrLoad(argThat(argument -> argument.system().equals(system) && argument.name().equals("station")))).thenReturn(station);
when(station.withFleetCarrier(false)).thenReturn(station);
when(station.marketUpdatedAt()).thenReturn(null);
when(station.withMarketUpdatedAt(timestamp)).thenReturn(station);

underTest.receive(message);

Expand Down

0 comments on commit e073bd3

Please sign in to comment.