Skip to content

Commit

Permalink
Flipp: use height value from server response (#3643)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoxaAntoxic authored Jan 2, 2025
1 parent 2daf96b commit d10f6f7
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 21 deletions.
44 changes: 33 additions & 11 deletions src/main/java/org/prebid/server/bidder/flipp/FlippBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class FlippBidder implements Bidder<CampaignRequestBody> {
private static final Set<Integer> AD_TYPES = Set.of(4309, 641);
private static final Set<Integer> DTX_TYPES = Set.of(5061);
private static final String EXT_REQUEST_TRANSMIT_EIDS = "transmitEids";
private static final int DEFAULT_STANDARD_HEIGHT = 2400;
private static final int DEFAULT_COMPACT_HEIGHT = 600;

private final String endpointUrl;
private final JacksonMapper mapper;
Expand Down Expand Up @@ -144,7 +146,7 @@ private static PrebidRequest createPrebidRequest(Imp imp, ExtImpFlipp extImp) {
final Format format = Optional.ofNullable(imp.getBanner())
.map(Banner::getFormat)
.filter(CollectionUtils::isNotEmpty)
.map(formats -> formats.getFirst())
.map(List::getFirst)
.orElse(null);

return PrebidRequest.builder()
Expand Down Expand Up @@ -272,32 +274,38 @@ public final Result<List<BidderBid>> makeBids(BidderCall<CampaignRequestBody> ht
}
}

private static List<BidderBid> extractBids(CampaignResponseBody campaignResponseBody, BidRequest bidRequest) {
private List<BidderBid> extractBids(CampaignResponseBody campaignResponseBody, BidRequest bidRequest) {
return Optional.ofNullable(campaignResponseBody)
.map(CampaignResponseBody::getDecisions)
.map(Decisions::getInline)
.stream()
.flatMap(Collection::stream)
.filter(inline -> isInlineValid(bidRequest, inline))
.map(inline -> BidderBid.of(constructBid(inline), BidType.banner, "USD"))
.map(inline -> makeBid(inline, getCorrespondingImp(bidRequest, inline)))
.filter(Objects::nonNull)
.toList();
}

private static boolean isInlineValid(BidRequest bidRequest, Inline inline) {
private static Imp getCorrespondingImp(BidRequest bidRequest, Inline inline) {
final String requestId = Optional.ofNullable(inline)
.map(Inline::getPrebid)
.map(Prebid::getRequestId)
.orElse(null);

return requestId != null && bidRequest.getImp().stream()
.map(Imp::getId)
.anyMatch(impId -> impId.equals(requestId));
return requestId != null
? bidRequest.getImp().stream().filter(imp -> imp.getId().equals(requestId)).findFirst().orElse(null)
: null;
}

private static Bid constructBid(Inline inline) {
private BidderBid makeBid(Inline inline, Imp imp) {
return imp == null
? null
: BidderBid.of(constructBid(inline, parseImpExt(imp)), BidType.banner, "USD");
}

private static Bid constructBid(Inline inline, ExtImpFlipp extImp) {
final Prebid prebid = inline.getPrebid();
final Data data = Optional.ofNullable(inline.getContents())
.map(content -> content.getFirst())
.map(List::getFirst)
.map(Content::getData)
.orElse(null);

Expand All @@ -308,7 +316,21 @@ private static Bid constructBid(Inline inline) {
.id(Integer.toString(inline.getAdId()))
.impid(prebid.getRequestId())
.w(data != null ? data.getWidth() : null)
.h(data != null ? 0 : null)
.h(resolveHeight(data, extImp))
.build();
}

private static Integer resolveHeight(Data data, ExtImpFlipp extImp) {
final boolean startCompact = Optional.ofNullable(extImp)
.map(ExtImpFlipp::getOptions)
.map(ExtImpFlippOptions::getStartCompact)
.orElse(false);

return Optional.ofNullable(data)
.map(Data::getCustomData)
.map(customData -> customData.get(startCompact ? "compactHeight" : "standardHeight"))
.filter(JsonNode::isNumber)
.map(JsonNode::asInt)
.orElse(startCompact ? DEFAULT_COMPACT_HEIGHT : DEFAULT_STANDARD_HEIGHT);
}
}
118 changes: 109 additions & 9 deletions src/test/java/org/prebid/server/bidder/flipp/FlippBidderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.node.BooleanNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.iab.openrtb.request.Banner;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Device;
Expand Down Expand Up @@ -917,15 +918,101 @@ public void makeBidsShouldPopulateBidWidthWithNullWhenInlineContentsDataWidthEmp
}

@Test
public void makeBidsShouldPopulateBidHeightWithZeroWhenInlineContentsIsPresent() throws JsonProcessingException {
public void makeBidsShouldPopulateBidDefaultStandardHeightWhenInlineCustomDataIsAbsent()
throws JsonProcessingException {

// given
final BidRequest bidRequest = givenBidRequest(identity());
final BidRequest bidRequest = givenBidRequest(givenImp(identity(), extImp -> extImp
.options(ExtImpFlippOptions.of(false, null, null))));

final ObjectNode customData = mapper.createObjectNode()
.put("compactHeight", 20)
.put("standardHeight", 30);

// and
final BidderCall<CampaignRequestBody> httpCall = givenHttpCall(CampaignRequestBody.builder().build(),
mapper.writeValueAsString(givenCampaignResponseBody(inlineBuilder ->
inlineBuilder.contents(singletonList(
Content.of("any", "custom", Data.of(null, 10, 20), "type"))))));
mapper.writeValueAsString(givenCampaignResponseBody(inlineBuilder -> inlineBuilder
.contents(singletonList(Content.of(
"any", "custom", Data.of(null, 10, 20), "type"))))));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).hasSize(1)
.extracting(BidderBid::getBid)
.extracting(Bid::getH)
.containsExactly(2400);
}

@Test
public void makeBidsShouldPopulateBidDefaultCompactHeightWhenInlineCustomDataIsAbsent()
throws JsonProcessingException {

// given
final BidRequest bidRequest = givenBidRequest(givenImp(identity(), extImp -> extImp
.options(ExtImpFlippOptions.of(true, null, null))));

final BidderCall<CampaignRequestBody> httpCall = givenHttpCall(CampaignRequestBody.builder().build(),
mapper.writeValueAsString(givenCampaignResponseBody(inlineBuilder -> inlineBuilder
.contents(singletonList(Content.of(
"any", "custom", Data.of(null, 10, 20), "type"))))));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).hasSize(1)
.extracting(BidderBid::getBid)
.extracting(Bid::getH)
.containsExactly(600);
}

@Test
public void makeBidsShouldPopulateBidCompactHeightFromCustomDataWhenStartCompactIsTrue()
throws JsonProcessingException {

// given
final BidRequest bidRequest = givenBidRequest(givenImp(identity(), extImp -> extImp
.options(ExtImpFlippOptions.of(true, null, null))));

final ObjectNode customData = mapper.createObjectNode()
.put("compactHeight", 20)
.put("standardHeight", 30);

final BidderCall<CampaignRequestBody> httpCall = givenHttpCall(CampaignRequestBody.builder().build(),
mapper.writeValueAsString(givenCampaignResponseBody(inlineBuilder -> inlineBuilder
.contents(singletonList(Content.of(
"any", "custom", Data.of(customData, 10, 20), "type"))))));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).hasSize(1)
.extracting(BidderBid::getBid)
.extracting(Bid::getH)
.containsExactly(20);
}

@Test
public void makeBidsShouldPopulateBidStandardHeightFromCustomDataWhenStartCompactIsFalse()
throws JsonProcessingException {

// given
final BidRequest bidRequest = givenBidRequest(givenImp(identity(), extImp -> extImp
.options(ExtImpFlippOptions.of(false, null, null))));

final ObjectNode customData = mapper.createObjectNode()
.put("compactHeight", 20)
.put("standardHeight", 30);

final BidderCall<CampaignRequestBody> httpCall = givenHttpCall(CampaignRequestBody.builder().build(),
mapper.writeValueAsString(givenCampaignResponseBody(inlineBuilder -> inlineBuilder
.contents(singletonList(Content.of(
"any", "custom", Data.of(customData, 10, 20), "type"))))));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);
Expand All @@ -935,7 +1022,7 @@ public void makeBidsShouldPopulateBidHeightWithZeroWhenInlineContentsIsPresent()
assertThat(result.getValue()).hasSize(1)
.extracting(BidderBid::getBid)
.extracting(Bid::getH)
.containsExactly(0);
.containsExactly(30);
}

@Test
Expand Down Expand Up @@ -1011,14 +1098,27 @@ private static BidRequest givenBidRequest(UnaryOperator<Imp.ImpBuilder> impCusto
return givenBidRequest(identity(), impCustomizer);
}

private static BidRequest givenBidRequest(Imp givenImp) {
return BidRequest.builder()
.device(Device.builder().ip("anyId").build())
.imp(singletonList(givenImp))
.build();
}

private static Imp givenImp(UnaryOperator<Imp.ImpBuilder> impCustomizer) {
return givenImp(impCustomizer, identity());
}

private static Imp givenImp(UnaryOperator<Imp.ImpBuilder> impCustomizer,
UnaryOperator<ExtImpFlipp.ExtImpFlippBuilder> extImpBuilder) {

return impCustomizer.apply(Imp.builder()
.id("123")
.banner(Banner.builder().w(23).h(25).build())
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpFlipp.builder()
.ext(mapper.valueToTree(ExtPrebid.of(null, extImpBuilder.apply(ExtImpFlipp.builder()
.publisherNameIdentifier("publisherName")
.creativeType("Any")
.zoneIds(List.of(12))
.zoneIds(List.of(12)))
.build()))))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"adm": "creativeContent",
"crid": "81325690",
"w": 300,
"h": 0,
"h": 600,
"ext": {
"origbidcpm": 12.34,
"origbidcur": "USD",
Expand Down

0 comments on commit d10f6f7

Please sign in to comment.