Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Price Floors: Check for enabled floors for bidder call #1860

Merged
merged 1 commit into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,6 +100,10 @@ public PriceFloorResult resolve(BidRequest bidRequest,
Format format,
List<String> warnings) {

if (isPriceFloorsDisabledForRequest(bidRequest)) {
return null;
}

final PriceFloorModelGroup modelGroup = extractFloorModelGroup(floorRules);

if (modelGroup == null) {
Expand Down Expand Up @@ -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<PriceFloorModelGroup> modelGroups = ObjectUtil.getIfNotNull(data, PriceFloorData::getModelGroups);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down