-
Notifications
You must be signed in to change notification settings - Fork 190
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
Merge site object for SmartadserverBidder #1225
Merge site object for SmartadserverBidder #1225
Conversation
final Publisher publisher = siteOpt.flatMap(site -> Optional.ofNullable(site.getPublisher())) | ||
.map(p -> p.toBuilder()) | ||
.orElse(Publisher.builder()) | ||
.id(networkId) | ||
.build(); | ||
final Site site = siteOpt | ||
.map(s -> s.toBuilder()) | ||
.orElse(Site.builder()) | ||
.publisher(publisher).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.
I'm coming from Scala with a focus on functional styles. Is this kind of programming style okay for this project?
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.
Usually we prefer to use methods like modify[DesiredObject], like this
private Site modifySite(Site site, Integer networkId) {
final Site.SiteBuilder siteBuilder = site != null ? site.toBuilder() : Site.builder();
final Publisher sitePublisher = site != null ? site.getPublisher() : null;
return siteBuilder.publisher(modifyPublisher(sitePublisher, networkId)).build();
}
private Publisher modifyPublisher(Publisher publisher, Integer networkId) {
final Publisher.PublisherBuilder publisherBuilder = publisher != null
? publisher.toBuilder()
: Publisher.builder();
return publisherBuilder.id(String.valueOf(networkId)).build();
}
Then your bidRequest can be created like
final BidRequest updatedRequest = request.toBuilder()
.imp(Collections.singletonList(imp))
.site(modifySite(request.getSite(), extImpSmartadserver.getNetworkId()))
.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.
I refactored according to your suggestions 😃
Out of curiosity. Was not using Optional
an explicit decisions and if why so? Performance, too much refactoring? I was thinking about opening an issue to discuss this as I'm stumbling over NPEs quite a lot 😂 (not used to null
anymore)
assertThat(result.getErrors()).isEmpty(); | ||
assertThat(result.getValue()).hasSize(1); | ||
final Site site = result.getValue().get(0).getPayload().getSite(); | ||
assertThat(site).isEqualTo(Site.builder() | ||
.domain("www.foo.com") | ||
.publisher(Publisher.builder().domain("foo.com").id("4").build()) | ||
.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.
We usually do like this
final Site expectedSite = Site.builder()
.domain("www.foo.com")
.publisher(Publisher.builder().domain("foo.com").id("4").build())
.build();
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.extracting(HttpRequest::getPayload)
.extracting(BidRequest::getSite)
.containsExactly(expectedSite);
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.
That looks nicer 😄
final Publisher publisher = siteOpt.flatMap(site -> Optional.ofNullable(site.getPublisher())) | ||
.map(p -> p.toBuilder()) | ||
.orElse(Publisher.builder()) | ||
.id(networkId) | ||
.build(); | ||
final Site site = siteOpt | ||
.map(s -> s.toBuilder()) | ||
.orElse(Site.builder()) | ||
.publisher(publisher).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.
Usually we prefer to use methods like modify[DesiredObject], like this
private Site modifySite(Site site, Integer networkId) {
final Site.SiteBuilder siteBuilder = site != null ? site.toBuilder() : Site.builder();
final Publisher sitePublisher = site != null ? site.getPublisher() : null;
return siteBuilder.publisher(modifyPublisher(sitePublisher, networkId)).build();
}
private Publisher modifyPublisher(Publisher publisher, Integer networkId) {
final Publisher.PublisherBuilder publisherBuilder = publisher != null
? publisher.toBuilder()
: Publisher.builder();
return publisherBuilder.id(String.valueOf(networkId)).build();
}
Then your bidRequest can be created like
final BidRequest updatedRequest = request.toBuilder()
.imp(Collections.singletonList(imp))
.site(modifySite(request.getSite(), extImpSmartadserver.getNetworkId()))
.build();
@@ -81,6 +83,30 @@ public void makeHttpRequestsShouldCreateCorrectURL() { | |||
.isEqualTo("https://test.endpoint.com/path/api/bid?testParam=testVal&callerId=5"); | |||
} | |||
|
|||
@Test | |||
public void makeHttpRequestsShouldMergeExistingPublisherData() { |
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.
Actually this test also checks that we update Site object, so it will be great to rename it like
makeHttpRequestsShouldUpdateSiteObjectIfPresent
or another one
Thanks a lot for the detailed code review ❤️ I implemented all the requested changes. |
@@ -107,6 +103,21 @@ private String getUri() { | |||
.toString(); | |||
} | |||
|
|||
private Site modifySite(Site site, Integer networkId) { |
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.
One more small change, pls, make methods modifySite and modifyPublisher to be static
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.
@muuki88 agree?
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.
Will do! I must have missed that comment.
* Merge site object for SmartadserverBidder * Fix integration test * Apply requested code review changes * Make modifySite and modifyPublisher static
* Merge site object for SmartadserverBidder * Fix integration test * Apply requested code review changes * Make modifySite and modifyPublisher static
* Merge site object for SmartadserverBidder * Fix integration test * Apply requested code review changes * Make modifySite and modifyPublisher static
The Smartadserver adapter overrides the entire site object, which removes all openrtb extensions like
domain
,page
or any other information that has been set.