Skip to content
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

Update SDK Protocol #2707

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.proto.openrtb.ext.response.BidType;
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;

Expand Down Expand Up @@ -90,7 +91,7 @@ private static BidType getBidType(Bid bid) {

private ObjectNode makeExt(String networkName) {
return mapper.mapper().valueToTree(ExtBidPrebid.builder()
.meta(mapper.mapper().createObjectNode().put("networkName", networkName))
.meta(ExtBidPrebidMeta.builder().networkName(networkName).build())
.build());
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/prebid/server/bidder/grid/GridBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.MissingNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.request.Site;
Expand Down Expand Up @@ -34,6 +33,7 @@
import org.prebid.server.proto.openrtb.ext.request.grid.ExtImpGrid;
import org.prebid.server.proto.openrtb.ext.response.BidType;
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 org.prebid.server.util.ObjectUtil;
Expand Down Expand Up @@ -235,7 +235,7 @@ private ObjectNode modifyBidExt(ObjectNode gridBid) {
}

final ExtBidPrebid extBidPrebid = ExtBidPrebid.builder()
.meta(mapper.mapper().createObjectNode().set("demandsource", TextNode.valueOf(demandSource)))
.meta(ExtBidPrebidMeta.builder().demandSource(demandSource).build())
.build();
return mapper.mapper().valueToTree(ExtPrebid.of(extBidPrebid, null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.IntNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.iab.openrtb.request.App;
Expand Down Expand Up @@ -105,6 +104,7 @@
import org.prebid.server.proto.openrtb.ext.request.rubicon.RubiconVideoParams;
import org.prebid.server.proto.openrtb.ext.response.BidType;
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 org.prebid.server.util.ObjectUtil;
Expand Down Expand Up @@ -1640,10 +1640,10 @@ private RubiconBid insertNetworkIdToMeta(RubiconBid bid, int networkId, List<Bid
return null;
}
final ExtBidPrebid extBidPrebid = extPrebid != null ? extPrebid.getPrebid() : null;
final ObjectNode meta = extBidPrebid != null ? extBidPrebid.getMeta() : null;

final ObjectNode updatedMeta = meta != null ? meta : mapper.mapper().createObjectNode();
updatedMeta.set("networkId", IntNode.valueOf(networkId));
final ExtBidPrebidMeta meta = extBidPrebid != null ? extBidPrebid.getMeta() : null;
final ExtBidPrebidMeta updatedMeta = meta != null
? meta.toBuilder().networkId(networkId).build()
: ExtBidPrebidMeta.builder().networkId(networkId).build();

final ExtBidPrebid modifiedExtBidPrebid = extBidPrebid != null
? extBidPrebid.toBuilder().meta(updatedMeta).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,10 @@ public class ExtRequestPrebid {

@JsonProperty("createtids")
Boolean createTids;

/**
* Defines the contract for bidrequest.ext.prebid.sdk
*/
ExtRequestPrebidSdk sdk;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.prebid.server.proto.openrtb.ext.request;

import lombok.Value;

import java.util.List;

/**
* Defines the contract for bidrequest.ext.prebid.sdk
*/
@Value(staticConstructor = "of")
public class ExtRequestPrebidSdk {

/**
* Defines the contract for bidrequest.ext.prebid.sdk.renderers
*/
List<ExtRequestPrebidSdkRenderer> renderers;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.prebid.server.proto.openrtb.ext.request;

import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Value;

/**
* Defines the contract for bidrequest.ext.prebid.sdk.renderers[i]
*/
@Value(staticConstructor = "of")
public class ExtRequestPrebidSdkRenderer {

/**
* Defines the contract for bidrequest.ext.prebid.sdk.renderers[i].name
*/
String name;

/**
* Defines the contract for bidrequest.ext.prebid.sdk.renderers[i].version
*/
String version;

/**
* Defines the contract for bidrequest.ext.prebid.sdk.renderers[i].url
*/
String url;

/**
* Defines the contract for bidrequest.ext.prebid.sdk.renderers[i].data
*/
ObjectNode data;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.iab.openrtb.request.Video;
import lombok.Builder;
import lombok.Value;
Expand Down Expand Up @@ -34,7 +33,7 @@ public class ExtBidPrebid {

ExtBidPrebidVideo video;

ObjectNode meta;
ExtBidPrebidMeta meta;

@JsonProperty("dealtiersatisfied")
Boolean dealTierSatisfied;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.prebid.server.proto.openrtb.ext.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Builder;
import lombok.Value;

import java.util.List;

@Builder(toBuilder = true)
@Value
public class ExtBidPrebidMeta {

@JsonProperty("adaptercode")
String adapterCode;

@JsonProperty("advertiserDomains")
List<String> advertiserDomains;

@JsonProperty("advertiserId")
Integer advertiserId;

@JsonProperty("advertiserName")
String advertiserName;

@JsonProperty("agencyId")
Integer agencyId;

@JsonProperty("agencyName")
String agencyName;

@JsonProperty("brandId")
Integer brandId;

@JsonProperty("brandName")
String brandName;

ObjectNode dchain;

@JsonProperty("demandSource")
String demandSource;

@JsonProperty("mediaType")
String mediaType;

@JsonProperty("networkId")
Integer networkId;

@JsonProperty("networkName")
String networkName;

@JsonProperty("primaryCatId")
String primaryCategoryId;

@JsonProperty("rendererName")
String rendererName;

@JsonProperty("rendererVersion")
String rendererVersion;

@JsonProperty("rendererUrl")
String rendererUrl;

@JsonProperty("rendererData")
ObjectNode rendererData;

@JsonProperty("secondaryCatIds")
List<String> secondaryCategoryIdList;

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Prebid {
Map passThrough
Events events
Boolean createTids
Sdk sdk

static class Channel {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.prebid.server.functional.model.request.auction

import groovy.transform.ToString

@ToString(includeNames = true, ignoreNulls = true)
class Renderer {

String name
String version
String url
RendererData data
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.prebid.server.functional.model.request.auction

import groovy.transform.ToString

@ToString(includeNames = true, ignoreNulls = true)
class RendererData {

String any
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.prebid.server.functional.model.request.auction

import groovy.transform.ToString

@ToString(includeNames = true, ignoreNulls = true)
class Sdk {

List<Renderer> renderers
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.prebid.server.functional.model.response.auction

import groovy.transform.ToString
import org.prebid.server.functional.model.request.auction.RendererData

@ToString(includeNames = true, ignoreNulls = true)
class Meta {

String adapterCode
List<String> advertiserDomains
Integer advertiserId
String advertiserName
Integer agencyId
String agencyName
Integer brandId
String brandName
String demandSource
String mediaType
Integer networkId
String networkName
String primaryCategoryId
String rendererName
String rendererVersion
String rendererUrl
RendererData rendererData
List<String> secondaryCategoryIdList
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ class Prebid {
String targetBidderCode
Cache cache
Events events
Meta meta
Map passThrough
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import org.prebid.server.functional.model.UidsCookie
import org.prebid.server.functional.model.db.Account
import org.prebid.server.functional.model.request.auction.BidRequest
import org.prebid.server.functional.model.request.auction.PrebidStoredRequest
import org.prebid.server.functional.model.request.auction.Renderer
import org.prebid.server.functional.model.request.auction.RendererData
import org.prebid.server.functional.model.request.auction.Sdk
import org.prebid.server.functional.model.request.auction.User
import org.prebid.server.functional.model.request.auction.UserExt
import org.prebid.server.functional.model.request.auction.UserExtPrebid
import org.prebid.server.functional.model.response.auction.BidExt
import org.prebid.server.functional.model.response.auction.BidResponse
import org.prebid.server.functional.model.response.auction.Meta
import org.prebid.server.functional.model.response.auction.Prebid
import org.prebid.server.functional.model.response.cookiesync.UserSyncInfo
import org.prebid.server.functional.service.PrebidServerException
import org.prebid.server.functional.service.PrebidServerService
Expand Down Expand Up @@ -310,4 +317,50 @@ class AuctionSpec extends BaseSpec {
and: "BidderRequest shouldn't populate fields"
assert !bidderRequest.ext.prebid.aliases
}

def "PBS auction should pass ext.prebid.sdk requested to bidder request when sdk specified"() {
given: "Default bid request with aliases"
def bidRequest = BidRequest.defaultBidRequest.tap {
ext.prebid.sdk = new Sdk(renderers: [new Renderer(
name: PBSUtils.randomString,
version: PBSUtils.randomString,
data: new RendererData(any: PBSUtils.randomString))])
}

when: "Requesting PBS auction"
defaultPbsService.sendAuctionRequest(bidRequest)

then: "Bidder request should contain sdk value same in request"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert bidderRequest.ext.prebid.sdk.renderers.name == bidRequest.ext.prebid.sdk.renderers.name
assert bidderRequest.ext.prebid.sdk.renderers.version == bidRequest.ext.prebid.sdk.renderers.version
assert bidderRequest.ext.prebid.sdk.renderers.data.any == bidRequest.ext.prebid.sdk.renderers.data.any
}

def "PBS auction should pass meta object to bid response when meta specified "() {
given: "Default bid request with aliases"
def bidRequest = BidRequest.defaultBidRequest

and: "Default bidder response without bid"
def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap {
seatbid[0].bid[0].ext = new BidExt(prebid: new Prebid(meta: new Meta(
rendererName: PBSUtils.randomString,
rendererUrl: PBSUtils.randomString,
rendererVersion: PBSUtils.getRandomString())))
}

and: "Set bidder response"
bidder.setResponse(bidRequest.id, bidResponse)

when: "Requesting PBS auction"
def response = defaultPbsService.sendAuctionRequest(bidRequest)

then: "Bid response should contain meta value same in request"
assert response.seatbid[0].bid[0].ext.prebid.meta.rendererName ==
bidResponse.seatbid[0].bid[0].ext.prebid.meta.rendererName
assert response.seatbid[0].bid[0].ext.prebid.meta.rendererUrl ==
bidResponse.seatbid[0].bid[0].ext.prebid.meta.rendererUrl
assert response.seatbid[0].bid[0].ext.prebid.meta.rendererVersion ==
bidResponse.seatbid[0].bid[0].ext.prebid.meta.rendererVersion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.prebid.server.proto.openrtb.ext.request.ExtRequest;
import org.prebid.server.proto.openrtb.ext.request.grid.ExtImpGrid;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebid;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebidMeta;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -370,8 +371,7 @@ public void makeBidsShouldModifyBidExtWithMetaIfDemandSourceIsPresentInBidExt()
// then
assertThat(result.getErrors()).isEmpty();

final ObjectNode expectedBidMeta = mapper.createObjectNode()
.set("demandsource", TextNode.valueOf("demandSource"));
final ExtBidPrebidMeta expectedBidMeta = ExtBidPrebidMeta.builder().demandSource("demandSource").build();
final ObjectNode expectedBidExt = mapper.valueToTree(
ExtPrebid.of(ExtBidPrebid.builder().meta(expectedBidMeta).build(), null));

Expand Down
Loading
Loading