Skip to content

Commit

Permalink
Adapters: Remove usersync for aliases (#2720)
Browse files Browse the repository at this point in the history
  • Loading branch information
CTMBNara authored Nov 2, 2023
1 parent a112450 commit f453666
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 36 deletions.
24 changes: 15 additions & 9 deletions src/main/java/org/prebid/server/auction/UidUpdater.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.server.auction;

import com.iab.openrtb.request.User;
import org.apache.commons.collections4.map.CaseInsensitiveMap;
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.auction.model.AuctionContext;
import org.prebid.server.bidder.BidderCatalog;
Expand All @@ -9,7 +10,9 @@
import org.prebid.server.model.UpdateResult;
import org.prebid.server.proto.openrtb.ext.request.ExtUser;
import org.prebid.server.proto.openrtb.ext.request.ExtUserPrebid;
import org.prebid.server.util.ObjectUtil;

import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -36,28 +39,31 @@ public UpdateResult<String> updateUid(String bidder, AuctionContext auctionConte
}

final String resolvedBidder = aliases.resolveBidder(bidder);
final String baseBidder = bidderCatalog.resolveBaseBidder(resolvedBidder);

final String uidFromExt = uidFromExtUser(user, resolvedBidder);
final String uidFromExt = uidFromExtUser(user, bidder, resolvedBidder, baseBidder);
final String uidFromUidsCookie = uidFromUidsCookie(auctionContext.getUidsCookie(), resolvedBidder);
final String uidFromHostCookie = uidFromHostCookie(auctionContext, resolvedBidder);

return Stream.of(uidFromExt, uidFromUidsCookie, uidFromHostCookie)
.filter(StringUtils::isNotBlank)
.map(UpdateResult::updated)
.findFirst()
.map(UpdateResult::updated)
.orElse(UpdateResult.unaltered(null));
}

private static String uidFromExtUser(User user, String bidder) {
return Optional.ofNullable(user)
private static String uidFromExtUser(User user, String bidder, String resolvedBidder, String baseBidder) {
final Map<String, String> buyeruids = Optional.ofNullable(user)
.map(User::getExt)
.map(ExtUser::getPrebid)
.map(ExtUserPrebid::getBuyeruids)
.flatMap(uids -> uids.entrySet().stream()
.filter(entry -> StringUtils.equalsIgnoreCase(entry.getKey(), bidder))
.findFirst())
.map(Map.Entry::getValue)
.orElse(null);
.<Map<String, String>>map(CaseInsensitiveMap::new)
.orElse(Collections.emptyMap());

return ObjectUtil.firstNonNull(
() -> buyeruids.get(bidder),
() -> buyeruids.get(resolvedBidder),
() -> buyeruids.get(baseBidder));
}

private String uidFromUidsCookie(UidsCookie uidsCookie, String bidder) {
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/org/prebid/server/bidder/BidderCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,19 @@ public Optional<Usersyncer> usersyncerByName(String name) {
.map(BidderInstanceDeps::getUsersyncer);
}

public boolean isAlias(String bidder) {
private Optional<String> aliasOf(String bidder) {
return Optional.ofNullable(bidder)
.map(bidderDepsMap::get)
.map(BidderInstanceDeps::getBidderInfo)
.map(BidderInfo::getAliasOf)
.isPresent();
.map(BidderInfo::getAliasOf);
}

public boolean isAlias(String bidder) {
return aliasOf(bidder).isPresent();
}

public String resolveBaseBidder(String bidder) {
return aliasOf(bidder).orElse(bidder);
}

public Optional<String> cookieFamilyName(String bidder) {
Expand Down
7 changes: 1 addition & 6 deletions src/main/resources/bidder-config/adf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ adapters:
adf:
endpoint: https://adx.adform.net/adx/openrtb
aliases:
adform:
usersync:
cookie-family-name: adform
redirect:
url: https://cm.adform.net/cookie?redirect_url={{redirect_url}}
uid-macro: '$UID'
adform: ~
meta-info:
maintainer-email: [email protected]
app-media-types:
Expand Down
12 changes: 0 additions & 12 deletions src/main/resources/bidder-config/adtelligent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ adapters:
meta-info:
maintainer-email: [email protected]
vendor-id: 411
usersync:
cookie-family-name: mediafuse
viewdeos:
enabled: false
endpoint: http://ghb.sync.viewdeos.com/pbs/ortb
meta-info:
maintainer-email: [email protected]
vendor-id: 924
usersync:
cookie-family-name: viewdeos
streamkey:
enabled: false
endpoint: http://ghb.hb.streamkey.net/pbs/ortb
Expand All @@ -28,32 +24,24 @@ adapters:
site-media-types:
- video
vendor-id: 0
usersync:
cookie-family-name: streamkey
janet:
enabled: false
endpoint: http://ghb.bidder.jmgads.com/pbs/ortb
meta-info:
maintainer-email: [email protected]
vendor-id: 0
usersync:
cookie-family-name: janet
pgam:
enabled: false
endpoint: http://ghb.pgamssp.com/pbs/ortb
meta-info:
maintainer-email: [email protected]
vendor-id: 0
usersync:
cookie-family-name: pgam
copper6:
enabled: false
endpoint: http://ghb.app.copper6.com/pbs/ortb
meta-info:
maintainer-email: [email protected]
vendor-id: 0
usersync:
cookie-family-name: copper6
meta-info:
maintainer-email: [email protected]
app-media-types:
Expand Down
8 changes: 2 additions & 6 deletions src/main/resources/bidder-config/apacdex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ adapters:
modifying-vast-xml-allowed: false
endpoint: http://useast.quantumdex.io/auction/pbs
aliases:
quantumdex:
usersync:
cookie-family-name: quantumdex
valueimpression:
usersync:
cookie-family-name: valueimpression
quantumdex: ~
valueimpression: ~
meta-info:
maintainer-email: [email protected]
app-media-types:
Expand Down
49 changes: 49 additions & 0 deletions src/test/java/org/prebid/server/auction/UidUpdaterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,55 @@ public void updateShouldReturnUpdatedUidWhenPresentInUserExtAndAbsentInUserIgnor
assertThat(result).isEqualTo(UpdateResult.updated("buyeruid-from-ext"));
}

@Test
public void updateShouldReturnUpdatedUidWhenResolvedNamePresentInUserExtAndAbsentInUserIgnoringCase() {
// given
given(bidderAliases.resolveBidder(eq("requestAlias"))).willReturn("bidDER");

final User user = User.builder()
.ext(ExtUser.builder()
.prebid(ExtUserPrebid.of(Map.of("BIDder", "buyeruid-from-ext")))
.build())
.build();

final AuctionContext auctionContext = AuctionContext.builder()
.httpRequest(givenHttpRequest("buyeruid-from-host-cookie"))
.bidRequest(BidRequest.builder().user(user).build())
.uidsCookie(givenUidsCookie(Map.of("bidder-cookie-family", "buyeruid-from-uids-cookie")))
.build();

// when
final UpdateResult<String> result = uidUpdater.updateUid("requestAlias", auctionContext, bidderAliases);

// then
assertThat(result).isEqualTo(UpdateResult.updated("buyeruid-from-ext"));
}

@Test
public void updateShouldReturnUpdatedUidWhenBaseNamePresentInUserExtAndAbsentInUserIgnoringCase() {
// given
given(bidderAliases.resolveBidder(eq("requestAlias"))).willReturn("configAlias");
given(bidderCatalog.resolveBaseBidder(eq("configAlias"))).willReturn("bidDER");

final User user = User.builder()
.ext(ExtUser.builder()
.prebid(ExtUserPrebid.of(Map.of("BIDder", "buyeruid-from-ext")))
.build())
.build();

final AuctionContext auctionContext = AuctionContext.builder()
.httpRequest(givenHttpRequest("buyeruid-from-host-cookie"))
.bidRequest(BidRequest.builder().user(user).build())
.uidsCookie(givenUidsCookie(Map.of("bidder-cookie-family", "buyeruid-from-uids-cookie")))
.build();

// when
final UpdateResult<String> result = uidUpdater.updateUid("requestAlias", auctionContext, bidderAliases);

// then
assertThat(result).isEqualTo(UpdateResult.updated("buyeruid-from-ext"));
}

@Test
public void updateShouldReturnUpdatedUidWhenPresentInUidsCookieAndAbsentInUserExtAndUser() {
// given
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/prebid/server/bidder/BidderCatalogTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,34 @@ public void isAliasShouldReturnTrueForAliasIgnoringCase() {
assertThat(target.isAlias("alIAS")).isTrue();
}

@Test
public void resolveBaseBidderShouldReturnBaseBidderName() {
// given
final BidderDeps bidderDeps = BidderDeps.of(singletonList(BidderInstanceDeps.builder()
.name("alias")
.bidderInfo(BidderInfo.create(
true,
null,
true,
null,
"bidder",
null,
emptyList(),
emptyList(),
emptyList(),
null,
0,
true,
false,
CompressionType.NONE))
.deprecatedNames(emptyList())
.build()));
target = new BidderCatalog(singletonList(bidderDeps));

// when and then
assertThat(target.resolveBaseBidder("alias")).isEqualTo("bidder");
}

@Test
public void metaInfoByNameShouldReturnNullForUnknownBidder() {
// given
Expand Down

0 comments on commit f453666

Please sign in to comment.