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

YahooSSP adapter video support. #1779

Merged
merged 3 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
75 changes: 52 additions & 23 deletions src/main/java/org/prebid/server/bidder/yahoossp/YahooSSPBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.iab.openrtb.request.Format;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.request.Site;
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.vertx.core.MultiMap;
Expand Down Expand Up @@ -92,25 +93,6 @@ private ExtImpYahooSSP parseAndValidateImpExt(ObjectNode impExtNode, int index)
}

private static BidRequest modifyRequest(BidRequest request, Imp imp, ExtImpYahooSSP extImpYahooSSP) {
final Banner banner = imp.getBanner();
final boolean hasBanner = banner != null;

final Integer bannerWidth = hasBanner ? banner.getW() : null;
final Integer bannerHeight = hasBanner ? banner.getH() : null;
final boolean hasBannerWidthAndHeight = bannerWidth != null && bannerHeight != null;

if (hasBannerWidthAndHeight && (bannerWidth == 0 || bannerHeight == 0)) {
throw new PreBidException(String.format(
"Invalid sizes provided for Banner %sx%s", bannerWidth, bannerHeight));
}

final Imp.ImpBuilder impBuilder = imp.toBuilder()
.tagid(extImpYahooSSP.getPos());

if (hasBanner && !hasBannerWidthAndHeight) {
impBuilder.banner(modifyBanner(banner));
}

final BidRequest.BidRequestBuilder requestBuilder = request.toBuilder();

final Site site = request.getSite();
Expand All @@ -122,11 +104,36 @@ private static BidRequest modifyRequest(BidRequest request, Imp imp, ExtImpYahoo
}

return requestBuilder
.imp(Collections.singletonList(impBuilder.build()))
.imp(Collections.singletonList(modifyImp(imp, extImpYahooSSP)))
.build();
}

private static Imp modifyImp(Imp imp, ExtImpYahooSSP extImpYahooSSP) {
final Banner banner = imp.getBanner();
return imp.toBuilder()
.tagid(extImpYahooSSP.getPos())
.banner(banner != null ? modifyBanner(imp.getBanner()) : null)
.build();
}

private static void validateBanner(Banner banner) {
final Integer bannerWidth = banner.getW();
final Integer bannerHeight = banner.getH();
final boolean hasBannerWidthAndHeight = bannerWidth != null && bannerHeight != null;

if (hasBannerWidthAndHeight && (bannerWidth == 0 || bannerHeight == 0)) {
throw new PreBidException(String.format(
"Invalid sizes provided for Banner %sx%s", bannerWidth, bannerHeight));
}
}

private static Banner modifyBanner(Banner banner) {
validateBanner(banner);

if (banner.getH() != null && banner.getW() != null) {
return banner;
}

final List<Format> bannerFormats = banner.getFormat();
if (CollectionUtils.isEmpty(bannerFormats)) {
throw new PreBidException("No sizes provided for Banner");
Expand Down Expand Up @@ -187,17 +194,39 @@ private static List<BidderBid> bidsFromResponse(BidResponse bidResponse, List<Im
.map(SeatBid::getBid)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.filter(bid -> checkBid(bid.getImpid(), imps))
.map(bid -> BidderBid.of(bid, BidType.banner, bidResponse.getCur()))
.filter(Objects::nonNull)
.map(bid -> makeBidderBid(bid, imps, bidResponse.getCur()))
.filter(Objects::nonNull)
.collect(Collectors.toList());
}

private static BidderBid makeBidderBid(Bid bid, List<Imp> imps, String currency) {
final BidType bidType = getBidType(bid, imps);
return bidType != null
? BidderBid.of(bid, bidType, currency)
: null;
}

private static boolean checkBid(String bidImpId, List<Imp> imps) {
for (Imp imp : imps) {
if (imp.getId().equals(bidImpId)) {
return imp.getBanner() != null;
return imp.getBanner() != null || imp.getVideo() != null;
}
}
throw new PreBidException(String.format("Unknown ad unit code '%s'", bidImpId));
}
CTMBNara marked this conversation as resolved.
Show resolved Hide resolved

private static BidType getBidType(Bid bid, List<Imp> imps) {
for (Imp imp : imps) {
if (imp.getId().equals(bid.getImpid())) {
if (imp.getBanner() != null) {
return BidType.banner;
} else if (imp.getVideo() != null) {
return BidType.video;
}
return null;
}
}
throw new PreBidException(String.format("Unknown ad unit code '%s'", bid.getImpid()));
}
}
2 changes: 2 additions & 0 deletions src/main/resources/bidder-config/yahoossp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ adapters:
maintainer-email: dsp-supply-prebid@verizonmedia.com
app-media-types:
- banner
- video
site-media-types:
- banner
- video
supported-vendors:
vendor-id: 25
usersync:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.iab.openrtb.request.Format;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.request.Site;
import com.iab.openrtb.request.Video;
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
Expand Down Expand Up @@ -35,6 +36,7 @@
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.tuple;
import static org.prebid.server.proto.openrtb.ext.response.BidType.banner;
import static org.prebid.server.proto.openrtb.ext.response.BidType.video;

public class YahooSSPBidderTest extends VertxTest {

Expand Down Expand Up @@ -370,6 +372,31 @@ public void makeBidsShouldSkipNotBannerImpAndReturnBannerBidWhenBannerPresent()
.containsOnly(BidderBid.of(Bid.builder().impid("321").build(), banner, "USD"));
}

@Test
public void makeBidsShouldSkipNotSupportedImpAndReturnVideoBidWhenVideoPresent() throws JsonProcessingException {
// given
final HttpCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder()
.imp(asList(Imp.builder().id("123").build(),
Imp.builder().video(Video.builder().build()).id("321").build()))
.build(),
mapper.writeValueAsString(BidResponse.builder()
.cur("USD")
.seatbid(singletonList(SeatBid.builder()
.bid(asList(Bid.builder().impid("123").build(),
Bid.builder().impid("321").build()))
.build()))
.build()));

// when
final Result<List<BidderBid>> result = yahooSSPBidder.makeBids(httpCall, null);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsOnly(BidderBid.of(Bid.builder().impid("321").build(), video, "USD"));
}

private static BidRequest givenBidRequest(
Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer,
Function<BidRequest.BidRequestBuilder, BidRequest.BidRequestBuilder> requestCustomizer) {
Expand Down