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

Kobler: New adapter (#3667) #3684

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

przemkaczmarek
Copy link
Collaborator

🔧 Type of changes

  • new bid adapter

✨ What's the context?

#3667

@Net-burst Net-burst linked an issue Jan 21, 2025 that may be closed by this pull request
return bidsFromResponse(bidResponse, errors);
}

private List<BidderBid> bidsFromResponse(BidResponse bidResponse, List<BidderError> errors) {
Copy link
Collaborator

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

Copy link
Collaborator

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/resources/bidder-config/kobler.yaml Show resolved Hide resolved
Comment on lines +32 to +35
BidderDeps koblerBidderDeps(BidderConfigurationProperties koblerConfigurationProperties,
CurrencyConversionService currencyConversionService,
@NotBlank @Value("${external-url}") String externalUrl,
JacksonMapper mapper) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

indentation is bad

Copy link
Collaborator Author

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?

Copy link
Collaborator

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

Copy link
Collaborator

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)

Copy link
Collaborator

@AntoxaAntoxic AntoxaAntoxic left a 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

return Result.withErrors(errors);
}

modifiedRequest = modifiedRequest.toBuilder().imp(modifiedImps).build();
Copy link
Collaborator

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

return imp;
}

public boolean extractTestMode(Imp imp) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why public?

try {
final ExtPrebid<?, ExtImpKobler> extPrebid = mapper.mapper().convertValue(imp.getExt(),
KOBLER_EXT_TYPE_REFERENCE);
final ExtImpKobler extImpKobler = extPrebid != null ? extPrebid.getBidder() : null;
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

Copy link
Collaborator

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

final List<Imp> imps = bidRequest.getImp();
if (!imps.isEmpty()) {
try {
testMode = parseImpExt(imps.get(0)).getTest();
Copy link
Collaborator

Choose a reason for hiding this comment

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

imps.getFirst()

Comment on lines 101 to 107
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);
}
Copy link
Collaborator

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

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

Copy link
Collaborator

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

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

Comment on lines 89 to 92
if (modifiedImps.isEmpty()) {
errors.add(BidderError.badInput("No valid impressions"));
return Result.withErrors(errors);
}
Copy link
Collaborator

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

Comment on lines 173 to 198
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;
}
}
}
Copy link
Collaborator

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

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

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

Comment on lines +32 to +35
BidderDeps koblerBidderDeps(BidderConfigurationProperties koblerConfigurationProperties,
CurrencyConversionService currencyConversionService,
@NotBlank @Value("${external-url}") String externalUrl,
JacksonMapper mapper) {
Copy link
Collaborator

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

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

Choose a reason for hiding this comment

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

any fix on that?

Comment on lines 164 to 169
.filter(Objects::nonNull)
.map(SeatBid::getBid)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.map(bid -> BidderBid.of(bid, getBidType(bid), bidResponse.getCur()))
.filter(Objects::nonNull)
Copy link
Collaborator

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

Comment on lines +32 to +35
BidderDeps koblerBidderDeps(BidderConfigurationProperties koblerConfigurationProperties,
CurrencyConversionService currencyConversionService,
@NotBlank @Value("${external-url}") String externalUrl,
JacksonMapper mapper) {
Copy link
Collaborator

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
Copy link
Collaborator

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

Comment on lines +86 to +113
@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();
}
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port PR from PBS-Go: New Adapter: Kobler
3 participants