Skip to content

Commit

Permalink
create a single bidrequest for multiple banner & native imps
Browse files Browse the repository at this point in the history
  • Loading branch information
sergseven committed Dec 23, 2024
1 parent 36c6760 commit 5feebf4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
19 changes: 9 additions & 10 deletions src/main/java/org/prebid/server/bidder/openx/OpenxBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class OpenxBidder implements Bidder<BidRequest> {

Expand Down Expand Up @@ -111,10 +112,14 @@ private List<BidRequest> makeRequests(
List<Imp> nativeImps,
List<BidderError> errors) {
final List<BidRequest> bidRequests = new ArrayList<>();
// single request for all banner imps
final BidRequest bannerRequest = createSingleRequest(bannerImps, bidRequest, errors);
if (bannerRequest != null) {
bidRequests.add(bannerRequest);
// single request for all banner and native imps
var bannerAndNativeImps = Stream.of(bannerImps, nativeImps)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.toList();
final BidRequest bannerAndNativeImpsRequest = createSingleRequest(bannerAndNativeImps, bidRequest, errors);
if (bannerAndNativeImpsRequest != null) {
bidRequests.add(bannerAndNativeImpsRequest);
}

if (CollectionUtils.isNotEmpty(videoImps)) {
Expand All @@ -125,12 +130,6 @@ private List<BidRequest> makeRequests(
.filter(Objects::nonNull)
.toList());
}

// single request for all native imps
final BidRequest nativeRequest = createSingleRequest(nativeImps, bidRequest, errors);
if (nativeRequest != null) {
bidRequests.add(nativeRequest);
}
return bidRequests;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,20 @@ public void makeHttpRequestsShouldReturnResultWithExpectedFieldsSet() {
}

@Test
public void makeHttpRequestsShouldReturnResultWithSingleBidRequestForMultipleNativeImps() {
public void makeHttpRequestsShouldReturnResultWithSingleBidRequestForMultipleBannerAndNativeImps() {
// given
final BidRequest bidRequest = BidRequest.builder()
.id("bidRequestId")
.imp(asList(
Imp.builder()
.id("impId4")
.banner(Banner.builder().build())
.ext(mapper.valueToTree(
ExtPrebid.of(null,
ExtImpOpenx.builder()
.customParams(givenCustomParams("foo4", "bar4"))
.delDomain("se-demo-d.openx.net")
.unit("4").build()))).build(),
Imp.builder()
.id("impId5")
.xNative(Native.builder().request("{\"testreq\":1}").build())
Expand Down Expand Up @@ -365,6 +374,16 @@ public void makeHttpRequestsShouldReturnResultWithSingleBidRequestForMultipleNat
BidRequest.builder()
.id("bidRequestId")
.imp(asList(
Imp.builder()
.id("impId4")
.tagid("4")
.banner(Banner.builder().build())
.ext(mapper.valueToTree(
ExtImpOpenx.builder()
.customParams(
givenCustomParams("foo4", "bar4"))
.build()))
.build(),
Imp.builder()
.id("impId5")
.tagid("5")
Expand Down

0 comments on commit 5feebf4

Please sign in to comment.