Skip to content
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 @@ -1595,8 +1595,10 @@ private ObjectNode prepareBidExt(RubiconBid bid,
final Integer networkId = resolveNetworkId(seatBid);
final String seat = seatBid.getSeat();
final String rendererUrl = resolveRendererUrl(imp, meta, bidType, hasApexRenderer);
final List<String> advertiserDomains = bid.getAdomain();
final Integer advertiserId = resolveAdvertiserId(bidExt);

if (ObjectUtils.allNull(networkId, rendererUrl, seat)) {
if (ObjectUtils.allNull(networkId, rendererUrl, seat, advertiserDomains, advertiserId)) {
return bidExt;
}

Expand All @@ -1606,6 +1608,8 @@ private ObjectNode prepareBidExt(RubiconBid bid,
.networkId(networkId)
.seat(seat)
.rendererUrl(rendererUrl)
.advertiserId(advertiserId)
.advertiserDomains(advertiserDomains)
.build();

final ExtBidPrebid modifiedExtBidPrebid = extBidPrebid != null
Expand Down Expand Up @@ -1652,6 +1656,31 @@ private static Boolean isVideoMetaMediaType(ExtBidPrebidMeta meta) {
.orElse(false);
}

private static Integer resolveAdvertiserId(ObjectNode bidExt) {
return Optional.ofNullable(bidExt)
.map(ext -> ext.get("rp"))
.filter(JsonNode::isObject)
.map(rp -> rp.get("advid"))
.map(RubiconBidder::convertToInt)
.orElse(null);
}

private static Integer convertToInt(JsonNode jsonNode) {
if (jsonNode.canConvertToInt()) {
return jsonNode.asInt();
}

if (jsonNode.isTextual()) {
try {
return Integer.parseInt(jsonNode.asText());
Copy link
Contributor

Choose a reason for hiding this comment

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

Using exceptions for control flow can burn quite a lot of CPU power, due to exceptions being created and immediately thrown away.

I would recommend first checking if the text node can be converted to an Int and then parse it. Feel free to read the blog post I wrote, when I got hit very hard by this 😅 https://medium.com/@muuki88/follow-the-stacktraces-jvm-performance-profiling-3c371d323e5f

} catch (NumberFormatException e) {
return null;
}
}

return null;
}

private String resolveBidId(Imp rubiconImp, RubiconBid bid) {
return generateBidId
? Optional.ofNullable(rubiconImp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3430,6 +3430,62 @@ public void makeBidsShouldSetSeatToMetaSeat() throws JsonProcessingException {
.containsExactly(expectedBidExt);
}

@Test
public void makeBidsShouldSetBidExtRpAdvidToMetaAdvertiserId() throws JsonProcessingException {
// given
final ObjectNode givenBidExt = mapper.createObjectNode()
.set("rp", mapper.createObjectNode().put("advid", "1"));

final BidderCall<BidRequest> httpCall = givenHttpCall(
givenBidRequest(identity()),
mapper.writeValueAsString(RubiconBidResponse.builder()
.cur("USD")
.seatbid(singletonList(RubiconSeatBid.builder()
.bid(singletonList(givenRubiconBid(bid -> bid.ext(givenBidExt))))
.build()))
.build()));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, givenBidRequest(identity()));

// then
final ObjectNode expectedBidExt = givenBidExt.deepCopy()
.set("prebid", mapper.createObjectNode()
.set("meta", mapper.createObjectNode().put("advertiserId", 1)));
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.extracting(BidderBid::getBid)
.extracting(Bid::getExt)
.containsExactly(expectedBidExt);
}

@Test
public void makeBidsShouldSetBidAdomainToMetaAdvertiserDomains() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(
givenBidRequest(identity()),
mapper.writeValueAsString(RubiconBidResponse.builder()
.cur("USD")
.seatbid(singletonList(RubiconSeatBid.builder()
.bid(singletonList(givenRubiconBid(bid -> bid.adomain(List.of("A", "B")))))
.build()))
.build()));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, givenBidRequest(identity()));

// then
final ObjectNode expectedBidExt = mapper.valueToTree(
ExtPrebid.of(ExtBidPrebid.builder()
.meta(ExtBidPrebidMeta.builder().advertiserDomains(List.of("A", "B")).build())
.build(), null));
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.extracting(BidderBid::getBid)
.extracting(Bid::getExt)
.containsExactly(expectedBidExt);
}

@Test
public void makeBidsShouldSetSeatBuyerToMetaNetworkId() throws JsonProcessingException {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"w": 300,
"h": 250,
"ext": {
"rp": {
"advid": "1"
},
"prebid": {
"meta": {
"advertiserId": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
"h": 250,
"w": 300,
"ext": {
"rp": {
"advid": "1"
},
"prebid": {
"meta": {
"advertiserId": 1,
"secondaryCatIds": [
"id1",
"id2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"w": 300,
"h": 250,
"ext": {
"rp": {
"advid": "1"
},
"prebid": {
"meta": {
"advertiserId": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
"h": 250,
"w": 300,
"ext": {
"rp": {
"advid": "1"
},
"prebid": {
"meta": {
"advertiserId": 1,
"secondaryCatIds": [
"id1",
"id2"
Expand Down
Loading