-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into remove-pg
# Conflicts: # src/main/java/org/prebid/server/auction/requestfactory/Ortb2RequestFactory.java # src/test/groovy/org/prebid/server/functional/service/PrebidServerService.groovy # src/test/groovy/org/prebid/server/functional/tests/privacy/PrivacyBaseSpec.groovy # src/test/java/org/prebid/server/auction/requestfactory/AmpRequestFactoryTest.java # src/test/java/org/prebid/server/auction/requestfactory/AuctionRequestFactoryTest.java # src/test/java/org/prebid/server/auction/requestfactory/Ortb2RequestFactoryTest.java # src/test/java/org/prebid/server/auction/requestfactory/VideoRequestFactoryTest.java # src/test/java/org/prebid/server/vast/VastModifierTest.java
- Loading branch information
Showing
139 changed files
with
4,855 additions
and
2,283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,4 @@ target/ | |
|
||
.DS_Store | ||
|
||
.allure/ | ||
src/main/proto/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/org/prebid/server/auction/GeoLocationServiceWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package org.prebid.server.auction; | ||
|
||
import com.iab.openrtb.request.Device; | ||
import com.iab.openrtb.request.Geo; | ||
import io.vertx.core.Future; | ||
import io.vertx.core.logging.Logger; | ||
import io.vertx.core.logging.LoggerFactory; | ||
import org.apache.commons.lang3.BooleanUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.prebid.server.auction.model.AuctionContext; | ||
import org.prebid.server.auction.model.IpAddress; | ||
import org.prebid.server.auction.requestfactory.Ortb2ImplicitParametersResolver; | ||
import org.prebid.server.execution.Timeout; | ||
import org.prebid.server.geolocation.GeoLocationService; | ||
import org.prebid.server.geolocation.model.GeoInfo; | ||
import org.prebid.server.metric.Metrics; | ||
import org.prebid.server.model.HttpRequestContext; | ||
import org.prebid.server.settings.model.Account; | ||
import org.prebid.server.settings.model.AccountSettings; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class GeoLocationServiceWrapper { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(GeoLocationServiceWrapper.class); | ||
|
||
private final GeoLocationService geoLocationService; | ||
private final Ortb2ImplicitParametersResolver implicitParametersResolver; | ||
private final Metrics metrics; | ||
|
||
public GeoLocationServiceWrapper(GeoLocationService geoLocationService, | ||
Ortb2ImplicitParametersResolver implicitParametersResolver, | ||
Metrics metrics) { | ||
|
||
this.geoLocationService = geoLocationService; | ||
this.implicitParametersResolver = Objects.requireNonNull(implicitParametersResolver); | ||
this.metrics = Objects.requireNonNull(metrics); | ||
} | ||
|
||
//todo: account settings will work as expected if the default account resolving refactoring is done | ||
public Future<GeoInfo> lookup(AuctionContext auctionContext) { | ||
final Account account = auctionContext.getAccount(); | ||
final Device device = auctionContext.getBidRequest().getDevice(); | ||
final HttpRequestContext requestContext = auctionContext.getHttpRequest(); | ||
final Timeout timeout = auctionContext.getTimeoutContext().getTimeout(); | ||
|
||
final boolean isGeoLookupEnabled = Optional.ofNullable(account.getSettings()) | ||
.map(AccountSettings::getGeoLookup) | ||
.map(BooleanUtils::isTrue) | ||
.orElse(false); | ||
|
||
return isGeoLookupEnabled | ||
? doLookup(getIpAddress(device, requestContext), getCountry(device), timeout).otherwiseEmpty() | ||
: Future.succeededFuture(); | ||
} | ||
|
||
public Future<GeoInfo> doLookup(String ipAddress, String requestCountry, Timeout timeout) { | ||
if (geoLocationService == null || ipAddress == null || StringUtils.isNotBlank(requestCountry)) { | ||
return Future.failedFuture("Geolocation lookup is skipped"); | ||
} | ||
return geoLocationService.lookup(ipAddress, timeout) | ||
.onSuccess(geoInfo -> metrics.updateGeoLocationMetric(true)) | ||
.onFailure(this::logError); | ||
} | ||
|
||
private String getCountry(Device device) { | ||
return Optional.ofNullable(device) | ||
.map(Device::getGeo) | ||
.map(Geo::getCountry) | ||
.filter(StringUtils::isNotBlank) | ||
.orElse(null); | ||
} | ||
|
||
private String getIpAddress(Device device, HttpRequestContext request) { | ||
final Optional<Device> optionalDevice = Optional.ofNullable(device); | ||
return optionalDevice.map(Device::getIp) | ||
.filter(StringUtils::isNotBlank) | ||
.or(() -> optionalDevice | ||
.map(Device::getIpv6) | ||
.filter(StringUtils::isNotBlank)) | ||
.or(() -> ipFromHeader(request)) | ||
.orElse(null); | ||
} | ||
|
||
private Optional<String> ipFromHeader(HttpRequestContext request) { | ||
final IpAddress headerIp = implicitParametersResolver.findIpFromRequest(request); | ||
return Optional.ofNullable(headerIp) | ||
.map(IpAddress::getIp); | ||
} | ||
|
||
private void logError(Throwable error) { | ||
final String message = "Geolocation lookup failed: " + error.getMessage(); | ||
logger.warn(message); | ||
logger.debug(message, error); | ||
|
||
metrics.updateGeoLocationMetric(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.