-
Notifications
You must be signed in to change notification settings - Fork 190
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
Core: Add new OwnAdx
bidder
#2868
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
897ad84
Add new OwnAdx bidder
marki1an cbdc1fe
Update after review
marki1an 07e525d
Update after review
marki1an 23ac6ac
Update after review
marki1an de08cf4
Update after review
marki1an a3c4956
Update due to fail check style
marki1an 9b3fae0
Update after review
marki1an 3396bd4
Merge branch 'refs/heads/master' into add-new-ownAdX-adapter
marki1an 7392e8c
Update url macros
marki1an 1247bc2
Add `gzip` compression
marki1an 7d86d8b
Merge branch 'master' into add-new-ownAdX-adapter
SerhiiNahornyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
src/main/java/org/prebid/server/bidder/ownadx/OwnAdxBidder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package org.prebid.server.bidder.ownadx; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.iab.openrtb.request.BidRequest; | ||
import com.iab.openrtb.request.Imp; | ||
import com.iab.openrtb.response.Bid; | ||
import com.iab.openrtb.response.BidResponse; | ||
import com.iab.openrtb.response.SeatBid; | ||
import io.vertx.core.MultiMap; | ||
import io.vertx.core.http.HttpMethod; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.prebid.server.bidder.Bidder; | ||
import org.prebid.server.bidder.model.BidderBid; | ||
import org.prebid.server.bidder.model.BidderCall; | ||
import org.prebid.server.bidder.model.BidderError; | ||
import org.prebid.server.bidder.model.HttpRequest; | ||
import org.prebid.server.bidder.model.Result; | ||
import org.prebid.server.exception.PreBidException; | ||
import org.prebid.server.json.DecodeException; | ||
import org.prebid.server.json.JacksonMapper; | ||
import org.prebid.server.proto.openrtb.ext.ExtPrebid; | ||
import org.prebid.server.proto.openrtb.ext.request.ownadx.ExtImpOwnAdx; | ||
import org.prebid.server.proto.openrtb.ext.response.BidType; | ||
import org.prebid.server.util.BidderUtil; | ||
import org.prebid.server.util.HttpUtil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class OwnAdxBidder implements Bidder<BidRequest> { | ||
|
||
private static final TypeReference<ExtPrebid<?, ExtImpOwnAdx>> OWN_EXT_TYPE_REFERENCE = | ||
new TypeReference<>() { | ||
}; | ||
private static final String X_OPEN_RTB_VERSION = "2.5"; | ||
private static final String ACCOUNT_ID_MACROS_ENDPOINT = "{{AccountID}}"; | ||
private static final String ZONE_ID_MACROS_ENDPOINT = "{{ZoneID}}"; | ||
private static final String SOURCE_ID_MACROS_ENDPOINT = "{{SourceId}}"; | ||
|
||
private final String endpointUrl; | ||
private final JacksonMapper mapper; | ||
|
||
public OwnAdxBidder(String endpointUrl, JacksonMapper mapper) { | ||
this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)); | ||
this.mapper = Objects.requireNonNull(mapper); | ||
} | ||
|
||
@Override | ||
public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequest) { | ||
final List<BidderError> errors = new ArrayList<>(); | ||
final List<HttpRequest<BidRequest>> httpRequests = new ArrayList<>(); | ||
for (Imp imp : bidRequest.getImp()) { | ||
try { | ||
final ExtImpOwnAdx impOwnAdx = parseImpExt(imp); | ||
httpRequests.add(createHttpRequest(bidRequest, impOwnAdx)); | ||
} catch (PreBidException e) { | ||
errors.add(BidderError.badInput(e.getMessage())); | ||
} | ||
} | ||
|
||
return Result.of(httpRequests, errors); | ||
} | ||
|
||
private ExtImpOwnAdx parseImpExt(Imp imp) { | ||
try { | ||
return mapper.mapper().convertValue(imp.getExt(), OWN_EXT_TYPE_REFERENCE).getBidder(); | ||
} catch (IllegalArgumentException e) { | ||
throw new PreBidException("Missing bidder ext in impression with id: " + imp.getId()); | ||
} | ||
} | ||
|
||
private HttpRequest<BidRequest> createHttpRequest(BidRequest bidRequest, ExtImpOwnAdx extImpOwnAdx) { | ||
return HttpRequest.<BidRequest>builder() | ||
.method(HttpMethod.POST) | ||
.uri(makeUrl(extImpOwnAdx)) | ||
.headers(makeHeader()) | ||
.body(mapper.encodeToBytes(bidRequest)) | ||
.impIds(BidderUtil.impIds(bidRequest)) | ||
.payload(bidRequest) | ||
.build(); | ||
} | ||
|
||
private String makeUrl(ExtImpOwnAdx extImpOwnAdx) { | ||
final Optional<ExtImpOwnAdx> ownAdx = Optional.ofNullable(extImpOwnAdx); | ||
return endpointUrl | ||
.replace(ACCOUNT_ID_MACROS_ENDPOINT, ownAdx.map(ExtImpOwnAdx::getSspId).orElse("")) | ||
.replace(ZONE_ID_MACROS_ENDPOINT, ownAdx.map(ExtImpOwnAdx::getSeatId).orElse("")) | ||
.replace(SOURCE_ID_MACROS_ENDPOINT, ownAdx.map(ExtImpOwnAdx::getTokenId).orElse("")); | ||
} | ||
|
||
private static MultiMap makeHeader() { | ||
AntoxaAntoxic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return HttpUtil.headers() | ||
.add(HttpUtil.X_OPENRTB_VERSION_HEADER, X_OPEN_RTB_VERSION); | ||
} | ||
|
||
@Override | ||
public final Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
try { | ||
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
return Result.withValues(extractBids(httpCall.getRequest().getPayload(), bidResponse)); | ||
} catch (DecodeException | PreBidException e) { | ||
return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
} | ||
} | ||
|
||
private static List<BidderBid> extractBids(BidRequest bidRequest, BidResponse bidResponse) { | ||
if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { | ||
return Collections.emptyList(); | ||
} | ||
return bidsFromResponse(bidRequest, bidResponse); | ||
} | ||
|
||
private static List<BidderBid> bidsFromResponse(BidRequest bidRequest, BidResponse bidResponse) { | ||
return bidResponse.getSeatbid().stream() | ||
.filter(Objects::nonNull) | ||
.map(SeatBid::getBid) | ||
.filter(Objects::nonNull) | ||
.flatMap(Collection::stream) | ||
AntoxaAntoxic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.map(bid -> BidderBid.of(bid, getBidMediaType(bid), bidResponse.getCur())) | ||
.toList(); | ||
} | ||
|
||
private static BidType getBidMediaType(Bid bid) { | ||
final Integer markupType = bid.getMtype(); | ||
if (markupType == null) { | ||
throw new PreBidException("Missing MType for bid: " + bid.getId()); | ||
} | ||
|
||
return switch (markupType) { | ||
case 1 -> BidType.banner; | ||
case 2 -> BidType.video; | ||
case 3 -> BidType.audio; | ||
case 4 -> BidType.xNative; | ||
default -> throw new PreBidException("Unable to fetch mediaType " + bid.getMtype()); | ||
}; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/prebid/server/proto/openrtb/ext/request/ownadx/ExtImpOwnAdx.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.prebid.server.proto.openrtb.ext.request.ownadx; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Value; | ||
|
||
@Value(staticConstructor = "of") | ||
public class ExtImpOwnAdx { | ||
|
||
@JsonProperty("sspId") | ||
String sspId; | ||
|
||
@JsonProperty("seatId") | ||
String seatId; | ||
|
||
@JsonProperty("tokenId") | ||
String tokenId; | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/prebid/server/spring/config/bidder/OwnAdxBidderConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.prebid.server.spring.config.bidder; | ||
|
||
import org.prebid.server.bidder.BidderDeps; | ||
import org.prebid.server.bidder.ownadx.OwnAdxBidder; | ||
import org.prebid.server.json.JacksonMapper; | ||
import org.prebid.server.spring.config.bidder.model.BidderConfigurationProperties; | ||
import org.prebid.server.spring.config.bidder.util.BidderDepsAssembler; | ||
import org.prebid.server.spring.config.bidder.util.UsersyncerCreator; | ||
import org.prebid.server.spring.env.YamlPropertySourceFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.PropertySource; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
|
||
@Configuration | ||
@PropertySource(value = "classpath:/bidder-config/ownadx.yaml", factory = YamlPropertySourceFactory.class) | ||
public class OwnAdxBidderConfiguration { | ||
|
||
private static final String BIDDER_NAME = "ownadx"; | ||
|
||
@Bean("ownAdxConfigurationProperties") | ||
@ConfigurationProperties("adapters.ownadx") | ||
BidderConfigurationProperties configurationProperties() { | ||
return new BidderConfigurationProperties(); | ||
} | ||
|
||
@Bean | ||
BidderDeps ownAdxBidderDeps(BidderConfigurationProperties ownAdxConfigurationProperties, | ||
@NotBlank @Value("${external-url}") String externalUrl, | ||
JacksonMapper mapper) { | ||
|
||
return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
.withConfig(ownAdxConfigurationProperties) | ||
.usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
.bidderCreator(config -> new OwnAdxBidder(config.getEndpoint(), mapper)) | ||
.assemble(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
adapters: | ||
ownadx: | ||
endpoint: "https://pbs.prebid-ownadx.com/bidder/bid/{{AccountID}}/{{ZoneID}}?token={{SourceId}}" | ||
meta-info: | ||
maintainer-email: prebid-team@techbravo.com | ||
app-media-types: | ||
- banner | ||
- video | ||
site-media-types: | ||
- banner | ||
- video | ||
supported-vendors: | ||
vendor-id: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "OwnAdx Adapter Params", | ||
"description": "A schema which validates params accepted by the OwnAdx adapter", | ||
"type": "object", | ||
"properties": { | ||
"sspId": { | ||
"type": "string", | ||
"description": "Ssp ID" | ||
}, | ||
"seatId": { | ||
"type": "string", | ||
"description": "Seat ID" | ||
}, | ||
"tokenId": { | ||
"type": "string", | ||
"description": "Token ID" | ||
} | ||
}, | ||
"oneOf": [ | ||
{ | ||
"required": [ | ||
"sspId" | ||
] | ||
}, | ||
{ | ||
"required": [ | ||
"feedId" | ||
] | ||
}, | ||
{ | ||
"required": [ | ||
"tokenId" | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
StringUtils.EMPTY