1818import org .prebid .server .hooks .modules .ortb2 .blocking .core .model .ResponseBlockingConfig ;
1919import org .prebid .server .hooks .modules .ortb2 .blocking .core .model .Result ;
2020import org .prebid .server .hooks .modules .ortb2 .blocking .core .util .MergeUtils ;
21+ import org .prebid .server .spring .config .bidder .model .MediaType ;
2122import org .prebid .server .util .ObjectUtil ;
2223import org .prebid .server .util .StreamUtil ;
2324
@@ -51,7 +52,11 @@ public class AccountConfigReader {
5152 private static final String ALLOWED_APP_FOR_DEALS_FIELD = "allowed-app-for-deals" ;
5253 private static final String BLOCKED_BANNER_TYPE_FIELD = "blocked-banner-type" ;
5354 private static final String BLOCKED_BANNER_ATTR_FIELD = "blocked-banner-attr" ;
55+ private static final String BLOCKED_VIDEO_ATTR_FIELD = "blocked-video-attr" ;
56+ private static final String BLOCKED_AUDIO_ATTR_FIELD = "blocked-audio-attr" ;
5457 private static final String ALLOWED_BANNER_ATTR_FOR_DEALS = "allowed-banner-attr-for-deals" ;
58+ private static final String ALLOWED_VIDEO_ATTR_FOR_DEALS = "allowed-video-attr-for-deals" ;
59+ private static final String ALLOWED_AUDIO_ATTR_FOR_DEALS = "allowed-audio-attr-for-deals" ;
5560 private static final String ACTION_OVERRIDES_FIELD = "action-overrides" ;
5661 private static final String OVERRIDE_FIELD = "override" ;
5762 private static final String CONDITIONS_FIELD = "conditions" ;
@@ -100,8 +105,14 @@ public Result<BlockedAttributes> blockedAttributesFor(BidRequest bidRequest) {
100105 blockedAttribute (BAPP_FIELD , String .class , BLOCKED_APP_FIELD , requestMediaTypes );
101106 final Result <Map <String , List <Integer >>> btype =
102107 blockedAttributesForImps (BTYPE_FIELD , Integer .class , BLOCKED_BANNER_TYPE_FIELD , bidRequest );
103- final Result <Map <String , List <Integer >>> battr =
108+ final Result <Map <String , List <Integer >>> bannerBattr =
104109 blockedAttributesForImps (BATTR_FIELD , Integer .class , BLOCKED_BANNER_ATTR_FIELD , bidRequest );
110+ final Result <Map <String , List <Integer >>> videoBattr =
111+ blockedAttributesForImps (BATTR_FIELD , Integer .class , BLOCKED_VIDEO_ATTR_FIELD , bidRequest );
112+ final Result <Map <String , List <Integer >>> audioBattr =
113+ blockedAttributesForImps (BATTR_FIELD , Integer .class , BLOCKED_AUDIO_ATTR_FIELD , bidRequest );
114+ final Result <Map <MediaType , Map <String , List <Integer >>>> battr =
115+ mergeBlockedAttributes (bannerBattr , videoBattr , audioBattr );
105116
106117 return Result .of (
107118 toBlockedAttributes (badv , bcat , cattaxComplement , bapp , btype , battr ),
@@ -133,22 +144,39 @@ public Result<ResponseBlockingConfig> responseBlockingConfigFor(BidderBid bidder
133144 ALLOWED_APP_FOR_DEALS_FIELD ,
134145 bidMediaTypes ,
135146 dealid );
136- final Result <BidAttributeBlockingConfig <Integer >> battr = blockingConfigForAttribute (
147+ final Result <BidAttributeBlockingConfig <Integer >> bannerBattr = blockingConfigForAttribute (
137148 BATTR_FIELD ,
138149 Integer .class ,
139150 ALLOWED_BANNER_ATTR_FOR_DEALS ,
140151 bidMediaTypes ,
141152 dealid );
153+ final Result <BidAttributeBlockingConfig <Integer >> videoBattr = blockingConfigForAttribute (
154+ BATTR_FIELD ,
155+ Integer .class ,
156+ ALLOWED_VIDEO_ATTR_FOR_DEALS ,
157+ bidMediaTypes ,
158+ dealid );
159+ final Result <BidAttributeBlockingConfig <Integer >> audioBattr = blockingConfigForAttribute (
160+ BATTR_FIELD ,
161+ Integer .class ,
162+ ALLOWED_AUDIO_ATTR_FOR_DEALS ,
163+ bidMediaTypes ,
164+ dealid );
165+ final Map <MediaType , BidAttributeBlockingConfig <Integer >> battr = new HashMap <>();
166+ battr .put (MediaType .BANNER , bannerBattr .getValue ());
167+ battr .put (MediaType .VIDEO , videoBattr .getValue ());
168+ battr .put (MediaType .AUDIO , audioBattr .getValue ());
142169
143170 final ResponseBlockingConfig response = ResponseBlockingConfig .builder ()
144171 .badv (badv .getValue ())
145172 .bcat (bcat .getValue ())
146173 .cattax (cattax .getValue ())
147174 .bapp (bapp .getValue ())
148- .battr (battr . getValue () )
175+ .battr (battr )
149176 .build ();
150177
151- final List <String > warnings = MergeUtils .mergeMessages (badv , bcat , cattax , bapp , battr );
178+ final List <String > warnings = MergeUtils .mergeMessages (
179+ badv , bcat , cattax , bapp , bannerBattr , videoBattr , audioBattr );
152180
153181 return Result .of (response , warnings );
154182 }
@@ -218,6 +246,28 @@ private <T> Result<Map<String, List<T>>> blockedAttributesForImps(String attribu
218246 MergeUtils .mergeMessages (results ));
219247 }
220248
249+ private static Result <Map <MediaType , Map <String , List <Integer >>>> mergeBlockedAttributes (
250+ Result <Map <String , List <Integer >>> bannerBattr ,
251+ Result <Map <String , List <Integer >>> videoBattr ,
252+ Result <Map <String , List <Integer >>> audioBattr ) {
253+
254+ final Map <MediaType , Map <String , List <Integer >>> battr = new HashMap <>();
255+
256+ if (bannerBattr .hasValue ()) {
257+ battr .put (MediaType .BANNER , bannerBattr .getValue ());
258+ }
259+ if (videoBattr .hasValue ()) {
260+ battr .put (MediaType .VIDEO , videoBattr .getValue ());
261+ }
262+ if (audioBattr .hasValue ()) {
263+ battr .put (MediaType .AUDIO , audioBattr .getValue ());
264+ }
265+
266+ return Result .of (
267+ !battr .isEmpty () ? battr : null ,
268+ MergeUtils .mergeMessages (bannerBattr , videoBattr , audioBattr ));
269+ }
270+
221271 private <T > Result <BidAttributeBlockingConfig <T >> blockingConfigForAttribute (String attribute ,
222272 Class <T > attributeType ,
223273 String blockUnknownField ,
@@ -360,8 +410,8 @@ private Result<JsonNode> toResult(List<JsonNode> specificBidderResults,
360410 Set <String > actualMediaTypes ) {
361411
362412 final JsonNode value = ObjectUtils .firstNonNull (
363- specificBidderResults .size () > 0 ? specificBidderResults .get ( 0 ) : null ,
364- catchAllBidderResults .size () > 0 ? catchAllBidderResults .get ( 0 ) : null );
413+ ! specificBidderResults .isEmpty () ? specificBidderResults .getFirst ( ) : null ,
414+ ! catchAllBidderResults .isEmpty () ? catchAllBidderResults .getFirst ( ) : null );
365415 final List <String > warnings = debugEnabled && specificBidderResults .size () + catchAllBidderResults .size () > 1
366416 ? Collections .singletonList (
367417 "More than one conditions matches request. Bidder: %s, request media types: %s"
@@ -376,7 +426,7 @@ private static BlockedAttributes toBlockedAttributes(Result<List<String>> badv,
376426 Result <Integer > cattaxComplement ,
377427 Result <List <String >> bapp ,
378428 Result <Map <String , List <Integer >>> btype ,
379- Result <Map <String , List <Integer >>> battr ) {
429+ Result <Map <MediaType , Map < String , List <Integer > >>> battr ) {
380430
381431 return badv .hasValue ()
382432 || bcat .hasValue ()
0 commit comments