@@ -122,59 +122,54 @@ public final Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, B
122122 try {
123123 final List <BidderError > errors = new ArrayList <>();
124124 final BidResponse bidResponse = mapper .decodeValue (httpCall .getResponse ().getBody (), BidResponse .class );
125- return Result .of (extractBids (httpCall . getRequest (). getPayload (), bidResponse , errors ), errors );
125+ return Result .of (extractBids (bidResponse , errors ), errors );
126126 } catch (DecodeException | PreBidException e ) {
127127 return Result .withError (BidderError .badServerResponse (e .getMessage ()));
128128 }
129129 }
130130
131- private static List <BidderBid > extractBids (BidRequest bidRequest , BidResponse bidResponse ,
132- List <BidderError > errors ) {
131+ private static List <BidderBid > extractBids (BidResponse bidResponse , List <BidderError > errors ) {
133132 if (bidResponse == null || CollectionUtils .isEmpty (bidResponse .getSeatbid ())) {
134133 return Collections .emptyList ();
135134 }
136- return bidsFromResponse (bidRequest , bidResponse , errors );
135+ return bidsFromResponse (bidResponse , errors );
137136 }
138137
139- private static List <BidderBid > bidsFromResponse (BidRequest bidRequest , BidResponse bidResponse ,
140- List <BidderError > errors ) {
138+ private static List <BidderBid > bidsFromResponse (BidResponse bidResponse , List <BidderError > errors ) {
141139 return bidResponse .getSeatbid ().stream ()
142140 .filter (Objects ::nonNull )
143141 .map (SeatBid ::getBid )
144142 .filter (Objects ::nonNull )
145143 .flatMap (Collection ::stream )
146- .map (bid -> resolveBidderBid (bid , bidResponse .getCur (), bidRequest . getImp (), errors ))
144+ .map (bid -> resolveBidderBid (bid , bidResponse .getCur (), errors ))
147145 .filter (Objects ::nonNull )
148146 .toList ();
149147 }
150148
151- private static BidderBid resolveBidderBid (Bid bid , String currency , List <Imp > imps , List < BidderError > errors ) {
149+ private static BidderBid resolveBidderBid (Bid bid , String currency , List <BidderError > errors ) {
152150 final BidType bidType ;
153151 try {
154- bidType = getBidType (bid . getImpid (), imps );
152+ bidType = getBidType (bid );
155153 } catch (PreBidException e ) {
156154 errors .add (BidderError .badServerResponse (e .getMessage ()));
157155 return null ;
158156 }
159157 return BidderBid .of (bid , bidType , currency );
160158 }
161159
162- private static BidType getBidType (String impId , List <Imp > imps ) {
163- for (Imp imp : imps ) {
164- if (imp .getId ().equals (impId )) {
165- if (imp .getBanner () != null ) {
166- return BidType .banner ;
167- }
168- if (imp .getVideo () != null ) {
169- return BidType .video ;
170- }
171- if (imp .getXNative () != null ) {
172- return BidType .xNative ;
173- }
174- throw new PreBidException ("Unknown impression type for ID: '%s'" .formatted (impId ));
175- }
160+ private static BidType getBidType (Bid bid ) {
161+ final Integer markupType = bid .getMtype ();
162+ if (markupType == null ) {
163+ throw new PreBidException ("Missing MType for bid: " + bid .getId ());
176164 }
177- throw new PreBidException ("Failed to find impression for ID: '%s'" .formatted (impId ));
165+
166+ return switch (markupType ) {
167+ case 1 -> BidType .banner ;
168+ case 2 -> BidType .video ;
169+ case 4 -> BidType .xNative ;
170+ default -> throw new PreBidException (
171+ "Unable to fetch mediaType " + bid .getMtype () + " in multi-format: " + bid .getImpid ());
172+ };
178173 }
179174
180175}
0 commit comments