Skip to content

Commit

Permalink
OpenX: Populate BidderBid.videoInfo for targeting (#3364)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurb9 authored Aug 9, 2024
1 parent 075fd90 commit b93c5ce
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main/java/org/prebid/server/bidder/openx/OpenxBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.prebid.server.proto.openrtb.ext.request.ExtRequest;
import org.prebid.server.proto.openrtb.ext.request.openx.ExtImpOpenx;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebidVideo;
import org.prebid.server.proto.openrtb.ext.response.FledgeAuctionConfig;
import org.prebid.server.util.BidderUtil;
import org.prebid.server.util.HttpUtil;
Expand Down Expand Up @@ -253,10 +254,26 @@ private static List<BidderBid> bidsFromResponse(BidRequest bidRequest, OpenxBidR
.map(SeatBid::getBid)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.map(bid -> BidderBid.of(bid, getBidType(bid, impIdToBidType), bidCurrency))
.map(bid -> toBidderBid(bid, impIdToBidType, bidCurrency))
.toList();
}

private static BidderBid toBidderBid(Bid bid, Map<String, BidType> impIdToBidType, String bidCurrency) {
final BidType bidType = getBidType(bid, impIdToBidType);
final ExtBidPrebidVideo videoInfo = bidType == BidType.video ? getVideoInfo(bid) : null;
return BidderBid.builder()
.bid(bid)
.type(bidType)
.bidCurrency(bidCurrency)
.videoInfo(videoInfo)
.build();
}

private static ExtBidPrebidVideo getVideoInfo(Bid bid) {
final String primaryCategory = CollectionUtils.isEmpty(bid.getCat()) ? null : bid.getCat().getFirst();
return ExtBidPrebidVideo.of(bid.getDur(), primaryCategory);
}

private static Map<String, BidType> impIdToBidType(BidRequest bidRequest) {
return bidRequest.getImp().stream()
.collect(Collectors.toMap(Imp::getId, imp -> imp.getBanner() != null ? BidType.banner : BidType.video));
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/org/prebid/server/bidder/openx/OpenxBidderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.prebid.server.proto.openrtb.ext.request.ExtUser;
import org.prebid.server.proto.openrtb.ext.request.openx.ExtImpOpenx;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebidVideo;
import org.prebid.server.proto.openrtb.ext.response.FledgeAuctionConfig;

import java.math.BigDecimal;
Expand Down Expand Up @@ -522,6 +523,42 @@ public void makeBidsShouldReturnResultWithExpectedFields() throws JsonProcessing
.build());
}

@Test
public void makeBidsShouldReturnVideoInfoWhenAvailable() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(mapper.writeValueAsString(BidResponse.builder()
.seatbid(singletonList(SeatBid.builder()
.bid(singletonList(Bid.builder()
.w(200)
.h(150)
.price(BigDecimal.ONE)
.impid("impId1")
.dealid("dealid")
.adm("<div>This is an Ad</div>")
.dur(30)
.cat(singletonList("category1"))
.build()))
.build()))
.build()));

final BidRequest bidRequest = BidRequest.builder()
.id("bidRequestId")
.imp(singletonList(Imp.builder()
.id("impId1")
.video(Video.builder().build())
.build()))
.build();

// when
final CompositeBidderResponse result = target.makeBidderResponse(httpCall, bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getBids()).hasSize(1)
.extracting(BidderBid::getVideoInfo)
.containsExactly(ExtBidPrebidVideo.of(30, "category1"));
}

@Test
public void makeBidsShouldReturnFledgeConfigEvenIfNoBids() throws JsonProcessingException {
// given
Expand Down

0 comments on commit b93c5ce

Please sign in to comment.