-
Notifications
You must be signed in to change notification settings - Fork 222
New Alvads Adapter #4194
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
SamuelAlejandroNT
wants to merge
16
commits into
prebid:master
Choose a base branch
from
SamuelAlejandroNT:new-alvads
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.
Open
New Alvads Adapter #4194
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
41913ef
initial release with code fixes
c395bcb
fixes
b49ced1
fixes
9f39685
fixes
e0a4564
added integration test
f1f8218
added integration test
82a225e
fixes
cbc014f
fixes
cfc08ea
fixes
f06ea5f
fixes
5ab2286
fixes
7c5532b
fixes
1e6638e
fixes
cb01d5c
fixes
c4dc21e
fixes
06e9df3
fixes
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
216 changes: 216 additions & 0 deletions
216
src/main/java/org/prebid/server/bidder/alvads/AlvadsBidder.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,216 @@ | ||
| package org.prebid.server.bidder.alvads; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.iab.openrtb.request.Banner; | ||
| import com.iab.openrtb.request.BidRequest; | ||
| import com.iab.openrtb.request.Imp; | ||
| import com.iab.openrtb.request.Video; | ||
| import com.iab.openrtb.response.Bid; | ||
| import com.iab.openrtb.response.BidResponse; | ||
| import com.iab.openrtb.response.SeatBid; | ||
| import io.vertx.core.http.HttpMethod; | ||
| import org.apache.commons.collections4.CollectionUtils; | ||
| import org.prebid.server.bidder.Bidder; | ||
| import org.prebid.server.bidder.alvads.model.AlvaAdsImp; | ||
| import org.prebid.server.bidder.alvads.model.AlvaAdsSite; | ||
| import org.prebid.server.bidder.alvads.model.AlvadsRequestOrtb; | ||
| 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.JacksonMapper; | ||
| import org.prebid.server.proto.openrtb.ext.ExtPrebid; | ||
| import org.prebid.server.proto.openrtb.ext.request.alvads.AlvadsImpExt; | ||
| import org.prebid.server.proto.openrtb.ext.response.BidType; | ||
| import org.prebid.server.util.HttpUtil; | ||
|
|
||
| import java.net.URI; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class AlvadsBidder implements Bidder<AlvadsRequestOrtb> { | ||
|
|
||
| private static final TypeReference<ExtPrebid<?, AlvadsImpExt>> | ||
| ALVADS_EXT_TYPE_REFERENCE = new TypeReference<>() { }; | ||
|
|
||
| private final String endpointUrl; | ||
| private final JacksonMapper mapper; | ||
|
|
||
| public AlvadsBidder(String endpointUrl, JacksonMapper mapper) { | ||
| this.endpointUrl = HttpUtil.validateUrlSyntax(Objects.requireNonNull(endpointUrl)); | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.mapper = Objects.requireNonNull(mapper); | ||
| } | ||
|
|
||
| @Override | ||
| public final Result<List<HttpRequest<AlvadsRequestOrtb>>> makeHttpRequests(BidRequest bidRequest) { | ||
| final List<BidderError> errors = new ArrayList<>(); | ||
| final List<HttpRequest<AlvadsRequestOrtb>> httpRequests = new ArrayList<>(); | ||
|
|
||
| for (Imp imp : bidRequest.getImp()) { | ||
| try { | ||
| final AlvadsImpExt impExt = parseImpExt(imp); | ||
| final HttpRequest<AlvadsRequestOrtb> request = makeHttpRequest(bidRequest, imp, impExt); | ||
|
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. Can be inlined. |
||
| httpRequests.add(request); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badInput(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| if (httpRequests.isEmpty()) { | ||
| errors.add(BidderError.badInput("found no valid impressions")); | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return Result.withErrors(errors); | ||
| } | ||
|
|
||
| return Result.of(httpRequests, errors); | ||
| } | ||
|
|
||
| private HttpRequest<AlvadsRequestOrtb> makeHttpRequest(BidRequest request, Imp imp, AlvadsImpExt impExt) { | ||
| final String resolvedUrl = makeUrl(impExt); | ||
| final AlvaAdsImp impObj = makeImp(imp); | ||
| final AlvaAdsSite siteObj = makeSite(request, impExt); | ||
| final AlvadsRequestOrtb alvadsRequest = AlvadsRequestOrtb.builder() | ||
| .id(request.getId()) | ||
| .imp(List.of(impObj)) | ||
| .device(request.getDevice()) | ||
| .user(request.getUser()) | ||
| .regs(request.getRegs()) | ||
| .site(siteObj) | ||
| .build(); | ||
|
|
||
| return HttpRequest.<AlvadsRequestOrtb>builder() | ||
| .method(HttpMethod.POST) | ||
| .uri(resolvedUrl) | ||
| .headers(HttpUtil.headers()) | ||
| .payload(alvadsRequest) | ||
| .body(mapper.encodeToBytes(alvadsRequest)) | ||
| .impIds(alvadsRequest.getImp().stream().map(AlvaAdsImp::getId).collect(Collectors.toSet())) | ||
| .build(); | ||
| } | ||
|
|
||
| private AlvadsImpExt parseImpExt(Imp imp) { | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try { | ||
| return mapper.mapper().convertValue(imp.getExt(), ALVADS_EXT_TYPE_REFERENCE).getBidder(); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new PreBidException("Missing or invalid bidder ext in impression with id: " + imp.getId()); | ||
| } | ||
| } | ||
|
|
||
| private String makeUrl(AlvadsImpExt impExt) { | ||
| final String resolvedUrl = impExt.getEndpointUrl() != null ? impExt.getEndpointUrl() : endpointUrl; | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try { | ||
| URI.create(resolvedUrl); | ||
| return resolvedUrl; | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } catch (IllegalArgumentException e) { | ||
| throw new PreBidException("Invalid endpoint URL: " + resolvedUrl, e); | ||
| } | ||
| } | ||
|
|
||
| private AlvaAdsImp makeImp(Imp imp) { | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| final Banner banner = imp.getBanner(); | ||
| Map<String, Object> bannerMap = null; | ||
| if (banner != null) { | ||
| bannerMap = new HashMap<>(); | ||
| if (banner.getW() != null) { | ||
| bannerMap.put("w", banner.getW()); | ||
| } | ||
| if (banner.getH() != null) { | ||
| bannerMap.put("h", banner.getH()); | ||
| } | ||
| } | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| final Video video = imp.getVideo(); | ||
| Map<String, Object> videoMap = null; | ||
| if (video != null) { | ||
| videoMap = new HashMap<>(); | ||
| if (video.getW() != null) { | ||
| videoMap.put("w", video.getW()); | ||
| } | ||
| if (video.getH() != null) { | ||
| videoMap.put("h", video.getH()); | ||
| } | ||
| } | ||
|
|
||
| return AlvaAdsImp.builder() | ||
| .id(imp.getId()) | ||
| .tagid(imp.getTagid()) | ||
| .bidfloor(imp.getBidfloor()) | ||
| .banner(bannerMap) | ||
| .video(videoMap) | ||
| .build(); | ||
SamuelAlejandroNT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private AlvaAdsSite makeSite(BidRequest request, AlvadsImpExt impExt) { | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| final String page = request.getSite() != null ? request.getSite().getPage() : null; | ||
| return AlvaAdsSite.builder() | ||
| .page(page) | ||
| .ref(page) | ||
| .publisher(Map.of("id", impExt.getPublisherUniqueId())) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public final Result<List<BidderBid>> makeBids(BidderCall<AlvadsRequestOrtb> httpCall, BidRequest bidRequest) { | ||
| try { | ||
| final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
| return Result.withValues(extractBids(bidResponse, httpCall.getRequest().getPayload())); | ||
| } catch (org.prebid.server.json.DecodeException e) { | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return Result.withError(BidderError.badServerResponse("Failed to decode BidResponse: " + e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| private List<BidderBid> extractBids(BidResponse bidResponse, AlvadsRequestOrtb request) { | ||
| if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { | ||
| return Collections.emptyList(); | ||
| } | ||
| return bidsFromResponse(bidResponse, request); | ||
| } | ||
|
|
||
| private List<BidderBid> bidsFromResponse(BidResponse bidResponse, AlvadsRequestOrtb request) { | ||
| return bidResponse.getSeatbid().stream() | ||
| .filter(Objects::nonNull) | ||
| .map(SeatBid::getBid) | ||
| .filter(Objects::nonNull) | ||
| .flatMap(Collection::stream) | ||
| .filter(Objects::nonNull) | ||
| .map(bid -> { | ||
| final AlvaAdsImp imp = request.getImp().stream() | ||
| .filter(i -> i.getId().equals(bid.getImpid())) | ||
| .findFirst() | ||
| .orElse(null); | ||
|
|
||
| return BidderBid.of(bid, getBidType(bid, imp), bidResponse.getCur()); | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }) | ||
| .filter(Objects::nonNull) | ||
SamuelAlejandroNT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .toList(); | ||
| } | ||
|
|
||
| private BidType getBidType(Bid bid, AlvaAdsImp imp) { | ||
| if (imp != null && imp.getVideo() != null) { | ||
| return BidType.video; | ||
| } | ||
|
|
||
| final ExtBidAlvads bidExt = getBidExt(bid); | ||
| if (bidExt == null) { | ||
| return BidType.banner; | ||
| } | ||
|
|
||
| final BidType crtype = bidExt.getCrtype(); | ||
| return crtype != null ? crtype : BidType.banner; | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private ExtBidAlvads getBidExt(Bid bid) { | ||
| try { | ||
| return mapper.mapper().convertValue(bid.getExt(), ExtBidAlvads.class); | ||
| } catch (IllegalArgumentException e) { | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
src/main/java/org/prebid/server/bidder/alvads/ExtBidAlvads.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,10 @@ | ||
| package org.prebid.server.bidder.alvads; | ||
|
|
||
| import lombok.Data; | ||
| import org.prebid.server.proto.openrtb.ext.response.BidType; | ||
|
|
||
| @Data | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public class ExtBidAlvads { | ||
|
|
||
| private BidType crtype; | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
src/main/java/org/prebid/server/bidder/alvads/model/AlvaAdsImp.java
SamuelAlejandroNT marked this conversation as resolved.
Show resolved
Hide resolved
|
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,18 @@ | ||
| package org.prebid.server.bidder.alvads.model; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Data; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.Map; | ||
|
|
||
| @Data | ||
| @Builder | ||
| public class AlvaAdsImp { | ||
|
|
||
| private String id; | ||
| private Map<String, Object> banner; | ||
| private Map<String, Object> video; | ||
| private String tagid; | ||
| private BigDecimal bidfloor; | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/prebid/server/bidder/alvads/model/AlvaAdsSite.java
SamuelAlejandroNT marked this conversation as resolved.
Show resolved
Hide resolved
|
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,15 @@ | ||
| package org.prebid.server.bidder.alvads.model; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Data; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @Data | ||
| @Builder | ||
| public class AlvaAdsSite { | ||
|
|
||
| private String page; | ||
| private String ref; | ||
| private Map<String, Object> publisher; | ||
| } |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/prebid/server/bidder/alvads/model/AlvadsRequestOrtb.java
SamuelAlejandroNT marked this conversation as resolved.
Show resolved
Hide resolved
|
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 @@ | ||
| package org.prebid.server.bidder.alvads.model; | ||
|
|
||
| import com.iab.openrtb.request.Device; | ||
| import com.iab.openrtb.request.Regs; | ||
| import com.iab.openrtb.request.User; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Data | ||
| @Builder(toBuilder = true) | ||
| public class AlvadsRequestOrtb { | ||
|
|
||
| private String id; | ||
| private List<AlvaAdsImp> imp; | ||
| private Device device; | ||
| private User user; | ||
| private Regs regs; | ||
| private AlvaAdsSite site; | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/prebid/server/proto/openrtb/ext/request/alvads/AlvadsImpExt.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,14 @@ | ||
| package org.prebid.server.proto.openrtb.ext.request.alvads; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.Value; | ||
|
|
||
| @Value(staticConstructor = "of") | ||
| public class AlvadsImpExt { | ||
|
|
||
| @JsonProperty("publisherUniqueId") | ||
| String publisherUniqueId; | ||
|
|
||
| @JsonProperty("endPointUrl") | ||
| String endpointUrl; | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
41 changes: 41 additions & 0 deletions
41
src/main/java/org/prebid/server/spring/config/bidder/AlvadsConfiguration.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.alvads.AlvadsBidder; | ||
| 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/alvads.yaml", factory = YamlPropertySourceFactory.class) | ||
| public class AlvadsConfiguration { | ||
|
|
||
| private static final String BIDDER_NAME = "alvads"; | ||
|
|
||
| @Bean("alvadsConfigurationProperties") | ||
| @ConfigurationProperties("adapters.alvads") | ||
| BidderConfigurationProperties configurationProperties() { | ||
| return new BidderConfigurationProperties(); | ||
| } | ||
|
|
||
| @Bean | ||
| BidderDeps alvadsBidderDeps(BidderConfigurationProperties alvadsConfigurationProperties, | ||
| @NotBlank @Value("${external-url}") String externalUrl, | ||
| JacksonMapper mapper) { | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
| .withConfig(alvadsConfigurationProperties) | ||
| .usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
| .bidderCreator(config -> new AlvadsBidder(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,14 @@ | ||
| adapters: | ||
| alvads: | ||
| endpoint: https://helios-ads-qa-core.ssidevops.com/decision/openrtb | ||
SamuelAlejandroNT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| meta-info: | ||
| maintainer-email: [email protected] | ||
SamuelAlejandroNT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| app-media-types: | ||
| - banner | ||
| - video | ||
| site-media-types: | ||
| - banner | ||
| - video | ||
| supported-vendors: | ||
| vendor-id: 0 | ||
|
|
||
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,19 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Alvads Adapter Params", | ||
| "description": "A schema which validates params accepted by the Alvads adapter", | ||
| "type": "object", | ||
|
|
||
| "properties": { | ||
| "publisherUniqueId": { | ||
| "type": "string", | ||
| "description": "Publisher Unique Id" | ||
| }, | ||
| "endPointUrl": { | ||
| "type": "string", | ||
| "description": "Url ads openrtb" | ||
| } | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
|
|
||
| "required": ["publisherUniqueId"] | ||
| } | ||
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.