-
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 2 commits
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.iab.openrtb.request.BidRequest; | ||
import com.iab.openrtb.request.Imp; | ||
|
@@ -40,19 +41,23 @@ public class KoblerBidder implements Bidder<BidRequest> { | |
private static final TypeReference<ExtPrebid<?, ExtImpKobler>> KOBLER_EXT_TYPE_REFERENCE = | ||
new TypeReference<>() { | ||
}; | ||
private static final String EXT_PREBID = "prebid"; | ||
private static final String DEFAULT_BID_CURRENCY = "USD"; | ||
private static final String DEV_ENDPOINT = "https://bid-service.dev.essrtb.com/bid/prebid_server_rtb_call"; | ||
|
||
private final String endpointUrl; | ||
private final String defaultBidCurrency; | ||
private final String devEndpoint; | ||
private final String extPrebid; | ||
private final CurrencyConversionService currencyConversionService; | ||
private final JacksonMapper mapper; | ||
|
||
public KoblerBidder(String endpointUrl, | ||
String defaultBidCurrency, | ||
String devEndpoint, | ||
String extPrebid, | ||
CurrencyConversionService currencyConversionService, | ||
JacksonMapper mapper) { | ||
|
||
this.endpointUrl = HttpUtil.validateUrl(endpointUrl); | ||
this.defaultBidCurrency = Objects.requireNonNull(defaultBidCurrency); | ||
this.devEndpoint = Objects.requireNonNull(devEndpoint); | ||
this.extPrebid = Objects.requireNonNull(extPrebid); | ||
this.currencyConversionService = Objects.requireNonNull(currencyConversionService); | ||
this.mapper = Objects.requireNonNull(mapper); | ||
} | ||
|
@@ -63,19 +68,13 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequ | |
boolean testMode = false; | ||
final List<Imp> modifiedImps = new ArrayList<>(); | ||
|
||
final List<String> currencies = new ArrayList<>(bidRequest.getCur()); | ||
if (!currencies.contains(DEFAULT_BID_CURRENCY)) { | ||
currencies.add(DEFAULT_BID_CURRENCY); | ||
} | ||
final List<String> currencies = normalizeCurrencies(bidRequest); | ||
|
||
final List<Imp> imps = bidRequest.getImp(); | ||
if (!imps.isEmpty()) { | ||
try { | ||
testMode = parseImpExt(imps.getFirst()).getTest(); | ||
} catch (PreBidException e) { | ||
errors.add(BidderError.badInput(e.getMessage())); | ||
return Result.withErrors(errors); | ||
} | ||
try { | ||
testMode = isTest(imps.getFirst()); | ||
} catch (PreBidException e) { | ||
errors.add(BidderError.badInput(e.getMessage())); | ||
} | ||
|
||
for (Imp imp : imps) { | ||
|
@@ -92,12 +91,28 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequ | |
.imp(modifiedImps) | ||
.build(); | ||
|
||
final String endpoint = testMode ? DEV_ENDPOINT : endpointUrl; | ||
final String endpoint = testMode ? devEndpoint : endpointUrl; | ||
|
||
final HttpRequest<BidRequest> httpRequest = BidderUtil.defaultRequest(modifiedRequest, endpoint, mapper); | ||
return Result.of(Collections.singletonList(httpRequest), errors); | ||
} | ||
|
||
private boolean isTest(Imp imp) { | ||
try { | ||
return parseImpExt(imp).getTest(); | ||
} catch (PreBidException e) { | ||
return false; | ||
} | ||
} | ||
|
||
private List<String> normalizeCurrencies(BidRequest bidRequest) { | ||
final List<String> currencies = new ArrayList<>(bidRequest.getCur()); | ||
if (!currencies.contains(defaultBidCurrency)) { | ||
currencies.add(defaultBidCurrency); | ||
} | ||
return currencies; | ||
} | ||
|
||
private Imp modifyImp(BidRequest bidRequest, Imp imp) { | ||
final Price resolvedBidFloor = resolveBidFloor(imp, bidRequest); | ||
|
||
|
@@ -109,7 +124,7 @@ private Imp modifyImp(BidRequest bidRequest, Imp imp) { | |
|
||
private Price resolveBidFloor(Imp imp, BidRequest bidRequest) { | ||
final Price initialBidFloorPrice = Price.of(imp.getBidfloorcur(), imp.getBidfloor()); | ||
return BidderUtil.shouldConvertBidFloor(initialBidFloorPrice, DEFAULT_BID_CURRENCY) | ||
return BidderUtil.shouldConvertBidFloor(initialBidFloorPrice, defaultBidCurrency) | ||
? convertBidFloor(initialBidFloorPrice, bidRequest) | ||
: initialBidFloorPrice; | ||
} | ||
|
@@ -119,9 +134,9 @@ private Price convertBidFloor(Price bidFloorPrice, BidRequest bidRequest) { | |
bidFloorPrice.getValue(), | ||
bidRequest, | ||
bidFloorPrice.getCurrency(), | ||
DEFAULT_BID_CURRENCY); | ||
defaultBidCurrency); | ||
|
||
return Price.of(DEFAULT_BID_CURRENCY, convertedPrice); | ||
return Price.of(defaultBidCurrency, convertedPrice); | ||
} | ||
|
||
private ExtImpKobler parseImpExt(Imp imp) { | ||
|
@@ -155,13 +170,15 @@ private List<BidderBid> bidsFromResponse(BidResponse bidResponse) { | |
.map(SeatBid::getBid) | ||
.filter(Objects::nonNull) | ||
.flatMap(Collection::stream) | ||
.filter(Objects::nonNull) | ||
.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 |
||
.toList(); | ||
} | ||
|
||
private BidType getBidType(Bid bid) { | ||
return Optional.ofNullable(bid.getExt()) | ||
.map(ext -> ext.get(EXT_PREBID)) | ||
.map(ext -> ext.get(extPrebid)) | ||
.filter(JsonNode::isObject) | ||
.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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
package org.prebid.server.proto.openrtb.ext.request.kobler; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Value; | ||
|
||
@Value(staticConstructor = "of") | ||
public class ExtImpKobler { | ||
|
||
@JsonProperty("test") | ||
Boolean test; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package org.prebid.server.spring.config.bidder; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import org.prebid.server.bidder.BidderDeps; | ||
import org.prebid.server.bidder.kobler.KoblerBidder; | ||
import org.prebid.server.currency.CurrencyConversionService; | ||
|
@@ -13,6 +16,7 @@ | |
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
|
@@ -24,20 +28,43 @@ public class KoblerConfiguration { | |
|
||
@Bean("koblerConfigurationProperties") | ||
@ConfigurationProperties("adapters.kobler") | ||
BidderConfigurationProperties configurationProperties() { | ||
return new BidderConfigurationProperties(); | ||
KoblerConfigurationProperties configurationProperties() { | ||
return new KoblerConfigurationProperties(); | ||
} | ||
|
||
@Bean | ||
BidderDeps koblerBidderDeps(BidderConfigurationProperties koblerConfigurationProperties, | ||
BidderDeps koblerBidderDeps(KoblerConfigurationProperties config, | ||
CurrencyConversionService currencyConversionService, | ||
@NotBlank @Value("${external-url}") String externalUrl, | ||
JacksonMapper mapper) { | ||
|
||
return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
.withConfig(koblerConfigurationProperties) | ||
return BidderDepsAssembler.<KoblerConfigurationProperties>forBidder(BIDDER_NAME) | ||
.withConfig(config) | ||
.usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
.bidderCreator(config -> new KoblerBidder(config.getEndpoint(), currencyConversionService, mapper)) | ||
.bidderCreator(cfg -> new KoblerBidder( | ||
cfg.getEndpoint(), | ||
cfg.getDefaultBidCurrency(), | ||
cfg.getDevEndpoint(), | ||
cfg.getExtPrebid(), | ||
currencyConversionService, | ||
mapper)) | ||
.assemble(); | ||
|
||
} | ||
|
||
@Validated | ||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
@NoArgsConstructor | ||
private static class KoblerConfigurationProperties extends BidderConfigurationProperties { | ||
|
||
@NotBlank | ||
private String defaultBidCurrency; | ||
|
||
@NotBlank | ||
private String devEndpoint; | ||
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. I believe only the devEndpoint was asked to be extracted to the properties, other stuff seems static and it doesn't have much sense being extracted 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. @CTMBNara marked these fields so I moved them all |
||
|
||
@NotBlank | ||
private String extPrebid; | ||
} | ||
} |
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