Skip to content

Commit

Permalink
Rubicon Bidder: Add Bid Meta Seat Field (#3587)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoxaAntoxic authored Dec 10, 2024
1 parent c5b85c3 commit 2513438
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1617,19 +1617,27 @@ private List<BidderBid> bidsFromResponse(BidRequest prebidRequest,
}

private RubiconSeatBid updateSeatBids(RubiconSeatBid seatBid, List<BidderError> errors) {
final String buyer = seatBid.getBuyer();
final int networkId = NumberUtils.toInt(buyer, 0);
if (networkId <= 0) {
final Integer networkId = resolveNetworkId(seatBid);
final String seat = seatBid.getSeat();

if (networkId == null && seat == null) {
return seatBid;
}

final List<RubiconBid> updatedBids = seatBid.getBid().stream()
.map(bid -> insertNetworkIdToMeta(bid, networkId, errors))
.map(bid -> prepareBidMeta(bid, seat, networkId, errors))
.filter(Objects::nonNull)
.toList();
return seatBid.toBuilder().bid(updatedBids).build();
}

private RubiconBid insertNetworkIdToMeta(RubiconBid bid, int networkId, List<BidderError> errors) {
private static Integer resolveNetworkId(RubiconSeatBid seatBid) {
final String buyer = seatBid.getBuyer();
final int networkId = NumberUtils.toInt(buyer, 0);
return networkId <= 0 ? null : networkId;
}

private RubiconBid prepareBidMeta(RubiconBid bid, String seat, Integer networkId, List<BidderError> errors) {
final ObjectNode bidExt = bid.getExt();
final ExtPrebid<ExtBidPrebid, ObjectNode> extPrebid;
try {
Expand All @@ -1640,9 +1648,13 @@ private RubiconBid insertNetworkIdToMeta(RubiconBid bid, int networkId, List<Bid
}
final ExtBidPrebid extBidPrebid = extPrebid != null ? extPrebid.getPrebid() : null;
final ExtBidPrebidMeta meta = extBidPrebid != null ? extBidPrebid.getMeta() : null;
final ExtBidPrebidMeta updatedMeta = meta != null
? meta.toBuilder().networkId(networkId).build()
: ExtBidPrebidMeta.builder().networkId(networkId).build();

final ExtBidPrebidMeta updatedMeta = Optional.ofNullable(meta)
.map(ExtBidPrebidMeta::toBuilder)
.orElseGet(ExtBidPrebidMeta::builder)
.networkId(networkId)
.seat(seat)
.build();

final ExtBidPrebid modifiedExtBidPrebid = extBidPrebid != null
? extBidPrebid.toBuilder().meta(updatedMeta).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ public class ExtBidPrebidMeta {
@JsonProperty("secondaryCatIds")
List<String> secondaryCategoryIdList;

String seat;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3305,6 +3305,34 @@ public void makeBidsShouldReplaceNotPresentAdmWithAdmNative() throws JsonProcess
.containsExactly("{\"admNativeProperty\":\"admNativeValue\"}");
}

@Test
public void makeBidsShouldSetSeatToMetaSeat() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(
givenBidRequest(identity()),
mapper.writeValueAsString(RubiconBidResponse.builder()
.cur("USD")
.seatbid(singletonList(RubiconSeatBid.builder()
.seat("seat")
.bid(singletonList(givenRubiconBid(bid -> bid.price(ONE))))
.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().seat("seat").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

0 comments on commit 2513438

Please sign in to comment.