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 3 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
34 changes: 33 additions & 1 deletion src/main/java/org/prebid/server/bidder/ix/IxBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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 +42,10 @@
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.ExtBidResponse;
import org.prebid.server.proto.openrtb.ext.response.ExtBidResponseFledge;
import org.prebid.server.proto.openrtb.ext.response.ExtBidResponsePrebid;
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 +109,16 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequ
return Result.of(httpRequests, errors);
}

@Override
public CompositeBidderResponse makeBidderResponse(BidderCall<BidRequest> httpCall, BidRequest bidRequest) {
try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return CompositeBidderResponse.withBids(extractIxBids(bidRequest, bidResponse), extractFledge(bidResponse));
} 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 @@ -243,7 +258,9 @@ private List<BidderBid> extractBids(BidResponse bidResponse, BidRequest bidReque
: bidsFromResponse(bidResponse, bidRequest, errors);
}

private List<BidderBid> bidsFromResponse(BidResponse bidResponse, BidRequest bidRequest, List<BidderError> errors) {
private List<BidderBid> bidsFromResponse(BidResponse bidResponse,
VeryExtraordinaryUsername marked this conversation as resolved.
Show resolved Hide resolved
BidRequest bidRequest,
List<BidderError> errors) {
return bidResponse.getSeatbid().stream()
.filter(Objects::nonNull)
.map(SeatBid::getBid)
Expand Down Expand Up @@ -384,4 +401,19 @@ private ObjectNode resolveBidExt(Integer duration) {
.video(ExtBidPrebidVideo.of(duration, null))
.build());
}

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

private List<FledgeAuctionConfig> extractFledge(BidResponse bidResponse) {
VeryExtraordinaryUsername marked this conversation as resolved.
Show resolved Hide resolved
return Optional.ofNullable(bidResponse)
.map(BidResponse::getExt)
.map(ExtBidResponse::getPrebid)
.map(ExtBidResponsePrebid::getFledge)
.map(ExtBidResponseFledge::getAuctionConfigs)
.orElse(Collections.emptyList());
}
}
46 changes: 46 additions & 0 deletions src/test/java/org/prebid/server/bidder/ix/IxBidderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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.HttpResponse;
import org.prebid.server.bidder.model.Result;
Expand All @@ -43,6 +44,10 @@
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.ExtBidResponse;
import org.prebid.server.proto.openrtb.ext.response.ExtBidResponseFledge;
import org.prebid.server.proto.openrtb.ext.response.ExtBidResponsePrebid;
import org.prebid.server.proto.openrtb.ext.response.FledgeAuctionConfig;
import org.prebid.server.version.PrebidVersionProvider;

import java.util.List;
Expand All @@ -56,6 +61,7 @@
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.BDDMockito.given;
import static org.prebid.server.proto.openrtb.ext.response.BidType.banner;

public class IxBidderTest extends VertxTest {

Expand Down Expand Up @@ -749,6 +755,46 @@ public void makeBidsShouldReturnCorrectTypeExtPrebidTypeInResponse() throws Json
.containsExactly(BidType.video);
}

@Test
public void makeBidderResponseShouldReturnFledgeAuctionConfig() throws JsonProcessingException {
// given
final String impId = "imp_id";
final BidResponse bidResponse = givenBidResponse(bidBuilder -> bidBuilder.impid(impId).mtype(1));
final ObjectNode fledgeConfigNode = mapper.createObjectNode();
final BidRequest bidRequest = BidRequest.builder()
.imp(List.of(Imp.builder().id(impId).build()))
.build();
final FledgeAuctionConfig fledgeAuctionConfig = FledgeAuctionConfig.builder()
.impId(impId)
.config(fledgeConfigNode)
.build();
final ExtBidResponseFledge extBidResponseFledge = ExtBidResponseFledge.of(List.of(fledgeAuctionConfig));
final ExtBidResponsePrebid extBidResponsePrebid = ExtBidResponsePrebid.builder()
.fledge(extBidResponseFledge)
.build();
final ExtBidResponse extBidResponse = ExtBidResponse.builder().prebid(extBidResponsePrebid).build();
final BidResponse bidResponseWithFledge = BidResponse.builder()
.cur(bidResponse.getCur())
.seatbid(bidResponse.getSeatbid())
.ext(extBidResponse)
.build();
final BidderCall<BidRequest> httpCall =
givenHttpCall(bidRequest, mapper.writeValueAsString(bidResponseWithFledge));

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

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getBids())
.containsOnly(BidderBid.of(Bid.builder().impid(impId).mtype(1).build(), banner, bidResponse.getCur()));
final FledgeAuctionConfig expectedFledge = FledgeAuctionConfig.builder()
.impId(impId)
.config(fledgeConfigNode)
.build();
assertThat(result.getFledgeAuctionConfigs()).containsExactly(expectedFledge);
}

private static ExtRequest givenExtRequest(String pbjsv) {
return ExtRequest.of(ExtRequestPrebid.builder()
.channel(ExtRequestPrebidChannel.of("pbjs", pbjsv))
Expand Down
Loading