Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bidderInfoResponse container as a first step to use BidInfo in workflow #1254

Merged
merged 5 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
374 changes: 189 additions & 185 deletions src/main/java/org/prebid/server/auction/BidResponseCreator.java

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/main/java/org/prebid/server/auction/model/BidInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ public class BidInfo {

Bid bid;

// Can be null
Imp correspondingImp;

String bidCurrency;

String bidder;

BidType bidType;

CacheInfo cacheInfo;

TargetingInfo targetingInfo;

public String getBidId() {
return generatedBidId != null ? generatedBidId : bid.getId();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.prebid.server.auction.model;

import lombok.AllArgsConstructor;
import lombok.Value;
import org.prebid.server.bidder.model.BidderSeatBidInfo;

@AllArgsConstructor(staticName = "of")
@Value
public class BidderResponseInfo {

String bidder;

BidderSeatBidInfo seatBid;

int responseTime;

public BidderResponseInfo with(BidderSeatBidInfo seatBid) {
return of(this.bidder, seatBid, this.responseTime);
}
}
19 changes: 19 additions & 0 deletions src/main/java/org/prebid/server/auction/model/TargetingInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.prebid.server.auction.model;

import lombok.Builder;
import lombok.Value;

@Builder(toBuilder = true)
@Value
public class TargetingInfo {

String bidderCode;

boolean isTargetingEnabled;

boolean isWinningBid;

boolean isBidderWinningBid;

boolean isAddTargetBidderCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.List;

/**
* Seatid returned by a {@link Bidder}.
* Seatbid returned by a {@link Bidder}.
* <p>
* This is distinct from the {@link com.iab.openrtb.response.SeatBid} so that the prebid-server ext can be passed
* back with type safety.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.prebid.server.bidder.model;

import lombok.AllArgsConstructor;
import lombok.Value;
import org.prebid.server.auction.model.BidInfo;
import org.prebid.server.proto.openrtb.ext.response.ExtHttpCall;

import java.util.List;

@AllArgsConstructor(staticName = "of")
@Value
public class BidderSeatBidInfo {

List<BidInfo> bidsInfos;

List<ExtHttpCall> httpCalls;

List<BidderError> errors;

public BidderSeatBidInfo with(List<BidInfo> bids) {
return BidderSeatBidInfo.of(bids, this.httpCalls, this.errors);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/prebid/server/cache/CacheService.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private CacheBid toCacheBid(BidInfo bidInfo,
final com.iab.openrtb.response.Bid bid = bidInfo.getBid();
final Integer bidTtl = bid.getExp();
final Imp correspondingImp = bidInfo.getCorrespondingImp();
final Integer impTtl = correspondingImp.getExp();
final Integer impTtl = correspondingImp != null ? correspondingImp.getExp() : null;
final Integer accountMediaTypeTtl = isVideoBid
? accountCacheTtl.getVideoCacheTtl()
: accountCacheTtl.getBannerCacheTtl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.prebid.server.auction.model.BidRequestCacheInfo;
import org.prebid.server.auction.model.BidderResponse;
import org.prebid.server.auction.model.MultiBidConfig;
import org.prebid.server.auction.model.TargetingInfo;
import org.prebid.server.bidder.BidderCatalog;
import org.prebid.server.bidder.model.BidderBid;
import org.prebid.server.bidder.model.BidderError;
Expand Down Expand Up @@ -245,8 +246,9 @@ public void shouldRequestCacheServiceWithExpectedArguments() {
// then
final BidInfo bidInfo1 = toBidInfo(bid1, imp1, "bidder1", banner);
final BidInfo bidInfo2 = toBidInfo(bid2, imp2, "bidder1", banner);
final BidInfo bidInfo3 = toBidInfo(bid3, imp1, "bidder2", banner);
final BidInfo bidInfo4 = toBidInfo(bid4, imp2, "bidder2", banner);
final TargetingInfo loosedTargetingInfo = toTargetingInfo("bidder2", false);
final BidInfo bidInfo3 = toBidInfo(bid3, null, imp1, "bidder2", banner, loosedTargetingInfo);
final BidInfo bidInfo4 = toBidInfo(bid4, null, imp2, "bidder2", banner, loosedTargetingInfo);
ArgumentCaptor<CacheContext> contextArgumentCaptor = ArgumentCaptor.forClass(CacheContext.class);
verify(cacheService).cacheBidsOpenrtb(
argThat(t -> t.containsAll(asList(bidInfo1, bidInfo2, bidInfo3, bidInfo4))),
Expand Down Expand Up @@ -305,10 +307,11 @@ public void shouldRequestCacheServiceWithWinningBidsOnlyWhenWinningonlyIsTrue()
bidResponseCreator.create(bidderResponses, auctionContext, cacheInfo, MULTI_BIDS, false);

// then

final BidInfo bidInfo1 = toBidInfo(bid1, imp1, "bidder1", banner);
final BidInfo bidInfo2 = toBidInfo(bid2, imp2, "bidder1", banner);
verify(cacheService).cacheBidsOpenrtb(
argThat(t -> t.containsAll(asList(bidInfo1, bidInfo2))),
argThat(t -> t.containsAll(asList(bidInfo2, bidInfo1))),
same(auctionContext),
any(),
eq(EventsContext.builder().auctionTimestamp(1000L).build()));
Expand Down Expand Up @@ -615,7 +618,16 @@ public void shouldUseGeneratedBidIdForEventAndCacheWhenIdGeneratorIsUUIDAndEvent
bidResponseCreator.create(bidderResponses, auctionContext, cacheInfo, MULTI_BIDS, false).result();

// then
final BidInfo expectedBidInfo = toBidInfo(bid, generatedBid, imp, bidder, banner);
TargetingInfo.builder()
.bidderCode(bidder)
.isTargetingEnabled(true)
.isWinningBid(true)
.isBidderWinningBid(true)
.isAddTargetBidderCode(false)
.build();

final TargetingInfo targetingInfo = toTargetingInfo(bidder, true);
final BidInfo expectedBidInfo = toBidInfo(bid, generatedBid, imp, bidder, banner, targetingInfo);
verify(cacheService).cacheBidsOpenrtb(eq(singletonList(expectedBidInfo)), any(), any(), any());

verify(eventsService).createEvent(eq(generatedBid), anyString(), anyString(), anyLong(), anyString());
Expand Down Expand Up @@ -2252,20 +2264,33 @@ private static BidInfo toBidInfo(Bid bid,
.correspondingImp(correspondingImp)
.bidder(bidder)
.bidType(bidType)
.targetingInfo(toTargetingInfo(bidder, true))
.build();
}

private static BidInfo toBidInfo(Bid bid,
String generatedBidId,
Imp correspondingImp,
String bidder,
BidType bidType) {
BidType bidType,
TargetingInfo targetingInfo) {
return BidInfo.builder()
.generatedBidId(generatedBidId)
.bid(bid)
.correspondingImp(correspondingImp)
.bidder(bidder)
.bidType(bidType)
.targetingInfo(targetingInfo)
.build();
}

private static TargetingInfo toTargetingInfo(String bidder, boolean isWinningBid) {
return TargetingInfo.builder()
.bidderCode(bidder)
.isTargetingEnabled(true)
.isWinningBid(isWinningBid)
.isBidderWinningBid(true)
.isAddTargetBidderCode(false)
.build();
}

Expand Down