66import com .iab .openrtb .request .Imp ;
77import com .iab .openrtb .response .Bid ;
88import org .apache .commons .collections4 .CollectionUtils ;
9- import org .apache .commons .lang3 .StringUtils ;
109import org .prebid .server .bidder .Bidder ;
1110import org .prebid .server .bidder .model .BidderBid ;
1211import org .prebid .server .bidder .model .BidderCall ;
1312import org .prebid .server .bidder .model .BidderError ;
1413import org .prebid .server .bidder .model .HttpRequest ;
15- import org .prebid .server .bidder .model .Price ;
1614import org .prebid .server .bidder .model .Result ;
1715import org .prebid .server .bidder .stroeercore .model .StroeerCoreBid ;
1816import org .prebid .server .bidder .stroeercore .model .StroeerCoreBidResponse ;
19- import org .prebid .server .currency .CurrencyConversionService ;
2017import org .prebid .server .exception .PreBidException ;
2118import org .prebid .server .json .DecodeException ;
2219import org .prebid .server .json .JacksonMapper ;
2623import org .prebid .server .util .BidderUtil ;
2724import org .prebid .server .util .HttpUtil ;
2825
29- import java .math .BigDecimal ;
3026import java .util .ArrayList ;
3127import java .util .Collections ;
3228import java .util .List ;
@@ -41,14 +37,10 @@ public class StroeerCoreBidder implements Bidder<BidRequest> {
4137
4238 private final String endpointUrl ;
4339 private final JacksonMapper mapper ;
44- private final CurrencyConversionService currencyConversionService ;
4540
46- public StroeerCoreBidder (String endpointUrl ,
47- JacksonMapper mapper ,
48- CurrencyConversionService currencyConversionService ) {
41+ public StroeerCoreBidder (String endpointUrl , JacksonMapper mapper ) {
4942 this .endpointUrl = HttpUtil .validateUrl (endpointUrl );
5043 this .mapper = Objects .requireNonNull (mapper );
51- this .currencyConversionService = Objects .requireNonNull (currencyConversionService );
5244 }
5345
5446 @ Override
@@ -57,37 +49,20 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequ
5749 final List <BidderError > errors = new ArrayList <>();
5850
5951 for (Imp imp : bidRequest .getImp ()) {
60- final ExtImpStroeerCore impExt ;
61- final Price price ;
62-
6352 try {
64- validateImp (imp );
65-
66- impExt = parseImpExt (imp );
67- validateImpExt (impExt );
68-
69- price = convertBidFloor (bidRequest , imp );
53+ final ExtImpStroeerCore impExt = parseImpExt (imp );
54+ modifiedImps .add (imp .toBuilder ().tagid (impExt .getSlotId ()).build ());
7055 } catch (PreBidException e ) {
7156 errors .add (BidderError .badInput ("%s. Ignore imp id = %s." .formatted (e .getMessage (), imp .getId ())));
72- continue ;
7357 }
74-
75- modifiedImps .add (modifyImp (imp , impExt , price ));
7658 }
7759
7860 if (modifiedImps .isEmpty ()) {
7961 return Result .withErrors (errors );
8062 }
8163
8264 final BidRequest outgoingRequest = bidRequest .toBuilder ().imp (modifiedImps ).build ();
83-
84- return createHttpRequests (errors , outgoingRequest );
85- }
86-
87- private static void validateImp (Imp imp ) {
88- if (imp .getBanner () == null && imp .getVideo () == null ) {
89- throw new PreBidException ("Expected banner or video impression" );
90- }
65+ return Result .withValue (BidderUtil .defaultRequest (outgoingRequest , endpointUrl , mapper ));
9166 }
9267
9368 private ExtImpStroeerCore parseImpExt (Imp imp ) {
@@ -98,95 +73,65 @@ private ExtImpStroeerCore parseImpExt(Imp imp) {
9873 }
9974 }
10075
101- private static void validateImpExt (ExtImpStroeerCore impExt ) {
102- if (StringUtils .isBlank (impExt .getSlotId ())) {
103- throw new PreBidException ("Custom param slot id (sid) is empty" );
104- }
105- }
106-
107- private Price convertBidFloor (BidRequest bidRequest , Imp imp ) {
108- final BigDecimal bidFloor = imp .getBidfloor ();
109- final String bidFloorCurrency = imp .getBidfloorcur ();
110-
111- if (!shouldConvertBidFloor (bidFloor , bidFloorCurrency )) {
112- return Price .of (bidFloorCurrency , bidFloor );
113- }
114-
115- final BigDecimal convertedBidFloor = currencyConversionService .convertCurrency (
116- bidFloor , bidRequest , bidFloorCurrency , BIDDER_CURRENCY );
117-
118- return Price .of (BIDDER_CURRENCY , convertedBidFloor );
119- }
120-
121- private Result <List <HttpRequest <BidRequest >>> createHttpRequests (List <BidderError > errors , BidRequest bidRequest ) {
122- return Result .of (Collections .singletonList (BidderUtil .defaultRequest (bidRequest , endpointUrl , mapper )), errors );
123- }
124-
125- private static boolean shouldConvertBidFloor (BigDecimal bidFloor , String bidFloorCurrency ) {
126- return BidderUtil .isValidPrice (bidFloor ) && !StringUtils .equalsIgnoreCase (bidFloorCurrency , BIDDER_CURRENCY );
127- }
128-
129- private static Imp modifyImp (Imp imp , ExtImpStroeerCore impExt , Price price ) {
130- return imp .toBuilder ()
131- .bidfloorcur (price .getCurrency ())
132- .bidfloor (price .getValue ())
133- .tagid (impExt .getSlotId ())
134- .build ();
135- }
136-
13776 @ Override
13877 public Result <List <BidderBid >> makeBids (BidderCall <BidRequest > httpCall , BidRequest bidRequest ) {
13978 try {
14079 final String body = httpCall .getResponse ().getBody ();
80+ final List <BidderError > errors = new ArrayList <>();
14181 final StroeerCoreBidResponse bidResponse = mapper .decodeValue (body , StroeerCoreBidResponse .class );
142- return Result .withValues (extractBids (httpCall . getRequest (). getPayload (), bidResponse ) );
82+ return Result .of (extractBids (bidResponse , errors ), errors );
14383 } catch (DecodeException e ) {
14484 return Result .withError (BidderError .badServerResponse (e .getMessage ()));
14585 }
14686 }
14787
148- private List <BidderBid > extractBids (BidRequest bidRequest , StroeerCoreBidResponse bidResponse ) {
88+ private List <BidderBid > extractBids (StroeerCoreBidResponse bidResponse , List < BidderError > errors ) {
14989 if (bidResponse == null || CollectionUtils .isEmpty (bidResponse .getBids ())) {
15090 return Collections .emptyList ();
15191 }
15292
15393 return bidResponse .getBids ().stream ()
15494 .filter (Objects ::nonNull )
155- .map (stroeerCoreBid -> toBidderBid (bidRequest , stroeerCoreBid ))
95+ .map (stroeerCoreBid -> toBidderBid (stroeerCoreBid , errors ))
96+ .filter (Objects ::nonNull )
15697 .toList ();
15798 }
15899
159- private BidderBid toBidderBid (BidRequest bidRequest , StroeerCoreBid stroeercoreBid ) {
100+ private BidderBid toBidderBid (StroeerCoreBid stroeercoreBid , List <BidderError > errors ) {
101+ final BidType bidType = getBidType (stroeercoreBid .getMtype ());
102+ if (bidType == null ) {
103+ errors .add (BidderError .badServerResponse (
104+ "Bid media type error: unable to determine media type for bid with id \" %s\" "
105+ .formatted (stroeercoreBid .getBidId ())));
106+ return null ;
107+ }
108+
160109 final ObjectNode bidExt = stroeercoreBid .getDsa () != null
161110 ? mapper .mapper ().createObjectNode ().set ("dsa" , stroeercoreBid .getDsa ())
162111 : null ;
163112
164113 return BidderBid .of (
165114 Bid .builder ()
166115 .id (stroeercoreBid .getId ())
167- .impid (stroeercoreBid .getImpId ())
116+ .impid (stroeercoreBid .getBidId ())
168117 .w (stroeercoreBid .getWidth ())
169118 .h (stroeercoreBid .getHeight ())
170119 .price (stroeercoreBid .getCpm ())
171120 .adm (stroeercoreBid .getAdMarkup ())
172121 .crid (stroeercoreBid .getCreativeId ())
122+ .adomain (stroeercoreBid .getAdomain ())
123+ .mtype (bidType .ordinal () + 1 )
173124 .ext (bidExt )
174125 .build (),
175- getBidType ( stroeercoreBid . getImpId (), bidRequest . getImp ()) ,
126+ bidType ,
176127 BIDDER_CURRENCY );
177128 }
178129
179- private static BidType getBidType (String impId , List <Imp > imps ) {
180- for (Imp imp : imps ) {
181- if (imp .getId ().equals (impId )) {
182- if (imp .getBanner () != null ) {
183- return BidType .banner ;
184- } else if (imp .getVideo () != null ) {
185- return BidType .video ;
186- }
187- }
188- }
189-
190- return BidType .banner ;
130+ private static BidType getBidType (String mtype ) {
131+ return switch (mtype ) {
132+ case "banner" -> BidType .banner ;
133+ case "video" -> BidType .video ;
134+ default -> null ;
135+ };
191136 }
192137}
0 commit comments