-
Notifications
You must be signed in to change notification settings - Fork 193
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 ported from Go #3684
base: master
Are you sure you want to change the base?
Changes from 1 commit
8ea1419
3e4f05e
858b5df
c3e11ce
5ca450c
7293b44
ac1eb72
9287f80
857a308
c385084
3078b30
d64f134
68770b0
4982cf4
3521a00
5ee2283
a8b9c4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ | |
import org.prebid.server.currency.CurrencyConversionService; | ||
import org.prebid.server.exception.PreBidException; | ||
import org.prebid.server.json.DecodeException; | ||
import org.prebid.server.json.EncodeException; | ||
import org.prebid.server.json.JacksonMapper; | ||
import org.prebid.server.proto.openrtb.ext.ExtPrebid; | ||
import org.prebid.server.proto.openrtb.ext.request.kobler.ExtImpKobler; | ||
|
@@ -34,6 +33,7 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class KoblerBidder implements Bidder<BidRequest> { | ||
|
||
|
@@ -71,40 +71,30 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequ | |
final List<Imp> imps = bidRequest.getImp(); | ||
if (!imps.isEmpty()) { | ||
try { | ||
testMode = parseImpExt(imps.get(0)).getTest(); | ||
testMode = parseImpExt(imps.getFirst()).getTest(); | ||
} catch (PreBidException e) { | ||
errors.add(BidderError.badInput(e.getMessage())); | ||
return Result.withErrors(errors); | ||
} | ||
} | ||
|
||
for (Imp imp : imps) { | ||
try { | ||
final Imp processedImp = processImp(bidRequest, imp); | ||
modifiedImps.add(processedImp); | ||
modifiedImps.add(processImp(bidRequest, imp)); | ||
} catch (PreBidException e) { | ||
errors.add(BidderError.badInput(e.getMessage())); | ||
} | ||
} | ||
|
||
if (modifiedImps.isEmpty()) { | ||
errors.add(BidderError.badInput("No valid impressions")); | ||
return Result.withErrors(errors); | ||
} | ||
|
||
final BidRequest modifiedRequest = bidRequest.toBuilder() | ||
.cur(currencies) | ||
.imp(modifiedImps) | ||
.build(); | ||
|
||
final String endpoint = testMode ? DEV_ENDPOINT : endpointUrl; | ||
|
||
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); | ||
} | ||
final HttpRequest<BidRequest> httpRequest = BidderUtil.defaultRequest(modifiedRequest, endpoint, mapper); | ||
return Result.of(Collections.singletonList(httpRequest), errors); | ||
} | ||
|
||
private Imp processImp(BidRequest bidRequest, Imp imp) { | ||
|
@@ -146,46 +136,34 @@ public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequ | |
try { | ||
final List<BidderError> errors = new ArrayList<>(); | ||
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
return Result.of(extractBids(bidResponse, errors), errors); | ||
return Result.of(extractBids(bidResponse), errors); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} catch (DecodeException e) { | ||
return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
} | ||
} | ||
|
||
private List<BidderBid> extractBids(BidResponse bidResponse, List<BidderError> errors) { | ||
private List<BidderBid> extractBids(BidResponse bidResponse) { | ||
if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { | ||
return Collections.emptyList(); | ||
} | ||
return bidsFromResponse(bidResponse, errors); | ||
return bidsFromResponse(bidResponse); | ||
} | ||
|
||
private List<BidderBid> bidsFromResponse(BidResponse bidResponse, List<BidderError> errors) { | ||
private List<BidderBid> bidsFromResponse(BidResponse bidResponse) { | ||
return bidResponse.getSeatbid().stream() | ||
.filter(Objects::nonNull) | ||
.map(SeatBid::getBid) | ||
.filter(Objects::nonNull) | ||
.flatMap(Collection::stream) | ||
.map(bid -> BidderBid.of(bid, getBidType(bid), bidResponse.getCur())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add |
||
.filter(Objects::nonNull) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please, return all the filters back except for the last one |
||
.toList(); | ||
} | ||
|
||
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ć | ||
return Optional.ofNullable(bid.getExt()) | ||
.map(ext -> ext.get(EXT_PREBID)) | ||
.map(ObjectNode.class::cast) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add |
||
.map(this::parseExtBidPrebid) | ||
.map(ExtBidPrebid::getType) | ||
.orElse(BidType.banner); | ||
} | ||
|
||
private ExtBidPrebid parseExtBidPrebid(ObjectNode prebid) { | ||
|
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?
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.
^^
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.
if processImp throws an exception, we immediately return Result.withErrors(errors), instead of continuing the loop.