From 14a490eeea586c60cfc3306366b42c2bc7296ba9 Mon Sep 17 00:00:00 2001 From: Philip Watson Date: Wed, 14 Feb 2024 11:24:10 +1300 Subject: [PATCH] StroeerCore: support DSA --- .../bidder/stroeercore/StroeerCoreBidder.java | 10 +++- .../stroeercore/model/StroeerCoreBid.java | 3 ++ .../stroeercore/StroeerCoreBidderTest.java | 48 ++++++++++++++++++- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/prebid/server/bidder/stroeercore/StroeerCoreBidder.java b/src/main/java/org/prebid/server/bidder/stroeercore/StroeerCoreBidder.java index d30208dea71..a3d02f5250d 100644 --- a/src/main/java/org/prebid/server/bidder/stroeercore/StroeerCoreBidder.java +++ b/src/main/java/org/prebid/server/bidder/stroeercore/StroeerCoreBidder.java @@ -1,6 +1,7 @@ package org.prebid.server.bidder.stroeercore; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.iab.openrtb.request.BidRequest; import com.iab.openrtb.request.Imp; import com.iab.openrtb.response.Bid; @@ -144,7 +145,7 @@ public Result> makeBids(BidderCall httpCall, BidRequ } } - private static List extractBids(BidRequest bidRequest, StroeerCoreBidResponse bidResponse) { + private List extractBids(BidRequest bidRequest, StroeerCoreBidResponse bidResponse) { if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getBids())) { return Collections.emptyList(); } @@ -155,7 +156,11 @@ private static List extractBids(BidRequest bidRequest, StroeerCoreBid .toList(); } - private static BidderBid toBidderBid(BidRequest bidRequest, StroeerCoreBid stroeercoreBid) { + private BidderBid toBidderBid(BidRequest bidRequest, StroeerCoreBid stroeercoreBid) { + final ObjectNode bidExt = stroeercoreBid.getDsa() != null + ? mapper.mapper().createObjectNode().set("dsa", stroeercoreBid.getDsa()) + : null; + return BidderBid.of( Bid.builder() .id(stroeercoreBid.getId()) @@ -165,6 +170,7 @@ private static BidderBid toBidderBid(BidRequest bidRequest, StroeerCoreBid stroe .price(stroeercoreBid.getCpm()) .adm(stroeercoreBid.getAdMarkup()) .crid(stroeercoreBid.getCreativeId()) + .ext(bidExt) .build(), getBidType(stroeercoreBid.getImpId(), bidRequest.getImp()), BIDDER_CURRENCY); diff --git a/src/main/java/org/prebid/server/bidder/stroeercore/model/StroeerCoreBid.java b/src/main/java/org/prebid/server/bidder/stroeercore/model/StroeerCoreBid.java index 9478adae356..e44b85f445e 100644 --- a/src/main/java/org/prebid/server/bidder/stroeercore/model/StroeerCoreBid.java +++ b/src/main/java/org/prebid/server/bidder/stroeercore/model/StroeerCoreBid.java @@ -1,6 +1,7 @@ package org.prebid.server.bidder.stroeercore.model; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.node.ObjectNode; import lombok.Builder; import lombok.Value; @@ -26,5 +27,7 @@ public class StroeerCoreBid { @JsonProperty("crid") String creativeId; + + ObjectNode dsa; } diff --git a/src/test/java/org/prebid/server/bidder/stroeercore/StroeerCoreBidderTest.java b/src/test/java/org/prebid/server/bidder/stroeercore/StroeerCoreBidderTest.java index c30ce3fcbf8..a8467d4b2df 100644 --- a/src/test/java/org/prebid/server/bidder/stroeercore/StroeerCoreBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/stroeercore/StroeerCoreBidderTest.java @@ -7,6 +7,7 @@ import com.iab.openrtb.request.BidRequest; import com.iab.openrtb.request.Imp; import com.iab.openrtb.request.Imp.ImpBuilder; +import com.iab.openrtb.request.Regs; import com.iab.openrtb.request.Video; import com.iab.openrtb.response.Bid; import io.vertx.core.http.HttpMethod; @@ -28,11 +29,15 @@ import org.prebid.server.currency.CurrencyConversionService; import org.prebid.server.exception.PreBidException; import org.prebid.server.proto.openrtb.ext.ExtPrebid; +import org.prebid.server.proto.openrtb.ext.request.ExtRegs; +import org.prebid.server.proto.openrtb.ext.request.ExtRegsDsa; +import org.prebid.server.proto.openrtb.ext.request.ExtRegsDsaTransparency; import org.prebid.server.proto.openrtb.ext.request.stroeercore.ExtImpStroeerCore; import org.prebid.server.proto.openrtb.ext.response.BidType; import org.prebid.server.util.HttpUtil; import java.math.BigDecimal; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -125,6 +130,31 @@ public void makeHttpRequestsShouldReturnImpsWithExpectedTagIds() { .containsExactly("827194", "abc"); } + @Test + public void makeHttpRequestsShouldReturnDSA() { + // given + final List transparencies = Arrays.asList( + ExtRegsDsaTransparency.of("platform-example.com", List.of(1, 2)), + ExtRegsDsaTransparency.of("ssp-example.com", List.of(1)) + ); + + final ExtRegsDsa dsa = ExtRegsDsa.of(3, 1, 2, transparencies); + + final BidRequest bidRequest = createBidRequest(createBannerImp("1")).toBuilder() + .regs(Regs.builder().ext(ExtRegs.of(null, null, null, dsa)).build()) + .build(); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(HttpRequest::getPayload) + .extracting(payload -> payload.getRegs().getExt().getDsa()) + .allSatisfy(actualDsa -> assertThat(actualDsa).isSameAs(dsa)); + } + @Test public void makeHttpRequestsShouldReturnErrorIfImpExtCouldNotBeParsed() { // given @@ -251,12 +281,14 @@ public void makeHttpRequestsShouldIgnoreBidIfCurrencyServiceThrowsException() { } @Test - public void makeBidsShouldReturnExpectedBidderBidsWithProperBidType() throws JsonProcessingException { + public void makeBidsShouldReturnExpectedBidderBids() throws JsonProcessingException { // given final Imp bannerImp = createBannerImp("banner-slot-id", impBuilder -> impBuilder.id("banner-imp-id")); final Imp videoImp = createVideoImp("video-slot-id", impBuilder -> impBuilder.id("video-imp-id")); final BidRequest bidRequest = createBidRequest(bannerImp, videoImp); + final ObjectNode dsaResponse = createDsaResponse(); + final StroeerCoreBid bannerBid = StroeerCoreBid.builder() .id("1") .impId("banner-imp-id") @@ -265,6 +297,7 @@ public void makeBidsShouldReturnExpectedBidderBidsWithProperBidType() throws Jso .creativeId("foo") .width(300) .height(600) + .dsa(dsaResponse.deepCopy()) .build(); final StroeerCoreBid videoBid = StroeerCoreBid.builder() @@ -273,6 +306,7 @@ public void makeBidsShouldReturnExpectedBidderBidsWithProperBidType() throws Jso .adMarkup("") .cpm(BigDecimal.valueOf(1.58)) .creativeId("vid") + .dsa(null) .build(); final StroeerCoreBidResponse response = StroeerCoreBidResponse.of(List.of(bannerBid, videoBid)); @@ -290,6 +324,7 @@ public void makeBidsShouldReturnExpectedBidderBidsWithProperBidType() throws Jso .crid("foo") .w(300) .h(600) + .ext(mapper.createObjectNode().set("dsa", dsaResponse)) .build(); final Bid expectedVideoBid = Bid.builder() @@ -298,6 +333,7 @@ public void makeBidsShouldReturnExpectedBidderBidsWithProperBidType() throws Jso .adm("") .price(BigDecimal.valueOf(1.58)) .crid("vid") + .ext(null) .build(); assertThat(result.getErrors()).isEmpty(); @@ -392,4 +428,14 @@ private BidderCall createHttpCallWithNonParsableResponse() { return createHttpCall(HttpRequest.builder().build(), HttpResponse.of(200, null, "[]")); } + + private ObjectNode createDsaResponse() { + final ObjectNode dsaTransparency = mapper.createObjectNode() + .put("domain", "example.com") + .set("dsaparams", mapper.createArrayNode().add(1).add(2)); + return mapper.createObjectNode() + .put("behalf", "advertiser-a") + .put("paid", "advertiser-b") + .set("transparency", mapper.createArrayNode().add(dsaTransparency)); + } }