-
Notifications
You must be signed in to change notification settings - Fork 252
New Adapter: Synapse HX #4620
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
Merged
Merged
New Adapter: Synapse HX #4620
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e06f2c4
Implementation of the Synapse HX adapter
prebid-compas 2219eb3
Adjustments after the review
prebid-compas d07eb02
Adjustments after the review # 2
prebid-compas ab19b2a
Fixes after Java update
prebid-compas d80fecc
Fix Synapse HX adapter compatibility with current master
osulzhenko ce8d76f
updated after code review
osulzhenko 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
160 changes: 160 additions & 0 deletions
160
src/main/java/org/prebid/server/bidder/synapsehx/SynapseHXBidder.java
This file contains hidden or 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,160 @@ | ||
| package org.prebid.server.bidder.synapsehx; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 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 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.synapsehx.ExtImpSynapseHX; | ||
| import org.prebid.server.proto.openrtb.ext.response.BidType; | ||
| import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebid; | ||
| import org.prebid.server.util.BidderUtil; | ||
| import org.prebid.server.util.HttpUtil; | ||
| import org.prebid.server.util.Uri; | ||
|
|
||
| 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 SynapseHXBidder implements Bidder<BidRequest> { | ||
|
|
||
| private static final TypeReference<ExtPrebid<?, ExtImpSynapseHX>> SYNAPSE_HX_EXT_TYPE_REFERENCE = | ||
| new TypeReference<>() { | ||
| }; | ||
|
|
||
| private static final TypeReference<ExtPrebid<ExtBidPrebid, ?>> EXT_PREBID_TYPE_REFERENCE = | ||
| new TypeReference<>() { | ||
| }; | ||
|
|
||
| private static final String OPENRTB_VERSION = "2.6"; | ||
|
|
||
| private final Uri endpoint; | ||
| private final JacksonMapper mapper; | ||
|
|
||
| public SynapseHXBidder(String endpoint, JacksonMapper mapper) { | ||
| this.endpoint = Uri.of(endpoint); | ||
| this.mapper = Objects.requireNonNull(mapper); | ||
| } | ||
|
|
||
| @Override | ||
| public final Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequest) { | ||
| final Imp firstImp = bidRequest.getImp().getFirst(); | ||
| final String uri; | ||
|
|
||
| try { | ||
| uri = makeUri(getTenantId(firstImp)); | ||
| } catch (PreBidException e) { | ||
| return Result.withError(BidderError.badInput(e.getMessage())); | ||
| } | ||
|
|
||
| final MultiMap headers = HttpUtil.headers(); | ||
| headers.add(HttpUtil.X_OPENRTB_VERSION_HEADER, OPENRTB_VERSION); | ||
|
|
||
| return Result.withValue(BidderUtil.defaultRequest(bidRequest, headers, uri, mapper)); | ||
| } | ||
|
|
||
| private String getTenantId(Imp firstImp) { | ||
| try { | ||
| return mapper.mapper() | ||
| .convertValue(firstImp.getExt(), SYNAPSE_HX_EXT_TYPE_REFERENCE) | ||
| .getBidder() | ||
| .getTenantId(); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new PreBidException("Failed to parse bidder parameters: %s".formatted(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| private String makeUri(String tenantId) { | ||
| return endpoint.addQueryParam("pid", tenantId).expand(); | ||
| } | ||
|
|
||
| @Override | ||
| public final Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
| try { | ||
| final List<BidderError> bidderErrors = new ArrayList<>(); | ||
| final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
| return Result.of(extractBids(bidResponse, bidderErrors), bidderErrors); | ||
| } catch (DecodeException e) { | ||
| return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| private List<BidderBid> extractBids(BidResponse bidResponse, List<BidderError> bidderErrors) { | ||
| if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { | ||
| return Collections.emptyList(); | ||
| } | ||
| return bidsFromResponse(bidResponse, bidderErrors); | ||
| } | ||
|
|
||
| private List<BidderBid> bidsFromResponse(BidResponse bidResponse, List<BidderError> bidderErrors) { | ||
| return bidResponse.getSeatbid().stream() | ||
| .filter(Objects::nonNull) | ||
| .map(SeatBid::getBid) | ||
| .filter(Objects::nonNull) | ||
| .flatMap(Collection::stream) | ||
| .filter(Objects::nonNull) | ||
| .map(bid -> makeBidderBid(bid, bidResponse, bidderErrors)) | ||
| .filter(Objects::nonNull) | ||
| .toList(); | ||
| } | ||
|
|
||
| private BidderBid makeBidderBid(Bid bid, BidResponse bidResponse, List<BidderError> bidderErrors) { | ||
| final BidType bidType = getBidType(bid, bidderErrors); | ||
| return bidType == null | ||
| ? null | ||
| : BidderBid.of(bid, bidType, bidResponse.getCur()); | ||
| } | ||
|
|
||
| private BidType getBidType(Bid bid, List<BidderError> errors) { | ||
| final Integer mType = bid.getMtype(); | ||
| return mType != null | ||
| ? getBidTypeFromMType(mType, errors) | ||
| : getBidTypeFromExt(bid.getExt(), errors); | ||
| } | ||
|
|
||
| private static BidType getBidTypeFromMType(Integer mType, List<BidderError> errors) { | ||
| return switch (mType) { | ||
| case 1 -> BidType.banner; | ||
| case 2 -> BidType.video; | ||
| default -> { | ||
| errors.add(BidderError.badServerResponse("Unsupported media type: %d".formatted(mType))); | ||
| yield null; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private BidType getBidTypeFromExt(ObjectNode bidExt, List<BidderError> errors) { | ||
| final BidType bidType = Optional.ofNullable(bidExt) | ||
| .map(ext -> mapper.mapper().convertValue(ext, EXT_PREBID_TYPE_REFERENCE)) | ||
| .map(ExtPrebid::getPrebid) | ||
| .map(ExtBidPrebid::getType) | ||
| .orElse(null); | ||
|
|
||
| return switch (bidType) { | ||
| case banner -> BidType.banner; | ||
| case video -> BidType.video; | ||
| case null, default -> { | ||
| errors.add(BidderError.badServerResponse("Unsupported media type: %s".formatted(bidType))); | ||
| yield null; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| } | ||
11 changes: 11 additions & 0 deletions
11
src/main/java/org/prebid/server/proto/openrtb/ext/request/synapsehx/ExtImpSynapseHX.java
This file contains hidden or 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,11 @@ | ||
| package org.prebid.server.proto.openrtb.ext.request.synapsehx; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.Value; | ||
|
|
||
| @Value(staticConstructor = "of") | ||
| public class ExtImpSynapseHX { | ||
|
|
||
| @JsonProperty("tenantId") | ||
| String tenantId; | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/main/java/org/prebid/server/spring/config/bidder/SynapseHXBidderConfiguration.java
This file contains hidden or 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,35 @@ | ||
| package org.prebid.server.spring.config.bidder; | ||
|
|
||
| import org.prebid.server.bidder.BidderDeps; | ||
| import org.prebid.server.bidder.synapsehx.SynapseHXBidder; | ||
| 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.env.YamlPropertySourceFactory; | ||
| 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; | ||
|
|
||
| @Configuration | ||
| @PropertySource(value = "classpath:/bidder-config/synapsehx.yaml", factory = YamlPropertySourceFactory.class) | ||
| public class SynapseHXBidderConfiguration { | ||
|
|
||
| private static final String BIDDER_NAME = "synapsehx"; | ||
|
|
||
| @Bean("synapsehxConfigurationProperties") | ||
| @ConfigurationProperties("adapters.synapsehx") | ||
| BidderConfigurationProperties configurationProperties() { | ||
| return new BidderConfigurationProperties(); | ||
| } | ||
|
|
||
| @Bean | ||
| BidderDeps synapsehxBidderDeps(BidderConfigurationProperties synapsehxConfigurationProperties, | ||
| JacksonMapper mapper) { | ||
|
|
||
| return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
| .withConfig(synapsehxConfigurationProperties) | ||
| .bidderCreator(config -> new SynapseHXBidder(config.getEndpoint(), mapper)) | ||
| .assemble(); | ||
| } | ||
| } |
This file contains hidden or 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,21 @@ | ||
| adapters: | ||
| synapsehx: | ||
| endpoint: https://rtb.hx.compasonline.com/pbs | ||
| openrtb-version: 2.6 | ||
| meta-info: | ||
| maintainer-email: prebid@compas-inc.com | ||
| app-media-types: | ||
| - banner | ||
| - video | ||
| site-media-types: | ||
| - banner | ||
| - video | ||
| vendor-id: 0 | ||
| usersync: | ||
| cookie-family-name: synapsehx | ||
| redirect: | ||
| url: https://sync.hx.compasonline.com/pbserver/image?gdpr={gdpr}&gdpr_consent={gdpr_consent}&ccpa={us_privacy}&gpp={gpp}&gpp_sid={gpp_sid}&redirect={redirect_url} | ||
| uid-macro: "${VISITOR_ID}" | ||
| iframe: | ||
| url: https://sync.hx.compasonline.com/pbserver/iframe?gdpr={gdpr}&gdpr_consent={gdpr_consent}&ccpa={us_privacy}&gpp={gpp}&gpp_sid={gpp_sid}&redirect={redirect_url} | ||
| uid-macro: "${VISITOR_ID}" |
This file contains hidden or 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,14 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Synapse HX Adapter Params", | ||
| "description": "A schema which validates params accepted by the Synapse HX adapter", | ||
| "type": "object", | ||
| "properties": { | ||
| "tenantId": { | ||
| "type": "string", | ||
| "description": "Synapse HX tenant identifier", | ||
| "minLength": 1 | ||
| } | ||
| }, | ||
| "required": ["tenantId"] | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.