Skip to content

Commit ae7fdf9

Browse files
authored
Secondary bidders (#4331)
1 parent c574d91 commit ae7fdf9

13 files changed

Lines changed: 1166 additions & 87 deletions

File tree

src/main/java/org/prebid/server/auction/ExchangeService.java

Lines changed: 169 additions & 69 deletions
Large diffs are not rendered by default.

src/main/java/org/prebid/server/auction/externalortb/StoredResponseProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ private List<SeatBid> resolveSeatBids(StoredResponse storedResponse,
224224
Map<String, String> idToStoredResponses,
225225
String impId) {
226226

227-
if (storedResponse instanceof StoredResponse.StoredResponseObject storedResponseObject) {
228-
return Collections.singletonList(storedResponseObject.seatBid());
227+
if (storedResponse instanceof StoredResponse.StoredResponseObject(SeatBid seatBid)) {
228+
return Collections.singletonList(seatBid);
229229
}
230230

231231
final String storedResponseId = ((StoredResponse.StoredResponseId) storedResponse).id();
@@ -313,7 +313,7 @@ private static AuctionParticipation updateStoredBidResponse(AuctionParticipation
313313
final BidRequest bidRequest = bidderRequest.getBidRequest();
314314

315315
final List<Imp> imps = bidRequest.getImp();
316-
// Аor now, Stored Bid Response works only for bid requests with single imp
316+
// For now, Stored Bid Response works only for bid requests with single imp
317317
if (imps.size() > 1 || StringUtils.isEmpty(bidderRequest.getStoredResponse())) {
318318
return auctionParticipation;
319319
}

src/main/java/org/prebid/server/auction/model/AuctionContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ public AuctionContext with(BidResponse bidResponse) {
8383
return this.toBuilder().bidResponse(bidResponse).build();
8484
}
8585

86+
public AuctionContext with(Map<String, BidRejectionTracker> bidRejectionTrackers) {
87+
return this.toBuilder().bidRejectionTrackers(bidRejectionTrackers).build();
88+
}
89+
8690
public AuctionContext with(List<AuctionParticipation> auctionParticipations) {
8791
return this.toBuilder().auctionParticipations(auctionParticipations).build();
8892
}

src/main/java/org/prebid/server/auction/model/BidRejectionTracker.java

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,48 @@ public BidRejectionTracker(String bidder, Set<String> involvedImpIds, double log
4545
rejections = new HashMap<>();
4646
}
4747

48-
public BidRejectionTracker(BidRejectionTracker anotherTracker, Set<String> additionalImpIds) {
49-
this.bidder = anotherTracker.bidder;
50-
this.logSamplingRate = anotherTracker.logSamplingRate;
51-
this.involvedImpIds = new HashSet<>(anotherTracker.involvedImpIds);
52-
this.involvedImpIds.addAll(additionalImpIds);
53-
54-
this.succeededBidsIds = new HashMap<>(anotherTracker.succeededBidsIds);
55-
this.rejections = new HashMap<>(anotherTracker.rejections);
48+
private BidRejectionTracker(
49+
String bidder,
50+
Set<String> involvedImpIds,
51+
Map<String, Set<String>> succeededBidsIds,
52+
Map<String, List<Rejection>> rejections,
53+
double logSamplingRate) {
54+
55+
this.bidder = bidder;
56+
this.involvedImpIds = new HashSet<>(involvedImpIds);
57+
this.logSamplingRate = logSamplingRate;
58+
59+
this.succeededBidsIds = MapUtil.mapValues(succeededBidsIds, v -> new HashSet<>(v));
60+
this.rejections = MapUtil.mapValues(rejections, ArrayList::new);
5661
}
5762

58-
public void succeed(Collection<BidderBid> bids) {
63+
public static BidRejectionTracker copyOf(BidRejectionTracker anotherTracker) {
64+
return new BidRejectionTracker(
65+
anotherTracker.bidder,
66+
anotherTracker.involvedImpIds,
67+
anotherTracker.succeededBidsIds,
68+
anotherTracker.rejections,
69+
anotherTracker.logSamplingRate);
70+
}
71+
72+
public static BidRejectionTracker withAdditionalImpIds(
73+
BidRejectionTracker anotherTracker,
74+
Set<String> additionalImpIds) {
75+
76+
final BidRejectionTracker newTracker = copyOf(anotherTracker);
77+
newTracker.involvedImpIds.addAll(additionalImpIds);
78+
return newTracker;
79+
}
80+
81+
public BidRejectionTracker succeed(Collection<BidderBid> bids) {
5982
bids.stream()
6083
.map(BidderBid::getBid)
6184
.filter(Objects::nonNull)
6285
.forEach(this::succeed);
86+
return this;
6387
}
6488

65-
private void succeed(Bid bid) {
89+
private BidRejectionTracker succeed(Bid bid) {
6690
final String bidId = bid.getId();
6791
final String impId = bid.getImpid();
6892
if (involvedImpIds.contains(impId)) {
@@ -73,21 +97,23 @@ private void succeed(Bid bid) {
7397
logSamplingRate);
7498
}
7599
}
100+
return this;
76101
}
77102

78103
public void restoreFromRejection(Collection<BidderBid> bids) {
79104
succeed(bids);
80105
}
81106

82-
public void reject(Collection<Rejection> rejections) {
107+
public BidRejectionTracker reject(Collection<Rejection> rejections) {
83108
rejections.forEach(this::reject);
109+
return this;
84110
}
85111

86-
public void reject(Rejection rejection) {
112+
public BidRejectionTracker reject(Rejection rejection) {
87113
if (rejection instanceof ImpRejection && rejection.reason().getValue() >= 300) {
88114
logger.warn("The rejected imp {} with the code {} equal to or higher than 300 assumes "
89115
+ "that there is a rejected bid that shouldn't be lost");
90-
return;
116+
return this;
91117
}
92118

93119
final String impId = rejection.impId();
@@ -113,14 +139,18 @@ public void reject(Rejection rejection) {
113139
}
114140
}
115141
}
142+
143+
return this;
116144
}
117145

118-
public void rejectImps(Collection<String> impIds, BidRejectionReason reason) {
146+
public BidRejectionTracker rejectImps(Collection<String> impIds, BidRejectionReason reason) {
119147
impIds.forEach(impId -> reject(ImpRejection.of(impId, reason)));
148+
return this;
120149
}
121150

122-
public void rejectAll(BidRejectionReason reason) {
151+
public BidRejectionTracker rejectAll(BidRejectionReason reason) {
123152
involvedImpIds.forEach(impId -> reject(ImpRejection.of(impId, reason)));
153+
return this;
124154
}
125155

126156
public Set<Rejection> getRejected() {

src/main/java/org/prebid/server/proto/openrtb/ext/request/ExtRequestPrebid.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import java.util.List;
1414
import java.util.Map;
15+
import java.util.Set;
1516

1617
/**
1718
* Defines the contract for bidrequest.ext.prebid
@@ -200,4 +201,7 @@ public class ExtRequestPrebid {
200201
ExtRequestPrebidAlternateBidderCodes alternateBidderCodes;
201202

202203
ObjectNode kvps;
204+
205+
@JsonProperty("secondarybidders")
206+
Set<String> secondaryBidders;
203207
}

src/main/java/org/prebid/server/settings/model/AccountAuctionConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.prebid.server.spring.config.bidder.model.MediaType;
1010

1111
import java.util.Map;
12+
import java.util.Set;
1213

1314
@Builder(toBuilder = true)
1415
@Value
@@ -65,4 +66,7 @@ public class AccountAuctionConfig {
6566
Integer impressionLimit;
6667

6768
AccountProfilesConfig profiles;
69+
70+
@JsonAlias("secondary-bidders")
71+
Set<String> secondaryBidders;
6872
}

src/main/java/org/prebid/server/util/MapUtil.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import java.util.Collections;
44
import java.util.HashMap;
55
import java.util.Map;
6+
import java.util.function.BiFunction;
7+
import java.util.function.Function;
8+
import java.util.stream.Collectors;
69

710
public class MapUtil {
811

@@ -15,4 +18,23 @@ public static <T, U> Map<T, U> merge(Map<T, U> left, Map<T, U> right) {
1518

1619
return Collections.unmodifiableMap(merged);
1720
}
21+
22+
public static <K, V1, V2> Map<K, V2> mapValues(Map<K, V1> map, Function<V1, V2> transform) {
23+
return mapValues(map, (ignored, value) -> transform.apply(value));
24+
}
25+
26+
public static <K, V1, V2> Map<K, V2> mapValues(Map<K, V1> map, BiFunction<K, V1, V2> transform) {
27+
return map.entrySet().stream().collect(
28+
Collectors.toMap(Map.Entry::getKey, entry -> transform.apply(entry.getKey(), entry.getValue())));
29+
}
30+
31+
public static <K, V1, V2> Function<Map.Entry<K, V1>, Map.Entry<K, V2>> mapEntryValueMapper(
32+
BiFunction<K, V1, V2> transform) {
33+
34+
return mapEntryMapper((key, value) -> Map.entry(key, transform.apply(key, value)));
35+
}
36+
37+
public static <K, V, T> Function<Map.Entry<K, V>, T> mapEntryMapper(BiFunction<K, V, T> transform) {
38+
return entry -> transform.apply(entry.getKey(), entry.getValue());
39+
}
1840
}

src/test/groovy/org/prebid/server/functional/model/config/AccountAuctionConfig.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class AccountAuctionConfig {
3737
BidAdjustment bidAdjustments
3838
BidRounding bidRounding
3939
Integer impressionLimit
40+
List<BidderName> secondaryBidders
4041

4142
@JsonProperty("price_granularity")
4243
PriceGranularityType priceGranularitySnakeCase
@@ -58,5 +59,7 @@ class AccountAuctionConfig {
5859
BidRounding bidRoundingSnakeCase
5960
@JsonProperty("impression_limit")
6061
Integer impressionLimitSnakeCase
62+
@JsonProperty("secondary_bidders")
63+
List<BidderName> secondaryBiddersSnakeCase
6164

6265
}

src/test/groovy/org/prebid/server/functional/model/request/auction/BidRequest.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,16 @@ class BidRequest {
170170
ext.prebid.events = new Events()
171171
}
172172
}
173+
174+
void enabledReturnAllBidStatus() {
175+
if (!ext) {
176+
ext = new BidRequestExt()
177+
}
178+
if (!ext.prebid) {
179+
ext.prebid = new Prebid()
180+
}
181+
if (!ext.prebid.returnAllBidStatus) {
182+
ext.prebid.returnAllBidStatus = true
183+
}
184+
}
173185
}

src/test/groovy/org/prebid/server/functional/model/request/auction/Prebid.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Prebid {
4949
List<String> profileNames
5050
@JsonProperty("kvps")
5151
Map<String, String> keyValuePairs
52+
List<BidderName> secondaryBidders
5253

5354
static class Channel {
5455

0 commit comments

Comments
 (0)