2323import org .apache .commons .lang3 .BooleanUtils ;
2424import org .apache .commons .lang3 .ObjectUtils ;
2525import org .apache .commons .lang3 .StringUtils ;
26- import org .prebid .server .auction .aliases .BidderAliases ;
2726import org .prebid .server .auction .categorymapping .CategoryMappingService ;
2827import org .prebid .server .auction .model .AuctionContext ;
2928import org .prebid .server .auction .model .AuctionParticipation ;
@@ -432,15 +431,9 @@ private List<BidderResponseInfo> toBidderResponseInfos(CategoryMappingResult cat
432431 final BidderSeatBid seatBid = bidderResponse .getSeatBid ();
433432
434433 for (final BidderBid bidderBid : seatBid .getBids ()) {
435- final BidInfo bidInfo = toBidInfo (
436- bidderBid .getBid (),
437- bidderBid .getType (),
438- bidderBid .getSeat (),
439- imps ,
440- bidder ,
441- categoryMappingResult ,
442- cacheInfo ,
443- account );
434+ final Bid bid = bidderBid .getBid ();
435+ final BidType type = bidderBid .getType ();
436+ final BidInfo bidInfo = toBidInfo (bid , type , imps , bidder , categoryMappingResult , cacheInfo , account );
444437 bidInfos .add (bidInfo );
445438 }
446439
@@ -460,7 +453,6 @@ private List<BidderResponseInfo> toBidderResponseInfos(CategoryMappingResult cat
460453
461454 private BidInfo toBidInfo (Bid bid ,
462455 BidType type ,
463- String seat ,
464456 List <Imp > imps ,
465457 String bidder ,
466458 CategoryMappingResult categoryMappingResult ,
@@ -472,7 +464,6 @@ private BidInfo toBidInfo(Bid bid,
472464 .bid (bid )
473465 .bidType (type )
474466 .bidder (bidder )
475- .seat (seat )
476467 .correspondingImp (correspondingImp )
477468 .ttl (resolveTtl (bid , type , correspondingImp , cacheInfo , account ))
478469 .vastTtl (type == BidType .video ? resolveVastTtl (bid , correspondingImp , cacheInfo , account ) : null )
@@ -770,16 +761,18 @@ private static List<BidInfo> injectTargeting(List<BidInfo> bidderImpIdBidInfos,
770761 final int multiBidSize = bidderImpIdBidInfos .size ();
771762 for (int i = 0 ; i < multiBidSize ; i ++) {
772763 // first bid have the highest value and can't be extra bid
773- final String targetingBidderCode = targetingCode (bidder , bidderCodePrefix , i );
774- final BidInfo bidInfo = bidderImpIdBidInfos .get (i );
764+ final boolean isFirstBid = i == 0 ;
765+ final String targetingBidderCode = isFirstBid
766+ ? bidder
767+ : bidderCodePrefix == null ? null : bidderCodePrefix + (i + 1 );
775768
769+ final BidInfo bidInfo = bidderImpIdBidInfos .get (i );
776770 final TargetingInfo targetingInfo = TargetingInfo .builder ()
777771 .isTargetingEnabled (targetingBidderCode != null )
778772 .isBidderWinningBid (winningBidsByBidder .contains (bidInfo ))
779773 .isWinningBid (winningBids .contains (bidInfo ))
780774 .isAddTargetBidderCode (targetingBidderCode != null && multiBidSize > 1 )
781775 .bidderCode (targetingBidderCode )
782- .seat (targetingCode (bidInfo .getSeat (), bidderCodePrefix , i ))
783776 .build ();
784777
785778 final BidInfo modifiedBidInfo = bidInfo .toBuilder ().targetingInfo (targetingInfo ).build ();
@@ -789,14 +782,6 @@ private static List<BidInfo> injectTargeting(List<BidInfo> bidderImpIdBidInfos,
789782 return result ;
790783 }
791784
792- private static String targetingCode (String base , String prefix , int i ) {
793- if (i == 0 ) {
794- return base ;
795- }
796-
797- return prefix != null ? prefix + (i + 1 ) : null ;
798- }
799-
800785 /**
801786 * Returns {@link ExtBidResponse} object, populated with response time, errors and debug info (if requested)
802787 * from all bidders.
@@ -1444,6 +1429,12 @@ private SeatBid toSeatBid(List<BidInfo> bidInfos,
14441429 Map <String , List <ExtBidderError >> bidErrors ,
14451430 Map <String , List <ExtBidderError >> bidWarnings ) {
14461431
1432+ final String bidder = bidInfos .stream ()
1433+ .map (BidInfo ::getBidder )
1434+ .findFirst ()
1435+ // Should never occur
1436+ .orElseThrow (() -> new IllegalArgumentException ("Bidder was not defined for bidInfo" ));
1437+
14471438 final List <Bid > bids = bidInfos .stream ()
14481439 .map (bidInfo -> injectAdmWithCacheInfo (
14491440 bidInfo ,
@@ -1460,14 +1451,8 @@ private SeatBid toSeatBid(List<BidInfo> bidInfos,
14601451 .filter (Objects ::nonNull )
14611452 .toList ();
14621453
1463- final String seat = bidInfos .stream ()
1464- .map (BidInfo ::getSeat )
1465- .findFirst ()
1466- // Should never occur
1467- .orElseThrow (() -> new IllegalArgumentException ("BidderCode was not defined for bidInfo" ));
1468-
14691454 return SeatBid .builder ()
1470- .seat (seat )
1455+ .seat (bidder )
14711456 .bid (bids )
14721457 .group (0 ) // prebid cannot support roadblocking
14731458 .build ();
@@ -1527,16 +1512,16 @@ private Bid toBid(BidInfo bidInfo,
15271512 final String videoCacheId = cacheInfo != null ? cacheInfo .getVideoCacheId () : null ;
15281513
15291514 final Map <String , String > targetingKeywords ;
1515+ final String bidderCode = targetingInfo .getBidderCode ();
15301516 if (shouldIncludeTargetingInResponse (targeting , bidInfo .getTargetingInfo ())) {
15311517 final TargetingKeywordsCreator keywordsCreator = resolveKeywordsCreator (
15321518 bidType , targeting , bidRequest , account , bidWarnings );
15331519
15341520 final boolean isWinningBid = targetingInfo .isWinningBid ();
1535- final String seat = targetingInfo .getSeat ();
15361521 final String categoryDuration = bidInfo .getCategory ();
15371522 targetingKeywords = keywordsCreator != null
15381523 ? keywordsCreator .makeFor (
1539- bid , seat , isWinningBid , cacheId , bidType .getName (), videoCacheId , categoryDuration )
1524+ bid , bidderCode , isWinningBid , cacheId , bidType .getName (), videoCacheId , categoryDuration )
15401525 : null ;
15411526 } else {
15421527 targetingKeywords = null ;
@@ -1554,7 +1539,7 @@ private Bid toBid(BidInfo bidInfo,
15541539 .map (ExtBidPrebid ::toBuilder )
15551540 .orElseGet (ExtBidPrebid ::builder )
15561541 .targeting (MapUtils .isNotEmpty (targetingKeywords ) ? targetingKeywords : null )
1557- .targetBidderCode (targetingInfo .isAddTargetBidderCode () ? targetingInfo . getBidderCode () : null )
1542+ .targetBidderCode (targetingInfo .isAddTargetBidderCode () ? bidderCode : null )
15581543 .dealTierSatisfied (dealsTierSatisfied )
15591544 .cache (cache )
15601545 .passThrough (extractPassThrough (bidInfo .getCorrespondingImp ()))
0 commit comments