From 06f93c666c990e4f1d1feef35bed7d6abfecd903 Mon Sep 17 00:00:00 2001 From: Andrey Paliy Date: Fri, 7 Feb 2020 16:40:14 +0200 Subject: [PATCH 01/14] Bid Id can be overwritten if application.yaml auction.generate-bid-id = true. Test added --- .../server/auction/BidResponseCreator.java | 29 ++++++++++++++++- .../spring/config/ServiceConfiguration.java | 6 ++-- .../auction/BidResponseCreatorTest.java | 32 ++++++++++++++++++- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index 3d98bb8dbfd..0332edc7b27 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -70,6 +70,8 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.UUID; +import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -87,9 +89,10 @@ public class BidResponseCreator { private final String cachePath; private final String cacheAssetUrlTemplate; private final StoredRequestProcessor storedRequestProcessor; + private final Consumer> overwriteBidIdConsumer; public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog, EventsService eventsService, - StoredRequestProcessor storedRequestProcessor) { + StoredRequestProcessor storedRequestProcessor, boolean generateBidId) { this.cacheService = Objects.requireNonNull(cacheService); this.bidderCatalog = Objects.requireNonNull(bidderCatalog); this.eventsService = Objects.requireNonNull(eventsService); @@ -97,6 +100,29 @@ public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog this.cachePath = Objects.requireNonNull(cacheService.getEndpointPath()); this.cacheAssetUrlTemplate = Objects.requireNonNull(cacheService.getCachedAssetURLTemplate()); this.storedRequestProcessor = Objects.requireNonNull(storedRequestProcessor); + + if (generateBidId) { + overwriteBidIdConsumer = bidderResponses -> { + if (CollectionUtils.isNotEmpty(bidderResponses)) { + bidderResponses.stream() + .filter(Objects::nonNull) + .map(BidderResponse::getSeatBid) + .filter(Objects::nonNull) + .map(BidderSeatBid::getBids) + .filter(Objects::nonNull) + .forEach(bidderBids -> { + bidderBids.stream() + .filter(Objects::nonNull) + .map(BidderBid::getBid) + .filter(Objects::nonNull) + .forEach(bid -> bid.setId(UUID.randomUUID().toString())); + }); + } + }; + } else { + overwriteBidIdConsumer = bidderResponses -> { + }; + } } /** @@ -119,6 +145,7 @@ Future create(List bidderResponses, BidRequest bidR CacheServiceResult.empty(), VideoStoredDataResult.empty(), debugEnabled, null))) .build()); } else { + overwriteBidIdConsumer.accept(bidderResponses); final Set winningBids = newOrEmptySet(targeting); final Set winningBidsByBidder = newOrEmptySet(targeting); diff --git a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java index f5f5b192627..3ca54ee4373 100644 --- a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java @@ -363,9 +363,11 @@ BidResponseCreator bidResponseCreator( CacheService cacheService, BidderCatalog bidderCatalog, EventsService eventsService, - StoredRequestProcessor storedRequestProcessor) { + StoredRequestProcessor storedRequestProcessor, + @Value("${auction.generate-bid-id:#{false}}") Boolean generateBidId) { - return new BidResponseCreator(cacheService, bidderCatalog, eventsService, storedRequestProcessor); + return new BidResponseCreator(cacheService, bidderCatalog, eventsService, + storedRequestProcessor, generateBidId); } @Bean diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index 35a3c26930f..becd2de3316 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -120,7 +120,8 @@ public void setUp() { given(storedRequestProcessor.videoStoredDataResult(any(), any(), any())) .willReturn(Future.succeededFuture(VideoStoredDataResult.empty())); - bidResponseCreator = new BidResponseCreator(cacheService, bidderCatalog, eventsService, storedRequestProcessor); + bidResponseCreator = new BidResponseCreator(cacheService, bidderCatalog, eventsService, + storedRequestProcessor, false); timeout = new TimeoutFactory(Clock.fixed(Instant.now(), ZoneId.systemDefault())).create(500); } @@ -370,6 +371,35 @@ public void shouldSkipBidderResponsesWhereSeatBidContainEmptyBids() { verify(cacheService, never()).cacheBidsOpenrtb(anyList(), anyList(), any(), any(), any()); } + @Test + public void shouldOverwriteBidderIdToUUID() { + // given + final BidRequest bidRequest = givenBidRequest(); + + final Bid bid = Bid.builder() + .id("123") + .impid("imp123") + .w(123) + .h(123) + .price(BigDecimal.ONE) + .build(); + final List bidderResponses = singletonList( + BidderResponse.of("bidder2", givenSeatBid(BidderBid.of(bid, banner, "USD")), 0)); + + final BidResponseCreator bidResponseCreator = new BidResponseCreator(cacheService, bidderCatalog, eventsService, + storedRequestProcessor, true); + // when + final BidResponse bidResponse = bidResponseCreator.create(bidderResponses, bidRequest, + null, CACHE_INFO, ACCOUNT, timeout, false).result(); + + // then + assertThat(bidResponse.getSeatbid()).hasSize(1); + assertThat(bidResponse.getSeatbid().get(0).getBid()).hasSize(1); + assertThat(bidResponse.getSeatbid().get(0).getBid().get(0).getId()).isNotEqualTo("123"); + + verify(cacheService, never()).cacheBidsOpenrtb(anyList(), anyList(), any(), any(), any()); + } + @Test public void shouldSetExpectedResponseSeatBidAndBidFields() { // given From 0e9eea09c9a0224e971d246764a26aebbb81aa40 Mon Sep 17 00:00:00 2001 From: Andrey Paliy Date: Mon, 16 Mar 2020 12:12:07 +0200 Subject: [PATCH 02/14] Overwriting exp.prebid.bid_id --- .../server/auction/BidResponseCreator.java | 39 +++++++++++++++---- .../openrtb/ext/response/ExtBidPrebid.java | 10 +++-- .../auction/BidResponseCreatorTest.java | 16 +++++--- .../server/auction/ExchangeServiceTest.java | 2 +- .../auction/StoredResponseProcessorTest.java | 2 +- .../auction/VideoResponseFactoryTest.java | 6 +-- .../handler/openrtb2/AmpHandlerTest.java | 28 ++++++------- 7 files changed, 66 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index 07ddc41c447..b6060baa1b3 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -114,13 +114,11 @@ public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog .filter(Objects::nonNull) .map(BidderSeatBid::getBids) .filter(Objects::nonNull) - .forEach(bidderBids -> { - bidderBids.stream() - .filter(Objects::nonNull) - .map(BidderBid::getBid) - .filter(Objects::nonNull) - .forEach(bid -> bid.setId(UUID.randomUUID().toString())); - }); + .forEach(bidderBids -> bidderBids.stream() + .filter(Objects::nonNull) + .map(BidderBid::getBid) + .filter(Objects::nonNull) + .forEach(this::replaceBidId)); } }; } else { @@ -129,6 +127,26 @@ public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog } } + private void replaceBidId(Bid bid) { + final ObjectNode ext = bid.getExt(); + final ExtBidPrebid extBidPrebid = parsePrebidExt(ext); + if (extBidPrebid != null) { + extBidPrebid.setBidId(UUID.randomUUID().toString()); + try { + bid.setExt(ext.set(PREBID_EXT, mapper.mapper().readTree(mapper.encode(extBidPrebid)))); + } catch (JsonProcessingException e) { + } + } + } + + private ExtBidPrebid parsePrebidExt(ObjectNode ext) { + try { + return mapper.decodeValue(ext.get(PREBID_EXT).toString(), ExtBidPrebid.class); + } catch (Exception e) { + return null; + } + } + /** * Creates an OpenRTB {@link BidResponse} from the bids supplied by the bidder, * including processing of winning bids with cache IDs. @@ -669,7 +687,12 @@ private Bid toBid(BidderBid bidderBid, String bidder, ExtRequestTargeting target final Video storedVideo = impIdToStoredVideo.get(bid.getImpid()); final Events events = eventsEnabled ? eventsService.createEvent(bid.getId(), account.getId()) : null; - final ExtBidPrebid prebidExt = ExtBidPrebid.of(bidType, targetingKeywords, cache, storedVideo, events, null); + final ExtBidPrebid prebidExt = ExtBidPrebid.builder().type(bidType) + .targeting(targetingKeywords) + .cache(cache) + .storedRequestAttributes(storedVideo) + .events(events) + .build(); final ExtPrebid bidExt = ExtPrebid.of(prebidExt, bid.getExt()); bid.setExt(mapper.mapper().valueToTree(bidExt)); diff --git a/src/main/java/org/prebid/server/proto/openrtb/ext/response/ExtBidPrebid.java b/src/main/java/org/prebid/server/proto/openrtb/ext/response/ExtBidPrebid.java index b9976575a06..61b2110f52d 100644 --- a/src/main/java/org/prebid/server/proto/openrtb/ext/response/ExtBidPrebid.java +++ b/src/main/java/org/prebid/server/proto/openrtb/ext/response/ExtBidPrebid.java @@ -2,18 +2,20 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.iab.openrtb.request.Video; -import lombok.AllArgsConstructor; -import lombok.Value; +import lombok.Builder; +import lombok.Data; import java.util.Map; /** * Defines the contract for bidresponse.seatbid.bid[i].ext.prebid */ -@AllArgsConstructor(staticName = "of") -@Value +@Builder(toBuilder = true) +@Data public class ExtBidPrebid { + String bidId; + BidType type; Map targeting; diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index 3473ea149d7..e6deef41736 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -86,8 +86,7 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -import static org.prebid.server.proto.openrtb.ext.response.BidType.banner; -import static org.prebid.server.proto.openrtb.ext.response.BidType.xNative; +import static org.prebid.server.proto.openrtb.ext.response.BidType.*; public class BidResponseCreatorTest extends VertxTest { @@ -371,16 +370,18 @@ public void shouldSkipBidderResponsesWhereSeatBidContainEmptyBids() { } @Test - public void shouldOverwriteBidderIdToUUID() { + public void shouldOverwriteBidderIdToUUID() throws JsonProcessingException { // given final BidRequest bidRequest = givenBidRequest(); + final ExtPrebid prebid = ExtPrebid.of(ExtBidPrebid.builder().type(banner).build(), null); final Bid bid = Bid.builder() .id("123") .impid("imp123") .w(123) .h(123) .price(BigDecimal.ONE) + .ext(mapper.valueToTree(prebid)) .build(); final List bidderResponses = singletonList( BidderResponse.of("bidder2", givenSeatBid(BidderBid.of(bid, banner, "USD")), 0)); @@ -394,8 +395,11 @@ public void shouldOverwriteBidderIdToUUID() { // then assertThat(bidResponse.getSeatbid()).hasSize(1); assertThat(bidResponse.getSeatbid().get(0).getBid()).hasSize(1); - assertThat(bidResponse.getSeatbid().get(0).getBid().get(0).getId()).isNotEqualTo("123"); + final ExtBidPrebid ext = mapper.readValue(bidResponse.getSeatbid().get(0).getBid().get(0) + .getExt().get("bidder").get("prebid").toString(), ExtBidPrebid.class); + assertThat(ext.getBidId()).isNotNull(); + System.out.println(ext.getBidId()); verify(cacheService, never()).cacheBidsOpenrtb(anyList(), anyList(), any(), any(), any()); } @@ -422,7 +426,7 @@ public void shouldSetExpectedResponseSeatBidAndBidFields() { .price(BigDecimal.ONE) .adm("adm") .ext(mapper.valueToTree(ExtPrebid.of( - ExtBidPrebid.of(banner, null, null, null, null, null), singletonMap("bidExt", 1)))) + ExtBidPrebid.builder().type(banner).build(), singletonMap("bidExt", 1)))) .build())) .build()); @@ -557,7 +561,7 @@ public void shouldTolerateMissingExtInSeatBidAndBid() { .id("bidId") .price(BigDecimal.ONE) .ext(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(banner, null, null, null, null, null), null))) + ExtPrebid.of(ExtBidPrebid.builder().type(banner).build(), null))) .build()); verify(cacheService, never()).cacheBidsOpenrtb(anyList(), anyList(), any(), any(), any()); diff --git a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java index 1095850944e..8e6bfe0122f 100644 --- a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java +++ b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java @@ -1769,7 +1769,7 @@ private static Bid givenBid(Function bidBuilder) return bidBuilder.apply(Bid.builder() .id("bidId") .price(BigDecimal.ONE) - .ext(mapper.valueToTree(ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null), null)))) + .ext(mapper.valueToTree(ExtPrebid.of(ExtBidPrebid.builder().build(), null)))) .build(); } diff --git a/src/test/java/org/prebid/server/auction/StoredResponseProcessorTest.java b/src/test/java/org/prebid/server/auction/StoredResponseProcessorTest.java index c6ca46ea3cc..d41263e9789 100644 --- a/src/test/java/org/prebid/server/auction/StoredResponseProcessorTest.java +++ b/src/test/java/org/prebid/server/auction/StoredResponseProcessorTest.java @@ -553,7 +553,7 @@ public void mergeWithBidderResponsesShouldResolveBidTypeFromStoredBidExt() { singletonList(BidderBid.of(Bid.builder().id("bid1").build(), BidType.banner, "USD")), emptyList(), emptyList()), 100)); - final ExtBidPrebid extBidPrebid = ExtBidPrebid.of(BidType.video, null, null, null, null, null); + final ExtBidPrebid extBidPrebid = ExtBidPrebid.builder().type(BidType.video).build(); final List seatBid = singletonList(SeatBid.builder() .seat("rubicon").bid(singletonList(Bid.builder().ext(mapper.createObjectNode() diff --git a/src/test/java/org/prebid/server/auction/VideoResponseFactoryTest.java b/src/test/java/org/prebid/server/auction/VideoResponseFactoryTest.java index d4949155a4f..b65c57f2f68 100644 --- a/src/test/java/org/prebid/server/auction/VideoResponseFactoryTest.java +++ b/src/test/java/org/prebid/server/auction/VideoResponseFactoryTest.java @@ -42,19 +42,19 @@ public void shouldReturnExpectedVideoResponse() { final Bid bid0 = Bid.builder() .impid("0_0") .ext(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(null, targeting, null, null, null, null), + ExtPrebid.of(ExtBidPrebid.builder().targeting(targeting).build(), mapper.createObjectNode()))) .build(); final Bid bid1 = Bid.builder() .impid("1_1") .ext(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(null, targeting, null, null, null, null), + ExtPrebid.of(ExtBidPrebid.builder().targeting(targeting).build(), mapper.createObjectNode()))) .build(); final Bid bid2 = Bid.builder() .impid("2_1") .ext(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null), mapper.createObjectNode()))) + ExtPrebid.of(ExtBidPrebid.builder().build(), mapper.createObjectNode()))) .build(); final BidResponse bidResponse = BidResponse.builder() diff --git a/src/test/java/org/prebid/server/handler/openrtb2/AmpHandlerTest.java b/src/test/java/org/prebid/server/handler/openrtb2/AmpHandlerTest.java index b5c7a0a6bc1..8d03ca090b4 100644 --- a/src/test/java/org/prebid/server/handler/openrtb2/AmpHandlerTest.java +++ b/src/test/java/org/prebid/server/handler/openrtb2/AmpHandlerTest.java @@ -349,7 +349,7 @@ public void shouldRespondWithExpectedResponse() { targeting.put("hb_cache_id_bidder1", "value2"); given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse( - mapper.valueToTree(ExtPrebid.of(ExtBidPrebid.of(null, targeting, null, null, null, null), null)))); + mapper.valueToTree(ExtPrebid.of(ExtBidPrebid.builder().targeting(targeting).build(), null)))); // when ampHandler.handle(routingContext); @@ -379,7 +379,7 @@ public void shouldRespondWithCustomTargetingIncluded() { .seat("bidder1") .bid(singletonList(Bid.builder() .ext(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(null, targeting, null, null, null, null), + ExtPrebid.of(ExtBidPrebid.builder().targeting(targeting).build(), mapper.createObjectNode()))) .build())) .build())) @@ -459,7 +459,7 @@ public void shouldIncrementOkAmpRequestMetrics() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null), null)))); + ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); // when ampHandler.handle(routingContext); @@ -476,7 +476,7 @@ public void shouldIncrementAppRequestMetrics() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null), null)))); + ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); // when ampHandler.handle(routingContext); @@ -493,7 +493,7 @@ public void shouldIncrementNoCookieMetrics() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null), null)))); + ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); given(uidsCookie.hasLiveUids()).willReturn(false); @@ -516,7 +516,7 @@ public void shouldIncrementImpsRequestedMetrics() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null), null)))); + ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); // when ampHandler.handle(routingContext); @@ -535,7 +535,7 @@ public void shouldIncrementImpsTypesMetrics() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null), null)))); + ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); // when ampHandler.handle(routingContext); @@ -619,7 +619,7 @@ public void shouldUpdateNetworkErrorMetric() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null), null)))); + ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); // simulate calling exception handler that is supposed to update networkerr timer value given(httpResponse.exceptionHandler(any())).willAnswer(inv -> { @@ -642,7 +642,7 @@ public void shouldNotUpdateNetworkErrorMetricIfResponseSucceeded() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null), null)))); + ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); // when ampHandler.handle(routingContext); @@ -659,7 +659,7 @@ public void shouldUpdateNetworkErrorMetricIfClientClosedConnection() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null), null)))); + ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); given(routingContext.response().closed()).willReturn(true); @@ -726,8 +726,8 @@ public void shouldPassSuccessfulEventToAnalyticsReporter() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.of(null, singletonMap("hb_cache_id_bidder1", "value1"), null, null, - null, null), + ExtPrebid.of(ExtBidPrebid.builder().targeting(singletonMap("hb_cache_id_bidder1", "value1")) + .build(), null)))); // when @@ -745,8 +745,8 @@ public void shouldPassSuccessfulEventToAnalyticsReporter() { .bidResponse(BidResponse.builder().seatbid(singletonList(SeatBid.builder() .bid(singletonList(Bid.builder() .ext(mapper.valueToTree(ExtPrebid.of( - ExtBidPrebid.of(null, singletonMap("hb_cache_id_bidder1", "value1"), null, - null, null, null), + ExtBidPrebid.builder().targeting(singletonMap("hb_cache_id_bidder1", "value1")) + .build(), null))) .build())) .build())) From 81ad0a7f9c78bf2ad74b5a4c8632420471b5b29f Mon Sep 17 00:00:00 2001 From: Andrey Paliy Date: Mon, 16 Mar 2020 13:21:33 +0200 Subject: [PATCH 03/14] Overwriting exp.prebid.bid_id --- .../server/auction/BidResponseCreator.java | 27 ++++++++----------- .../auction/BidResponseCreatorTest.java | 2 +- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index b6060baa1b3..0fe3709d008 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -91,7 +91,7 @@ public class BidResponseCreator { private final String cachePath; private final String cacheAssetUrlTemplate; private final StoredRequestProcessor storedRequestProcessor; - private final Consumer> overwriteBidIdConsumer; + private final Consumer overwriteBidIdConsumer; public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog, EventsService eventsService, StoredRequestProcessor storedRequestProcessor, @@ -107,24 +107,18 @@ public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog if (generateBidId) { overwriteBidIdConsumer = bidderResponses -> { - if (CollectionUtils.isNotEmpty(bidderResponses)) { - bidderResponses.stream() - .filter(Objects::nonNull) - .map(BidderResponse::getSeatBid) - .filter(Objects::nonNull) - .map(BidderSeatBid::getBids) - .filter(Objects::nonNull) - .forEach(bidderBids -> bidderBids.stream() - .filter(Objects::nonNull) - .map(BidderBid::getBid) - .filter(Objects::nonNull) - .forEach(this::replaceBidId)); - } + bidderResponses.getSeatbid().stream() + .map(SeatBid::getBid) + .forEach(bids -> bids.stream() + .filter(Objects::nonNull) + .forEach(this::replaceBidId)); + }; } else { overwriteBidIdConsumer = bidderResponses -> { }; } + } private void replaceBidId(Bid bid) { @@ -167,7 +161,6 @@ Future create(List bidderResponses, BidRequest bidR CacheServiceResult.empty(), VideoStoredDataResult.empty(), debugEnabled, null))) .build()); } else { - overwriteBidIdConsumer.accept(bidderResponses); final Set winningBids = newOrEmptySet(targeting); final Set winningBidsByBidder = newOrEmptySet(targeting); @@ -560,12 +553,14 @@ private BidResponse toBidResponse( toExtBidResponse(bidderResponses, bidRequest, cacheResult, videoStoredDataResult, debugEnabled, bidErrors); - return BidResponse.builder() + BidResponse response = BidResponse.builder() .id(bidRequest.getId()) .cur(bidRequest.getCur().get(0)) .seatbid(seatBids) .ext(mapper.mapper().valueToTree(extBidResponse)) .build(); + overwriteBidIdConsumer.accept(response); + return response; } private Future videoStoredDataResult(List imps, Timeout timeout) { diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index e6deef41736..edc0cb5c500 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -396,7 +396,7 @@ public void shouldOverwriteBidderIdToUUID() throws JsonProcessingException { assertThat(bidResponse.getSeatbid()).hasSize(1); assertThat(bidResponse.getSeatbid().get(0).getBid()).hasSize(1); final ExtBidPrebid ext = mapper.readValue(bidResponse.getSeatbid().get(0).getBid().get(0) - .getExt().get("bidder").get("prebid").toString(), ExtBidPrebid.class); + .getExt().get("prebid").toString(), ExtBidPrebid.class); assertThat(ext.getBidId()).isNotNull(); System.out.println(ext.getBidId()); From 91f51d5d20695e76e2acf5adf255d3b9d1beed7e Mon Sep 17 00:00:00 2001 From: Andrey Paliy Date: Mon, 16 Mar 2020 13:26:25 +0200 Subject: [PATCH 04/14] Overwriting exp.prebid.bid_id --- .../server/auction/BidResponseCreator.java | 20 +++++++++++-------- .../spring/config/ServiceConfiguration.java | 2 +- src/main/resources/application.yaml | 1 + 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index 0fe3709d008..4fc127bfb3b 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -106,14 +106,7 @@ public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog this.mapper = Objects.requireNonNull(mapper); if (generateBidId) { - overwriteBidIdConsumer = bidderResponses -> { - bidderResponses.getSeatbid().stream() - .map(SeatBid::getBid) - .forEach(bids -> bids.stream() - .filter(Objects::nonNull) - .forEach(this::replaceBidId)); - - }; + overwriteBidIdConsumer = overwriteBidIdConsumer(); } else { overwriteBidIdConsumer = bidderResponses -> { }; @@ -121,6 +114,17 @@ public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog } + private Consumer overwriteBidIdConsumer() { + return bidderResponses -> { + bidderResponses.getSeatbid().stream() + .map(SeatBid::getBid) + .forEach(bids -> bids.stream() + .filter(Objects::nonNull) + .forEach(this::replaceBidId)); + + }; + } + private void replaceBidId(Bid bid) { final ObjectNode ext = bid.getExt(); final ExtBidPrebid extBidPrebid = parsePrebidExt(ext); diff --git a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java index 576a9ca0fb7..8278cc667b2 100644 --- a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java @@ -407,7 +407,7 @@ BidResponseCreator bidResponseCreator( EventsService eventsService, StoredRequestProcessor storedRequestProcessor, JacksonMapper mapper, - @Value("${auction.generate-bid-id:#{false}}") Boolean generateBidId) { + @Value("${auction.generate-bid-id}") Boolean generateBidId) { return new BidResponseCreator(cacheService, bidderCatalog, eventsService, storedRequestProcessor, mapper, generateBidId); diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 4dcb6fd5460..85b80d522fb 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -37,6 +37,7 @@ auction: timeout-adjustment-ms: 30 stored-requests-timeout-ms: 50 max-request-size: 262144 + generate-bid-id: false cache: expected-request-time-ms: 10 only-winning-bids: false From 76140ca4c7cb812d1249ba6ced3f206a8a4044bb Mon Sep 17 00:00:00 2001 From: Andrey Paliy Date: Tue, 24 Mar 2020 13:21:08 +0200 Subject: [PATCH 05/14] PR fix --- .../server/auction/BidResponseCreator.java | 19 +++++++++++-------- .../auction/BidResponseCreatorTest.java | 8 ++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index 4fc127bfb3b..3fe19efd02a 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -16,6 +16,8 @@ import com.iab.openrtb.response.Response; import com.iab.openrtb.response.SeatBid; import io.vertx.core.Future; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.MapUtils; @@ -79,6 +81,8 @@ public class BidResponseCreator { + private static final Logger logger = LoggerFactory.getLogger(BidResponseCreator.class); + private static final String CACHE = "cache"; private static final String PREBID_EXT = "prebid"; @@ -95,7 +99,7 @@ public class BidResponseCreator { public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog, EventsService eventsService, StoredRequestProcessor storedRequestProcessor, - JacksonMapper mapper, boolean generateBidId) { + JacksonMapper mapper, Boolean generateBidId) { this.cacheService = Objects.requireNonNull(cacheService); this.bidderCatalog = Objects.requireNonNull(bidderCatalog); this.eventsService = Objects.requireNonNull(eventsService); @@ -105,12 +109,8 @@ public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog this.storedRequestProcessor = Objects.requireNonNull(storedRequestProcessor); this.mapper = Objects.requireNonNull(mapper); - if (generateBidId) { - overwriteBidIdConsumer = overwriteBidIdConsumer(); - } else { - overwriteBidIdConsumer = bidderResponses -> { - }; - } + overwriteBidIdConsumer = BooleanUtils.isTrue(generateBidId) ? overwriteBidIdConsumer() : bidResponse -> { + }; } @@ -131,8 +131,11 @@ private void replaceBidId(Bid bid) { if (extBidPrebid != null) { extBidPrebid.setBidId(UUID.randomUUID().toString()); try { - bid.setExt(ext.set(PREBID_EXT, mapper.mapper().readTree(mapper.encode(extBidPrebid)))); + final JsonNode extBidPrebidValue = mapper.mapper().readTree(mapper.encode(extBidPrebid)); + final ObjectNode prebidExtNode = ext.set(PREBID_EXT, extBidPrebidValue); + bid.setExt(prebidExtNode); } catch (JsonProcessingException e) { + logger.debug("Parsing error", e); } } } diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index edc0cb5c500..ff6f5b93d15 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -378,9 +378,6 @@ public void shouldOverwriteBidderIdToUUID() throws JsonProcessingException { final Bid bid = Bid.builder() .id("123") .impid("imp123") - .w(123) - .h(123) - .price(BigDecimal.ONE) .ext(mapper.valueToTree(prebid)) .build(); final List bidderResponses = singletonList( @@ -395,11 +392,10 @@ public void shouldOverwriteBidderIdToUUID() throws JsonProcessingException { // then assertThat(bidResponse.getSeatbid()).hasSize(1); assertThat(bidResponse.getSeatbid().get(0).getBid()).hasSize(1); - final ExtBidPrebid ext = mapper.readValue(bidResponse.getSeatbid().get(0).getBid().get(0) + final ExtBidPrebid expectedExtBidPrebid = mapper.readValue(bidResponse.getSeatbid().get(0).getBid().get(0) .getExt().get("prebid").toString(), ExtBidPrebid.class); - assertThat(ext.getBidId()).isNotNull(); + assertThat(expectedExtBidPrebid.getBidId()).isNotNull(); - System.out.println(ext.getBidId()); verify(cacheService, never()).cacheBidsOpenrtb(anyList(), anyList(), any(), any(), any()); } From 485e411e1ffa426878fbb1291192ba2b93250bd9 Mon Sep 17 00:00:00 2001 From: Andrey Paliy Date: Tue, 24 Mar 2020 15:46:54 +0200 Subject: [PATCH 06/14] test fix --- .../prebid/server/auction/BidResponseCreatorTest.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index ff6f5b93d15..b61709ead6f 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -392,9 +392,14 @@ public void shouldOverwriteBidderIdToUUID() throws JsonProcessingException { // then assertThat(bidResponse.getSeatbid()).hasSize(1); assertThat(bidResponse.getSeatbid().get(0).getBid()).hasSize(1); - final ExtBidPrebid expectedExtBidPrebid = mapper.readValue(bidResponse.getSeatbid().get(0).getBid().get(0) - .getExt().get("prebid").toString(), ExtBidPrebid.class); - assertThat(expectedExtBidPrebid.getBidId()).isNotNull(); + assertThat(bidResponse.getSeatbid()) + .flatExtracting(SeatBid::getBid) + .extracting(Bid::getExt) + .extracting(ext -> ext.get("prebid")) + .extracting(extPrebid -> mapper.treeToValue(extPrebid, ExtBidPrebid.class)) + .extracting(ExtBidPrebid::getBidId) + .hasSize(1) + .doesNotContainNull(); verify(cacheService, never()).cacheBidsOpenrtb(anyList(), anyList(), any(), any(), any()); } From 85dbf6e156b6237e14c281f68bfce1d9afc22c5f Mon Sep 17 00:00:00 2001 From: Andrey Paliy Date: Thu, 26 Mar 2020 13:29:23 +0200 Subject: [PATCH 07/14] applying change request --- .../server/auction/BidResponseCreator.java | 33 ++++++++++--------- .../openrtb/ext/response/ExtBidPrebid.java | 8 ++--- .../auction/BidResponseCreatorTest.java | 9 ++--- .../server/auction/ExchangeServiceTest.java | 2 +- .../auction/StoredResponseProcessorTest.java | 2 +- .../auction/VideoResponseFactoryTest.java | 6 ++-- .../handler/openrtb2/AmpHandlerTest.java | 28 ++++++++-------- 7 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index 3fe19efd02a..91f8c17e241 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -115,23 +115,27 @@ public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog } private Consumer overwriteBidIdConsumer() { - return bidderResponses -> { - bidderResponses.getSeatbid().stream() - .map(SeatBid::getBid) - .forEach(bids -> bids.stream() - .filter(Objects::nonNull) - .forEach(this::replaceBidId)); - - }; + return bidderResponses -> bidderResponses.getSeatbid().stream() + .map(SeatBid::getBid) + .forEach(bids -> bids.stream() + .filter(Objects::nonNull) + .forEach(this::replaceBidId)); } private void replaceBidId(Bid bid) { final ObjectNode ext = bid.getExt(); final ExtBidPrebid extBidPrebid = parsePrebidExt(ext); if (extBidPrebid != null) { - extBidPrebid.setBidId(UUID.randomUUID().toString()); + final ExtBidPrebid modifiedExtBidPrebid = ExtBidPrebid.of( + UUID.randomUUID().toString(), + extBidPrebid.getType(), + extBidPrebid.getTargeting(), + extBidPrebid.getCache(), + extBidPrebid.getStoredRequestAttributes(), + extBidPrebid.getEvents(), + extBidPrebid.getVideo()); try { - final JsonNode extBidPrebidValue = mapper.mapper().readTree(mapper.encode(extBidPrebid)); + final JsonNode extBidPrebidValue = mapper.mapper().readTree(mapper.encode(modifiedExtBidPrebid)); final ObjectNode prebidExtNode = ext.set(PREBID_EXT, extBidPrebidValue); bid.setExt(prebidExtNode); } catch (JsonProcessingException e) { @@ -689,12 +693,9 @@ private Bid toBid(BidderBid bidderBid, String bidder, ExtRequestTargeting target final Video storedVideo = impIdToStoredVideo.get(bid.getImpid()); final Events events = eventsEnabled ? eventsService.createEvent(bid.getId(), account.getId()) : null; - final ExtBidPrebid prebidExt = ExtBidPrebid.builder().type(bidType) - .targeting(targetingKeywords) - .cache(cache) - .storedRequestAttributes(storedVideo) - .events(events) - .build(); + final ExtBidPrebid prebidExt = ExtBidPrebid.of(null, bidType, targetingKeywords, cache, storedVideo, + events, null); + final ExtPrebid bidExt = ExtPrebid.of(prebidExt, bid.getExt()); bid.setExt(mapper.mapper().valueToTree(bidExt)); diff --git a/src/main/java/org/prebid/server/proto/openrtb/ext/response/ExtBidPrebid.java b/src/main/java/org/prebid/server/proto/openrtb/ext/response/ExtBidPrebid.java index 61b2110f52d..2c7cf635864 100644 --- a/src/main/java/org/prebid/server/proto/openrtb/ext/response/ExtBidPrebid.java +++ b/src/main/java/org/prebid/server/proto/openrtb/ext/response/ExtBidPrebid.java @@ -2,16 +2,16 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.iab.openrtb.request.Video; -import lombok.Builder; -import lombok.Data; +import lombok.AllArgsConstructor; +import lombok.Value; import java.util.Map; /** * Defines the contract for bidresponse.seatbid.bid[i].ext.prebid */ -@Builder(toBuilder = true) -@Data +@AllArgsConstructor(staticName = "of") +@Value public class ExtBidPrebid { String bidId; diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index b61709ead6f..c3b8ea57fff 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -370,11 +370,12 @@ public void shouldSkipBidderResponsesWhereSeatBidContainEmptyBids() { } @Test - public void shouldOverwriteBidderIdToUUID() throws JsonProcessingException { + public void shouldOverwriteBidderIdToUUID() { // given final BidRequest bidRequest = givenBidRequest(); - final ExtPrebid prebid = ExtPrebid.of(ExtBidPrebid.builder().type(banner).build(), null); + final ExtPrebid prebid = ExtPrebid.of(ExtBidPrebid.of(null, banner, null, + null, null, null, null), null); final Bid bid = Bid.builder() .id("123") .impid("imp123") @@ -427,7 +428,7 @@ public void shouldSetExpectedResponseSeatBidAndBidFields() { .price(BigDecimal.ONE) .adm("adm") .ext(mapper.valueToTree(ExtPrebid.of( - ExtBidPrebid.builder().type(banner).build(), singletonMap("bidExt", 1)))) + ExtBidPrebid.of(null, banner, null, null, null, null, null), singletonMap("bidExt", 1)))) .build())) .build()); @@ -562,7 +563,7 @@ public void shouldTolerateMissingExtInSeatBidAndBid() { .id("bidId") .price(BigDecimal.ONE) .ext(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().type(banner).build(), null))) + ExtPrebid.of(ExtBidPrebid.of(null, banner, null, null, null, null, null), null))) .build()); verify(cacheService, never()).cacheBidsOpenrtb(anyList(), anyList(), any(), any(), any()); diff --git a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java index 8e6bfe0122f..ecb6c5fb4be 100644 --- a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java +++ b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java @@ -1769,7 +1769,7 @@ private static Bid givenBid(Function bidBuilder) return bidBuilder.apply(Bid.builder() .id("bidId") .price(BigDecimal.ONE) - .ext(mapper.valueToTree(ExtPrebid.of(ExtBidPrebid.builder().build(), null)))) + .ext(mapper.valueToTree(ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null, null), null)))) .build(); } diff --git a/src/test/java/org/prebid/server/auction/StoredResponseProcessorTest.java b/src/test/java/org/prebid/server/auction/StoredResponseProcessorTest.java index d41263e9789..43ea37f7b59 100644 --- a/src/test/java/org/prebid/server/auction/StoredResponseProcessorTest.java +++ b/src/test/java/org/prebid/server/auction/StoredResponseProcessorTest.java @@ -553,7 +553,7 @@ public void mergeWithBidderResponsesShouldResolveBidTypeFromStoredBidExt() { singletonList(BidderBid.of(Bid.builder().id("bid1").build(), BidType.banner, "USD")), emptyList(), emptyList()), 100)); - final ExtBidPrebid extBidPrebid = ExtBidPrebid.builder().type(BidType.video).build(); + final ExtBidPrebid extBidPrebid = ExtBidPrebid.of(null, BidType.video, null, null, null, null, null); final List seatBid = singletonList(SeatBid.builder() .seat("rubicon").bid(singletonList(Bid.builder().ext(mapper.createObjectNode() diff --git a/src/test/java/org/prebid/server/auction/VideoResponseFactoryTest.java b/src/test/java/org/prebid/server/auction/VideoResponseFactoryTest.java index b65c57f2f68..cc18484f07d 100644 --- a/src/test/java/org/prebid/server/auction/VideoResponseFactoryTest.java +++ b/src/test/java/org/prebid/server/auction/VideoResponseFactoryTest.java @@ -42,19 +42,19 @@ public void shouldReturnExpectedVideoResponse() { final Bid bid0 = Bid.builder() .impid("0_0") .ext(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().targeting(targeting).build(), + ExtPrebid.of(ExtBidPrebid.of(null, null, targeting, null, null, null, null), mapper.createObjectNode()))) .build(); final Bid bid1 = Bid.builder() .impid("1_1") .ext(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().targeting(targeting).build(), + ExtPrebid.of(ExtBidPrebid.of(null, null, targeting, null, null, null, null), mapper.createObjectNode()))) .build(); final Bid bid2 = Bid.builder() .impid("2_1") .ext(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().build(), mapper.createObjectNode()))) + ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null, null), mapper.createObjectNode()))) .build(); final BidResponse bidResponse = BidResponse.builder() diff --git a/src/test/java/org/prebid/server/handler/openrtb2/AmpHandlerTest.java b/src/test/java/org/prebid/server/handler/openrtb2/AmpHandlerTest.java index 8d03ca090b4..ede852b9e66 100644 --- a/src/test/java/org/prebid/server/handler/openrtb2/AmpHandlerTest.java +++ b/src/test/java/org/prebid/server/handler/openrtb2/AmpHandlerTest.java @@ -349,7 +349,7 @@ public void shouldRespondWithExpectedResponse() { targeting.put("hb_cache_id_bidder1", "value2"); given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse( - mapper.valueToTree(ExtPrebid.of(ExtBidPrebid.builder().targeting(targeting).build(), null)))); + mapper.valueToTree(ExtPrebid.of(ExtBidPrebid.of(null, null, targeting, null, null, null, null), null)))); // when ampHandler.handle(routingContext); @@ -379,7 +379,7 @@ public void shouldRespondWithCustomTargetingIncluded() { .seat("bidder1") .bid(singletonList(Bid.builder() .ext(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().targeting(targeting).build(), + ExtPrebid.of(ExtBidPrebid.of(null, null, targeting, null, null, null, null), mapper.createObjectNode()))) .build())) .build())) @@ -459,7 +459,7 @@ public void shouldIncrementOkAmpRequestMetrics() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); + ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null, null), null)))); // when ampHandler.handle(routingContext); @@ -476,7 +476,7 @@ public void shouldIncrementAppRequestMetrics() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); + ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null, null), null)))); // when ampHandler.handle(routingContext); @@ -493,7 +493,7 @@ public void shouldIncrementNoCookieMetrics() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); + ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null, null), null)))); given(uidsCookie.hasLiveUids()).willReturn(false); @@ -516,7 +516,7 @@ public void shouldIncrementImpsRequestedMetrics() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); + ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null, null), null)))); // when ampHandler.handle(routingContext); @@ -535,7 +535,7 @@ public void shouldIncrementImpsTypesMetrics() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); + ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null, null), null)))); // when ampHandler.handle(routingContext); @@ -619,7 +619,7 @@ public void shouldUpdateNetworkErrorMetric() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); + ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null, null), null)))); // simulate calling exception handler that is supposed to update networkerr timer value given(httpResponse.exceptionHandler(any())).willAnswer(inv -> { @@ -642,7 +642,7 @@ public void shouldNotUpdateNetworkErrorMetricIfResponseSucceeded() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); + ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null, null), null)))); // when ampHandler.handle(routingContext); @@ -659,7 +659,7 @@ public void shouldUpdateNetworkErrorMetricIfClientClosedConnection() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().build(), null)))); + ExtPrebid.of(ExtBidPrebid.of(null, null, null, null, null, null, null), null)))); given(routingContext.response().closed()).willReturn(true); @@ -726,8 +726,8 @@ public void shouldPassSuccessfulEventToAnalyticsReporter() { given(exchangeService.holdAuction(any())) .willReturn(givenBidResponse(mapper.valueToTree( - ExtPrebid.of(ExtBidPrebid.builder().targeting(singletonMap("hb_cache_id_bidder1", "value1")) - .build(), + ExtPrebid.of(ExtBidPrebid.of(null, null, singletonMap("hb_cache_id_bidder1", "value1"), + null, null, null, null), null)))); // when @@ -745,8 +745,8 @@ public void shouldPassSuccessfulEventToAnalyticsReporter() { .bidResponse(BidResponse.builder().seatbid(singletonList(SeatBid.builder() .bid(singletonList(Bid.builder() .ext(mapper.valueToTree(ExtPrebid.of( - ExtBidPrebid.builder().targeting(singletonMap("hb_cache_id_bidder1", "value1")) - .build(), + ExtBidPrebid.of(null, null, singletonMap("hb_cache_id_bidder1", "value1"), + null, null, null, null), null))) .build())) .build())) From 61471de7a22c072b6c2659442b4466cd77a1116e Mon Sep 17 00:00:00 2001 From: Andrey Paliy Date: Mon, 30 Mar 2020 10:30:36 +0300 Subject: [PATCH 08/14] change request --- .../java/org/prebid/server/auction/BidResponseCreator.java | 4 ++-- .../org/prebid/server/auction/BidResponseCreatorTest.java | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index 91f8c17e241..d65a5aea588 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -139,14 +139,14 @@ private void replaceBidId(Bid bid) { final ObjectNode prebidExtNode = ext.set(PREBID_EXT, extBidPrebidValue); bid.setExt(prebidExtNode); } catch (JsonProcessingException e) { - logger.debug("Parsing error", e); + logger.debug("Error overwriting bid id", e); } } } private ExtBidPrebid parsePrebidExt(ObjectNode ext) { try { - return mapper.decodeValue(ext.get(PREBID_EXT).toString(), ExtBidPrebid.class); + return mapper.mapper().treeToValue(ext.get(PREBID_EXT), ExtBidPrebid.class); } catch (Exception e) { return null; } diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index c3b8ea57fff..350cd69bd2e 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -391,8 +391,6 @@ public void shouldOverwriteBidderIdToUUID() { null, CACHE_INFO, ACCOUNT, timeout, false).result(); // then - assertThat(bidResponse.getSeatbid()).hasSize(1); - assertThat(bidResponse.getSeatbid().get(0).getBid()).hasSize(1); assertThat(bidResponse.getSeatbid()) .flatExtracting(SeatBid::getBid) .extracting(Bid::getExt) From 813a7d184c94f3d14b816b1b0c05031db7b391e3 Mon Sep 17 00:00:00 2001 From: Andrey Paliy Date: Tue, 31 Mar 2020 11:00:08 +0300 Subject: [PATCH 09/14] change request --- .../server/auction/BidResponseCreator.java | 54 +++---------------- .../auction/BidResponseCreatorTest.java | 3 +- 2 files changed, 10 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index d65a5aea588..b0899131e6d 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -73,8 +73,8 @@ import java.util.Objects; import java.util.Set; import java.util.UUID; -import java.util.function.Consumer; import java.util.function.Function; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -95,7 +95,7 @@ public class BidResponseCreator { private final String cachePath; private final String cacheAssetUrlTemplate; private final StoredRequestProcessor storedRequestProcessor; - private final Consumer overwriteBidIdConsumer; + private final Supplier bidIdSupplier; public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog, EventsService eventsService, StoredRequestProcessor storedRequestProcessor, @@ -109,49 +109,12 @@ public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog this.storedRequestProcessor = Objects.requireNonNull(storedRequestProcessor); this.mapper = Objects.requireNonNull(mapper); - overwriteBidIdConsumer = BooleanUtils.isTrue(generateBidId) ? overwriteBidIdConsumer() : bidResponse -> { - }; + bidIdSupplier = BooleanUtils.isTrue(generateBidId) + ? () -> UUID.randomUUID().toString() + : () -> null; } - private Consumer overwriteBidIdConsumer() { - return bidderResponses -> bidderResponses.getSeatbid().stream() - .map(SeatBid::getBid) - .forEach(bids -> bids.stream() - .filter(Objects::nonNull) - .forEach(this::replaceBidId)); - } - - private void replaceBidId(Bid bid) { - final ObjectNode ext = bid.getExt(); - final ExtBidPrebid extBidPrebid = parsePrebidExt(ext); - if (extBidPrebid != null) { - final ExtBidPrebid modifiedExtBidPrebid = ExtBidPrebid.of( - UUID.randomUUID().toString(), - extBidPrebid.getType(), - extBidPrebid.getTargeting(), - extBidPrebid.getCache(), - extBidPrebid.getStoredRequestAttributes(), - extBidPrebid.getEvents(), - extBidPrebid.getVideo()); - try { - final JsonNode extBidPrebidValue = mapper.mapper().readTree(mapper.encode(modifiedExtBidPrebid)); - final ObjectNode prebidExtNode = ext.set(PREBID_EXT, extBidPrebidValue); - bid.setExt(prebidExtNode); - } catch (JsonProcessingException e) { - logger.debug("Error overwriting bid id", e); - } - } - } - - private ExtBidPrebid parsePrebidExt(ObjectNode ext) { - try { - return mapper.mapper().treeToValue(ext.get(PREBID_EXT), ExtBidPrebid.class); - } catch (Exception e) { - return null; - } - } - /** * Creates an OpenRTB {@link BidResponse} from the bids supplied by the bidder, * including processing of winning bids with cache IDs. @@ -564,14 +527,12 @@ private BidResponse toBidResponse( toExtBidResponse(bidderResponses, bidRequest, cacheResult, videoStoredDataResult, debugEnabled, bidErrors); - BidResponse response = BidResponse.builder() + return BidResponse.builder() .id(bidRequest.getId()) .cur(bidRequest.getCur().get(0)) .seatbid(seatBids) .ext(mapper.mapper().valueToTree(extBidResponse)) .build(); - overwriteBidIdConsumer.accept(response); - return response; } private Future videoStoredDataResult(List imps, Timeout timeout) { @@ -693,7 +654,8 @@ private Bid toBid(BidderBid bidderBid, String bidder, ExtRequestTargeting target final Video storedVideo = impIdToStoredVideo.get(bid.getImpid()); final Events events = eventsEnabled ? eventsService.createEvent(bid.getId(), account.getId()) : null; - final ExtBidPrebid prebidExt = ExtBidPrebid.of(null, bidType, targetingKeywords, cache, storedVideo, + final String bidId = bidIdSupplier.get(); + final ExtBidPrebid prebidExt = ExtBidPrebid.of(bidId, bidType, targetingKeywords, cache, storedVideo, events, null); final ExtPrebid bidExt = ExtPrebid.of(prebidExt, bid.getExt()); diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index 350cd69bd2e..8696b2a186c 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -86,7 +86,8 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -import static org.prebid.server.proto.openrtb.ext.response.BidType.*; +import static org.prebid.server.proto.openrtb.ext.response.BidType.banner; +import static org.prebid.server.proto.openrtb.ext.response.BidType.xNative; public class BidResponseCreatorTest extends VertxTest { From 42c412e7dcdfd17b97631ae3e85649989915fc2c Mon Sep 17 00:00:00 2001 From: Andrey Paliy Date: Tue, 31 Mar 2020 14:53:34 +0300 Subject: [PATCH 10/14] simplify code --- .../server/auction/BidResponseCreator.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index b0899131e6d..dbe1500dbb3 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -16,8 +16,6 @@ import com.iab.openrtb.response.Response; import com.iab.openrtb.response.SeatBid; import io.vertx.core.Future; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.MapUtils; @@ -74,15 +72,12 @@ import java.util.Set; import java.util.UUID; import java.util.function.Function; -import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; public class BidResponseCreator { - private static final Logger logger = LoggerFactory.getLogger(BidResponseCreator.class); - private static final String CACHE = "cache"; private static final String PREBID_EXT = "prebid"; @@ -95,7 +90,7 @@ public class BidResponseCreator { private final String cachePath; private final String cacheAssetUrlTemplate; private final StoredRequestProcessor storedRequestProcessor; - private final Supplier bidIdSupplier; + private final Boolean generateBidId; public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog, EventsService eventsService, StoredRequestProcessor storedRequestProcessor, @@ -108,11 +103,7 @@ public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog this.cacheAssetUrlTemplate = Objects.requireNonNull(cacheService.getCachedAssetURLTemplate()); this.storedRequestProcessor = Objects.requireNonNull(storedRequestProcessor); this.mapper = Objects.requireNonNull(mapper); - - bidIdSupplier = BooleanUtils.isTrue(generateBidId) - ? () -> UUID.randomUUID().toString() - : () -> null; - + this.generateBidId = generateBidId; } /** @@ -651,12 +642,14 @@ private Bid toBid(BidderBid bidderBid, String bidder, ExtRequestTargeting target cache = null; } + final String generatedBidId = BooleanUtils.toBoolean(this.generateBidId) ? UUID.randomUUID().toString() : null; final Video storedVideo = impIdToStoredVideo.get(bid.getImpid()); - final Events events = eventsEnabled ? eventsService.createEvent(bid.getId(), account.getId()) : null; + final Events events = eventsEnabled ? eventsService.createEvent( + generatedBidId != null ? generatedBidId : bid.getId(), account.getId()) : null; - final String bidId = bidIdSupplier.get(); - final ExtBidPrebid prebidExt = ExtBidPrebid.of(bidId, bidType, targetingKeywords, cache, storedVideo, - events, null); + final ExtBidPrebid prebidExt = ExtBidPrebid.of( + generatedBidId, bidType, targetingKeywords, cache, storedVideo, events, null + ); final ExtPrebid bidExt = ExtPrebid.of(prebidExt, bid.getExt()); bid.setExt(mapper.mapper().valueToTree(bidExt)); From fb1cef490d772b4f04980463d9e9d3459e13a330 Mon Sep 17 00:00:00 2001 From: Andrey Paliy Date: Tue, 31 Mar 2020 15:12:17 +0300 Subject: [PATCH 11/14] simplify code --- .../org/prebid/server/auction/BidResponseCreator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index dbe1500dbb3..3e745ed3ad6 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -642,13 +642,13 @@ private Bid toBid(BidderBid bidderBid, String bidder, ExtRequestTargeting target cache = null; } - final String generatedBidId = BooleanUtils.toBoolean(this.generateBidId) ? UUID.randomUUID().toString() : null; + final String extBidPrebidId = BooleanUtils.toBoolean(this.generateBidId) ? UUID.randomUUID().toString() : null; + final String eventId = BooleanUtils.toBoolean(this.generateBidId) ? extBidPrebidId : bid.getId(); final Video storedVideo = impIdToStoredVideo.get(bid.getImpid()); - final Events events = eventsEnabled ? eventsService.createEvent( - generatedBidId != null ? generatedBidId : bid.getId(), account.getId()) : null; + final Events events = eventsEnabled ? eventsService.createEvent(eventId, account.getId()) : null; final ExtBidPrebid prebidExt = ExtBidPrebid.of( - generatedBidId, bidType, targetingKeywords, cache, storedVideo, events, null + extBidPrebidId, bidType, targetingKeywords, cache, storedVideo, events, null ); final ExtPrebid bidExt = ExtPrebid.of(prebidExt, bid.getExt()); From 87ee7d108ffd7f7a4d70ada89b6b614eed6775da Mon Sep 17 00:00:00 2001 From: rpanchyk Date: Fri, 8 May 2020 12:05:03 +0300 Subject: [PATCH 12/14] Minor changes --- .../prebid/server/auction/BidResponseCreator.java | 12 ++++++------ .../server/spring/config/ServiceConfiguration.java | 6 +++--- .../server/auction/BidResponseCreatorTest.java | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index 32642bbd115..983e2e01606 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -20,6 +20,7 @@ import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.ObjectUtils; import org.prebid.server.auction.model.BidRequestCacheInfo; import org.prebid.server.auction.model.BidderResponse; import org.prebid.server.bidder.BidderCatalog; @@ -87,8 +88,8 @@ public class BidResponseCreator { private final BidderCatalog bidderCatalog; private final EventsService eventsService; private final StoredRequestProcessor storedRequestProcessor; + private final boolean generateBidId; private final JacksonMapper mapper; - private final Boolean generateBidId; private final String cacheHost; private final String cachePath; @@ -96,7 +97,7 @@ public class BidResponseCreator { public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog, EventsService eventsService, StoredRequestProcessor storedRequestProcessor, - JacksonMapper mapper, Boolean generateBidId) { + boolean generateBidId, JacksonMapper mapper) { this.cacheService = Objects.requireNonNull(cacheService); this.bidderCatalog = Objects.requireNonNull(bidderCatalog); this.eventsService = Objects.requireNonNull(eventsService); @@ -662,16 +663,15 @@ private Bid toBid(BidderBid bidderBid, String bidder, ExtRequestTargeting target cache = null; } - final String extBidPrebidId = BooleanUtils.toBoolean(this.generateBidId) ? UUID.randomUUID().toString() : null; - final String eventId = BooleanUtils.toBoolean(this.generateBidId) ? extBidPrebidId : bid.getId(); + final String extBidPrebidId = generateBidId ? UUID.randomUUID().toString() : null; + final String eventId = ObjectUtils.defaultIfNull(extBidPrebidId, bid.getId()); final Video storedVideo = impIdToStoredVideo.get(bid.getImpid()); final Events events = eventsEnabled && eventsAllowedByRequest ? eventsService.createEvent(eventId, bidder, account.getId(), auctionTimestamp) : null; final ExtBidPrebid prebidExt = ExtBidPrebid.of( - extBidPrebidId, bidType, targetingKeywords, cache, storedVideo, events, null - ); + extBidPrebidId, bidType, targetingKeywords, cache, storedVideo, events, null); final ExtPrebid bidExt = ExtPrebid.of(prebidExt, bid.getExt()); bid.setExt(mapper.mapper().valueToTree(bidExt)); diff --git a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java index 550981d9d42..a11542d5ea0 100644 --- a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java @@ -469,11 +469,11 @@ BidResponseCreator bidResponseCreator( BidderCatalog bidderCatalog, EventsService eventsService, StoredRequestProcessor storedRequestProcessor, - JacksonMapper mapper, - @Value("${auction.generate-bid-id}") Boolean generateBidId) { + @Value("${auction.generate-bid-id}") boolean generateBidId, + JacksonMapper mapper) { return new BidResponseCreator(cacheService, bidderCatalog, eventsService, storedRequestProcessor, - mapper, generateBidId); + generateBidId, mapper); } @Bean diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index 72a8b993858..bae404f06d4 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -125,7 +125,7 @@ public void setUp() { .willReturn(Future.succeededFuture(VideoStoredDataResult.empty())); bidResponseCreator = new BidResponseCreator(cacheService, bidderCatalog, eventsService, storedRequestProcessor, - jacksonMapper, false); + false, jacksonMapper); timeout = new TimeoutFactory(Clock.fixed(Instant.now(), ZoneId.systemDefault())).create(500); } @@ -430,7 +430,7 @@ public void shouldOverwriteBidderIdToUUID() { BidderResponse.of("bidder2", givenSeatBid(BidderBid.of(bid, banner, "USD")), 0)); final BidResponseCreator bidResponseCreator = new BidResponseCreator(cacheService, bidderCatalog, eventsService, - storedRequestProcessor, jacksonMapper, true); + storedRequestProcessor, true, jacksonMapper); // when final BidResponse bidResponse = bidResponseCreator.create(bidderResponses, bidRequest, null, CACHE_INFO, ACCOUNT, false, 1000L, false, timeout).result(); From 5273bac0929643f098c383c9eba8aa1b451d8122 Mon Sep 17 00:00:00 2001 From: rpanchyk Date: Fri, 8 May 2020 12:25:35 +0300 Subject: [PATCH 13/14] Fix org.prebid.server.proto.openrtb.ext.response.ExtBidPrebid.bidid --- .../org/prebid/server/auction/BidResponseCreator.java | 10 +++++----- .../proto/openrtb/ext/response/ExtBidPrebid.java | 2 +- .../prebid/server/auction/BidResponseCreatorTest.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index 983e2e01606..54578cc22b8 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -102,8 +102,8 @@ public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog this.bidderCatalog = Objects.requireNonNull(bidderCatalog); this.eventsService = Objects.requireNonNull(eventsService); this.storedRequestProcessor = Objects.requireNonNull(storedRequestProcessor); - this.mapper = Objects.requireNonNull(mapper); this.generateBidId = generateBidId; + this.mapper = Objects.requireNonNull(mapper); cacheHost = Objects.requireNonNull(cacheService.getEndpointHost()); cachePath = Objects.requireNonNull(cacheService.getEndpointPath()); @@ -663,15 +663,15 @@ private Bid toBid(BidderBid bidderBid, String bidder, ExtRequestTargeting target cache = null; } - final String extBidPrebidId = generateBidId ? UUID.randomUUID().toString() : null; - final String eventId = ObjectUtils.defaultIfNull(extBidPrebidId, bid.getId()); + final String generatedBidId = generateBidId ? UUID.randomUUID().toString() : null; + final String eventBidId = ObjectUtils.defaultIfNull(generatedBidId, bid.getId()); final Video storedVideo = impIdToStoredVideo.get(bid.getImpid()); final Events events = eventsEnabled && eventsAllowedByRequest - ? eventsService.createEvent(eventId, bidder, account.getId(), auctionTimestamp) + ? eventsService.createEvent(eventBidId, bidder, account.getId(), auctionTimestamp) : null; final ExtBidPrebid prebidExt = ExtBidPrebid.of( - extBidPrebidId, bidType, targetingKeywords, cache, storedVideo, events, null); + generatedBidId, bidType, targetingKeywords, cache, storedVideo, events, null); final ExtPrebid bidExt = ExtPrebid.of(prebidExt, bid.getExt()); bid.setExt(mapper.mapper().valueToTree(bidExt)); diff --git a/src/main/java/org/prebid/server/proto/openrtb/ext/response/ExtBidPrebid.java b/src/main/java/org/prebid/server/proto/openrtb/ext/response/ExtBidPrebid.java index 2c7cf635864..d4fb6fd0b00 100644 --- a/src/main/java/org/prebid/server/proto/openrtb/ext/response/ExtBidPrebid.java +++ b/src/main/java/org/prebid/server/proto/openrtb/ext/response/ExtBidPrebid.java @@ -14,7 +14,7 @@ @Value public class ExtBidPrebid { - String bidId; + String bidid; BidType type; diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index bae404f06d4..8b6f00fcd20 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -441,7 +441,7 @@ public void shouldOverwriteBidderIdToUUID() { .extracting(Bid::getExt) .extracting(ext -> ext.get("prebid")) .extracting(extPrebid -> mapper.treeToValue(extPrebid, ExtBidPrebid.class)) - .extracting(ExtBidPrebid::getBidId) + .extracting(ExtBidPrebid::getBidid) .hasSize(1) .doesNotContainNull(); From 9867e3058abb381dde7ef305800f188ea788baef Mon Sep 17 00:00:00 2001 From: rpanchyk Date: Fri, 8 May 2020 13:20:42 +0300 Subject: [PATCH 14/14] Fix tests --- .../org/prebid/server/auction/BidResponseCreatorTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index 8b6f00fcd20..3aa95219beb 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -71,6 +71,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; @@ -221,7 +222,7 @@ public void shouldRequestCacheServiceWithWinningBidsOnlyWhenWinningonlyIsTrue() // just a stub to get through method call chain givenCacheServiceResult(singletonMap(bid1, CacheIdInfo.of(null, null))); - // when\ + // when bidResponseCreator.create(bidderResponses, bidRequest, targeting, cacheInfo, ACCOUNT, false, 1000L, false, timeout); @@ -415,7 +416,7 @@ public void shouldSkipBidderResponsesWhereSeatBidContainEmptyBids() { } @Test - public void shouldOverwriteBidderIdToUUID() { + public void shouldOverrideBidIdWhenGenerateBidIdIsTurnedOn() { // given final BidRequest bidRequest = givenBidRequest(); @@ -443,7 +444,8 @@ public void shouldOverwriteBidderIdToUUID() { .extracting(extPrebid -> mapper.treeToValue(extPrebid, ExtBidPrebid.class)) .extracting(ExtBidPrebid::getBidid) .hasSize(1) - .doesNotContainNull(); + .first() + .satisfies(bidId -> assertThat(UUID.fromString(bidId)).isInstanceOf(UUID.class)); verify(cacheService, never()).cacheBidsOpenrtb(anyList(), anyList(), any(), any(), any(), any()); }