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();