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 1 commit
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
42 changes: 37 additions & 5 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,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 IxBidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), IxBidResponse.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 @@ -229,21 +242,23 @@ private static Publisher modifyPublisher(Publisher publisher, String id) {
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 IxBidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), IxBidResponse.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) {
private List<BidderBid> extractBids(IxBidResponse bidResponse, BidRequest bidRequest, List<BidderError> errors) {
return bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())
? Collections.emptyList()
: bidsFromResponse(bidResponse, bidRequest, errors);
}

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 +269,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 +399,21 @@ private ObjectNode resolveBidExt(Integer duration) {
.video(ExtBidPrebidVideo.of(duration, null))
.build());
}

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

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;

}
37 changes: 37 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 @@ -28,10 +28,13 @@
import org.mockito.junit.MockitoRule;
import org.prebid.server.VertxTest;
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.HttpResponse;
import org.prebid.server.bidder.model.Result;
Expand All @@ -43,9 +46,11 @@
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.version.PrebidVersionProvider;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.UnaryOperator;

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,37 @@ 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 fledgeAuctionConfig = mapper.createObjectNode();
final BidRequest bidRequest = BidRequest.builder()
.imp(List.of(Imp.builder().id(impId).build()))
.build();
final IxBidResponse bidResponseWithFledge = IxBidResponse.builder()
.cur(bidResponse.getCur())
.seatbid(bidResponse.getSeatbid())
.ext(IxExtBidResponse.of(Map.of(impId, fledgeAuctionConfig)))
.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(fledgeAuctionConfig)
.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