-
Notifications
You must be signed in to change notification settings - Fork 224
OMS: add video support #3779
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
OMS: add video support #3779
Changes from 2 commits
d87670e
6459db5
f32d656
ed5230c
057d343
2d95af3
cef4cb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| package org.prebid.server.bidder.oms; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.iab.openrtb.request.BidRequest; | ||
| import com.iab.openrtb.request.Imp; | ||
| import com.iab.openrtb.response.Bid; | ||
| import com.iab.openrtb.response.BidResponse; | ||
| import com.iab.openrtb.response.SeatBid; | ||
| import org.apache.commons.collections4.CollectionUtils; | ||
|
|
@@ -10,9 +13,13 @@ | |
| import org.prebid.server.bidder.model.BidderError; | ||
| import org.prebid.server.bidder.model.HttpRequest; | ||
| import org.prebid.server.bidder.model.Result; | ||
| import org.prebid.server.exception.PreBidException; | ||
| import org.prebid.server.json.DecodeException; | ||
| import org.prebid.server.json.JacksonMapper; | ||
| import org.prebid.server.proto.openrtb.ext.ExtPrebid; | ||
| import org.prebid.server.proto.openrtb.ext.request.omx.ExtImpOms; | ||
| import org.prebid.server.proto.openrtb.ext.response.BidType; | ||
| import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebidVideo; | ||
| import org.prebid.server.util.BidderUtil; | ||
| import org.prebid.server.util.HttpUtil; | ||
|
|
||
|
|
@@ -23,6 +30,8 @@ | |
|
|
||
| public class OmsBidder implements Bidder<BidRequest> { | ||
|
|
||
| private static final TypeReference<ExtPrebid<?, ExtImpOms>> EXT_TYPE_REFERENCE = new TypeReference<>() { | ||
| }; | ||
| private final String endpointUrl; | ||
| private final JacksonMapper mapper; | ||
|
|
||
|
|
@@ -32,16 +41,39 @@ public OmsBidder(String endpointUrl, JacksonMapper mapper) { | |
| } | ||
|
|
||
| @Override | ||
| public final Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequest) { | ||
| return Result.withValue(BidderUtil.defaultRequest(bidRequest, endpointUrl, mapper)); | ||
| public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request) { | ||
| if (!request.getImp().isEmpty()) { | ||
| try { | ||
| final ExtImpOms impExt = parseImpExt(request.getImp().getFirst()); | ||
| final String publisherId = impExt.getPid() == null | ||
CTMBNara marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| && impExt.getPublisherId() != null | ||
| && impExt.getPublisherId() > 0 | ||
| ? String.valueOf(impExt.getPublisherId()) | ||
| : impExt.getPid(); | ||
CTMBNara marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
CTMBNara marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| final String url = "%s?publisherId=%s".formatted(endpointUrl, publisherId); | ||
| return Result.withValue(BidderUtil.defaultRequest(request, url, mapper)); | ||
| } catch (PreBidException e) { | ||
| return Result.withError(BidderError.badInput(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| return Result.withValue(BidderUtil.defaultRequest(request, endpointUrl, mapper)); | ||
| } | ||
|
|
||
| private ExtImpOms parseImpExt(Imp imp) throws PreBidException { | ||
| try { | ||
| return mapper.mapper().convertValue(imp.getExt(), EXT_TYPE_REFERENCE).getBidder(); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new PreBidException("Invalid ext. Imp.Id: " + imp.getId()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public final Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
| try { | ||
| final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
| return Result.withValues(extractBids(bidResponse)); | ||
| } catch (DecodeException e) { | ||
| } catch (DecodeException | PreBidException e) { | ||
|
||
| return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
| } | ||
|
|
@@ -59,7 +91,37 @@ private static List<BidderBid> bidsFromResponse(BidResponse bidResponse) { | |
| .map(SeatBid::getBid) | ||
| .filter(Objects::nonNull) | ||
| .flatMap(Collection::stream) | ||
| .map(bid -> BidderBid.of(bid, BidType.banner, bidResponse.getCur())) | ||
| .map(bid -> BidderBid.builder() | ||
| .bid(bid) | ||
| .type(getBidType(bid)) | ||
| .bidCurrency(bidResponse.getCur()) | ||
| .videoInfo(videoInfo(bid)) | ||
| .build()) | ||
| .toList(); | ||
| } | ||
|
|
||
| private static BidType getBidType(Bid bid) { | ||
| final Integer markupType = bid.getMtype(); | ||
| return switch (markupType) { | ||
| case 1 -> BidType.banner; | ||
| case 2 -> BidType.video; | ||
| case null, default -> BidType.banner; | ||
| }; | ||
| } | ||
|
|
||
| private static ExtBidPrebidVideo videoInfo(Bid bid) { | ||
| if (!Integer.valueOf(2).equals(bid.getMtype())) { | ||
|
||
| return null; | ||
| } | ||
| final List<String> cat = bid.getCat(); | ||
| final Integer duration = bid.getDur(); | ||
|
|
||
| final boolean catNotEmpty = CollectionUtils.isNotEmpty(cat); | ||
| final boolean durationValid = duration != null && duration > 0; | ||
| return catNotEmpty || durationValid | ||
| ? ExtBidPrebidVideo.of( | ||
| durationValid ? duration : null, | ||
| catNotEmpty ? cat.getFirst() : null) | ||
| : null; | ||
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package org.prebid.server.proto.openrtb.ext.request.omx; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.Value; | ||
|
|
||
| @Value(staticConstructor = "of") | ||
| public class ExtImpOms { | ||
|
|
||
| String pid; | ||
| @JsonProperty("publisherId") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an empty line |
||
| Integer publisherId; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add JsonProperty also I would change the integration test payload to cover
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have cheanged pid to publisherId but IMO its indifferent
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant, it makes sense to add a publisherId to the test instead of deprecated pid, but pid is still can be used, it's deprecated, not removed, please revert this change |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.