-
Notifications
You must be signed in to change notification settings - Fork 222
IX Adapter feature dynamic account id support #4218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,11 +68,16 @@ public class IxBidder implements Bidder<BidRequest> { | |
| private static final String PBS_VERSION_UNKNOWN = "unknown"; | ||
|
|
||
| private final String endpointUrl; | ||
| private final String defaultAccountId; | ||
| private final PrebidVersionProvider prebidVersionProvider; | ||
| private final JacksonMapper mapper; | ||
|
|
||
| public IxBidder(String endpointUrl, PrebidVersionProvider prebidVersionProvider, JacksonMapper mapper) { | ||
| public IxBidder(String endpointUrl, | ||
| String defaultAccountId, | ||
| PrebidVersionProvider prebidVersionProvider, | ||
| JacksonMapper mapper) { | ||
|
Comment on lines
+75
to
+78
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add an empty line between lines 78 and 79 (according to the repo's code style) |
||
| this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)); | ||
| this.defaultAccountId = (defaultAccountId != null) ? defaultAccountId : ""; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| this.prebidVersionProvider = Objects.requireNonNull(prebidVersionProvider); | ||
| this.mapper = Objects.requireNonNull(mapper); | ||
| } | ||
|
|
@@ -82,6 +87,7 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequ | |
| final Set<String> siteIds = new HashSet<>(); | ||
| final List<Imp> imps = new ArrayList<>(); | ||
| final List<BidderError> errors = new ArrayList<>(); | ||
| final Set<String> accountIds = new HashSet<>(); | ||
|
|
||
| for (Imp imp : bidRequest.getImp()) { | ||
| try { | ||
|
|
@@ -91,6 +97,11 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequ | |
| siteIds.add(siteId); | ||
| } | ||
|
|
||
| final String accountId = impExt.getAccountId(); | ||
| if (StringUtils.isNotEmpty(accountId)) { | ||
| accountIds.add(accountId); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like the set of accounts isn't really needed please replace the final String accountId = impExt.getAccountId();
if (StringUtils.isNotEmpty(accountId)) {
accountIds.add(accountId);
}with the accountId = accountId == null ? impExt.getAccountId() : accountId; |
||
|
|
||
| imps.add(modifyImp(imp, impExt)); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badInput(e.getMessage())); | ||
|
|
@@ -102,12 +113,24 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequ | |
| } | ||
|
|
||
| final BidRequest modifiedBidRequest = modifyBidRequest(bidRequest, imps, siteIds); | ||
|
|
||
| final String resolvedAccountId = accountIds.isEmpty() | ||
| ? null | ||
| : accountIds.iterator().next(); | ||
|
Comment on lines
+117
to
+119
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is not needed after implementing https://github.com/prebid/prebid-server-java/pull/4218/files#r2406121593 |
||
|
|
||
| final String resolvedEndpoint = resolveEndpointMacro(endpointUrl, resolvedAccountId); | ||
|
|
||
| final List<HttpRequest<BidRequest>> httpRequests = Collections.singletonList( | ||
| BidderUtil.defaultRequest(modifiedBidRequest, endpointUrl, mapper)); | ||
| BidderUtil.defaultRequest(modifiedBidRequest, resolvedEndpoint, mapper)); | ||
|
|
||
| return Result.of(httpRequests, errors); | ||
| } | ||
|
|
||
| private String resolveEndpointMacro(String endpoint, String accountId) { | ||
| final String resolvedAccountId = StringUtils.isNotEmpty(accountId) ? accountId : this.defaultAccountId; | ||
| return endpoint.replace("${IX_ACCOUNT_ID}", resolvedAccountId); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| private ExtImpIx parseImpExt(Imp imp) { | ||
| try { | ||
| return mapper.mapper().convertValue(imp.getExt(), IX_EXT_TYPE_REFERENCE).getBidder(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,8 @@ public class BidderConfigurationProperties { | |
| @NotBlank | ||
| private String endpoint; | ||
|
|
||
| private String defaultAccountId; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this property should be added only for the IX bidder, not for all bidders, please create a custom BidderConfigurationProperties for the IX bidder please check the |
||
|
|
||
| private Boolean pbsEnforcesCcpa; | ||
|
|
||
| private Boolean modifyingVastXmlAllowed; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,8 @@ | |
| @ExtendWith(MockitoExtension.class) | ||
| public class IxBidderTest extends VertxTest { | ||
|
|
||
| private static final String ENDPOINT_URL = "http://exchange.org/"; | ||
| private static final String ENDPOINT_URL = "http://exchange.org/?s=${IX_ACCOUNT_ID}"; | ||
| private static final String DEFAULT_ACCOUNT_ID = "123456"; | ||
| private static final String SITE_ID = "site id"; | ||
|
|
||
| @Mock(strictness = LENIENT) | ||
|
|
@@ -77,14 +78,14 @@ public class IxBidderTest extends VertxTest { | |
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| target = new IxBidder(ENDPOINT_URL, prebidVersionProvider, jacksonMapper); | ||
| target = new IxBidder(ENDPOINT_URL, DEFAULT_ACCOUNT_ID, prebidVersionProvider, jacksonMapper); | ||
| given(prebidVersionProvider.getNameVersionRecord()).willReturn(null); | ||
| } | ||
|
|
||
| @Test | ||
| public void creationShouldFailOnInvalidEndpointUrl() { | ||
| assertThatIllegalArgumentException().isThrownBy( | ||
| () -> new IxBidder("invalid_url", prebidVersionProvider, jacksonMapper)); | ||
| () -> new IxBidder("invalid_url", DEFAULT_ACCOUNT_ID, prebidVersionProvider, jacksonMapper)); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -107,7 +108,7 @@ public void makeHttpRequestsShouldReturnErrorIfImpExtCouldNotBeParsed() { | |
| public void makeHttpRequestsShouldModifyImpExtWithSid() { | ||
| // given | ||
| final BidRequest bidRequest = givenBidRequest( | ||
| impBuilder -> impBuilder.ext(givenImpExt(null, "sid"))); | ||
| impBuilder -> impBuilder.ext(givenImpExt(null, "sid", null))); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
@@ -128,7 +129,7 @@ public void makeHttpRequestsShouldSetImpBannerFormatsToFormatWithWidthAndHeightI | |
| final BidRequest bidRequest = givenBidRequest( | ||
| impBuilder -> impBuilder | ||
| .banner(Banner.builder().w(1).h(2).build()) | ||
| .ext(givenImpExt(null, null))); | ||
| .ext(givenImpExt(null, null, null))); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
@@ -154,7 +155,7 @@ public void makeHttpRequestsShouldSetImpBannerWidthAndHeightIfTheyAreAbsentAndBa | |
| final BidRequest bidRequest = givenBidRequest( | ||
| impBuilder -> impBuilder | ||
| .banner(Banner.builder().format(singletonList(Format.builder().w(1).h(2).build())).build()) | ||
| .ext(givenImpExt(null, null))); | ||
| .ext(givenImpExt(null, null, null))); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
@@ -220,8 +221,8 @@ public void makeHttpRequestsShouldReturnIxDiagWithPbsVersion() { | |
| public void makeHttpRequestsShouldReturnIxDiagWithMultipleSiteIdsWhenMultipleImpExtSiteIdPresent() { | ||
| // given | ||
| final BidRequest bidRequest = givenBidRequest( | ||
| impBuilder -> impBuilder.ext(givenImpExt("site1", null)), | ||
| impBuilder -> impBuilder.ext(givenImpExt("site2", null))); | ||
| impBuilder -> impBuilder.ext(givenImpExt("site1", null, null)), | ||
| impBuilder -> impBuilder.ext(givenImpExt("site2", null, null))); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
@@ -255,8 +256,8 @@ public void makeHttpRequestsShouldPassThroughProvidedIxDiagFields() { | |
| "pbjsv1", | ||
| givenIxDiag)), | ||
| List.of( | ||
| impBuilder -> impBuilder.ext(givenImpExt("site1", null)), | ||
| impBuilder -> impBuilder.ext(givenImpExt("site2", null)))); | ||
| impBuilder -> impBuilder.ext(givenImpExt("site1", null, null)), | ||
| impBuilder -> impBuilder.ext(givenImpExt("site2", null, null)))); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
@@ -284,7 +285,7 @@ public void makeHttpRequestsShouldModifyRequestSiteWithPublisherAndSetIdWhenImpE | |
| // given | ||
| final BidRequest bidRequest = givenBidRequest( | ||
| bidRequestBuilder -> bidRequestBuilder.site(Site.builder().build()), | ||
| singletonList(impBuilder -> impBuilder.ext(givenImpExt("site1", null)))); | ||
| singletonList(impBuilder -> impBuilder.ext(givenImpExt("site1", null, null)))); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
@@ -304,7 +305,7 @@ public void makeHttpRequestsShouldModifyRequestSiteWithPublisherAndSetIdWhenImpE | |
| public void makeHttpRequestsShouldNotCreateRequestSiteWhenImpExtSiteIdPresentAndSiteIsAbsent() { | ||
| // given | ||
| final BidRequest bidRequest = givenBidRequest( | ||
| impBuilder -> impBuilder.ext(givenImpExt("site1", null))); | ||
| impBuilder -> impBuilder.ext(givenImpExt("site1", null, null))); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
@@ -322,7 +323,7 @@ public void makeHttpRequestsShouldModifyRequestAppWithPublisherAndSetIdWhenImpEx | |
| // given | ||
| final BidRequest bidRequest = givenBidRequest( | ||
| bidRequestBuilder -> bidRequestBuilder.app(App.builder().build()), | ||
| singletonList(impBuilder -> impBuilder.ext(givenImpExt("site1", null)))); | ||
| singletonList(impBuilder -> impBuilder.ext(givenImpExt("site1", null, null)))); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
@@ -342,7 +343,7 @@ public void makeHttpRequestsShouldModifyRequestAppWithPublisherAndSetIdWhenImpEx | |
| public void makeHttpRequestsShouldNotCreateRequestAppWhenImpExtSiteIdPresentAndSiteIsAbsent() { | ||
| // given | ||
| final BidRequest bidRequest = givenBidRequest( | ||
| impBuilder -> impBuilder.ext(givenImpExt("site1", null))); | ||
| impBuilder -> impBuilder.ext(givenImpExt("site1", null, null))); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
@@ -355,6 +356,41 @@ public void makeHttpRequestsShouldNotCreateRequestAppWhenImpExtSiteIdPresentAndS | |
| .containsOnlyNulls(); | ||
| } | ||
|
|
||
| @Test | ||
| public void makeHttpRequestsShouldReplaceAccountIdMacroInEndpointUrlWithEXTAccountId() { | ||
| // given | ||
| final String accountId = "account123"; | ||
| final BidRequest bidRequest = givenBidRequest( | ||
| impBuilder -> impBuilder.ext(givenImpExt("site1", "sid", accountId))); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
||
| // then | ||
| assertThat(result.getErrors()).isEmpty(); | ||
| assertThat(result.getValue()).hasSize(1); | ||
| assertThat(result.getValue().get(0).getUri()) | ||
| .doesNotContain("${IX_ACCOUNT_ID}") | ||
| .contains(accountId); | ||
|
Comment on lines
+370
to
+374
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use |
||
| } | ||
|
|
||
| @Test | ||
| public void makeHttpRequestsShouldReplaceAccountIdMacroInEndpointUrlWithDefaultAccountId() { | ||
| // given | ||
| final BidRequest bidRequest = givenBidRequest( | ||
| impBuilder -> impBuilder.ext(givenImpExt("site1", "sid", null))); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
||
| // then | ||
| assertThat(result.getErrors()).isEmpty(); | ||
| assertThat(result.getValue()).hasSize(1); | ||
| assertThat(result.getValue().get(0).getUri()) | ||
| .doesNotContain("${IX_ACCOUNT_ID}") | ||
| .contains(DEFAULT_ACCOUNT_ID); | ||
| } | ||
|
|
||
| @Test | ||
| public void makeBidderResponseShouldReturnErrorIfResponseBodyCouldNotBeParsed() { | ||
| // given | ||
|
|
@@ -937,8 +973,8 @@ private static ExtRequest givenExtRequestWithIxDiag(String pbjsv, ObjectNode ixD | |
| return extRequest; | ||
| } | ||
|
|
||
| private static ObjectNode givenImpExt(String siteId, String sid) { | ||
| return mapper.valueToTree(ExtPrebid.of(null, ExtImpIx.of(siteId, null, sid))); | ||
| private static ObjectNode givenImpExt(String siteId, String sid, String accountId) { | ||
| return mapper.valueToTree(ExtPrebid.of(null, ExtImpIx.of(siteId, null, sid, accountId))); | ||
|
Comment on lines
+976
to
+977
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's create a separate overloaded |
||
| } | ||
|
|
||
| private static BidRequest givenBidRequest(UnaryOperator<Imp.ImpBuilder>... impCustomizers) { | ||
|
|
@@ -961,7 +997,7 @@ private static Imp givenImp(Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomiz | |
| return impCustomizer.apply(Imp.builder() | ||
| .id("123") | ||
| .banner(Banner.builder().w(1).h(1).build()) | ||
| .ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpIx.of(SITE_ID, null, null))))) | ||
| .ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpIx.of(SITE_ID, null, null, null))))) | ||
| .build(); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please format the parameters list