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

IX: bidder response enriched with FledgeAuctionConfig #2807

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
61 changes: 44 additions & 17 deletions src/main/java/org/prebid/server/bidder/ix/IxBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
import com.iab.openrtb.request.ntv.EventTrackingMethod;
import com.iab.openrtb.request.ntv.EventType;
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.EventTracker;
import com.iab.openrtb.response.Response;
import com.iab.openrtb.response.SeatBid;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.bidder.Bidder;
import org.prebid.server.bidder.ix.model.request.IxDiag;
import org.prebid.server.bidder.ix.model.response.IxBidResponse;
import org.prebid.server.bidder.ix.model.response.IxExtBidResponse;
import org.prebid.server.bidder.ix.model.response.NativeV11Wrapper;
import org.prebid.server.bidder.model.BidderBid;
import org.prebid.server.bidder.model.BidderCall;
import org.prebid.server.bidder.model.BidderError;
import org.prebid.server.bidder.model.CompositeBidderResponse;
import org.prebid.server.bidder.model.HttpRequest;
import org.prebid.server.bidder.model.Result;
import org.prebid.server.exception.PreBidException;
Expand All @@ -41,6 +43,7 @@
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebid;
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;
import org.prebid.server.util.ObjectUtil;
Expand Down Expand Up @@ -104,6 +107,21 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequ
return Result.of(httpRequests, errors);
}

@Override
public CompositeBidderResponse makeBidderResponse(BidderCall<BidRequest> httpCall, BidRequest bidRequest) {
try {
final IxBidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), IxBidResponse.class);
final List<BidderError> bidderErrors = new ArrayList<>();
return CompositeBidderResponse.builder()
.bids(extractIxBids(bidRequest, bidResponse, bidderErrors))
.fledgeAuctionConfigs(extractFledge(bidResponse))
.errors(bidderErrors)
.build();
} catch (DecodeException e) {
return CompositeBidderResponse.withError(BidderError.badServerResponse(e.getMessage()));
}
}

private ExtImpIx parseImpExt(Imp imp) {
try {
return mapper.mapper().convertValue(imp.getExt(), IX_EXT_TYPE_REFERENCE).getBidder();
Expand Down Expand Up @@ -226,24 +244,14 @@ private static Publisher modifyPublisher(Publisher publisher, String id) {
}

@Override
@Deprecated(since = "Not used, since Bidder.makeBidderResponse(...) was overridden.")
public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) {
VeryExtraordinaryUsername marked this conversation as resolved.
Show resolved Hide resolved
try {
final List<BidderError> errors = new ArrayList<>();
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
final BidRequest payload = httpCall.getRequest().getPayload();
return Result.of(extractBids(bidResponse, payload, errors), errors);
} catch (DecodeException e) {
return Result.withError(BidderError.badServerResponse(e.getMessage()));
}
}

private List<BidderBid> extractBids(BidResponse bidResponse, BidRequest bidRequest, List<BidderError> errors) {
return bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())
? Collections.emptyList()
: bidsFromResponse(bidResponse, bidRequest, errors);
return Result.withError(BidderError.generic("Invalid method call"));
}

private List<BidderBid> bidsFromResponse(BidResponse bidResponse, BidRequest bidRequest, List<BidderError> errors) {
private List<BidderBid> bidsFromResponse(IxBidResponse bidResponse,
BidRequest bidRequest,
List<BidderError> errors) {
return bidResponse.getSeatbid().stream()
.filter(Objects::nonNull)
.map(SeatBid::getBid)
Expand All @@ -254,7 +262,7 @@ private List<BidderBid> bidsFromResponse(BidResponse bidResponse, BidRequest bid
.toList();
}

private BidderBid toBidderBid(Bid bid, BidRequest bidRequest, BidResponse bidResponse, List<BidderError> errors) {
private BidderBid toBidderBid(Bid bid, BidRequest bidRequest, IxBidResponse bidResponse, List<BidderError> errors) {
final BidType bidType;
try {
bidType = getBidType(bid, bidRequest.getImp());
Expand Down Expand Up @@ -384,4 +392,23 @@ private ObjectNode resolveBidExt(Integer duration) {
.video(ExtBidPrebidVideo.of(duration, null))
.build());
}

private List<BidderBid> extractIxBids(BidRequest bidRequest,
IxBidResponse bidResponse,
List<BidderError> bidderErrors) {
return bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())
? Collections.emptyList()
: bidsFromResponse(bidResponse, bidRequest, bidderErrors);
}

private List<FledgeAuctionConfig> extractFledge(IxBidResponse bidResponse) {
return Optional.ofNullable(bidResponse)
.map(IxBidResponse::getExt)
.map(IxExtBidResponse::getFledgeAuctionConfigs)
.orElse(Collections.emptyMap())
.entrySet()
.stream()
.map(e -> FledgeAuctionConfig.builder().impId(e.getKey()).config(e.getValue()).build())
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.prebid.server.bidder.ix.model.response;

import com.iab.openrtb.response.SeatBid;
import lombok.Builder;
import lombok.Value;

import java.util.List;

@Builder(toBuilder = true)
@Value
public class IxBidResponse {
VeryExtraordinaryUsername marked this conversation as resolved.
Show resolved Hide resolved

String id;

List<SeatBid> seatbid;

String bidid;

String cur;

String customdata;

Integer nbr;

IxExtBidResponse ext;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.prebid.server.bidder.ix.model.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Value;

import java.util.Map;

@Value(staticConstructor = "of")
public class IxExtBidResponse {

@JsonProperty("fledge_auction_configs")
Map<String, ObjectNode> fledgeAuctionConfigs;

}
Loading
Loading