Skip to content

Commit

Permalink
Synacormedia: Renames to "imds", GPP macros (#2371)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecammit authored Jul 11, 2023
1 parent fc90e77 commit 96d8ba5
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1052,8 +1052,13 @@ private static List<ExtBidderError> errorsDetails(List<BidderError> errors) {
*/
private Map<String, List<ExtBidderError>> extractDeprecatedBiddersErrors(BidRequest bidRequest) {
return bidRequest.getImp().stream()
.filter(imp -> imp.getExt() != null)
.flatMap(imp -> StreamUtil.asStream(imp.getExt().fieldNames()))
.flatMap(imp -> Optional.ofNullable(imp.getExt())
.flatMap(ext -> getExtPrebid(ext, ExtImpPrebid.class))
.map(ExtImpPrebid::getBidder)
.map(ObjectNode::fieldNames)
.map(StreamUtil::asStream)
.orElseGet(Stream::empty)
)
.distinct()
.filter(bidderCatalog::isDeprecatedName)
.collect(Collectors.toMap(Function.identity(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.prebid.server.bidder.synacormedia;
package org.prebid.server.bidder.imds;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand All @@ -20,52 +20,56 @@
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.synacormedia.ExtImpSynacormedia;
import org.prebid.server.proto.openrtb.ext.request.synacormedia.ExtRequestSynacormedia;
import org.prebid.server.proto.openrtb.ext.request.imds.ExtImpImds;
import org.prebid.server.proto.openrtb.ext.request.imds.ExtRequestImds;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.util.BidderUtil;
import org.prebid.server.util.HttpUtil;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public class SynacormediaBidder implements Bidder<BidRequest> {
public class ImdsBidder implements Bidder<BidRequest> {

private static final TypeReference<ExtPrebid<?, ExtImpSynacormedia>> SYNACORMEDIA_EXT_TYPE_REFERENCE =
private static final TypeReference<ExtPrebid<?, ExtImpImds>> IMDS_EXT_TYPE_REFERENCE =
new TypeReference<>() {
};

private final String endpointUrl;
private final String prebidVersion;
private final JacksonMapper mapper;

public SynacormediaBidder(String endpointUrl, JacksonMapper mapper) {
public ImdsBidder(String endpointUrl, String prebidVersion, JacksonMapper mapper) {
this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl));
this.prebidVersion = Objects.requireNonNull(prebidVersion);
this.mapper = Objects.requireNonNull(mapper);
}

@Override
public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequest) {
final List<BidderError> errors = new ArrayList<>();
final List<Imp> validImps = new ArrayList<>();
ExtImpSynacormedia firstExtImp = null;
ExtImpImds firstExtImp = null;

for (Imp imp : bidRequest.getImp()) {
final ExtImpSynacormedia extImpSynacormedia;
final ExtImpImds extImpImds;
try {
extImpSynacormedia = parseAndValidateExtImp(imp.getExt());
extImpImds = parseAndValidateExtImp(imp.getExt());
} catch (PreBidException e) {
errors.add(BidderError.badInput("Invalid Impression: " + e.getMessage()));
continue;
}

final Imp updatedImp = imp.toBuilder().tagid(extImpSynacormedia.getTagId()).build();
final Imp updatedImp = imp.toBuilder().tagid(extImpImds.getTagId()).build();
validImps.add(updatedImp);

if (firstExtImp == null) {
firstExtImp = extImpSynacormedia;
firstExtImp = extImpImds;
}
}

Expand All @@ -75,19 +79,31 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequ

final BidRequest outgoingRequest = bidRequest.toBuilder()
.imp(validImps)
.ext(mapper.fillExtension(ExtRequest.empty(), ExtRequestSynacormedia.of(firstExtImp.getSeatId())))
.ext(mapper.fillExtension(ExtRequest.empty(), ExtRequestImds.of(firstExtImp.getSeatId())))
.build();

return Result.of(Collections.singletonList(
return Result.of(
Collections.singletonList(
BidderUtil.defaultRequest(
outgoingRequest,
endpointUrl.replaceAll("\\{\\{Host}}", firstExtImp.getSeatId()),
mapper)),
errors);
outgoingRequest,
generateEndpointUrl(firstExtImp),
mapper
)
),
errors
);
}

private ExtImpSynacormedia parseAndValidateExtImp(ObjectNode impExt) {
final ExtImpSynacormedia extImp = parseExtImp(impExt);
private String generateEndpointUrl(ExtImpImds firstExtImp) {
final String accountId = URLEncoder.encode(firstExtImp.getSeatId(), StandardCharsets.UTF_8);
final String sourceId = URLEncoder.encode(prebidVersion, StandardCharsets.UTF_8);
return endpointUrl
.replaceAll("\\{\\{AccountID}}", accountId)
.replaceAll("\\{\\{SourceId}}", sourceId);
}

private ExtImpImds parseAndValidateExtImp(ObjectNode impExt) {
final ExtImpImds extImp = parseExtImp(impExt);

if (StringUtils.isBlank(extImp.getSeatId()) || StringUtils.isBlank(extImp.getTagId())) {
throw new PreBidException("imp.ext has no seatId or tagId");
Expand All @@ -96,9 +112,9 @@ private ExtImpSynacormedia parseAndValidateExtImp(ObjectNode impExt) {
return extImp;
}

private ExtImpSynacormedia parseExtImp(ObjectNode impExt) {
private ExtImpImds parseExtImp(ObjectNode impExt) {
try {
return mapper.mapper().convertValue(impExt, SYNACORMEDIA_EXT_TYPE_REFERENCE).getBidder();
return mapper.mapper().convertValue(impExt, IMDS_EXT_TYPE_REFERENCE).getBidder();
} catch (IllegalArgumentException e) {
throw new PreBidException(e.getMessage());
}
Expand Down Expand Up @@ -140,7 +156,7 @@ private static BidderBid mapBidToBidderBid(Bid bid, List<Imp> imps, String curre
}

private static BidType getBidType(String impId, List<Imp> imps) {
for (Imp imp : imps) {
for (final Imp imp : imps) {
if (imp.getId().equals(impId)) {
if (imp.getBanner() != null) {
return BidType.banner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.prebid.server.proto.openrtb.ext.request.synacormedia;
package org.prebid.server.proto.openrtb.ext.request.imds;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Value;

/**
* Defines the contract for bidRequest.imp[i].ext.synacormedia
* Defines the contract for bidRequest.imp[i].ext.imds
*/
@AllArgsConstructor(staticName = "of")
@Value
public class ExtImpSynacormedia {
public class ExtImpImds {

@JsonProperty("seatId")
String seatId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.prebid.server.proto.openrtb.ext.request.synacormedia;
package org.prebid.server.proto.openrtb.ext.request.imds;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
Expand All @@ -9,7 +9,7 @@
*/
@AllArgsConstructor(staticName = "of")
@Value
public class ExtRequestSynacormedia {
public class ExtRequestImds {

@JsonProperty("seatId")
String seatId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.prebid.server.spring.config.bidder;

import org.prebid.server.bidder.BidderDeps;
import org.prebid.server.bidder.synacormedia.SynacormediaBidder;
import org.prebid.server.bidder.imds.ImdsBidder;
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.prebid.server.version.PrebidVersionProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand All @@ -16,26 +17,31 @@
import javax.validation.constraints.NotBlank;

@Configuration
@PropertySource(value = "classpath:/bidder-config/synacormedia.yaml", factory = YamlPropertySourceFactory.class)
public class SynacormediaConfiguration {
@PropertySource(value = "classpath:/bidder-config/imds.yaml", factory = YamlPropertySourceFactory.class)
public class ImdsConfiguration {

private static final String BIDDER_NAME = "synacormedia";
private static final String BIDDER_NAME = "imds";

@Bean("synacormediaConfigurationProperties")
@ConfigurationProperties("adapters.synacormedia")
@Bean("imdsConfigurationProperties")
@ConfigurationProperties("adapters.imds")
BidderConfigurationProperties configurationProperties() {
return new BidderConfigurationProperties();
}

@Bean
BidderDeps synacormediaBidderDeps(BidderConfigurationProperties synacormediaConfigurationProperties,
@NotBlank @Value("${external-url}") String externalUrl,
JacksonMapper mapper) {
BidderDeps imdsBidderDeps(BidderConfigurationProperties imdsConfigurationProperties,
@NotBlank @Value("${external-url}") String externalUrl,
PrebidVersionProvider prebidVersionProvider,
JacksonMapper mapper) {

return BidderDepsAssembler.forBidder(BIDDER_NAME)
.withConfig(synacormediaConfigurationProperties)
.withConfig(imdsConfigurationProperties)
.usersyncerCreator(UsersyncerCreator.create(externalUrl))
.bidderCreator(config -> new SynacormediaBidder(config.getEndpoint(), mapper))
.bidderCreator(config -> new ImdsBidder(
config.getEndpoint(),
prebidVersionProvider.getNameVersionRecord(),
mapper)
)
.assemble();
}
}
28 changes: 28 additions & 0 deletions src/main/resources/bidder-config/imds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
adapters:
imds:
deprecated-names: synacormedia
aliases:
synacormedia:
deprecated-names: null # Must re-declare as empty or the deprecation error in the response is incorrect
endpoint: "https://pbs.technoratimedia.com/openrtb/bids/{{AccountID}}?src={{SourceId}}&adapter=synacormedia"
endpoint: "https://pbs.technoratimedia.com/openrtb/bids/{{AccountID}}?src={{SourceId}}&adapter=imds"
meta-info:
maintainer-email: eng-demand@imds.tv
app-media-types:
- banner
- video
site-media-types:
- banner
- video
supported-vendors:
vendor-id: 0
usersync:
cookie-family-name: "imds"
iframe:
url: "https://ad-cdn.technoratimedia.com/html/usersync.html?gdpr={{gdpr}}&consent={{gdpr_consent}}&us_privacy={{us_privacy}}&gpp={{gpp}}&gppsid={{gpp_sid}}&cb={{redirect_url}}"
support-cors: true
uid-macro: '[USER_ID]'
redirect:
url: "https://sync.technoratimedia.com/services?srv=cs&gdpr={{gdpr}}&consent={{gdpr_consent}}&us_privacy={{us_privacy}}&gpp={{gpp}}&gppsid={{gpp_sid}}&cb={{redirect_url}}"
support-cors: true
uid-macro: '[USER_ID]'
19 changes: 0 additions & 19 deletions src/main/resources/bidder-config/synacormedia.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Synacormedia Adapter Params",
"description": "A schema which validates params accepted by the Synacormedia adapter",
"title": "iMDS Adapter Params",
"description": "A schema which validates params accepted by the iMDS adapter",
"type": "object",
"properties": {
"seatId": {
Expand All @@ -16,4 +16,4 @@
"required": [
"seatId"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2916,7 +2916,12 @@ public void shouldProcessRequestAndAddErrorAboutDeprecatedBidder() {
final String invalidBidderName = "invalid";

final BidRequest bidRequest = givenBidRequest(Imp.builder()
.ext(mapper.valueToTree(singletonMap(invalidBidderName, 0)))
.ext(mapper.valueToTree(
ExtImp.of(ExtImpPrebid.builder()
.bidder(mapper.valueToTree(singletonMap(invalidBidderName, 0)))
.build(),
null)
))
.build());

final List<BidderResponse> bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(), 100));
Expand Down
Loading

0 comments on commit 96d8ba5

Please sign in to comment.