Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoxaAntoxic committed Mar 14, 2024
1 parent 4100bba commit 31fa9eb
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Future<GeoInfo> lookup(AuctionContext auctionContext) {
final BidRequest bidRequest = auctionContext.getBidRequest();
final Timeout timeout = auctionContext.getTimeoutContext().getTimeout();

final Boolean isGeoLookupEnabled = Optional.ofNullable(account.getSettings())
final boolean isGeoLookupEnabled = Optional.ofNullable(account.getSettings())
.map(AccountSettings::getGeoLookup)
.map(BooleanUtils::isTrue)
.orElse(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public Future<PrivacyContext> contextFrom(AuctionContext auctionContext) {
final Privacy strippedPrivacy = stripPrivacy(initialPrivacy, auctionContext);
final Device device = bidRequest.getDevice();

//todo: pass geo info here as well
return tcfDefinerService.resolveTcfContext(
strippedPrivacy,
resolveAlpha2CountryCode(device),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public Future<AuctionContext> fromRequest(RoutingContext routingContext, long st
.compose(auctionContext -> geoLocationServiceWrapper.lookup(auctionContext)
.map(auctionContext::with))

.map(auctionContext -> auctionContext.with(
ortb2RequestFactory.enrichBidRequestWithGeolocationData(auctionContext)))
.compose(auctionContext -> ortb2RequestFactory.enrichBidRequestWithGeolocationData(auctionContext)
.map(auctionContext::with))

.compose(auctionContext -> gppService.contextFrom(auctionContext)
.map(auctionContext::with))
Expand All @@ -164,8 +164,8 @@ public Future<AuctionContext> fromRequest(RoutingContext routingContext, long st
.compose(auctionContext -> ampPrivacyContextFactory.contextFrom(auctionContext)
.map(auctionContext::with))

.map(auctionContext -> auctionContext.with(
ortb2RequestFactory.enrichBidRequestWithAccountAndPrivacyData(auctionContext)))
.compose(auctionContext -> ortb2RequestFactory.enrichBidRequestWithAccountAndPrivacyData(auctionContext)
.map(auctionContext::with))

.compose(auctionContext -> ortb2RequestFactory.executeProcessedAuctionRequestHooks(auctionContext)
.map(auctionContext::with))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public Future<AuctionContext> fromRequest(RoutingContext routingContext, long st
.compose(auctionContext -> geoLocationServiceWrapper.lookup(auctionContext)
.map(auctionContext::with))

.map(auctionContext -> auctionContext.with(
ortb2RequestFactory.enrichBidRequestWithGeolocationData(auctionContext)))
.compose(auctionContext -> ortb2RequestFactory.enrichBidRequestWithGeolocationData(auctionContext)
.map(auctionContext::with))

.compose(auctionContext -> gppService.contextFrom(auctionContext)
.map(auctionContext::with))
Expand All @@ -131,8 +131,8 @@ public Future<AuctionContext> fromRequest(RoutingContext routingContext, long st
.compose(auctionContext -> auctionPrivacyContextFactory.contextFrom(auctionContext)
.map(auctionContext::with))

.map(auctionContext -> auctionContext.with(
ortb2RequestFactory.enrichBidRequestWithAccountAndPrivacyData(auctionContext)))
.compose(auctionContext -> ortb2RequestFactory.enrichBidRequestWithAccountAndPrivacyData(auctionContext)
.map(auctionContext::with))

.compose(auctionContext -> ortb2RequestFactory.executeProcessedAuctionRequestHooks(auctionContext)
.map(auctionContext::with))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public Future<BidRequest> validateRequest(BidRequest bidRequest,
: Future.succeededFuture(bidRequest);
}

public BidRequest enrichBidRequestWithGeolocationData(AuctionContext auctionContext) {
public Future<BidRequest> enrichBidRequestWithGeolocationData(AuctionContext auctionContext) {
final BidRequest bidRequest = auctionContext.getBidRequest();
final Device device = bidRequest.getDevice();
final GeoInfo geoInfo = auctionContext.getGeoInfo();
Expand All @@ -230,25 +230,28 @@ public BidRequest enrichBidRequestWithGeolocationData(AuctionContext auctionCont
final UpdateResult<String> resolvedCountry = resolveCountry(geo, geoInfo);
final UpdateResult<String> resolvedRegion = resolveRegion(geo, geoInfo);

if (resolvedCountry.isUpdated() || resolvedRegion.isUpdated()) {
final Geo updatedGeo = Optional.ofNullable(geo)
.map(Geo::toBuilder)
.orElseGet(Geo::builder)
.country(resolvedCountry.getValue())
.region(resolvedRegion.getValue())
.build();
if (!resolvedCountry.isUpdated() && !resolvedRegion.isUpdated()) {
return Future.succeededFuture(bidRequest);
}

final Device updatedDevice = ObjectUtil.getIfNotNullOrDefault(device, Device::toBuilder, Device::builder)
.geo(updatedGeo)
.build();
final Geo updatedGeo = Optional.ofNullable(geo)
.map(Geo::toBuilder)
.orElseGet(Geo::builder)
.country(resolvedCountry.getValue())
.region(resolvedRegion.getValue())
.build();

return bidRequest.toBuilder().device(updatedDevice).build();
}
final Device updatedDevice = Optional.ofNullable(device)
.map(Device::toBuilder)
.orElseGet(Device::builder)
.geo(updatedGeo)
.build();

return Future.succeededFuture(bidRequest.toBuilder().device(updatedDevice).build());

return bidRequest;
}

public BidRequest enrichBidRequestWithAccountAndPrivacyData(AuctionContext auctionContext) {
public Future<BidRequest> enrichBidRequestWithAccountAndPrivacyData(AuctionContext auctionContext) {
final BidRequest bidRequest = auctionContext.getBidRequest();
final Account account = auctionContext.getAccount();
final PrivacyContext privacyContext = auctionContext.getPrivacyContext();
Expand All @@ -262,15 +265,16 @@ public BidRequest enrichBidRequestWithAccountAndPrivacyData(AuctionContext aucti
final Regs regs = bidRequest.getRegs();
final Regs enrichedRegs = enrichRegs(regs, privacyContext, account);

if (enrichedRequestExt != null || enrichedDevice != null || enrichedRegs != null) {
return bidRequest.toBuilder()
.ext(ObjectUtils.defaultIfNull(enrichedRequestExt, requestExt))
.device(ObjectUtils.defaultIfNull(enrichedDevice, device))
.regs(ObjectUtils.defaultIfNull(enrichedRegs, regs))
.build();
if (enrichedRequestExt == null && enrichedDevice == null && enrichedRegs == null) {
return Future.succeededFuture(bidRequest);
}

return bidRequest;
return Future.succeededFuture(bidRequest.toBuilder()
.ext(ObjectUtils.defaultIfNull(enrichedRequestExt, requestExt))
.device(ObjectUtils.defaultIfNull(enrichedDevice, device))
.regs(ObjectUtils.defaultIfNull(enrichedRegs, regs))
.build());

}

private static Regs enrichRegs(Regs regs, PrivacyContext privacyContext, Account account) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ public Future<WithPodErrors<AuctionContext>> fromRequest(RoutingContext routingC
.compose(auctionContext -> geoLocationServiceWrapper.lookup(auctionContext)
.map(auctionContext::with))

.map(auctionContext -> auctionContext.with(
ortb2RequestFactory.enrichBidRequestWithGeolocationData(auctionContext)))
.compose(auctionContext -> ortb2RequestFactory.enrichBidRequestWithGeolocationData(auctionContext)
.map(auctionContext::with))

.compose(auctionContext -> ortb2RequestFactory.activityInfrastructureFrom(auctionContext)
.map(auctionContext::with))

.compose(auctionContext -> auctionPrivacyContextFactory.contextFrom(auctionContext)
.map(auctionContext::with))

.map(auctionContext -> auctionContext.with(
ortb2RequestFactory.enrichBidRequestWithAccountAndPrivacyData(auctionContext)))
.compose(auctionContext -> ortb2RequestFactory.enrichBidRequestWithAccountAndPrivacyData(auctionContext)
.map(auctionContext::with))

.compose(auctionContext -> ortb2RequestFactory.executeProcessedAuctionRequestHooks(auctionContext)
.map(auctionContext::with))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ private Future<DeviceInfo> lookupDeviceInfo(Device device) {
: Future.failedFuture("Device info is disabled by configuration");
}

//todo: to be removed
private Future<GeoInfo> lookupGeoInfo(Device device, Timeout timeout) {
return geoLocationService != null
? geoLocationService.lookup(ObjectUtils.defaultIfNull(device.getIp(), device.getIpv6()), timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.ArrayList;
import java.util.List;

@Configuration
public class GeoLocationConfiguration {

@Configuration
Expand Down Expand Up @@ -182,35 +183,27 @@ static class GeoInfo {
}
}

@Configuration
static class CountryCodeMapperConfiguration {

@Bean
public CountryCodeMapper countryCodeMapper(@Value("classpath:country-codes.csv") Resource countryCodes,
@Value("classpath:mcc-country-codes.csv") Resource mccCountryCodes)
throws IOException {

return new CountryCodeMapper(readCsv(countryCodes), readCsv(mccCountryCodes));
}
@Bean
public CountryCodeMapper countryCodeMapper(@Value("classpath:country-codes.csv") Resource countryCodes,
@Value("classpath:mcc-country-codes.csv") Resource mccCountryCodes)
throws IOException {

private String readCsv(Resource resource) throws IOException {
final Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8);
final String csv = FileCopyUtils.copyToString(reader);
reader.close();
return csv;
}
return new CountryCodeMapper(readCsv(countryCodes), readCsv(mccCountryCodes));
}

@Configuration
static class GeoLocationWrapperConfiguration {
private String readCsv(Resource resource) throws IOException {
final Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8);
final String csv = FileCopyUtils.copyToString(reader);
reader.close();
return csv;
}

@Bean
GeoLocationServiceWrapper geoLocationServiceWrapper(
@Autowired(required = false) GeoLocationService geoLocationService,
Metrics metrics) {
@Bean
GeoLocationServiceWrapper geoLocationServiceWrapper(
@Autowired(required = false) GeoLocationService geoLocationService,
Metrics metrics) {

return new GeoLocationServiceWrapper(geoLocationService, metrics);
}
return new GeoLocationServiceWrapper(geoLocationService, metrics);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1713,9 +1713,11 @@ private void givenBidRequest(
.willAnswer(invocation -> Future.succeededFuture((BidRequest) invocation.getArgument(0)));

given(ortb2RequestFactory.enrichBidRequestWithAccountAndPrivacyData(any()))
.willAnswer(invocation -> ((AuctionContext) invocation.getArgument(0)).getBidRequest());
.willAnswer(invocation -> Future.succeededFuture(((AuctionContext) invocation.getArgument(0))
.getBidRequest()));
given(ortb2RequestFactory.enrichBidRequestWithGeolocationData(any()))
.willAnswer(invocation -> ((AuctionContext) invocation.getArgument(0)).getBidRequest());
.willAnswer(invocation -> Future.succeededFuture(((AuctionContext) invocation.getArgument(0))
.getBidRequest()));
given(ortb2RequestFactory.executeProcessedAuctionRequestHooks(any()))
.willAnswer(invocation -> Future.succeededFuture(
((AuctionContext) invocation.getArgument(0)).getBidRequest()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,11 @@ public void setUp() {
.willReturn(Future.succeededFuture(defaultPrivacyContext));

given(ortb2RequestFactory.enrichBidRequestWithAccountAndPrivacyData(any()))
.willAnswer(invocation -> ((AuctionContext) invocation.getArgument(0)).getBidRequest());
.willAnswer(invocation -> Future.succeededFuture(((AuctionContext) invocation.getArgument(0))
.getBidRequest()));
given(ortb2RequestFactory.enrichBidRequestWithGeolocationData(any()))
.willAnswer(invocation -> ((AuctionContext) invocation.getArgument(0)).getBidRequest());
.willAnswer(invocation -> Future.succeededFuture(((AuctionContext) invocation.getArgument(0))
.getBidRequest()));
given(ortb2RequestFactory.executeProcessedAuctionRequestHooks(any()))
.willAnswer(invocation -> Future.succeededFuture(
((AuctionContext) invocation.getArgument(0)).getBidRequest()));
Expand Down
Loading

0 comments on commit 31fa9eb

Please sign in to comment.