Open
Conversation
CTMBNara
requested changes
Feb 19, 2026
Comment on lines
+71
to
84
| private ExtImpResetDigital parseImpExt(Imp imp) { | ||
| try { | ||
| final BigDecimal convertedPrice = currencyConversionService | ||
| .convertCurrency(bidFloorPrice.getValue(), bidRequest, bidFloorCur, DEFAULT_CURRENCY); | ||
| final ExtPrebid<?, ExtImpResetDigital> extPrebid = mapper.mapper() | ||
| .convertValue(imp.getExt(), EXT_TYPE_REFERENCE); | ||
|
|
||
| return Price.of(DEFAULT_CURRENCY, convertedPrice); | ||
| } catch (PreBidException e) { | ||
| throw new PreBidException( | ||
| "Unable to convert provided bid floor currency from %s to %s for imp `%s`" | ||
| .formatted(bidFloorCur, DEFAULT_CURRENCY, impId)); | ||
| } | ||
| } | ||
| if (extPrebid == null || extPrebid.getBidder() == null) { | ||
| throw new PreBidException("imp.ext.bidder is required"); | ||
| } | ||
|
|
||
| private static void populateBannerImps(List<Imp> bannerImps, Price bidFloorPrice, Imp imp) { | ||
| if (imp.getBanner() != null) { | ||
| final Imp bannerImp = imp.toBuilder().video(null).xNative(null).audio(null).build(); | ||
| bannerImps.add(modifyImp(bannerImp, bidFloorPrice)); | ||
| return extPrebid.getBidder(); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new PreBidException("Error parsing resetDigitalExt from imp.ext: " + e.getMessage()); | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
private ExtImpResetDigital parseImpExt(Imp imp) {
try {
return mapper.mapper().convertValue(imp.getExt(), EXT_TYPE_REFERENCE).getBidder();
} catch (IllegalArgumentException e) {
throw new PreBidException("Error parsing resetDigitalExt from imp.ext: " + e.getMessage());
}
}
| populateBannerImps(bannerImps, bidFloorPrice, imp); | ||
| populateVideoImps(videoImps, bidFloorPrice, imp); | ||
| populateAudiImps(audioImps, bidFloorPrice, imp); | ||
| if (CollectionUtils.isEmpty(request.getImp()) || request.getImp().size() != 1) { |
Comment on lines
+86
to
+93
| private static Imp modifyImp(Imp imp, ExtImpResetDigital extImp) { | ||
| final Imp.ImpBuilder impBuilder = imp.toBuilder(); | ||
|
|
||
| private static void populateAudiImps(List<Imp> audioImps, Price bidFloorPrice, Imp imp) { | ||
| if (imp.getAudio() != null) { | ||
| final Imp audioImp = imp.toBuilder().banner(null).xNative(null).video(null).build(); | ||
| audioImps.add(modifyImp(audioImp, bidFloorPrice)); | ||
| if (StringUtils.isBlank(imp.getTagid())) { | ||
| impBuilder.tagid(extImp.getPlacementId()); | ||
| } | ||
|
|
||
| return impBuilder.build(); |
Collaborator
There was a problem hiding this comment.
private static Imp modifyImp(Imp imp, ExtImpResetDigital extImp) {
return StringUtils.isBlank(imp.getTagid())
? imp.toBuilder().tagid(extImp.getPlacementId()).build()
: imp;
}
| : initialBidFloorPrice; | ||
| final String uri = endpointUrl + "?pid=" + HttpUtil.encodeUrl(extImp.getPlacementId()); | ||
|
|
||
| return Result.withValue(BidderUtil.defaultRequest(outgoingRequest, uri, mapper)); |
Collaborator
There was a problem hiding this comment.
Add "X-OpenRTB-Version" header
Comment on lines
+106
to
+175
| private static Result<List<BidderBid>> extractBids(BidResponse bidResponse, BidRequest bidRequest) { | ||
| if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { | ||
| return Collections.emptyList(); | ||
| } | ||
| if (bidResponse.getCur() != null && !StringUtils.equalsIgnoreCase(DEFAULT_CURRENCY, bidResponse.getCur())) { | ||
| throw new PreBidException("Bidder support only USD currency"); | ||
| return Result.withValues(Collections.emptyList()); | ||
| } | ||
| return bidsFromResponse(bidResponse, bidRequest); | ||
| } | ||
|
|
||
| private static List<BidderBid> bidsFromResponse(BidResponse bidResponse, BidRequest bidRequest) { | ||
| return bidResponse.getSeatbid().stream() | ||
| .filter(Objects::nonNull) | ||
| .map(SeatBid::getBid) | ||
| .filter(Objects::nonNull) | ||
| .flatMap(Collection::stream) | ||
| .map(bid -> BidderBid.of(bid, getBidType(bid, bidRequest.getImp()), DEFAULT_CURRENCY)) | ||
| .toList(); | ||
| final String currency = StringUtils.isNotBlank(bidResponse.getCur()) | ||
| ? bidResponse.getCur() | ||
| : DEFAULT_CURRENCY; | ||
|
|
||
| return bidsFromResponse(bidResponse, bidRequest, currency); | ||
| } | ||
|
|
||
| private static BidType getBidType(Bid bid, List<Imp> imps) { | ||
| final String impId = bid.getImpid(); | ||
| for (Imp imp : imps) { | ||
| if (imp.getId().equals(impId)) { | ||
| if (imp.getBanner() != null) { | ||
| return BidType.banner; | ||
| } else if (imp.getVideo() != null) { | ||
| return BidType.video; | ||
| } else if (imp.getAudio() != null) { | ||
| return BidType.audio; | ||
| private static Result<List<BidderBid>> bidsFromResponse(BidResponse bidResponse, | ||
| BidRequest bidRequest, | ||
| String currency) { | ||
| final List<BidderBid> bids = new ArrayList<>(); | ||
| final List<BidderError> errors = new ArrayList<>(); | ||
|
|
||
| for (SeatBid seatBid : bidResponse.getSeatbid()) { | ||
| if (seatBid == null || seatBid.getBid() == null) { | ||
| continue; | ||
| } | ||
| for (Bid bid : seatBid.getBid()) { | ||
| if (!BidderUtil.isValidPrice(bid.getPrice())) { | ||
| errors.add(BidderError.badServerResponse( | ||
| "price %s <= 0 filtered out".formatted(bid.getPrice()))); | ||
| continue; | ||
| } | ||
|
|
||
| try { | ||
| final BidType bidType = getBidType(bid, bidRequest); | ||
| bids.add(BidderBid.of(bid, bidType, currency)); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
| } | ||
| } | ||
| throw new PreBidException("Failed to find banner/video/audio impression " + impId); | ||
|
|
||
| return Result.of(bids, errors); | ||
| } | ||
|
|
||
| private static BidType getBidType(Bid bid, BidRequest bidRequest) { | ||
| final Integer mtype = bid.getMtype(); | ||
| if (mtype != null) { | ||
| return switch (mtype) { | ||
| case 1 -> BidType.banner; | ||
| case 2 -> BidType.video; | ||
| case 3 -> BidType.audio; | ||
| case 4 -> BidType.xNative; | ||
| default -> throw new PreBidException("Unsupported MType: " + mtype); | ||
| }; | ||
| } | ||
|
|
||
| final Imp imp = bidRequest.getImp().getFirst(); | ||
| if (!imp.getId().equals(bid.getImpid())) { | ||
| throw new PreBidException("No matching impression found for ImpID: " + bid.getImpid()); | ||
| } | ||
|
|
||
| return getMediaType(imp); | ||
| } | ||
|
|
||
| private static BidType getMediaType(Imp imp) { | ||
| if (imp.getVideo() != null) { | ||
| return BidType.video; | ||
| } else if (imp.getAudio() != null) { | ||
| return BidType.audio; | ||
| } else if (imp.getXNative() != null) { | ||
| return BidType.xNative; | ||
| } | ||
| return BidType.banner; |
Collaborator
There was a problem hiding this comment.
@Override
public final Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) {
try {
final List<BidderError> errors = new ArrayList<>();
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return Result.of(extractBids(bidResponse, httpCall.getRequest().getPayload(), errors), errors);
} catch (DecodeException | PreBidException e) {
return Result.withError(BidderError.badServerResponse(e.getMessage()));
}
}
private static List<BidderBid> extractBids(BidResponse bidResponse,
BidRequest bidRequest,
List<BidderError> errors) {
if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) {
return Collections.emptyList();
}
final Imp imp = bidRequest.getImp().getFirst();
final String currency = StringUtils.isNotBlank(bidResponse.getCur())
? bidResponse.getCur()
: bidRequest.getCur().stream().findFirst().orElse(DEFAULT_CURRENCY);
final List<BidderBid> bidderBids = new ArrayList<>();
for (SeatBid seatBid : bidResponse.getSeatbid()) {
if (seatBid == null || CollectionUtils.isEmpty(seatBid.getBid())) {
continue;
}
for (Bid bid : seatBid.getBid()) {
try {
bidderBids.add(makeBidderBid(bid, seatBid.getSeat(), currency, imp));
} catch (PreBidException e) {
errors.add(BidderError.badServerResponse(e.getMessage()));
}
}
}
return bidderBids;
}
private static BidderBid makeBidderBid(Bid bid, String seat, String currency, Imp imp) {
if (!BidderUtil.isValidPrice(bid.getPrice())) {
throw new PreBidException("price %s <= 0 filtered out".formatted(bid.getPrice()));
}
final BidType bidType = Optional.ofNullable(getBidType(bid))
.orElseGet(() -> getBidType(bid, imp));
return StringUtils.isNotBlank(seat)
? BidderBid.of(bid, bidType, seat, currency)
: BidderBid.of(bid, bidType, currency);
}
private static BidType getBidType(Bid bid) {
final Integer mtype = bid.getMtype();
return switch (mtype) {
case 1 -> BidType.banner;
case 2 -> BidType.video;
case 3 -> BidType.audio;
case 4 -> BidType.xNative;
case null -> null;
default -> throw new PreBidException("Unsupported MType: " + mtype);
};
}
private static BidType getBidType(Bid bid, Imp imp) {
if (!imp.getId().equals(bid.getImpid())) {
throw new PreBidException("No matching impression found for ImpID: " + bid.getImpid());
}
if (imp.getVideo() != null) {
return BidType.video;
} else if (imp.getAudio() != null) {
return BidType.audio;
} else if (imp.getXNative() != null) {
return BidType.xNative;
}
return BidType.banner;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔧 Type of changes
✨ What's the context?
#4340