-
Notifications
You must be signed in to change notification settings - Fork 226
Nativo: Add optional placementId parameter and SDK Renderer Version in response #4380
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
Open
rafataveira
wants to merge
3
commits into
prebid:master
Choose a base branch
from
rafataveira:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+768
−31
Open
Changes from all commits
Commits
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
155 changes: 155 additions & 0 deletions
155
src/main/java/org/prebid/server/bidder/nativo/NativoBidder.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,155 @@ | ||
| package org.prebid.server.bidder.nativo; | ||
|
|
||
| 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 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.ExtRequest; | ||
| import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebid; | ||
| import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidSdk; | ||
| import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidSdkRenderer; | ||
| import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebid; | ||
| import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebidMeta; | ||
| 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.Map; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class NativoBidder implements Bidder<BidRequest> { | ||
|
|
||
| private static final String NATIVO_RENDERER_NAME = "NativoRenderer"; | ||
| private static final String PREBID_EXT = "prebid"; | ||
| private static final TypeReference<ExtPrebid<ExtBidPrebid, ?>> EXT_PREBID_TYPE_REFERENCE = | ||
| new TypeReference<>() { | ||
| }; | ||
|
|
||
| private final String endpointUrl; | ||
| private final JacksonMapper mapper; | ||
|
|
||
| public NativoBidder(String endpointUrl, JacksonMapper mapper) { | ||
| this.endpointUrl = HttpUtil.validateUrlSyntax(Objects.requireNonNull(endpointUrl)); | ||
| this.mapper = Objects.requireNonNull(mapper); | ||
| } | ||
|
|
||
| @Override | ||
| public final Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequest) { | ||
| return Result.withValue(BidderUtil.defaultRequest(bidRequest, endpointUrl, mapper)); | ||
| } | ||
|
|
||
| @Override | ||
| public final Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
| try { | ||
| final List<BidderError> errors = new ArrayList<>(); | ||
| final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
| return Result.of(extractBids(httpCall.getRequest().getPayload(), bidResponse, errors), errors); | ||
| } catch (DecodeException e) { | ||
| return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| private List<BidderBid> extractBids(BidRequest bidRequest, BidResponse bidResponse, List<BidderError> errors) { | ||
| if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { | ||
| return Collections.emptyList(); | ||
| } | ||
| return bidsFromResponse(bidRequest, bidResponse, errors); | ||
| } | ||
|
|
||
| private List<BidderBid> bidsFromResponse(BidRequest bidRequest, BidResponse bidResponse, List<BidderError> errors) { | ||
| final Map<String, Imp> impMap = bidRequest.getImp().stream() | ||
| .collect(Collectors.toMap(Imp::getId, Function.identity())); | ||
| final String rendererVersion = getNativoRendererVersion(bidRequest); | ||
|
|
||
| return bidResponse.getSeatbid().stream() | ||
| .filter(Objects::nonNull) | ||
| .map(seatBid -> seatBid.getBid().stream() | ||
| .filter(Objects::nonNull) | ||
| .map(bid -> updateBid(bid, rendererVersion, errors)) | ||
| .filter(Objects::nonNull) | ||
| .map(bid -> BidderBid.of(bid, BidderUtil.getBidType(bid, impMap), bidResponse.getCur())) | ||
| .toList()) | ||
| .flatMap(Collection::stream) | ||
| .toList(); | ||
| } | ||
|
|
||
| private String getNativoRendererVersion(BidRequest bidRequest) { | ||
| return Optional.ofNullable(bidRequest.getExt()) | ||
| .map(ExtRequest::getPrebid) | ||
| .map(ExtRequestPrebid::getSdk) | ||
| .map(ExtRequestPrebidSdk::getRenderers) | ||
| .orElse(Collections.emptyList()) | ||
| .stream() | ||
| .filter(renderer -> NATIVO_RENDERER_NAME.equals(renderer.getName())) | ||
| .map(ExtRequestPrebidSdkRenderer::getVersion) | ||
| .findFirst() | ||
| .orElse(null); | ||
| } | ||
|
|
||
| private Bid updateBid(Bid bid, String rendererVersion, List<BidderError> errors) { | ||
| if (rendererVersion == null) { | ||
| return bid; | ||
| } | ||
|
|
||
| final ObjectNode updateBidExt; | ||
| try { | ||
| updateBidExt = updateBidExt(bid, rendererVersion); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badServerResponse(e.getMessage())); | ||
| return bid; | ||
| } | ||
|
|
||
| return bid.toBuilder().ext(updateBidExt).build(); | ||
| } | ||
|
|
||
| private ObjectNode updateBidExt(Bid bid, String rendererVersion) { | ||
| final ObjectNode bidExt = bid.getExt(); | ||
| final Optional<ExtBidPrebid> extBidPrebid = Optional.ofNullable(bidExt) | ||
| .map(ext -> parseExtBidPrebid(bidExt, bid.getId())); | ||
|
|
||
| final ExtBidPrebidMeta updatedMeta = extBidPrebid | ||
| .map(ExtBidPrebid::getMeta) | ||
| .map(ExtBidPrebidMeta::toBuilder) | ||
| .orElseGet(ExtBidPrebidMeta::builder) | ||
| .rendererVersion(rendererVersion) | ||
| .build(); | ||
|
|
||
| final ExtBidPrebid modifiedExtBidPrebid = extBidPrebid | ||
| .map(ExtBidPrebid::toBuilder) | ||
| .orElseGet(ExtBidPrebid::builder) | ||
| .meta(updatedMeta) | ||
| .build(); | ||
|
|
||
| final ObjectNode updatedBidExt = bidExt != null ? bidExt : mapper.mapper().createObjectNode(); | ||
| updatedBidExt.set(PREBID_EXT, mapper.mapper().valueToTree(modifiedExtBidPrebid)); | ||
| return updatedBidExt; | ||
| } | ||
|
|
||
| private ExtBidPrebid parseExtBidPrebid(ObjectNode bidExt, String bidId) { | ||
| try { | ||
| return mapper.mapper().convertValue(bidExt, EXT_PREBID_TYPE_REFERENCE).getPrebid(); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new PreBidException("Invalid ext passed in bid with id: " + bidId); | ||
| } | ||
| } | ||
|
|
||
| } | ||
11 changes: 11 additions & 0 deletions
11
src/main/java/org/prebid/server/proto/openrtb/ext/request/nativo/ExtImpNativo.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.nativo; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.Value; | ||
|
|
||
| @Value(staticConstructor = "of") | ||
| public class ExtImpNativo { | ||
|
|
||
| @JsonProperty("placementId") | ||
| Object placementId; | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/prebid/server/spring/config/bidder/NativoConfiguration.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,41 @@ | ||
| package org.prebid.server.spring.config.bidder; | ||
|
|
||
| import org.prebid.server.bidder.BidderDeps; | ||
| import org.prebid.server.bidder.nativo.NativoBidder; | ||
| 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 jakarta.validation.constraints.NotBlank; | ||
|
|
||
| @Configuration | ||
| @PropertySource(value = "classpath:/bidder-config/nativo.yaml", factory = YamlPropertySourceFactory.class) | ||
| public class NativoConfiguration { | ||
|
|
||
| private static final String BIDDER_NAME = "nativo"; | ||
|
|
||
| @Bean("nativoConfigurationProperties") | ||
| @ConfigurationProperties("adapters.nativo") | ||
| BidderConfigurationProperties configurationProperties() { | ||
| return new BidderConfigurationProperties(); | ||
| } | ||
|
|
||
| @Bean | ||
| BidderDeps nativoBidderDeps(BidderConfigurationProperties nativoConfigurationProperties, | ||
| @NotBlank @Value("${external-url}") String externalUrl, | ||
| JacksonMapper mapper) { | ||
|
|
||
| return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
| .withConfig(nativoConfigurationProperties) | ||
| .usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
| .bidderCreator(config -> new NativoBidder(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
|
Collaborator
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 see that in GO version this adapter supports Ortb2.6
Contributor
Author
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. updated |
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,23 @@ | ||
| adapters: | ||
| nativo: | ||
| endpoint: https://exchange.postrelease.com/esi?ntv_epid=7 | ||
| ortb-version: "2.6" | ||
| pbs-enforces-ccpa: false | ||
| meta-info: | ||
| maintainer-email: prebiddev@nativo.com | ||
| app-media-types: | ||
| - banner | ||
| - video | ||
| - native | ||
| site-media-types: | ||
| - banner | ||
| - video | ||
| - native | ||
| supported-vendors: | ||
| vendor-id: 263 | ||
| usersync: | ||
| cookie-family-name: nativo | ||
| redirect: | ||
| url: https://jadserve.postrelease.com/suid/101787?gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&ntv_gpp_consent={{gpp}}&ntv_r={{redirect_url}} | ||
| support-cors: false | ||
| uid-macro: 'NTV_USER_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,12 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Nativo Adapter Params", | ||
| "description": "A schema which validates params accepted by the Nativo adapter", | ||
| "type": "object", | ||
| "properties": { | ||
| "placementId": { | ||
| "type": ["integer", "string"], | ||
| "description": "Placement 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
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
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.
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.
refactored