-
Notifications
You must be signed in to change notification settings - Fork 188
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
Kobler: New adapter (#3667) #3684
base: master
Are you sure you want to change the base?
Conversation
src/main/java/org/prebid/server/bidder/kobler/KoblerBidder.java
Outdated
Show resolved
Hide resolved
src/main/java/org/prebid/server/bidder/kobler/KoblerBidder.java
Outdated
Show resolved
Hide resolved
src/main/java/org/prebid/server/bidder/kobler/KoblerBidder.java
Outdated
Show resolved
Hide resolved
src/main/java/org/prebid/server/bidder/kobler/KoblerBidder.java
Outdated
Show resolved
Hide resolved
return bidsFromResponse(bidResponse, errors); | ||
} | ||
|
||
private List<BidderBid> bidsFromResponse(BidResponse bidResponse, List<BidderError> errors) { |
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 errors list is redundant
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 errors list is still redundant
src/main/java/org/prebid/server/bidder/kobler/KoblerBidder.java
Outdated
Show resolved
Hide resolved
BidderDeps koblerBidderDeps(BidderConfigurationProperties koblerConfigurationProperties, | ||
CurrencyConversionService currencyConversionService, | ||
@NotBlank @Value("${external-url}") String externalUrl, | ||
JacksonMapper mapper) { |
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.
indentation is bad
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 used a checkstyle and it didnt show mistakes. How it should looks like?
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.
as least the method parameter should be aligned
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.
it's still not aligned)
src/main/java/org/prebid/server/bidder/kobler/KoblerBidder.java
Outdated
Show resolved
Hide resolved
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.
Ping me when you finish addressing the comments, probably this time I commented too early
src/main/java/org/prebid/server/bidder/kobler/KoblerBidder.java
Outdated
Show resolved
Hide resolved
return Result.withErrors(errors); | ||
} | ||
|
||
modifiedRequest = modifiedRequest.toBuilder().imp(modifiedImps).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 modify the request once
src/main/java/org/prebid/server/bidder/kobler/KoblerBidder.java
Outdated
Show resolved
Hide resolved
return imp; | ||
} | ||
|
||
public boolean extractTestMode(Imp imp) { |
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.
why public?
src/main/java/org/prebid/server/bidder/kobler/KoblerBidder.java
Outdated
Show resolved
Hide resolved
try { | ||
final ExtPrebid<?, ExtImpKobler> extPrebid = mapper.mapper().convertValue(imp.getExt(), | ||
KOBLER_EXT_TYPE_REFERENCE); | ||
final ExtImpKobler extImpKobler = extPrebid != null ? extPrebid.getBidder() : 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.
parse the imp.ext
in the same way you did before, please make it in the same style other bidders do
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 changed the code. My question is:
-Can we receive an empty ext in the request? If so, the parseImpExt method will return null. shuould I handle NPE? impExtKobler field is not rerequired.
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.
in order to reach the bidder you have to declare it as the imp.ext.prebid.BIDDER, otherwise the PBS doesn't know what to call, so this object will be always present, but it can be empty
src/main/java/org/prebid/server/bidder/kobler/KoblerBidder.java
Outdated
Show resolved
Hide resolved
final List<Imp> imps = bidRequest.getImp(); | ||
if (!imps.isEmpty()) { | ||
try { | ||
testMode = parseImpExt(imps.get(0)).getTest(); |
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.
imps.getFirst()
try { | ||
final HttpRequest<BidRequest> httpRequest = BidderUtil.defaultRequest(modifiedRequest, endpoint, mapper); | ||
return Result.of(Collections.singletonList(httpRequest), errors); | ||
} catch (EncodeException e) { | ||
errors.add(BidderError.badInput("Failed to encode request: " + e.getMessage())); | ||
return Result.withErrors(errors); | ||
} |
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 try-catch is redundant
final Imp processedImp = processImp(bidRequest, imp); | ||
modifiedImps.add(processedImp); | ||
} catch (PreBidException e) { | ||
errors.add(BidderError.badInput(e.getMessage())); |
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.
as I can see, in case of any imp processing error it's immediately should return the Result
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.
any fix on that?
|
||
for (Imp imp : imps) { | ||
try { | ||
final Imp processedImp = processImp(bidRequest, imp); |
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.
let's rename the method to modifyImp
and make everything inline
modifiedImps.add(modifyImp(bidRequest, imp));
if (modifiedImps.isEmpty()) { | ||
errors.add(BidderError.badInput("No valid impressions")); | ||
return Result.withErrors(errors); | ||
} |
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 check is redundant because the process should stop on the very first imp modification failure
private BidType getBidType(Bid bid) { | ||
if (bid.getExt() == null) { | ||
return BidType.banner; | ||
} | ||
|
||
final ObjectNode prebidNode = (ObjectNode) bid.getExt().get(EXT_PREBID); | ||
if (prebidNode == null) { | ||
return BidType.banner; | ||
} | ||
|
||
final ExtBidPrebid extBidPrebid = parseExtBidPrebid(prebidNode); | ||
if (extBidPrebid == null || extBidPrebid.getType() == null) { | ||
return BidType.banner; | ||
} | ||
|
||
return extBidPrebid.getType(); // jeśli udało się sparsować | ||
} | ||
|
||
private ExtBidPrebid parseExtBidPrebid(ObjectNode prebid) { | ||
try { | ||
return mapper.mapper().treeToValue(prebid, ExtBidPrebid.class); | ||
} catch (JsonProcessingException e) { | ||
return 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.
private BidType getBidType(Bid bid) {
return Optional.ofNullable(bid.getExt())
.map(ext -> ext.get(EXT_PREBID))
.map(ObjectNode.class::cast)
.map(this::parseExtBidPrebid)
.map(ExtBidPrebid::getType)
.orElse(BidType.banner);
}
private ExtBidPrebid parseExtBidPrebid(ObjectNode prebid) {
try {
return mapper.mapper().treeToValue(prebid, ExtBidPrebid.class);
} catch (JsonProcessingException e) {
return null;
}
}
.filter(Objects::nonNull) | ||
.flatMap(Collection::stream) | ||
.map(bid -> BidderBid.of(bid, getBidType(bid), bidResponse.getCur())) | ||
.filter(Objects::nonNull) |
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 filter is redundant
return bidsFromResponse(bidResponse, errors); | ||
} | ||
|
||
private List<BidderBid> bidsFromResponse(BidResponse bidResponse, List<BidderError> errors) { |
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 errors list is still redundant
BidderDeps koblerBidderDeps(BidderConfigurationProperties koblerConfigurationProperties, | ||
CurrencyConversionService currencyConversionService, | ||
@NotBlank @Value("${external-url}") String externalUrl, | ||
JacksonMapper mapper) { |
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.
as least the method parameter should be aligned
try { | ||
final List<BidderError> errors = new ArrayList<>(); | ||
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
return Result.of(extractBids(bidResponse), errors); |
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.
Result.withValues(...)
+ get rid of redundant errors
final Imp processedImp = processImp(bidRequest, imp); | ||
modifiedImps.add(processedImp); | ||
} catch (PreBidException e) { | ||
errors.add(BidderError.badInput(e.getMessage())); |
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.
any fix on that?
.filter(Objects::nonNull) | ||
.map(SeatBid::getBid) | ||
.filter(Objects::nonNull) | ||
.flatMap(Collection::stream) | ||
.map(bid -> BidderBid.of(bid, getBidType(bid), bidResponse.getCur())) | ||
.filter(Objects::nonNull) |
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, return all the filters back except for the last one
BidderDeps koblerBidderDeps(BidderConfigurationProperties koblerConfigurationProperties, | ||
CurrencyConversionService currencyConversionService, | ||
@NotBlank @Value("${external-url}") String externalUrl, | ||
JacksonMapper mapper) { |
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.
it's still not aligned)
|
||
@Test | ||
public void makeHttpRequestsShouldReturnErrorIfNoValidImps() { | ||
// Given |
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 use lower-cased given-when-then
, it's a nitpick, but it's worth preserving the common style
@Test | ||
public void makeBidsShouldReturnEmptyListWhenBidResponseIsNull() { | ||
// Given | ||
final BidderCall<BidRequest> httpCall = givenHttpCallWithBody("null"); | ||
|
||
// When | ||
final Result<List<BidderBid>> result = target.makeBids(httpCall, BidRequest.builder().build()); | ||
|
||
// Then | ||
assertThat(result.getValue()).isEmpty(); | ||
assertThat(result.getErrors()).isEmpty(); | ||
} | ||
|
||
@Test | ||
public void makeBidsShouldReturnEmptyListWhenSeatbidIsEmpty() throws JsonProcessingException { | ||
// Given | ||
final BidResponse bidResponse = BidResponse.builder() | ||
.seatbid(Collections.emptyList()) | ||
.build(); | ||
final BidderCall<BidRequest> httpCall = givenHttpCall(bidResponse); | ||
|
||
// When | ||
final Result<List<BidderBid>> result = target.makeBids(httpCall, BidRequest.builder().build()); | ||
|
||
// Then | ||
assertThat(result.getValue()).isEmpty(); | ||
assertThat(result.getErrors()).isEmpty(); | ||
} |
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 do not mix up makeBids
and makeHttpRequests
test cases
🔧 Type of changes
✨ What's the context?
#3667