Skip to content

Commit

Permalink
Replaced some fields from BidInfo with BidderBid.
Browse files Browse the repository at this point in the history
  • Loading branch information
CTMBNara committed Jan 14, 2022
1 parent 3d49469 commit c39115d
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 77 deletions.
27 changes: 14 additions & 13 deletions src/main/java/org/prebid/server/auction/BidResponseCreator.java
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 Expand Up @@ -410,8 +410,7 @@ private BidInfo toBidInfo(Bid bid,
final String lineItemId = extDealLine != null ? extDealLine.getLineItemId() : null;

return BidInfo.builder()
.bid(bid)
.bidType(type)
.bidderBid(BidderBid.builder().bid(bid).type(type).build())
.bidder(bidder)
.correspondingImp(correspondingImp)
.lineItemId(lineItemId)
Expand Down Expand Up @@ -642,7 +641,7 @@ private static void updateTopMatchAndLostAuctionLineItemsMetric(Set<BidInfo> win
if (winningLineItemId != null) {
txnLog.lineItemSentToClientAsTopMatch().add(winningLineItemId);

final String impIdOfWinningBid = winningBidInfo.getBid().getImpid();
final String impIdOfWinningBid = winningBidInfo.getBidderBid().getBid().getImpid();
impToLineItemIds.get(impIdOfWinningBid).stream()
.filter(lineItemId -> !Objects.equals(lineItemId, winningLineItemId))
.forEach(lineItemId -> txnLog.lostAuctionToLineItems().get(lineItemId).add(winningLineItemId));
Expand Down Expand Up @@ -808,7 +807,7 @@ private Future<CacheServiceResult> cacheBids(Set<BidInfo> bidsToCache,
}

private static boolean isValidForCaching(BidInfo bidInfo) {
final Bid bid = bidInfo.getBid();
final Bid bid = bidInfo.getBidderBid().getBid();
final BigDecimal price = bid.getPrice();
return bid.getDealid() != null ? price.compareTo(BigDecimal.ZERO) >= 0 : price.compareTo(BigDecimal.ZERO) > 0;
}
Expand All @@ -818,7 +817,8 @@ private static boolean isValidForCaching(BidInfo bidInfo) {
*/
private static Map<Bid, CacheInfo> toMapBidsWithEmptyCacheIds(Set<BidInfo> bids) {
return bids.stream()
.map(BidInfo::getBid)
.map(BidInfo::getBidderBid)
.map(BidderBid::getBid)
.collect(Collectors.toMap(Function.identity(), ignored -> CacheInfo.empty()));
}

Expand All @@ -831,7 +831,7 @@ private static CacheServiceResult addNotCachedBids(CacheServiceResult cacheResul
if (bidInfos.size() > bidToCacheId.size()) {
final Map<Bid, CacheInfo> updatedBidToCacheInfo = new HashMap<>(bidToCacheId);
for (BidInfo bidInfo : bidInfos) {
final Bid bid = bidInfo.getBid();
final Bid bid = bidInfo.getBidderBid().getBid();
if (!updatedBidToCacheInfo.containsKey(bid)) {
updatedBidToCacheInfo.put(bid, CacheInfo.empty());
}
Expand Down Expand Up @@ -1206,8 +1206,8 @@ private BidInfo injectAdmWithCacheInfo(BidInfo bidInfo,
Map<Bid, CacheInfo> bidsWithCacheIds,
Map<String, List<ExtBidderError>> bidErrors) {

final Bid bid = bidInfo.getBid();
final BidType bidType = bidInfo.getBidType();
final BidderBid bidderBid = bidInfo.getBidderBid();
final Bid bid = bidderBid.getBid();
final String bidder = bidInfo.getBidder();
final Imp correspondingImp = bidInfo.getCorrespondingImp();

Expand All @@ -1221,7 +1221,7 @@ private BidInfo injectAdmWithCacheInfo(BidInfo bidInfo,
modifiedBidAdm = null;
}

if (bidType.equals(BidType.xNative) && modifiedBidAdm != null) {
if (bidderBid.getType().equals(BidType.xNative) && modifiedBidAdm != null) {
try {
modifiedBidAdm = createNativeMarkup(modifiedBidAdm, correspondingImp);
} catch (PreBidException e) {
Expand All @@ -1233,7 +1233,7 @@ private BidInfo injectAdmWithCacheInfo(BidInfo bidInfo,

final Bid modifiedBid = bid.toBuilder().adm(modifiedBidAdm).build();
return bidInfo.toBuilder()
.bid(modifiedBid)
.bidderBid(bidderBid.toBuilder().bid(modifiedBid).build())
.cacheInfo(cacheInfo)
.build();
}
Expand All @@ -1243,8 +1243,9 @@ private BidInfo injectAdmWithCacheInfo(BidInfo bidInfo,
*/
private Bid toBid(BidInfo bidInfo, ExtRequestTargeting targeting, BidRequest bidRequest, Account account) {
final TargetingInfo targetingInfo = bidInfo.getTargetingInfo();
final BidType bidType = bidInfo.getBidType();
final Bid bid = bidInfo.getBid();
final BidderBid bidderBid = bidInfo.getBidderBid();
final BidType bidType = bidderBid.getType();
final Bid bid = bidderBid.getBid();

final CacheInfo cacheInfo = bidInfo.getCacheInfo();
final String cacheId = cacheInfo != null ? cacheInfo.getCacheId() : null;
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 @@ -43,8 +43,8 @@ private static class WinningBidDealComparator implements Comparator<BidInfo> {

@Override
public int compare(BidInfo bidInfo1, BidInfo bidInfo2) {
final boolean isPresentBidDealId1 = bidInfo1.getBid().getDealid() != null;
final boolean isPresentBidDealId2 = bidInfo2.getBid().getDealid() != null;
final boolean isPresentBidDealId1 = bidInfo1.getBidderBid().getBid().getDealid() != null;
final boolean isPresentBidDealId2 = bidInfo2.getBidderBid().getBid().getDealid() != null;

if (!Boolean.logicalXor(isPresentBidDealId1, isPresentBidDealId2)) {
return 0;
Expand Down Expand Up @@ -76,8 +76,8 @@ public int compare(BidInfo bidInfo1, BidInfo bidInfo2) {
return 0;
}

final Bid bid1 = bidInfo1.getBid();
final Bid bid2 = bidInfo2.getBid();
final Bid bid1 = bidInfo1.getBidderBid().getBid();
final Bid bid2 = bidInfo2.getBidderBid().getBid();

int indexOfBidDealId1 = -1;
int indexOfBidDealId2 = -1;
Expand Down Expand Up @@ -111,7 +111,8 @@ public int compare(BidInfo bidInfo1, BidInfo bidInfo2) {
*/
private static class WinningBidPriceComparator implements Comparator<BidInfo> {

private static final Comparator<BidInfo> PRICE_COMPARATOR = Comparator.comparing(o -> o.getBid().getPrice());
private static final Comparator<BidInfo> PRICE_COMPARATOR =
Comparator.comparing(o -> o.getBidderBid().getBid().getPrice());

@Override
public int compare(BidInfo bidInfo1, BidInfo bidInfo2) {
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/prebid/server/auction/model/BidInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
import com.iab.openrtb.response.Bid;
import lombok.Builder;
import lombok.Value;
import org.prebid.server.bidder.model.BidderBid;
import org.prebid.server.cache.model.CacheInfo;
import org.prebid.server.proto.openrtb.ext.response.BidType;

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

Bid bid;
BidderBid bidderBid;

Imp correspondingImp;

String bidCurrency;

String bidder;

BidType bidType;

CacheInfo cacheInfo;

String lineItemId;
Expand All @@ -36,6 +32,7 @@ public class BidInfo {
Boolean satisfiedPriority;

public String getBidId() {
final Bid bid = bidderBid != null ? bidderBid.getBid() : null;
final ObjectNode extNode = bid != null ? bid.getExt() : null;
final JsonNode bidIdNode = extNode != null ? extNode.path("prebid").path("bidid") : null;
final String generatedBidId = bidIdNode != null && bidIdNode.isTextual() ? bidIdNode.textValue() : null;
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/prebid/server/bidder/model/BidderBid.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Bid returned by a {@link Bidder}.
*/
@Builder
@Builder(toBuilder = true)
@Value
public class BidderBid {

Expand Down Expand Up @@ -46,8 +46,4 @@ public static BidderBid of(Bid bid, BidType bidType, String bidCurrency) {
.bidCurrency(bidCurrency)
.build();
}

public BidderBid with(Bid bid) {
return BidderBid.of(bid, this.type, this.bidCurrency);
}
}
31 changes: 17 additions & 14 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 All @@ -15,6 +16,7 @@
import org.prebid.server.auction.model.AuctionContext;
import org.prebid.server.auction.model.BidInfo;
import org.prebid.server.auction.model.CachedDebugLog;
import org.prebid.server.bidder.model.BidderBid;
import org.prebid.server.cache.model.CacheBid;
import org.prebid.server.cache.model.CacheContext;
import org.prebid.server.cache.model.CacheHttpRequest;
Expand Down Expand Up @@ -294,7 +296,7 @@ private List<CacheBid> getVideoCacheBids(List<BidInfo> bidInfos,
CacheTtl accountCacheTtl) {

return bidInfos.stream()
.filter(bidInfo -> Objects.equals(bidInfo.getBidType(), BidType.video))
.filter(bidInfo -> Objects.equals(bidInfo.getBidderBid().getType(), BidType.video))
.map(bidInfo -> toCacheBid(bidInfo, cacheBidsTtl, accountCacheTtl, true))
.collect(Collectors.toList());
}
Expand All @@ -307,7 +309,7 @@ private CacheBid toCacheBid(BidInfo bidInfo,
CacheTtl accountCacheTtl,
boolean isVideoBid) {

final com.iab.openrtb.response.Bid bid = bidInfo.getBid();
final Bid bid = bidInfo.getBidderBid().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 +468,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.getBidderBid().getBid();
final ObjectNode bidObjectNode = mapper.mapper().valueToTree(bid);

final String eventUrl =
Expand Down Expand Up @@ -494,7 +496,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.getBidderBid().getBid();
final String vastXml = bid.getAdm();

final String customCacheKey = resolveCustomCacheKey(hbCacheId, bidInfo.getCategory());
Expand Down Expand Up @@ -583,26 +585,27 @@ 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)
.map(BidInfo::getBidderBid)
.map(BidderBid::getBid)
.collect(Collectors.toList());

final int bidsSize = cacheBids.size();
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.getBidderBid().getBid();
final Integer ttl = cacheBid.getTtl();

// determine uuid for video bid
Expand All @@ -617,8 +620,8 @@ private static Map<com.iab.openrtb.response.Bid, CacheInfo> toResultMap(List<Cac
for (int i = 0; i < cacheVideoBids.size(); i++) {
final CacheBid cacheBid = cacheVideoBids.get(i);
final BidInfo bidInfo = cacheBid.getBidInfo();
result.put(bidInfo.getBid(), CacheInfo.of(null, resolveVideoBidUuid(uuids.get(i), hbCacheId), null,
cacheBid.getTtl()));
result.put(bidInfo.getBidderBid().getBid(),
CacheInfo.of(null, resolveVideoBidUuid(uuids.get(i), hbCacheId), null, cacheBid.getTtl()));
}
}

Expand Down
Loading

0 comments on commit c39115d

Please sign in to comment.