Skip to content
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

Merged
merged 19 commits into from
Sep 24, 2021
Merged

Updating admixer bidder #1401

merged 19 commits into from
Sep 24, 2021

Conversation

javaAndScriptDeveloper
Copy link
Contributor

Updated admixer due to this:
prebid/prebid-server#1872

Plz take a look at AdmixerBidder.java / line 109

Comment on lines 96 to 100
final BigDecimal customFloor = extImpAdmixer.getCustomFloor();
final BigDecimal impFloor = isValidBidFloor(imp.getBidfloor()) ? imp.getBidfloor() : null;
final BigDecimal bidfloor = isValidBidFloor(customFloor) && !isValidBidFloor(impFloor)
? customFloor
: impFloor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Extract to separate method.
  2. 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() {
Copy link
Contributor

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.

Copy link
Member

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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)

Copy link
Contributor

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) {
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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);

Copy link
Contributor Author

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) {
Copy link
Contributor

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());
Copy link
Contributor

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) {
Copy link
Contributor

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)))
Copy link
Contributor

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();
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be static

@rpanchyk rpanchyk merged commit b36c977 into master Sep 24, 2021
@rpanchyk rpanchyk deleted the updatingAdmixerBidder branch September 24, 2021 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants