Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/main/java/org/prebid/server/auction/InterstitialProcessor.java

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make your change consistent with the project's style, old code needs to be refactored. So, to simplify your work and the review process, please copy the attached file :)

InterstitialProcessor.java

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import org.prebid.server.proto.openrtb.ext.request.ExtDevice;
import org.prebid.server.proto.openrtb.ext.request.ExtDeviceInt;
import org.prebid.server.proto.openrtb.ext.request.ExtDevicePrebid;
import org.prebid.server.proto.openrtb.ext.request.ExtRequest;
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebid;
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidSdk;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -36,15 +40,17 @@ private BidRequest processBidRequest(BidRequest bidRequest) {
if (extDeviceInt != null) {
final int minWidthPerc = extDeviceInt.getMinWidthPerc();
final int minHeightPerc = extDeviceInt.getMinHeightPerc();
final boolean usePxRatio = usePxRatio(bidRequest);
final List<Imp> updatedImps = bidRequest.getImp().stream()
.map(imp -> processInterstitialImp(imp, device, minWidthPerc, minHeightPerc))
.map(imp -> processInterstitialImp(imp, device, minWidthPerc, minHeightPerc, usePxRatio))
.toList();
bidRequest = bidRequest.toBuilder().imp(updatedImps).build();
}
return bidRequest;
}

private Imp processInterstitialImp(Imp imp, Device device, int minWidthPerc, int minHeightPerc) {
private Imp processInterstitialImp(Imp imp, Device device, int minWidthPerc, int minHeightPerc,
boolean usePxRatio) {
if (!isInterstitial(imp)) {
return imp;
}
Expand All @@ -62,6 +68,11 @@ private Imp processInterstitialImp(Imp imp, Device device, int minWidthPerc, int
if (maxHeight == null || maxWidth == null || (maxHeight == 1 && maxWidth == 1)) {
maxHeight = device.getH();
maxWidth = device.getW();
if (usePxRatio) {
final BigDecimal pxratio = device.getPxratio();
maxHeight = deviceSizeToDips(maxHeight, pxratio);
maxWidth = deviceSizeToDips(maxWidth, pxratio);
}
}

if (maxHeight == null || maxWidth == null) {
Expand Down Expand Up @@ -92,6 +103,21 @@ private ExtDeviceInt getExtDeviceInt(Device device) {
return extDevicePrebid != null ? extDevicePrebid.getInterstitial() : null;
}

private static boolean usePxRatio(BidRequest bidRequest) {
final ExtRequest extRequest = bidRequest.getExt();
final ExtRequestPrebid prebid = extRequest != null ? extRequest.getPrebid() : null;
final ExtRequestPrebidSdk sdk = prebid != null ? prebid.getSdk() : null;
return sdk != null && Objects.equals(sdk.getUsePxRatio(), true);
}

private static Integer deviceSizeToDips(Integer size, BigDecimal pxratio) {
if (size == null || pxratio == null || pxratio.signum() <= 0) {
return size;
}

return Math.max(1, (int) Math.round(size / pxratio.doubleValue()));
}

private static class InterstitialSize {

private static final List<InterstitialSize> INTERSTITIAL_SIZES = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
package org.prebid.server.proto.openrtb.ext.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Value;

import java.util.List;

/**
* Defines the contract for bidrequest.ext.prebid.sdk
*/
@Value(staticConstructor = "of")
@Value
public class ExtRequestPrebidSdk {

/**
* Defines the contract for bidrequest.ext.prebid.sdk.renderers
*/
List<ExtRequestPrebidSdkRenderer> renderers;

/**
* Defines the contract for bidrequest.ext.prebid.sdk.usepxratio
*/
@JsonProperty("usepxratio")
Boolean usePxRatio;

public static ExtRequestPrebidSdk of(List<ExtRequestPrebidSdkRenderer> renderers) {
return new ExtRequestPrebidSdk(renderers, null);
}
Comment on lines +25 to +27

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this static constructor and update all usages providing usePxRatio = null


public static ExtRequestPrebidSdk of(List<ExtRequestPrebidSdkRenderer> renderers, Boolean usePxRatio) {
return new ExtRequestPrebidSdk(renderers, usePxRatio);
}
}
124 changes: 124 additions & 0 deletions src/test/java/org/prebid/server/auction/InterstitialProcessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import org.prebid.server.proto.openrtb.ext.request.ExtDevice;
import org.prebid.server.proto.openrtb.ext.request.ExtDeviceInt;
import org.prebid.server.proto.openrtb.ext.request.ExtDevicePrebid;
import org.prebid.server.proto.openrtb.ext.request.ExtRequest;
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebid;
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidSdk;

import java.math.BigDecimal;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
Expand Down Expand Up @@ -71,6 +76,28 @@ public void processShouldReturnBidRequestUpdatedWithInterstitialFormatsUsingSize
Format.builder().w(320).h(481).build());
}

@Test
public void processShouldReturnBidRequestUpdatedWithInterstitialFormatsUsingDeviceSizeInDipsWhenFormatIsEmpty() {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(singletonList(Imp.builder().banner(Banner.builder().build()).instl(1).build()))
.device(Device.builder().w(1080).h(1920).pxratio(BigDecimal.valueOf(3))
.ext(ExtDevice.of(null, ExtDevicePrebid.of(ExtDeviceInt.of(60, 60))))
.build())
Comment on lines +84 to +86

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                .device(Device.builder()
                        .w(1080)
                        .h(1920)
                        .pxratio(BigDecimal.valueOf(3))
                        .ext(ExtDevice.of(null, ExtDevicePrebid.of(ExtDeviceInt.of(60, 60))))
                        .build()

.ext(usePxRatioExt())
.build();

// when
final BidRequest result = interstitialProcessor.process(bidRequest);

// then
assertThat(result.getImp())
.extracting(Imp::getBanner)
.flatExtracting(Banner::getFormat)
.contains(Format.builder().w(320).h(480).build())
.doesNotContain(Format.builder().w(768).h(1024).build());
Comment on lines +97 to +98

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge into containsExactly(Format.builder().w(320).h(480).build())

}

@Test
public void processShouldReturnBidRequestUpdatedWithInterstitialFormatsUsingSizesFromDeviceWhenFormatIsOneToOne() {
// given
Expand All @@ -96,6 +123,97 @@ public void processShouldReturnBidRequestUpdatedWithInterstitialFormatsUsingSize
Format.builder().w(320).h(481).build());
}

@Test
public void processShouldReturnBidRequestUpdatedWithInterstitialFormatsUsingDeviceSizeInDipsWhenFormatIsOneToOne() {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(singletonList(Imp.builder().banner(Banner.builder().format(singletonList(
Format.builder().w(1).h(1).build())).build()).instl(1).build()))
.device(Device.builder().w(1080).h(1920).pxratio(BigDecimal.valueOf(3))
.ext(ExtDevice.of(null, ExtDevicePrebid.of(ExtDeviceInt.of(60, 60))))
.build())
Comment on lines +130 to +134

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

.ext(usePxRatioExt())
.build();

// when
final BidRequest result = interstitialProcessor.process(bidRequest);

// then
assertThat(result.getImp())
.extracting(Imp::getBanner)
.flatExtracting(Banner::getFormat)
.contains(Format.builder().w(320).h(480).build())
.doesNotContain(Format.builder().w(768).h(1024).build());
Comment on lines +145 to +146

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

}

@Test
public void processShouldNotConvertExplicitFormatSizeUsingDevicePxratio() {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(singletonList(Imp.builder().banner(Banner.builder()
.format(singletonList(Format.builder().w(400).h(600).build())).build()).instl(1)
.build()))
.device(Device.builder().w(1080).h(1920).pxratio(BigDecimal.valueOf(3))
.ext(ExtDevice.of(null, ExtDevicePrebid.of(ExtDeviceInt.of(80, 80))))
.build())
Comment on lines +153 to +158

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

.ext(usePxRatioExt())
.build();

// when
final BidRequest result = interstitialProcessor.process(bidRequest);

// then
assertThat(result.getImp())
.extracting(Imp::getBanner)
.flatExtracting(Banner::getFormat)
.containsOnly(Format.builder().w(320).h(480).build(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

containsOnly -> containsExactly

Format.builder().w(336).h(544).build(),
Format.builder().w(320).h(568).build(),
Format.builder().w(320).h(500).build(),
Format.builder().w(320).h(481).build());
}

@Test
public void processShouldKeepCurrentDeviceSizeBehaviorWhenUsePxRatioIsTrueAndDevicePxRatioIsAbsent() {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(singletonList(Imp.builder().banner(Banner.builder().build()).instl(1).build()))
.device(Device.builder().w(1080).h(1920)
.ext(ExtDevice.of(null, ExtDevicePrebid.of(ExtDeviceInt.of(1, 1))))
.build())
Comment on lines +181 to +183

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

.ext(usePxRatioExt())
.build();

// when
final BidRequest result = interstitialProcessor.process(bidRequest);

// then
assertThat(result.getImp())
.extracting(Imp::getBanner)
.flatExtracting(Banner::getFormat)
.contains(Format.builder().w(768).h(1024).build());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

}

@Test
public void processShouldKeepCurrentDeviceSizeBehaviorWhenUsePxRatioIsAbsent() {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(singletonList(Imp.builder().banner(Banner.builder().build()).instl(1).build()))
.device(Device.builder().w(1080).h(1920).pxratio(BigDecimal.valueOf(3))
.ext(ExtDevice.of(null, ExtDevicePrebid.of(ExtDeviceInt.of(1, 1))))
.build())
Comment on lines +202 to +204

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

.build();

// when
final BidRequest result = interstitialProcessor.process(bidRequest);

// then
assertThat(result.getImp())
.extracting(Imp::getBanner)
.flatExtracting(Banner::getFormat)
.contains(Format.builder().w(768).h(1024).build());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

}

@Test
public void processShouldReturnBidRequestUpdatedWithInterstitialFormatsLimitedByTen() {
// given
Expand Down Expand Up @@ -266,4 +384,10 @@ public void processShouldNotUpdateImpWhenInterstitialSizesWereNotFound() {
.build())
.build());
}

private static ExtRequest usePxRatioExt() {
return ExtRequest.of(ExtRequestPrebid.builder()
.sdk(ExtRequestPrebidSdk.of(null, true))
.build());
}
}