diff --git a/src/main/java/org/prebid/server/bidder/yieldmo/YieldmoBidder.java b/src/main/java/org/prebid/server/bidder/yieldmo/YieldmoBidder.java index 9030a7de9fb..194ce9308db 100644 --- a/src/main/java/org/prebid/server/bidder/yieldmo/YieldmoBidder.java +++ b/src/main/java/org/prebid/server/bidder/yieldmo/YieldmoBidder.java @@ -16,6 +16,7 @@ import org.prebid.server.bidder.model.BidderError; import org.prebid.server.bidder.model.HttpRequest; import org.prebid.server.bidder.model.Result; +import org.prebid.server.bidder.yieldmo.proto.YieldmoBidExt; import org.prebid.server.bidder.yieldmo.proto.YieldmoImpExt; import org.prebid.server.exception.PreBidException; import org.prebid.server.json.DecodeException; @@ -97,13 +98,13 @@ private HttpRequest makeRequest(BidRequest bidRequest) { public Result> makeBids(BidderCall httpCall, BidRequest bidRequest) { try { final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); - return Result.withValues(extractBids(httpCall.getRequest().getPayload(), bidResponse)); + return Result.withValues(extractBids(bidResponse)); } catch (DecodeException e) { return Result.withError(BidderError.badServerResponse(e.getMessage())); } } - private static List extractBids(BidRequest bidRequest, BidResponse bidResponse) { + private List extractBids(BidResponse bidResponse) { if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { return Collections.emptyList(); } @@ -114,16 +115,20 @@ private static List extractBids(BidRequest bidRequest, BidResponse bi .filter(Objects::nonNull) .flatMap(Collection::stream) .filter(Objects::nonNull) - .map(bid -> BidderBid.of(bid, resolveBidType(bid, bidRequest.getImp()), bidResponse.getCur())) + .map(bid -> { + final BidType bidType = resolveBidType(bid); + return bidType != null ? BidderBid.of(bid, bidType, bidResponse.getCur()) : null; + }) + .filter(Objects::nonNull) .toList(); } - private static BidType resolveBidType(Bid bid, List imps) { - for (Imp imp : imps) { - if (Objects.equals(imp.getId(), bid.getImpid())) { - return imp.getBanner() != null ? BidType.banner : BidType.video; - } + private BidType resolveBidType(Bid bid) { + try { + final YieldmoBidExt bidExt = mapper.mapper().treeToValue(bid.getExt(), YieldmoBidExt.class); + return BidType.fromString(bidExt.getMediaType()); + } catch (Exception e) { + return null; } - return BidType.video; } } diff --git a/src/main/java/org/prebid/server/bidder/yieldmo/proto/YieldmoBidExt.java b/src/main/java/org/prebid/server/bidder/yieldmo/proto/YieldmoBidExt.java new file mode 100644 index 00000000000..54742a92d24 --- /dev/null +++ b/src/main/java/org/prebid/server/bidder/yieldmo/proto/YieldmoBidExt.java @@ -0,0 +1,15 @@ +package org.prebid.server.bidder.yieldmo.proto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Value; + +/** + * Defines the contract for bidresponse.seatbid[i].bid[i].ext + */ +@Value(staticConstructor = "of") +public class YieldmoBidExt { + + @JsonProperty("mediatype") + String mediaType; +} + diff --git a/src/test/java/org/prebid/server/bidder/yieldmo/YieldmoBidderTest.java b/src/test/java/org/prebid/server/bidder/yieldmo/YieldmoBidderTest.java index 3b27bcb5acf..f0e76b2425b 100644 --- a/src/test/java/org/prebid/server/bidder/yieldmo/YieldmoBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/yieldmo/YieldmoBidderTest.java @@ -1,6 +1,8 @@ package org.prebid.server.bidder.yieldmo; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.TextNode; import com.iab.openrtb.request.Banner; @@ -199,7 +201,7 @@ public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsNull() throws Jso } @Test - public void makeBidsShouldReturnVideoBidByDefault() throws JsonProcessingException { + public void makeBidsShouldReturnEmptyListIfBidExtHasNoMediaType() throws JsonProcessingException { // given final BidderCall httpCall = givenHttpCall( BidRequest.builder() @@ -213,8 +215,7 @@ public void makeBidsShouldReturnVideoBidByDefault() throws JsonProcessingExcepti // then assertThat(result.getErrors()).isEmpty(); - assertThat(result.getValue()) - .containsExactly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD")); + assertThat(result.getValue()).isEmpty(); } @Test @@ -225,7 +226,7 @@ public void makeBidsShouldReturnBannerBidIfBannerIsPresentInRequestImp() throws .imp(singletonList(Imp.builder().banner(Banner.builder().build()).id("123").build())) .build(), mapper.writeValueAsString( - givenBidResponse(bidBuilder -> bidBuilder.impid("123")))); + givenBidResponse(bidBuilder -> bidBuilder.impid("123").ext(toObjectNode("banner"))))); // when final Result> result = target.makeBids(httpCall, null); @@ -233,7 +234,8 @@ public void makeBidsShouldReturnBannerBidIfBannerIsPresentInRequestImp() throws // then assertThat(result.getErrors()).isEmpty(); assertThat(result.getValue()) - .containsExactly(BidderBid.of(Bid.builder().impid("123").build(), banner, "USD")); + .containsExactly(BidderBid.of(Bid.builder().impid("123").ext(toObjectNode("banner")).build(), + banner, "USD")); } @Test @@ -244,7 +246,7 @@ public void makeBidsShouldReturnVideoBidIfVideoIsPresentInRequestImp() throws Js .imp(singletonList(Imp.builder().video(Video.builder().build()).id("123").build())) .build(), mapper.writeValueAsString( - givenBidResponse(bidBuilder -> bidBuilder.impid("123")))); + givenBidResponse(bidBuilder -> bidBuilder.impid("123").ext(toObjectNode("video"))))); // when final Result> result = target.makeBids(httpCall, null); @@ -252,7 +254,8 @@ public void makeBidsShouldReturnVideoBidIfVideoIsPresentInRequestImp() throws Js // then assertThat(result.getErrors()).isEmpty(); assertThat(result.getValue()) - .containsExactly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD")); + .containsExactly(BidderBid.of(Bid.builder().impid("123").ext(toObjectNode("video")).build(), + video, "USD")); } private static BidRequest givenBidRequest( @@ -291,4 +294,11 @@ private static BidderCall givenHttpCall(BidRequest bidRequest, Strin HttpResponse.of(200, null, body), null); } + + private ObjectNode toObjectNode(String mediaType) { + final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode root = mapper.createObjectNode(); + root.set("mediatype", mapper.convertValue(mediaType, JsonNode.class)); + return root; + } } diff --git a/src/test/resources/org/prebid/server/it/openrtb2/yieldmo/test-auction-yieldmo-response.json b/src/test/resources/org/prebid/server/it/openrtb2/yieldmo/test-auction-yieldmo-response.json index 1a0e67d6d93..15089c43484 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/yieldmo/test-auction-yieldmo-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/yieldmo/test-auction-yieldmo-response.json @@ -17,7 +17,8 @@ "prebid": { "type": "banner" }, - "origbidcpm": 3.33 + "origbidcpm": 3.33, + "mediatype": "banner" } } ], diff --git a/src/test/resources/org/prebid/server/it/openrtb2/yieldmo/test-yieldmo-bid-response.json b/src/test/resources/org/prebid/server/it/openrtb2/yieldmo/test-yieldmo-bid-response.json index 8901429253e..9679171d65e 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/yieldmo/test-yieldmo-bid-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/yieldmo/test-yieldmo-bid-response.json @@ -12,9 +12,12 @@ "cid": "cid", "adm": "adm001", "h": 250, - "w": 300 + "w": 300, + "ext" : { + "mediatype" : "banner" + } } ] } ] -} \ No newline at end of file +}