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 First Party Data workflow and introduce Bidder Config #573

Merged
merged 26 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e628e84
Update First Party Data workflow and introduce Bidder Config
RossGoncharuk Dec 23, 2019
e9a0782
Merge branch 'master' into fpd-update
RossGoncharuk Dec 23, 2019
a4395f8
Post-merge fix
RossGoncharuk Dec 23, 2019
791e9e1
Merge branch 'master' into fpd-update
RossGoncharuk Jan 16, 2020
c8d62ef
Fix post-merge errors
RossGoncharuk Jan 16, 2020
92887aa
Fix integration tests for new bidders
RossGoncharuk Jan 16, 2020
4984948
Merge branch 'master' into fpd-update
RossGoncharuk Jan 16, 2020
3b728dd
Fix post-merge errors
RossGoncharuk Jan 16, 2020
7e59386
Merge branch 'master' into fpd-update
RossGoncharuk Jan 16, 2020
bbfc9ef
Merge remote-tracking branch 'github-rubicon/master' into fpd-update
DGarbar Feb 5, 2020
176cc5e
Add tests to validate no mask
AndriyPavlyuk Feb 14, 2020
90e69af
Merge remote-tracking branch 'github-rubicon/fpd-update' into fpd-update
DGarbar Feb 19, 2020
965d4af
Handling of empty fpd json parameter
DGarbar Feb 19, 2020
0bc8cd7
Merge remote-tracking branch 'github-rubicon/master' into fpd-update
DGarbar Feb 19, 2020
32ca2f6
Fix tests
DGarbar Feb 19, 2020
00d7198
Add amp handling off targeting parameter
DGarbar Feb 19, 2020
c58b62c
Merge remote-tracking branch 'github-rubicon/master' into fpd-update
DGarbar Feb 20, 2020
90ebb6b
Merge remote-tracking branch 'github-rubicon/master' into fpd-update
DGarbar Feb 21, 2020
6399f6a
Minor refactoring
Mar 5, 2020
d2de2e5
Merge branch 'master' into fpd-update
Mar 13, 2020
6fd26e1
Merge branch 'master' into fpd-update
May 6, 2020
356a43d
Merge branch 'master' into fpd-update
May 22, 2020
5db231d
Merge branch 'master' into fpd-update
Jun 2, 2020
815e083
Make context field in imp.ext to be not required if null
Jun 3, 2020
d7b85ba
Revert test JSONs
Jun 3, 2020
9647883
Revert test JSONs
Jun 3, 2020
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
68 changes: 57 additions & 11 deletions src/main/java/org/prebid/server/auction/AmpRequestFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidCache;
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidCacheBids;
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidCacheVastxml;
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidData;
import org.prebid.server.proto.openrtb.ext.request.ExtRequestTargeting;
import org.prebid.server.proto.openrtb.ext.request.ExtSite;
import org.prebid.server.proto.openrtb.ext.request.ExtUser;
import org.prebid.server.proto.request.Targeting;
import org.prebid.server.util.HttpUtil;

import java.util.ArrayList;
Expand All @@ -43,6 +45,7 @@
public class AmpRequestFactory {

private static final String TAG_ID_REQUEST_PARAM = "tag_id";
private static final String TARGETING_REQUEST_PARAM = "targeting";
private static final String DEBUG_REQUEST_PARAM = "debug";
private static final String OW_REQUEST_PARAM = "ow";
private static final String OH_REQUEST_PARAM = "oh";
Expand Down Expand Up @@ -81,7 +84,6 @@ public Future<AuctionContext> fromRequest(RoutingContext routingContext, long st
if (StringUtils.isBlank(tagId)) {
return Future.failedFuture(new InvalidRequestException("AMP requests require an AMP tag_id", true));
}

return createBidRequest(routingContext, tagId)
.compose(bidRequest ->
auctionRequestFactory.toAuctionContext(routingContext, bidRequest, startTime, timeoutResolver));
Expand Down Expand Up @@ -208,11 +210,15 @@ private static Integer debugFromQueryStringParam(RoutingContext context) {
* Extracts parameters from http request and overrides corresponding attributes in {@link BidRequest}.
*/
private BidRequest overrideParameters(BidRequest bidRequest, HttpServerRequest request) {
final Site updatedSite = overrideSite(bidRequest.getSite(), request);
final String requestTargeting = request.getParam(TARGETING_REQUEST_PARAM);
final Targeting targeting = parseTargeting(requestTargeting);

final Site updatedSite = overrideSite(bidRequest.getSite(), targeting, request);
final Imp updatedImp = overrideImp(bidRequest.getImp().get(0), request);
final Long updatedTimeout = overrideTimeout(bidRequest.getTmax(), request);
final User updatedUser = overrideUser(bidRequest.getUser(), request);
final User updatedUser = overrideUser(bidRequest.getUser(), targeting, request);
final Regs updatedRegs = overrideRegs(bidRequest.getRegs(), request);
final ObjectNode updatedExt = overrideExt(bidRequest.getExt(), targeting);

final BidRequest result;
if (updatedSite != null || updatedImp != null || updatedTimeout != null || updatedUser != null
Expand All @@ -223,20 +229,33 @@ private BidRequest overrideParameters(BidRequest bidRequest, HttpServerRequest r
.tmax(updatedTimeout != null ? updatedTimeout : bidRequest.getTmax())
.user(updatedUser != null ? updatedUser : bidRequest.getUser())
.regs(updatedRegs != null ? updatedRegs : bidRequest.getRegs())
.ext(updatedExt != null ? updatedExt : bidRequest.getExt())
.build();
} else {
result = bidRequest;
}
return result;
}

private Site overrideSite(Site site, HttpServerRequest request) {
private Targeting parseTargeting(String jsonTargeting) {
try {
final String decodedJsonTargeting = HttpUtil.decodeUrl(jsonTargeting);
return decodedJsonTargeting == null
? Targeting.empty()
: mapper.mapper().readValue(decodedJsonTargeting, Targeting.class);
schernysh marked this conversation as resolved.
Show resolved Hide resolved
} catch (JsonProcessingException | IllegalArgumentException e) {
throw new InvalidRequestException(String.format("Error decoding targeting from url: %s", e.getMessage()));
}
}

private Site overrideSite(Site site, Targeting targeting, HttpServerRequest request) {
final String canonicalUrl = canonicalUrl(request);
final String accountId = request.getParam(ACCOUNT_REQUEST_PARAM);

final boolean hasSite = site != null;
final ObjectNode siteExt = hasSite ? site.getExt() : null;
final boolean shouldSetExtAmp = siteExt == null || siteExt.get("amp") == null;
final ObjectNode targetingSite = targeting.getSite();
final boolean shouldSetExtAmp = targetingSite != null || siteExt == null || siteExt.get("amp") == null;

if (StringUtils.isNotBlank(canonicalUrl) || StringUtils.isNotBlank(accountId) || shouldSetExtAmp) {
final Site.SiteBuilder siteBuilder = hasSite ? site.toBuilder() : Site.builder();
Expand All @@ -251,8 +270,12 @@ private Site overrideSite(Site site, HttpServerRequest request) {
siteBuilder.publisher(publisherBuilder.id(accountId).build());
}
if (shouldSetExtAmp) {
final ObjectNode data = siteExt != null ? (ObjectNode) siteExt.get("data") : null;
siteBuilder.ext(mapper.mapper().valueToTree(ExtSite.of(1, data)));
if (targetingSite != null) {
siteBuilder.ext(mapper.mapper().valueToTree(ExtSite.of(1, targetingSite)));
} else {
final ObjectNode data = siteExt != null ? (ObjectNode) siteExt.get("data") : null;
siteBuilder.ext(mapper.mapper().valueToTree(ExtSite.of(1, data)));
}
}
return siteBuilder.build();
}
Expand Down Expand Up @@ -381,9 +404,10 @@ private static Long overrideTimeout(Long tmax, HttpServerRequest request) {
return timeout > 0 && !Objects.equals(timeout, tmax) ? timeout : null;
}

private User overrideUser(User user, HttpServerRequest request) {
private User overrideUser(User user, Targeting targeting, HttpServerRequest request) {
final String gdprConsent = request.getParam(GDPR_CONSENT_PARAM);
if (StringUtils.isBlank(gdprConsent)) {
final ObjectNode targetingUser = targeting.getUser();
if (StringUtils.isBlank(gdprConsent) && targetingUser == null) {
return null;
}

Expand All @@ -394,12 +418,18 @@ private User overrideUser(User user, HttpServerRequest request) {
? extractExtUser(extUserNode).toBuilder()
: ExtUser.builder();

final ExtUser updatedExtUser = extUserBuilder.consent(gdprConsent).build();
if (StringUtils.isNotBlank(gdprConsent)) {
extUserBuilder.consent(gdprConsent);
}

if (targetingUser != null) {
extUserBuilder.data(targetingUser);
}

final User.UserBuilder userBuilder = hasUser ? user.toBuilder() : User.builder();

return userBuilder
.ext(mapper.mapper().valueToTree(updatedExtUser))
.ext(mapper.mapper().valueToTree(extUserBuilder.build()))
.build();
}

Expand Down Expand Up @@ -430,6 +460,22 @@ private Regs overrideRegs(Regs regs, HttpServerRequest request) {
return Regs.of(coppa, mapper.mapper().valueToTree(ExtRegs.of(gdpr, usPrivacyParam)));
}

private ObjectNode overrideExt(ObjectNode ext, Targeting targeting) {
final List<String> bidders = targeting.getBidders();
if (bidders == null) {
return null;
}
final ExtBidRequest extBidRequest = extBidRequest(ext);
final ExtRequestPrebid prebid = extBidRequest.getPrebid();
final ExtRequestPrebidData data = ExtRequestPrebidData.of(bidders);

final ExtRequestPrebid updatedPrebid = prebid == null
? ExtRequestPrebid.builder().data(data).build()
: prebid.toBuilder().data(data).build();

return mapper.mapper().valueToTree(ExtBidRequest.of(updatedPrebid));
}

/**
* Extracts {@link ExtRegs} from bidrequest.regs.ext {@link ObjectNode}.
*/
Expand Down
Loading