1
1
package org .prebid .server .bidder .ix ;
2
2
3
+ import com .fasterxml .jackson .core .JsonProcessingException ;
3
4
import com .fasterxml .jackson .core .type .TypeReference ;
5
+ import com .fasterxml .jackson .databind .node .ObjectNode ;
4
6
import com .iab .openrtb .request .Banner ;
5
7
import com .iab .openrtb .request .BidRequest ;
6
8
import com .iab .openrtb .request .Format ;
24
26
import org .prebid .server .proto .openrtb .ext .ExtPrebid ;
25
27
import org .prebid .server .proto .openrtb .ext .request .ix .ExtImpIx ;
26
28
import org .prebid .server .proto .openrtb .ext .response .BidType ;
29
+ import org .prebid .server .proto .openrtb .ext .response .ExtBidPrebid ;
30
+ import org .prebid .server .proto .openrtb .ext .response .ExtBidPrebidVideo ;
27
31
import org .prebid .server .util .HttpUtil ;
28
32
29
33
import java .util .ArrayList ;
@@ -46,6 +50,8 @@ public class IxBidder implements Bidder<BidRequest> {
46
50
// maximum number of bid requests
47
51
private static final int REQUEST_LIMIT = 20 ;
48
52
53
+ private static final String PREBID = "prebid" ;
54
+
49
55
private final String endpointUrl ;
50
56
private final JacksonMapper mapper ;
51
57
@@ -194,21 +200,48 @@ public Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidReques
194
200
}
195
201
}
196
202
197
- private static List <BidderBid > extractBids (BidResponse bidResponse , BidRequest bidRequest ) {
203
+ private List <BidderBid > extractBids (BidResponse bidResponse , BidRequest bidRequest ) {
198
204
return bidResponse == null || CollectionUtils .isEmpty (bidResponse .getSeatbid ())
199
205
? Collections .emptyList ()
200
206
: bidsFromResponse (bidResponse , bidRequest );
201
207
}
202
208
203
- private static List <BidderBid > bidsFromResponse (BidResponse bidResponse , BidRequest bidRequest ) {
209
+ private List <BidderBid > bidsFromResponse (BidResponse bidResponse , BidRequest bidRequest ) {
204
210
return bidResponse .getSeatbid ().stream ()
205
211
.map (SeatBid ::getBid )
206
212
.flatMap (Collection ::stream )
207
- .map (bid -> prepareBid (bid , bidRequest ))
208
- .map (bid -> BidderBid .of (bid , getBidType (bid .getImpid (), bidRequest .getImp ()), bidResponse .getCur ()))
213
+ .map (bid -> toBidderBid (bid , bidRequest , bidResponse ))
209
214
.collect (Collectors .toList ());
210
215
}
211
216
217
+ private BidderBid toBidderBid (Bid bid , BidRequest bidRequest , BidResponse bidResponse ) {
218
+ final BidType bidType = getBidType (bid .getImpid (), bidRequest .getImp ());
219
+
220
+ final boolean bidHasNoSizes = bid .getH () == null || bid .getW () == null ;
221
+ final Banner banner = bidRequest .getImp ().get (0 ).getBanner ();
222
+ if (bidHasNoSizes && banner != null ) {
223
+ bid = bid .toBuilder ()
224
+ .w (banner .getW ())
225
+ .h (banner .getH ())
226
+ .build ();
227
+ }
228
+
229
+ final ExtBidPrebid bidExt = parseBidExt (bid .getExt ());
230
+ if (bidExt != null && bidExt .getVideo () != null ) {
231
+ final ExtBidPrebidVideo video = bidExt .getVideo ();
232
+ bid = bid .toBuilder ()
233
+ .ext (toBidderBidExt (video ))
234
+ .build ();
235
+ if (bid .getCat ().size () == 0 ) {
236
+ bid = bid .toBuilder ()
237
+ .cat (List .of (video .getPrimaryCategory ()))
238
+ .build ();
239
+ }
240
+ }
241
+
242
+ return BidderBid .of (bid , bidType , bidResponse .getCur ());
243
+ }
244
+
212
245
private static BidType getBidType (String impId , List <Imp > imps ) {
213
246
for (Imp imp : imps ) {
214
247
if (imp .getId ().equals (impId )) {
@@ -226,16 +259,18 @@ private static BidType getBidType(String impId, List<Imp> imps) {
226
259
throw new PreBidException (String .format ("Unmatched impression id %s" , impId ));
227
260
}
228
261
229
- private static Bid prepareBid (Bid bid , BidRequest bidRequest ) {
230
- // Current implementation ensure that we have at least one imp in request
231
- final boolean bidHasNoSizes = bid .getH () == null || bid .getW () == null ;
232
- final Banner banner = bidRequest .getImp ().get (0 ).getBanner ();
233
- if (bidHasNoSizes && banner != null ) {
234
- return bid .toBuilder ()
235
- .w (banner .getW ())
236
- .h (banner .getH ())
237
- .build ();
262
+ private ExtBidPrebid parseBidExt (ObjectNode bidExt ) {
263
+ try {
264
+ return bidExt == null
265
+ ? null
266
+ : mapper .mapper ().treeToValue (bidExt , ExtBidPrebid .class );
267
+ } catch (JsonProcessingException e ) {
268
+ throw new PreBidException (e .getMessage ());
238
269
}
239
- return bid ;
240
270
}
271
+
272
+ private ObjectNode toBidderBidExt (ExtBidPrebidVideo extBidVideo ) {
273
+ return mapper .mapper ().valueToTree (ExtBidPrebidVideo .of (extBidVideo .getDuration (), null ));
274
+ }
275
+
241
276
}
0 commit comments