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

fix bid floor in between bidder #1315

Merged
merged 4 commits into from
Jun 11, 2021
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 @@ -27,7 +27,6 @@
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.util.HttpUtil;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -44,7 +43,6 @@ public class BetweenBidder implements Bidder<BidRequest> {
new TypeReference<ExtPrebid<?, ExtImpBetween>>() {
};
private static final String URL_HOST_MACRO = "{{Host}}";
private static final BigDecimal DEFAULT_BID_FLOOR = BigDecimal.valueOf(0.00001);

private final String endpointUrl;
private final JacksonMapper mapper;
Expand All @@ -64,7 +62,7 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request
try {
validateImp(imp);
extImpBetween = parseImpExt(imp);
modifiedImps.add(modifyImp(imp, secure, extImpBetween.getBidFloor(), extImpBetween.getBidFloorCur()));
modifiedImps.add(modifyImp(imp, secure));
} catch (PreBidException e) {
errors.add(BidderError.badInput(e.getMessage()));
}
Expand Down Expand Up @@ -110,14 +108,12 @@ private ExtImpBetween parseImpExt(Imp imp) {
return extImpBetween;
}

private static Imp modifyImp(Imp imp, Integer secure, BigDecimal bidFloor, String bidFloorCur) {
private static Imp modifyImp(Imp imp, Integer secure) {
final Banner resolvedBanner = resolveBanner(imp.getBanner());

return imp.toBuilder()
.banner(resolvedBanner)
.secure(secure)
.bidfloor(bidFloor == null || bidFloor.compareTo(BigDecimal.ZERO) <= 0 ? DEFAULT_BID_FLOOR : bidFloor)
.bidfloorcur(StringUtils.isNotBlank(bidFloorCur) ? bidFloorCur : imp.getBidfloorcur())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
import lombok.AllArgsConstructor;
import lombok.Value;

import java.math.BigDecimal;

@AllArgsConstructor(staticName = "of")
@Value
public class ExtImpBetween {

String host;

String publisherId;

BigDecimal bidFloor;

String bidFloorCur;
}
9 changes: 0 additions & 9 deletions src/main/resources/static/bidder-params/between.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@
"publisher_id": {
"type": "string",
"description": "Publisher ID from Between Exchange control panel"
},
"bid_floor": {
"type": "number",
"description": "The minimum price acceptable for a bid"
},
"bid_floor_cur": {
"type": "string",
"description": "Currency of bid floor",
"enum": ["USD", "EUR", "RUB"]
}
},
"required": ["host", "publisher_id"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.prebid.server.proto.openrtb.ext.request.between.ExtImpBetween;
import org.prebid.server.util.HttpUtil;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -59,11 +58,11 @@ public void creationShouldFailOnInvalidEndpointUrl() {
public void makeHttpRequestsShouldReturnErrorIfImpExtContainEmptyOrNullHostParam() {
// given
final Imp firstImp = givenImp(impBuilder -> impBuilder
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("", "pubId", null, null)))));
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("", "pubId")))));

final Imp secondImp = givenImp(impBuilder -> impBuilder
.id("456")
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of(null, "pubId", null, null)))));
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of(null, "pubId")))));

final BidRequest bidRequest = BidRequest.builder()
.imp(Arrays.asList(firstImp, secondImp))
Expand All @@ -86,11 +85,11 @@ public void makeHttpRequestsShouldReturnErrorIfBannerNotPresentOrSizesNotExists(
// given
final Imp firstImp = givenImp(impBuilder -> impBuilder
.banner(null)
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("host", "pubId", null, null)))));
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("host", "pubId")))));

final Imp secondImp = givenImp(impBuilder -> impBuilder
.banner(Banner.builder().build())
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("host", "pubId", null, null)))));
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("host", "pubId")))));

final BidRequest bidRequest = BidRequest.builder()
.imp(Arrays.asList(firstImp, secondImp))
Expand All @@ -111,7 +110,7 @@ public void makeHttpRequestsShouldCorrectlyAddHeaders() {
// given
final Imp firstImp = givenImp(impBuilder -> impBuilder
.ext(mapper.valueToTree(ExtPrebid.of(null,
ExtImpBetween.of("host", "pubId", null, null)))));
ExtImpBetween.of("host", "pubId")))));

final BidRequest bidRequest = BidRequest.builder()
.device(Device.builder().ua("someUa").dnt(5).ip("someIp").language("someLanguage").build())
Expand Down Expand Up @@ -140,11 +139,11 @@ public void makeHttpRequestsShouldCorrectlyAddHeaders() {
public void makeHttpRequestsShouldReturnErrorIfImpExtContainEmptyOrNullPublisherIdParam() {
// given
final Imp firstImp = givenImp(impBuilder -> impBuilder
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("host", "", null, null)))));
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("host", "")))));

final Imp secondImp = givenImp(impBuilder -> impBuilder
.id("456")
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("host", null, null, null)))));
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("host", null)))));

final BidRequest bidRequest = BidRequest.builder()
.imp(Arrays.asList(firstImp, secondImp))
Expand Down Expand Up @@ -197,7 +196,7 @@ public void makeHttpRequestsShouldCreateCorrectURL() {
}

@Test
public void makeHttpRequestsShouldEnrichEveryImpWithSecureBidFlorAndBidFloorCurParams() {
public void makeHttpRequestsShouldEnrichEveryImpWithSecureBidFlor() {
// given
final BidRequest bidRequest = givenBidRequest(bidRequestBuilder -> bidRequestBuilder
.site(Site.builder().page("https://page.com").build()),
Expand All @@ -213,8 +212,8 @@ public void makeHttpRequestsShouldEnrichEveryImpWithSecureBidFlorAndBidFloorCurP
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getPayload)
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getSecure, Imp::getBidfloor, Imp::getBidfloorcur)
.containsExactly(tuple(1, BigDecimal.ONE, "EUR"));
.extracting(Imp::getSecure)
.containsExactly(1);
}

@Test
Expand All @@ -223,10 +222,7 @@ public void makeHttpRequestsShouldSetDefaultParamsIfAnotherNotPresent() {
final BidRequest bidRequest = givenBidRequest(bidRequestBuilder -> bidRequestBuilder
.site(Site.builder().page("http://page.com").build()),
impBuilder -> impBuilder
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("127.0.0.1", "pubId",
BigDecimal.valueOf(-1), ""))))
.bidfloor(BigDecimal.valueOf(12))
.bidfloorcur("USD"));
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("127.0.0.1", "pubId")))));

// when
final Result<List<HttpRequest<BidRequest>>> result = betweenBidder.makeHttpRequests(bidRequest);
Expand All @@ -236,8 +232,8 @@ public void makeHttpRequestsShouldSetDefaultParamsIfAnotherNotPresent() {
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getPayload)
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getSecure, Imp::getBidfloor, Imp::getBidfloorcur)
.containsExactly(tuple(0, BigDecimal.valueOf(0.00001), "USD"));
.extracting(Imp::getSecure)
.containsExactly(0);
}

@Test
Expand Down Expand Up @@ -357,8 +353,7 @@ private static Imp givenImp(Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomiz
return impCustomizer.apply(Imp.builder()
.id("123")
.banner(Banner.builder().w(23).h(25).build())
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("127.0.0.1", "pubId",
BigDecimal.ONE, "EUR")))))
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("127.0.0.1", "pubId")))))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"ext": {
"between": {
"host": "lbs-ru1.ads",
"publisher_id": "publisherTestID",
"bid_floor": 12.2345,
"bid_floor_cur": "RUB"
"publisher_id": "publisherTestID"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@
"w": 300,
"h": 250
},
"bidfloor": 12.2345,
"bidfloorcur": "RUB",
"secure": 0,
"ext": {
"bidder": {
"host": "lbs-ru1.ads",
"publisher_id": "publisherTestID",
"bid_floor": 12.2345,
"bid_floor_cur": "RUB"
"publisher_id": "publisherTestID"
}
}
}
Expand Down