From 3e61178f07d57e82a7db73e31e1c81bbb6da18d4 Mon Sep 17 00:00:00 2001 From: Serhii Nahornyi Date: Thu, 12 May 2022 17:12:47 +0300 Subject: [PATCH] Price Floors: Check for enabled floors, from bidder call --- .../floors/BasicPriceFloorProcessor.java | 2 +- .../floors/BasicPriceFloorResolver.java | 15 +++++++++++++++ .../floors/BasicPriceFloorResolverTest.java | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/prebid/server/floors/BasicPriceFloorProcessor.java b/src/main/java/org/prebid/server/floors/BasicPriceFloorProcessor.java index deb987d3cd2..c14fac18eca 100644 --- a/src/main/java/org/prebid/server/floors/BasicPriceFloorProcessor.java +++ b/src/main/java/org/prebid/server/floors/BasicPriceFloorProcessor.java @@ -79,7 +79,7 @@ public AuctionContext enrichWithPriceFloors(AuctionContext auctionContext) { return auctionContext.with(updatedBidRequest); } - private boolean isPriceFloorsDisabled(Account account, BidRequest bidRequest) { + private static boolean isPriceFloorsDisabled(Account account, BidRequest bidRequest) { return isPriceFloorsDisabledForAccount(account) || isPriceFloorsDisabledForRequest(bidRequest); } diff --git a/src/main/java/org/prebid/server/floors/BasicPriceFloorResolver.java b/src/main/java/org/prebid/server/floors/BasicPriceFloorResolver.java index 3adb5e3398d..2e8f20e1017 100644 --- a/src/main/java/org/prebid/server/floors/BasicPriceFloorResolver.java +++ b/src/main/java/org/prebid/server/floors/BasicPriceFloorResolver.java @@ -19,6 +19,7 @@ import org.apache.commons.collections4.IterableUtils; import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.math3.util.CombinatoricsUtils; @@ -99,6 +100,10 @@ public PriceFloorResult resolve(BidRequest bidRequest, Format format, List warnings) { + if (isPriceFloorsDisabledForRequest(bidRequest)) { + return null; + } + final PriceFloorModelGroup modelGroup = extractFloorModelGroup(floorRules); if (modelGroup == null) { @@ -145,6 +150,16 @@ public PriceFloorResult resolve(BidRequest bidRequest, return null; } + private static boolean isPriceFloorsDisabledForRequest(BidRequest bidRequest) { + final PriceFloorRules requestFloors = extractRequestFloors(bidRequest); + return BooleanUtils.isFalse(ObjectUtil.getIfNotNull(requestFloors, PriceFloorRules::getEnabled)); + } + + private static PriceFloorRules extractRequestFloors(BidRequest bidRequest) { + final ExtRequestPrebid prebid = ObjectUtil.getIfNotNull(bidRequest.getExt(), ExtRequest::getPrebid); + return ObjectUtil.getIfNotNull(prebid, ExtRequestPrebid::getFloors); + } + private static PriceFloorModelGroup extractFloorModelGroup(PriceFloorRules floors) { final PriceFloorData data = ObjectUtil.getIfNotNull(floors, PriceFloorRules::getData); final List modelGroups = ObjectUtil.getIfNotNull(data, PriceFloorData::getModelGroups); diff --git a/src/test/java/org/prebid/server/floors/BasicPriceFloorResolverTest.java b/src/test/java/org/prebid/server/floors/BasicPriceFloorResolverTest.java index c456dfabf51..d04e8280398 100644 --- a/src/test/java/org/prebid/server/floors/BasicPriceFloorResolverTest.java +++ b/src/test/java/org/prebid/server/floors/BasicPriceFloorResolverTest.java @@ -69,6 +69,25 @@ public void setUp() { priceFloorResolver = new BasicPriceFloorResolver(currencyConversionService, countryCodeMapper, metrics); } + @Test + public void resolveShouldReturnNullWhenRulesDisabledInRequest() { + // given + final BidRequest bidRequest = BidRequest.builder() + .ext(ExtRequest.of(ExtRequestPrebid.builder() + .floors(PriceFloorRules.builder() + .enabled(false) + .build()) + .build())) + .build(); + + // when and then + assertThat(priceFloorResolver.resolve(bidRequest, + givenRules(PriceFloorModelGroup.builder() + .schema(PriceFloorSchema.of("|", singletonList(PriceFloorField.siteDomain))) + .value("siteDomain", BigDecimal.TEN) + .build()), givenImp(identity()), null)).isNull(); + } + @Test public void resolveShouldReturnNullWhenModelGroupIsNotPresent() { // given