From 2513438e6cf5201506ab68c9d8308c966a9c141a Mon Sep 17 00:00:00 2001 From: Anton Babak <76536883+AntoxaAntoxic@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:06:44 +0100 Subject: [PATCH] Rubicon Bidder: Add Bid Meta Seat Field (#3587) --- .../server/bidder/rubicon/RubiconBidder.java | 28 +++++++++++++------ .../ext/response/ExtBidPrebidMeta.java | 2 ++ .../bidder/rubicon/RubiconBidderTest.java | 28 +++++++++++++++++++ 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java b/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java index 031f7590475..a420efed87d 100644 --- a/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java +++ b/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java @@ -1617,19 +1617,27 @@ private List bidsFromResponse(BidRequest prebidRequest, } private RubiconSeatBid updateSeatBids(RubiconSeatBid seatBid, List 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 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 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 errors) { final ObjectNode bidExt = bid.getExt(); final ExtPrebid extPrebid; try { @@ -1640,9 +1648,13 @@ private RubiconBid insertNetworkIdToMeta(RubiconBid bid, int networkId, List secondaryCategoryIdList; + String seat; + } diff --git a/src/test/java/org/prebid/server/bidder/rubicon/RubiconBidderTest.java b/src/test/java/org/prebid/server/bidder/rubicon/RubiconBidderTest.java index 7658e5be17a..d49f874c0e8 100644 --- a/src/test/java/org/prebid/server/bidder/rubicon/RubiconBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/rubicon/RubiconBidderTest.java @@ -3305,6 +3305,34 @@ public void makeBidsShouldReplaceNotPresentAdmWithAdmNative() throws JsonProcess .containsExactly("{\"admNativeProperty\":\"admNativeValue\"}"); } + @Test + public void makeBidsShouldSetSeatToMetaSeat() throws JsonProcessingException { + // given + final BidderCall 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> 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