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

Refactor bidder bid #1684

Merged
merged 4 commits into from
Feb 1, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private List<BidderResponse> updateBids(List<BidderResponse> bidderResponses,

final Bid updatedBid = updateBid(
receivedBid, bidType, bidder, videoStoredDataResult, auctionContext, eventsContext, lineItemId);
modifiedBidderBids.add(bidderBid.with(updatedBid));
modifiedBidderBids.add(bidderBid.toBuilder().bid(updatedBid).build());
}

final BidderSeatBid modifiedSeatBid = seatBid.with(modifiedBidderBids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ private BidderBid updateBidderBidWithBidPriceChanges(BidderBid bidderBid,
bidBuilder.ext(updatedBidExt);
}

return bidderBid.with(bidBuilder.build());
return bidderBid.toBuilder().bid(bidBuilder.build()).build();
}

private static BidAdjustmentMediaType resolveBidAdjustmentMediaType(String bidImpId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,13 @@ private BidderBid toBidderBid(Bid bid, String currency, List<BidderError> errors
cat = Collections.emptyList();
}

return BidderBid.of(
bid.toBuilder().cat(cat).build(),
bidType(appnexus.getBidAdType()),
currency,
appnexus.getDealPriority(),
makeExtBidVideo(appnexus));
return BidderBid.builder()
.bid(bid.toBuilder().cat(cat).build())
.type(bidType(appnexus.getBidAdType()))
.bidCurrency(currency)
.dealPriority(appnexus.getDealPriority())
.videoInfo(makeExtBidVideo(appnexus))
.build();
}

private static ExtBidPrebidVideo makeExtBidVideo(AppnexusBidExtAppnexus extAppnexus) {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/prebid/server/bidder/model/BidderBid.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.prebid.server.bidder.model;

import com.iab.openrtb.response.Bid;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Value;
import org.prebid.server.bidder.Bidder;
import org.prebid.server.proto.openrtb.ext.response.BidType;
Expand All @@ -10,14 +10,10 @@
/**
* Bid returned by a {@link Bidder}.
*/
@AllArgsConstructor(staticName = "of")
@Builder(toBuilder = true)
@Value
public class BidderBid {

public static BidderBid of(Bid bid, BidType bidType, String bidCurrency) {
return BidderBid.of(bid, bidType, bidCurrency, null, null);
}

/**
* bid.ext will become "response.seatbid[i].bid.ext.bidder" in the final OpenRTB response
*/
Expand All @@ -43,7 +39,11 @@ public static BidderBid of(Bid bid, BidType bidType, String bidCurrency) {
*/
ExtBidPrebidVideo videoInfo;

public BidderBid with(Bid bid) {
return BidderBid.of(bid, this.type, this.bidCurrency);
public static BidderBid of(Bid bid, BidType bidType, String bidCurrency) {
return BidderBid.builder()
.bid(bid)
.type(bidType)
.bidCurrency(bidCurrency)
.build();
}
}
21 changes: 11 additions & 10 deletions src/main/java/org/prebid/server/cache/CacheService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.response.Bid;
import io.vertx.core.Future;
import io.vertx.core.MultiMap;
import io.vertx.core.logging.Logger;
Expand Down Expand Up @@ -307,7 +308,7 @@ private CacheBid toCacheBid(BidInfo bidInfo,
CacheTtl accountCacheTtl,
boolean isVideoBid) {

final com.iab.openrtb.response.Bid bid = bidInfo.getBid();
final Bid bid = bidInfo.getBid();
final Integer bidTtl = bid.getExp();
final Imp correspondingImp = bidInfo.getCorrespondingImp();
final Integer impTtl = correspondingImp != null ? correspondingImp.getExp() : null;
Expand Down Expand Up @@ -466,7 +467,7 @@ private CachedCreative createJsonPutObjectOpenrtb(CacheBid cacheBid,
EventsContext eventsContext) {

final BidInfo bidInfo = cacheBid.getBidInfo();
final com.iab.openrtb.response.Bid bid = bidInfo.getBid();
final Bid bid = bidInfo.getBid();
final ObjectNode bidObjectNode = mapper.mapper().valueToTree(bid);

final String eventUrl =
Expand Down Expand Up @@ -494,7 +495,7 @@ private CachedCreative createJsonPutObjectOpenrtb(CacheBid cacheBid,
*/
private CachedCreative createXmlPutObjectOpenrtb(CacheBid cacheBid, String requestId, String hbCacheId) {
final BidInfo bidInfo = cacheBid.getBidInfo();
final com.iab.openrtb.response.Bid bid = bidInfo.getBid();
final Bid bid = bidInfo.getBid();
final String vastXml = bid.getAdm();

final String customCacheKey = resolveCustomCacheKey(hbCacheId, bidInfo.getCategory());
Expand Down Expand Up @@ -583,17 +584,17 @@ private <T> List<T> toResponse(BidCacheResponse bidCacheResponse, Function<Cache
/**
* Creates a map with bids as a key and {@link CacheInfo} as a value from obtained UUIDs.
*/
private static Map<com.iab.openrtb.response.Bid, CacheInfo> toResultMap(List<CacheBid> cacheBids,
List<CacheBid> cacheVideoBids,
List<String> uuids,
String hbCacheId) {
private static Map<Bid, CacheInfo> toResultMap(List<CacheBid> cacheBids,
List<CacheBid> cacheVideoBids,
List<String> uuids,
String hbCacheId) {

final Map<com.iab.openrtb.response.Bid, CacheInfo> result = new HashMap<>(uuids.size());
final Map<Bid, CacheInfo> result = new HashMap<>(uuids.size());

// here we assume "videoBids" is a sublist of "bids"
// so, no need for a separate loop on "videoBids" if "bids" is not empty
if (!cacheBids.isEmpty()) {
final List<com.iab.openrtb.response.Bid> videoBids = cacheVideoBids.stream()
final List<Bid> videoBids = cacheVideoBids.stream()
.map(CacheBid::getBidInfo)
.map(BidInfo::getBid)
.collect(Collectors.toList());
Expand All @@ -602,7 +603,7 @@ private static Map<com.iab.openrtb.response.Bid, CacheInfo> toResultMap(List<Cac
for (int i = 0; i < bidsSize; i++) {
final CacheBid cacheBid = cacheBids.get(i);
final BidInfo bidInfo = cacheBid.getBidInfo();
final com.iab.openrtb.response.Bid bid = bidInfo.getBid();
final Bid bid = bidInfo.getBid();
final Integer ttl = cacheBid.getTtl();

// determine uuid for video bid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1194,11 +1194,16 @@ private static BidderResponse givenBidderResponse(String bidder, BidderBid... bi
}

private static BidderBid givenBidderBid(Bid bid, BidType bidType, Integer duration) {
return BidderBid.of(bid, bidType, null, 5, ExtBidPrebidVideo.of(duration, null));
return givenBidderBid(bid, bidType, duration, null);
}

private static BidderBid givenBidderBid(Bid bid, BidType bidType, Integer duration, String primaryCategory) {
return BidderBid.of(bid, bidType, null, 5, ExtBidPrebidVideo.of(duration, primaryCategory));
return BidderBid.builder()
.bid(bid)
.type(bidType)
.dealPriority(5)
.videoInfo(ExtBidPrebidVideo.of(duration, primaryCategory))
.build();
}

private static Bid givenBid(String bidId, String impId, String price, List<String> cat) {
Expand Down