-
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 13 commits
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
194 changes: 194 additions & 0 deletions
194
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,194 @@ | ||
| 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.Site; | ||
| import com.iab.openrtb.request.Video; | ||
| import com.iab.openrtb.response.Bid; | ||
| import com.iab.openrtb.response.BidResponse; | ||
| 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.DecodeException; | ||
| 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.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| 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.validateUrl(Objects.requireNonNull(endpointUrl)); | ||
| 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); | ||
| httpRequests.add(request); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badInput(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| return httpRequests.isEmpty() ? Result.withErrors(errors) : Result.of(httpRequests, errors); | ||
| } | ||
|
|
||
| private AlvadsImpExt parseImpExt(Imp imp) { | ||
| 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 HttpRequest<AlvadsRequestOrtb> makeHttpRequest(BidRequest request, Imp imp, AlvadsImpExt impExt) { | ||
| final AlvaAdsImp impObj = makeImp(imp); | ||
| final AlvaAdsSite siteObj = makeSite(request.getSite(), impExt.getPublisherUniqueId()); | ||
| 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(endpointUrl) | ||
| .headers(HttpUtil.headers()) | ||
| .payload(alvadsRequest) | ||
| .body(mapper.encodeToBytes(alvadsRequest)) | ||
| .impIds(alvadsRequest.getImp().stream().map(AlvaAdsImp::getId).collect(Collectors.toSet())) | ||
| .build(); | ||
| } | ||
|
|
||
| private static AlvaAdsImp makeImp(Imp imp) { | ||
| final Banner banner = imp.getBanner(); | ||
| final Video video = imp.getVideo(); | ||
|
|
||
| return AlvaAdsImp.builder() | ||
| .id(imp.getId()) | ||
| .tagid(imp.getTagid()) | ||
| .bidfloor(imp.getBidfloor()) | ||
| .banner(banner != null ? sizes(banner.getW(), banner.getH()) : null) | ||
| .video(video != null ? sizes(video.getW(), video.getH()) : null) | ||
| .build(); | ||
SamuelAlejandroNT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private static Map<String, Object> sizes(Integer w, Integer h) { | ||
| if (w == null || h == null) { | ||
| return null; | ||
| } | ||
| final Map<String, Object> map = new HashMap<>(); | ||
| map.put("w", w); | ||
| map.put("h", h); | ||
| return map; | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private static AlvaAdsSite makeSite(Site site, String publisherUniqueId) { | ||
| final String page = site != null ? site.getPage() : null; | ||
| return AlvaAdsSite.builder() | ||
| .page(page) | ||
| .ref(page) | ||
| .publisher(Map.of("id", publisherUniqueId)) | ||
| .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 (DecodeException e) { | ||
| 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() | ||
| .flatMap(sb -> sb.getBid().stream()) | ||
| .map(bid -> makeBid(bid, request, bidResponse.getCur())) | ||
| .filter(Objects::nonNull) | ||
SamuelAlejandroNT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .toList(); | ||
| } | ||
SamuelAlejandroNT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private BidderBid makeBid(Bid bid, AlvadsRequestOrtb request, String currency) { | ||
| final AlvaAdsImp imp = request.getImp().stream() | ||
| .filter(i -> i.getId().equals(bid.getImpid())) | ||
| .findFirst() | ||
| .orElse(null); | ||
SamuelAlejandroNT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| final BidType type = getBidType(bid, imp); | ||
|
|
||
| if (type == null) { | ||
| return null; | ||
| } | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return BidderBid.of(bid, type, currency); | ||
| } | ||
|
|
||
| private BidType getBidType(Bid bid, AlvaAdsImp imp) { | ||
| if (imp != null) { | ||
SamuelAlejandroNT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (imp.getVideo() != null) { | ||
| return BidType.video; | ||
| } | ||
|
|
||
| return Optional.ofNullable(getBidExt(bid)) | ||
| .map(ExtBidAlvads::getCrtype) | ||
| .orElse(BidType.banner); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| 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.Value; | ||
| import org.prebid.server.proto.openrtb.ext.response.BidType; | ||
|
|
||
| @Value | ||
| public class ExtBidAlvads { | ||
|
|
||
| BidType crtype; | ||
| } |
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
| package org.prebid.server.bidder.alvads.model; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Value; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.Map; | ||
|
|
||
| @Value | ||
| @Builder | ||
| public class AlvaAdsImp { | ||
|
|
||
| String id; | ||
|
|
||
| Map<String, Object> banner; | ||
|
|
||
| Map<String, Object> video; | ||
|
|
||
| String tagid; | ||
|
|
||
| BigDecimal bidfloor; | ||
| } |
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
| package org.prebid.server.bidder.alvads.model; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Value; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @Value | ||
| @Builder | ||
| public class AlvaAdsSite { | ||
|
|
||
| String page; | ||
|
|
||
| String ref; | ||
|
|
||
| Map<String, Object> publisher; | ||
| } |
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
| 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.Value; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Value | ||
| @Builder(toBuilder = true) | ||
| public class AlvadsRequestOrtb { | ||
|
|
||
| String id; | ||
|
|
||
| List<AlvaAdsImp> imp; | ||
|
|
||
| Device device; | ||
|
|
||
| User user; | ||
|
|
||
| Regs regs; | ||
|
|
||
| AlvaAdsSite site; | ||
| } |
12 changes: 12 additions & 0 deletions
12
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,12 @@ | ||
| 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; | ||
|
|
||
| } |
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
| 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) { | ||
|
|
||
| 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,15 @@ | ||
| { | ||
| "$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" | ||
| } | ||
| }, | ||
|
|
||
| "required": ["publisherUniqueId"] | ||
| } |
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.
Can be inlined.