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

Sovrn: Accept Imp.ext Bidfloor either as a number or string #3484

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 19 additions & 4 deletions src/main/java/org/prebid/server/bidder/sovrn/SovrnBidder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.server.bidder.sovrn;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Device;
Expand Down Expand Up @@ -103,10 +104,24 @@ private ExtImpSovrn parseExtImpSovrn(ObjectNode ext) {
}
}

private static BigDecimal resolveBidFloor(BigDecimal impBidFloor, BigDecimal extBidFloor) {
return !BidderUtil.isValidPrice(impBidFloor) && BidderUtil.isValidPrice(extBidFloor)
? extBidFloor
: impBidFloor;
private static BigDecimal resolveBidFloor(BigDecimal impBidFloor, JsonNode extBidFloor) {
final BigDecimal fromExt = parseBidFloor(extBidFloor);
return !BidderUtil.isValidPrice(impBidFloor) && BidderUtil.isValidPrice(fromExt) ? fromExt : impBidFloor;
}

private static BigDecimal parseBidFloor(JsonNode extBidFloor) {
if (extBidFloor != null) {
if (extBidFloor.isNumber()) {
return extBidFloor.decimalValue();
} else if (extBidFloor.isTextual()) {
try {
return new BigDecimal(extBidFloor.textValue());
} catch (NumberFormatException e) {
return BigDecimal.ZERO;
}
}
}
return BigDecimal.ZERO;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can revert this entirely as well as reverting the type change in the ExtImpSovrn, since both a string and a number will be successfully deserialized to BigDecimal

the only change you need is changing the json scheme, everything else should work fine

in order to test whether it works you can play with the integration test SovrnTest by changing values in the request json to double-check it works as intended

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for making it simpler.

}

private String resolveTagId(ExtImpSovrn sovrnExt) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.prebid.server.proto.openrtb.ext.request.sovrn;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.AllArgsConstructor;
import lombok.Value;

import java.math.BigDecimal;

@Value
@AllArgsConstructor(staticName = "of")
public class ExtImpSovrn {
Expand All @@ -16,7 +15,7 @@ public class ExtImpSovrn {
@JsonProperty("tagId")
String legacyTagId;

BigDecimal bidfloor;
JsonNode bidfloor;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert


String adunitcode;
}
12 changes: 10 additions & 2 deletions src/main/resources/static/bidder-params/sovrn.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
"description": "An ID which identifies the sovrn ad tag (DEPRECATED, use \"tagid\" instead)"
},
"bidfloor": {
"type": "number",
"description": "The minimum acceptable bid, in CPM, using US Dollars"
"anyOf": [
{
"type": "number",
"description": "The minimum acceptable bid, in CPM, using US Dollars"
},
{
"type": "string",
"description": "The minimum acceptable bid, in CPM, using US Dollars (as a string)"
}
]
},
"adunitcode": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,52 @@ public void makeHttpRequestsShouldSetBidFloorFromExtIfImpBidFloorIsMissed() {
.containsExactly(BigDecimal.TEN);
}

@Test
public void makeHttpRequestsShouldSetBidFloorFromExtOfStringIfImpBidFloorIsMissed() {
// given
final BidRequest bidRequest = givenBidRequest(impBuilder -> impBuilder
.banner(Banner.builder().format(singletonList(Format.builder().w(200).h(300).build()))
.w(200)
.h(300)
.build())
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpSovrn.of("tagid",
"legacyTagId", mapper.valueToTree("10.2"), "sovrn_auc")))));

// when
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getBody)
.extracting(SovrnBidderTest::mappedToBidRequest)
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getBidfloor)
.containsExactly(BigDecimal.valueOf(10.2));
}

@Test
public void makeHttpRequestsShouldNotSetBidFloorFromErroneousExtOfStringIfImpBidFloorIsMissed() {
// given
final BidRequest bidRequest = givenBidRequest(impBuilder -> impBuilder
.banner(Banner.builder().format(singletonList(Format.builder().w(200).h(300).build()))
.w(200)
.h(300)
.build())
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpSovrn.of("tagid",
"legacyTagId", mapper.valueToTree("error"), "sovrn_auc")))));

// when
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getBody)
.extracting(SovrnBidderTest::mappedToBidRequest)
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getBidfloor)
.containsOnlyNulls();
}

@Test
public void makeHttpRequestsShouldNotSetBidFloorFromExtIfImpBidFloorIsValid() {
// given
Expand Down Expand Up @@ -545,7 +591,7 @@ private static Imp givenImp(UnaryOperator<Imp.ImpBuilder> impCustomizer) {
.protocols(singletonList(1))
.build())
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpSovrn.of("tagid",
"legacyTagId", BigDecimal.TEN, "sovrn_auc")))))
"legacyTagId", mapper.valueToTree(10), "sovrn_auc")))))
.build();
}

Expand Down
Loading