|
| 1 | +package org.prebid.server.hooks.modules.pb.request.correction.core.correction.interstitial; |
| 2 | + |
| 3 | +import com.iab.openrtb.request.App; |
| 4 | +import com.iab.openrtb.request.BidRequest; |
| 5 | +import com.iab.openrtb.request.Imp; |
| 6 | +import org.apache.commons.lang3.StringUtils; |
| 7 | +import org.prebid.server.hooks.modules.pb.request.correction.core.config.model.Config; |
| 8 | +import org.prebid.server.hooks.modules.pb.request.correction.core.correction.Correction; |
| 9 | +import org.prebid.server.hooks.modules.pb.request.correction.core.correction.CorrectionProducer; |
| 10 | +import org.prebid.server.hooks.modules.pb.request.correction.core.util.VersionUtil; |
| 11 | +import org.prebid.server.proto.openrtb.ext.request.ExtApp; |
| 12 | +import org.prebid.server.proto.openrtb.ext.request.ExtAppPrebid; |
| 13 | + |
| 14 | +import java.util.List; |
| 15 | +import java.util.Optional; |
| 16 | + |
| 17 | +public class InterstitialCorrectionProducer implements CorrectionProducer { |
| 18 | + |
| 19 | + private static final InterstitialCorrection CORRECTION_INSTANCE = new InterstitialCorrection(); |
| 20 | + |
| 21 | + private static final String PREBID_MOBILE = "prebid-mobile"; |
| 22 | + private static final String ANDROID = "android"; |
| 23 | + |
| 24 | + private static final int MAX_VERSION_MAJOR = 2; |
| 25 | + private static final int MAX_VERSION_MINOR = 2; |
| 26 | + private static final int MAX_VERSION_PATCH = 3; |
| 27 | + |
| 28 | + @Override |
| 29 | + public boolean shouldProduce(Config config, BidRequest bidRequest) { |
| 30 | + final App app = bidRequest.getApp(); |
| 31 | + return config.isInterstitialCorrectionEnabled() |
| 32 | + && hasInterstitialToRemove(bidRequest.getImp()) |
| 33 | + && isPrebidMobile(app) |
| 34 | + && isAndroid(app) |
| 35 | + && isApplicableVersion(app); |
| 36 | + } |
| 37 | + |
| 38 | + private static boolean hasInterstitialToRemove(List<Imp> imps) { |
| 39 | + for (Imp imp : imps) { |
| 40 | + final Integer interstitial = imp.getInstl(); |
| 41 | + if (interstitial != null && interstitial == 1) { |
| 42 | + return true; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + return false; |
| 47 | + } |
| 48 | + |
| 49 | + private static boolean isPrebidMobile(App app) { |
| 50 | + final String source = Optional.ofNullable(app) |
| 51 | + .map(App::getExt) |
| 52 | + .map(ExtApp::getPrebid) |
| 53 | + .map(ExtAppPrebid::getSource) |
| 54 | + .orElse(null); |
| 55 | + |
| 56 | + return StringUtils.equalsIgnoreCase(source, PREBID_MOBILE); |
| 57 | + } |
| 58 | + |
| 59 | + private static boolean isAndroid(App app) { |
| 60 | + return StringUtils.containsIgnoreCase(app.getBundle(), ANDROID); |
| 61 | + } |
| 62 | + |
| 63 | + private static boolean isApplicableVersion(App app) { |
| 64 | + return Optional.ofNullable(app) |
| 65 | + .map(App::getExt) |
| 66 | + .map(ExtApp::getPrebid) |
| 67 | + .map(ExtAppPrebid::getVersion) |
| 68 | + .map(InterstitialCorrectionProducer::checkVersion) |
| 69 | + .orElse(false); |
| 70 | + } |
| 71 | + |
| 72 | + private static boolean checkVersion(String version) { |
| 73 | + return VersionUtil.isVersionLessThan(version, MAX_VERSION_MAJOR, MAX_VERSION_MINOR, MAX_VERSION_PATCH); |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public Correction produce(Config config) { |
| 78 | + return CORRECTION_INSTANCE; |
| 79 | + } |
| 80 | +} |
0 commit comments