diff --git a/src/main/java/org/prebid/server/bidder/taboola/TaboolaBidder.java b/src/main/java/org/prebid/server/bidder/taboola/TaboolaBidder.java index c33ef88b520..cbd180f2e6f 100644 --- a/src/main/java/org/prebid/server/bidder/taboola/TaboolaBidder.java +++ b/src/main/java/org/prebid/server/bidder/taboola/TaboolaBidder.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.iab.openrtb.request.App; import com.iab.openrtb.request.Banner; import com.iab.openrtb.request.BidRequest; import com.iab.openrtb.request.Imp; @@ -151,13 +152,24 @@ private BidRequest createRequest(BidRequest request, List imps, ExtImpTaboo final List impExtBCat = impExt.getBCat(); final String impExtPageType = impExt.getPageType(); - final Site site = Optional.ofNullable(request.getSite()) - .map(Site::toBuilder) - .orElseGet(Site::builder) + final Publisher publisher = Publisher.builder().id(impExtPublisherId).build(); + + final Site site = request.getSite(); + final Site modifiedSite = site == null + ? null + : site.toBuilder() .id(impExtPublisherId) .name(impExtPublisherId) .domain(resolveDomain(impExt.getPublisherDomain(), request)) - .publisher(Publisher.builder().id(impExtPublisherId).build()) + .publisher(publisher) + .build(); + + final App app = request.getApp(); + final App modifiedApp = app == null + ? null + : app.toBuilder() + .id(impExtPublisherId) + .publisher(publisher) .build(); final ExtRequest extRequest = StringUtils.isNotEmpty(impExtPageType) @@ -166,7 +178,8 @@ private BidRequest createRequest(BidRequest request, List imps, ExtImpTaboo return request.toBuilder() .imp(imps) - .site(site) + .site(modifiedSite) + .app(modifiedApp) .badv(CollectionUtils.isNotEmpty(impExtBAdv) ? impExtBAdv : request.getBadv()) .bcat(CollectionUtils.isNotEmpty(impExtBCat) ? impExtBCat : request.getBcat()) .ext(extRequest) @@ -189,11 +202,11 @@ private ExtRequest createExtRequest(String pageType) { private HttpRequest createHttpRequest(MediaType type, BidRequest outgoingRequest) { return BidderUtil.defaultRequest(outgoingRequest, - buildEndpointUrl(outgoingRequest.getSite().getId(), type), + buildEndpointUrl(outgoingRequest, type), mapper); } - private String buildEndpointUrl(String publisherId, MediaType mediaType) { + private String buildEndpointUrl(BidRequest bidRequest, MediaType mediaType) { final String type = switch (mediaType) { case BANNER -> DISPLAY_ENDPOINT_PREFIX; case NATIVE -> NATIVE_ENDPOINT_PREFIX; @@ -202,6 +215,10 @@ private String buildEndpointUrl(String publisherId, MediaType mediaType) { default -> throw new AssertionError(); }; + final String publisherId = Optional.ofNullable(bidRequest.getSite()).map(Site::getId) + .or(() -> Optional.ofNullable(bidRequest.getApp()).map(App::getId)) + .orElse(StringUtils.EMPTY); + return endpointTemplate .replace("{{GvlID}}", gvlId) .replace("{{MediaType}}", type) diff --git a/src/test/java/org/prebid/server/bidder/taboola/TaboolaBidderTest.java b/src/test/java/org/prebid/server/bidder/taboola/TaboolaBidderTest.java index 4406373d114..a185687bb5f 100644 --- a/src/test/java/org/prebid/server/bidder/taboola/TaboolaBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/taboola/TaboolaBidderTest.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.TextNode; +import com.iab.openrtb.request.App; import com.iab.openrtb.request.Audio; import com.iab.openrtb.request.Banner; import com.iab.openrtb.request.BidRequest; @@ -337,6 +338,7 @@ public void makeHttpRequestsShouldModifyExtIfImpExtPageTypeIsNotEmpty() { public void makeHttpRequestShouldContainProperUriWhenTypeIsBanner() { // given final BidRequest bidRequest = givenBidRequest( + request -> request.site(Site.builder().build()), givenBannerImp(identity(), ext -> ext.publisherId("publisherId"))); // when @@ -353,6 +355,7 @@ public void makeHttpRequestShouldContainProperUriWhenTypeIsBanner() { public void makeHttpRequestShouldContainProperUriWithEncodedPublisherId() { // given final BidRequest bidRequest = givenBidRequest( + request -> request.app(App.builder().build()), givenBannerImp(identity(), extImp -> extImp.publisherId("not/encoded"))); // when @@ -369,6 +372,7 @@ public void makeHttpRequestShouldContainProperUriWithEncodedPublisherId() { public void makeHttpRequestShouldContainProperUriWhenTypeIsNative() { // given final BidRequest bidRequest = givenBidRequest( + request -> request.app(App.builder().build()), givenImp(imp -> imp.xNative(Native.builder().build()), ext -> ext.publisherId("publisherId"))); // when @@ -411,30 +415,38 @@ public void makeHttpRequestShouldModifySiteDependsOnExtPublisherId() { } @Test - public void makeHttpRequestShouldModifySiteDomainIfExtPublisherDomainIsNotEmpty() { + public void makeHttpRequestShouldModifyAppDependsOnExtPublisherId() { // given + final App givenApp = App.builder() + .id("id") + .publisher(Publisher.builder().id("id").build()) + .build(); + final BidRequest bidRequest = givenBidRequest( - request -> request.site(Site.builder().domain("domain").build()), - givenBannerImp(identity(), ext -> ext.publisherDomain("extDomain"))); + request -> request.app(givenApp), + givenBannerImp(identity(), ext -> ext.publisherId("extPublisherId"))); // when final Result>> result = target.makeHttpRequests(bidRequest); // then + final App expectedApp = givenApp.toBuilder() + .publisher(Publisher.builder().id("extPublisherId").build()) + .id("extPublisherId") + .build(); assertThat(result.getErrors()).isEmpty(); assertThat(result.getValue()) .extracting(HttpRequest::getPayload) - .extracting(BidRequest::getSite) - .extracting(Site::getDomain) - .containsExactly("extDomain"); + .extracting(BidRequest::getApp) + .containsOnly(expectedApp); } @Test - public void makeHttpRequestShouldNotModifySiteDomainIfExtPublisherDomainIsEmpty() { + public void makeHttpRequestShouldModifySiteDomainIfExtPublisherDomainIsNotEmpty() { // given final BidRequest bidRequest = givenBidRequest( request -> request.site(Site.builder().domain("domain").build()), - givenBannerImp(identity(), ext -> ext.publisherDomain(""))); + givenBannerImp(identity(), ext -> ext.publisherDomain("extDomain"))); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -445,15 +457,15 @@ public void makeHttpRequestShouldNotModifySiteDomainIfExtPublisherDomainIsEmpty( .extracting(HttpRequest::getPayload) .extracting(BidRequest::getSite) .extracting(Site::getDomain) - .containsExactly("domain"); + .containsExactly("extDomain"); } @Test - public void makeHttpRequestShouldAddEmptyDomainIfNoOtherSources() { + public void makeHttpRequestShouldNotModifySiteDomainIfExtPublisherDomainIsEmpty() { // given final BidRequest bidRequest = givenBidRequest( - request -> request.site(Site.builder().build()), - givenBannerImp(identity(), identity())); + request -> request.site(Site.builder().domain("domain").build()), + givenBannerImp(identity(), ext -> ext.publisherDomain(""))); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -464,13 +476,15 @@ public void makeHttpRequestShouldAddEmptyDomainIfNoOtherSources() { .extracting(HttpRequest::getPayload) .extracting(BidRequest::getSite) .extracting(Site::getDomain) - .containsExactly(""); + .containsExactly("domain"); } @Test - public void makeHttpRequestShouldCreateSiteIfNotPresent() { + public void makeHttpRequestShouldAddEmptyDomainIfNoOtherSources() { // given - final BidRequest bidRequest = givenBidRequest(givenBannerImp(identity(), identity())); + final BidRequest bidRequest = givenBidRequest( + request -> request.site(Site.builder().build()), + givenBannerImp(identity(), identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -480,13 +494,15 @@ public void makeHttpRequestShouldCreateSiteIfNotPresent() { assertThat(result.getValue()) .extracting(HttpRequest::getPayload) .extracting(BidRequest::getSite) - .doesNotContainNull(); + .extracting(Site::getDomain) + .containsExactly(""); } @Test public void makeHttpRequestShouldUseDataFromLastImpExtForRequest() { // given final BidRequest bidRequest = givenBidRequest( + request -> request.site(Site.builder().build()), givenBannerImp(identity(), ext -> ext.publisherId("1")), givenBannerImp(identity(), ext -> ext.publisherId("2")));