-
Notifications
You must be signed in to change notification settings - Fork 175
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
Updating admixer bidder #1401
Updating admixer bidder #1401
Conversation
final BigDecimal customFloor = extImpAdmixer.getCustomFloor(); | ||
final BigDecimal impFloor = isValidBidFloor(imp.getBidfloor()) ? imp.getBidfloor() : null; | ||
final BigDecimal bidfloor = isValidBidFloor(customFloor) && !isValidBidFloor(impFloor) | ||
? customFloor | ||
: impFloor; |
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.
- Extract to separate method.
- Why you're checking
imp.getBidfloor()
two times?
@@ -303,6 +267,91 @@ public void makeBidsShouldReturnBannerBidIfAudioIsPresentInRequestImp() throws J | |||
.containsExactly(BidderBid.of(Bid.builder().impid("123").build(), audio, "USD")); | |||
} | |||
|
|||
@Test | |||
public void shouldReturnNullIfBidFloorNullCustomFloorNull() { |
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.
Method you're testing returns Result<List<HttpRequest<BidRequest>>>
. It doesn't returns null.
Rename to something like makeHttpRequestsShouldReturnBidFloorAs...
to be in code style with other tests.
PS. Change all other test names below.
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.
Maybe name it as makeHttpRequestsShouldOmitBidFloor...
?
} | ||
|
||
//method where zoneId cut from ext and passed to tagId field | ||
private static Imp givenImpWithParsedTagID(UnaryOperator<Imp.ImpBuilder> impCustomizer) { |
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.
This method almost duplicates the above.
Can we call givenImp(...)
here instead?
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.
The difference is that in givenImp tagId is located as a part of json in ext field, in givenImpWithParsedTagID tagId is cropped out of json and assigned to field tagId; givenImpWithParsedTagID is quite useful to compare imps after request(during request tagId is cropped and assigned)
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.
ok, but you can call givenImp(...)
inside of givenImpWithParsedTagID(...)
.
So, you'll rid off the code duplication.
.ext(makeImpExt(extImpAdmixer.getCustomParams())) | ||
.build(); | ||
} | ||
|
||
private BigDecimal calculateBifLoor(BigDecimal customFloor, BigDecimal bidFloor) { |
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.
Suggestion:
resolveBidFloor(BigDecimal impBidFloor, BigDecimal customBidFloor)`
.ext(makeImpExt(extImpAdmixer.getCustomParams())) | ||
.build(); | ||
} | ||
|
||
private BigDecimal calculateBifLoor(BigDecimal customFloor, BigDecimal bidFloor) { | ||
customFloor = isValidBidFloor(customFloor) ? customFloor : null; |
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.
Create new final
variable resolvedCustomBidFloor
. Do not override input args.
private BigDecimal calculateBifLoor(BigDecimal customFloor, BigDecimal bidFloor) { | ||
customFloor = isValidBidFloor(customFloor) ? customFloor : null; | ||
|
||
return isValidBidFloor(bidFloor) ? bidFloor : customFloor; |
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.
Suggestion:
final BigDecimal resolvedBidFloor = isValidBidFloor(impBidFloor) ? impBidFloor : null;
return ObjectUtils.defaultIfNull(resolvedBidFloor, resolvedCustomBidFloor);
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.
have used isValidBidFloor because it checks whether decimal is zero or less than zero, not only null;
|
||
} | ||
|
||
private static boolean isValidBidFloor(BigDecimal impFloor) { |
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.
Rename impFloor
to bidFloor
.
throw new PreBidException("ZoneId must be UUID/GUID"); | ||
} | ||
|
||
return extImpAdmixer; | ||
} | ||
|
||
private Imp processImp(Imp imp, ExtImpAdmixer extImpAdmixer) { | ||
final Double extImpFloor = extImpAdmixer.getCustomFloor(); | ||
final BigDecimal customFloor = extImpFloor != null ? BigDecimal.valueOf(extImpFloor) : BigDecimal.ZERO; | ||
final BigDecimal bidFloor = calculateBifLoor(extImpAdmixer.getCustomFloor(), imp.getBidfloor()); |
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.
Inline this call. No need for separate variable since it is quite clear and doesn't required to use twice.
@@ -85,23 +85,34 @@ private ExtImpAdmixer parseImpExt(Imp imp) { | |||
} catch (IllegalArgumentException e) { | |||
throw new PreBidException(String.format("Wrong Admixer bidder ext in imp with id : %s", imp.getId())); | |||
} | |||
if (StringUtils.length(extImpAdmixer.getZone()) != 36) { | |||
if (StringUtils.length(extImpAdmixer.getZone()) < 32 || StringUtils.length(extImpAdmixer.getZone()) > 36) { |
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.
Extract extImpAdmixer.getZone()
to separate variable.
@@ -218,7 +182,7 @@ public void makeBidsShouldReturnBannerBidByDefault() throws JsonProcessingExcept | |||
// when | |||
final Result<List<BidderBid>> result = admixerBidder.makeBids(httpCall, | |||
BidRequest.builder() | |||
.imp(singletonList(Imp.builder().id("123").build())) | |||
.imp(singletonList(givenImp(builder -> builder))) |
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.
Use indentity()
instead.
@@ -85,23 +86,34 @@ private ExtImpAdmixer parseImpExt(Imp imp) { | |||
} catch (IllegalArgumentException e) { | |||
throw new PreBidException(String.format("Wrong Admixer bidder ext in imp with id : %s", imp.getId())); | |||
} | |||
if (StringUtils.length(extImpAdmixer.getZone()) != 36) { | |||
String zoneId = extImpAdmixer.getZone(); |
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.
Can be final
.ext(makeImpExt(extImpAdmixer.getCustomParams())) | ||
.build(); | ||
} | ||
|
||
private BigDecimal resolveBidFloor(BigDecimal customBidFloor, BigDecimal bidFloor) { |
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.
Can be static
Updated admixer due to this:
prebid/prebid-server#1872
Plz take a look at AdmixerBidder.java / line 109