-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GPP4: Add
USNat
privacy module (#2521)
- Loading branch information
Showing
121 changed files
with
9,388 additions
and
1,442 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
36 changes: 36 additions & 0 deletions
36
.../org/prebid/server/activity/infrastructure/creator/ActivityControllerCreationContext.java
This file contains 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,36 @@ | ||
package org.prebid.server.activity.infrastructure.creator; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.Value; | ||
import org.prebid.server.activity.Activity; | ||
import org.prebid.server.activity.infrastructure.privacy.PrivacyModuleQualifier; | ||
import org.prebid.server.auction.gpp.model.GppContext; | ||
import org.prebid.server.settings.model.activity.privacy.AccountPrivacyModuleConfig; | ||
|
||
import java.util.EnumSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
@Value(staticConstructor = "of") | ||
public class ActivityControllerCreationContext { | ||
|
||
Activity activity; | ||
|
||
Map<PrivacyModuleQualifier, AccountPrivacyModuleConfig> privacyModulesConfigs; | ||
|
||
@Getter(AccessLevel.NONE) | ||
@Setter(AccessLevel.NONE) | ||
Set<PrivacyModuleQualifier> usedPrivacyModules = EnumSet.noneOf(PrivacyModuleQualifier.class); | ||
|
||
GppContext gppContext; | ||
|
||
public boolean isUsed(PrivacyModuleQualifier qualifier) { | ||
return usedPrivacyModules.contains(qualifier); | ||
} | ||
|
||
public void use(PrivacyModuleQualifier qualifier) { | ||
usedPrivacyModules.add(qualifier); | ||
} | ||
} |
This file contains 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
This file contains 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
16 changes: 16 additions & 0 deletions
16
.../java/org/prebid/server/activity/infrastructure/creator/PrivacyModuleCreationContext.java
This file contains 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,16 @@ | ||
package org.prebid.server.activity.infrastructure.creator; | ||
|
||
import lombok.Value; | ||
import org.prebid.server.activity.Activity; | ||
import org.prebid.server.auction.gpp.model.GppContext; | ||
import org.prebid.server.settings.model.activity.privacy.AccountPrivacyModuleConfig; | ||
|
||
@Value(staticConstructor = "of") | ||
public class PrivacyModuleCreationContext { | ||
|
||
Activity activity; | ||
|
||
AccountPrivacyModuleConfig privacyModuleConfig; | ||
|
||
GppContext gppContext; | ||
} |
12 changes: 12 additions & 0 deletions
12
.../java/org/prebid/server/activity/infrastructure/creator/privacy/PrivacyModuleCreator.java
This file contains 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.activity.infrastructure.creator.privacy; | ||
|
||
import org.prebid.server.activity.infrastructure.creator.PrivacyModuleCreationContext; | ||
import org.prebid.server.activity.infrastructure.privacy.PrivacyModule; | ||
import org.prebid.server.activity.infrastructure.privacy.PrivacyModuleQualifier; | ||
|
||
public interface PrivacyModuleCreator { | ||
|
||
PrivacyModuleQualifier qualifier(); | ||
|
||
PrivacyModule from(PrivacyModuleCreationContext creationContext); | ||
} |
24 changes: 24 additions & 0 deletions
24
...rg/prebid/server/activity/infrastructure/creator/privacy/usnat/USNatGppReaderFactory.java
This file contains 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,24 @@ | ||
package org.prebid.server.activity.infrastructure.creator.privacy.usnat; | ||
|
||
import com.iab.gpp.encoder.GppModel; | ||
import org.prebid.server.activity.infrastructure.privacy.usnat.USNatGppReader; | ||
import org.prebid.server.activity.infrastructure.privacy.usnat.reader.USCaliforniaGppReader; | ||
import org.prebid.server.activity.infrastructure.privacy.usnat.reader.USColoradoGppReader; | ||
import org.prebid.server.activity.infrastructure.privacy.usnat.reader.USConnecticutGppReader; | ||
import org.prebid.server.activity.infrastructure.privacy.usnat.reader.USNationalGppReader; | ||
import org.prebid.server.activity.infrastructure.privacy.usnat.reader.USUtahGppReader; | ||
import org.prebid.server.activity.infrastructure.privacy.usnat.reader.USVirginiaGppReader; | ||
|
||
public class USNatGppReaderFactory { | ||
|
||
public USNatGppReader forSection(Integer sectionId, GppModel gppModel) { | ||
return switch (USNatSection.from(sectionId)) { | ||
case NATIONAL -> new USNationalGppReader(gppModel); | ||
case CALIFORNIA -> new USCaliforniaGppReader(gppModel); | ||
case VIRGINIA -> new USVirginiaGppReader(gppModel); | ||
case COLORADO -> new USColoradoGppReader(gppModel); | ||
case UTAH -> new USUtahGppReader(gppModel); | ||
case CONNECTICUT -> new USConnecticutGppReader(gppModel); | ||
}; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...a/org/prebid/server/activity/infrastructure/creator/privacy/usnat/USNatModuleCreator.java
This file contains 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,68 @@ | ||
package org.prebid.server.activity.infrastructure.creator.privacy.usnat; | ||
|
||
import com.iab.gpp.encoder.GppModel; | ||
import org.apache.commons.collections4.SetUtils; | ||
import org.prebid.server.activity.Activity; | ||
import org.prebid.server.activity.infrastructure.creator.PrivacyModuleCreationContext; | ||
import org.prebid.server.activity.infrastructure.creator.privacy.PrivacyModuleCreator; | ||
import org.prebid.server.activity.infrastructure.privacy.PrivacyModule; | ||
import org.prebid.server.activity.infrastructure.privacy.PrivacyModuleQualifier; | ||
import org.prebid.server.activity.infrastructure.privacy.usnat.USNatModule; | ||
import org.prebid.server.activity.infrastructure.rule.AndRule; | ||
import org.prebid.server.auction.gpp.model.GppContext; | ||
import org.prebid.server.settings.model.activity.privacy.AccountUSNatModuleConfig; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class USNatModuleCreator implements PrivacyModuleCreator { | ||
|
||
private static final Set<Integer> ALLOWED_SECTIONS_IDS = | ||
Arrays.stream(USNatSection.values()) | ||
.map(USNatSection::sectionId) | ||
.collect(Collectors.toSet()); | ||
|
||
private final USNatGppReaderFactory gppReaderFactory; | ||
|
||
public USNatModuleCreator(USNatGppReaderFactory gppReaderFactory) { | ||
this.gppReaderFactory = Objects.requireNonNull(gppReaderFactory); | ||
} | ||
|
||
@Override | ||
public PrivacyModuleQualifier qualifier() { | ||
return PrivacyModuleQualifier.US_NAT; | ||
} | ||
|
||
@Override | ||
public PrivacyModule from(PrivacyModuleCreationContext creationContext) { | ||
final AccountUSNatModuleConfig moduleConfig = moduleConfig(creationContext); | ||
final GppContext.Scope scope = creationContext.getGppContext().scope(); | ||
|
||
final List<PrivacyModule> innerPrivacyModules = SetUtils.emptyIfNull(scope.getSectionsIds()).stream() | ||
.filter(sectionId -> !shouldSkip(sectionId, moduleConfig)) | ||
.map(sectionId -> forSection(creationContext.getActivity(), sectionId, scope.getGppModel())) | ||
.toList(); | ||
|
||
final AndRule andRule = new AndRule(innerPrivacyModules); | ||
return andRule::proceed; | ||
} | ||
|
||
private static AccountUSNatModuleConfig moduleConfig(PrivacyModuleCreationContext creationContext) { | ||
return (AccountUSNatModuleConfig) creationContext.getPrivacyModuleConfig(); | ||
} | ||
|
||
private static boolean shouldSkip(Integer sectionId, AccountUSNatModuleConfig moduleConfig) { | ||
final AccountUSNatModuleConfig.Config config = moduleConfig.getConfig(); | ||
final List<Integer> skipSectionIds = config != null ? config.getSkipSids() : null; | ||
|
||
return !ALLOWED_SECTIONS_IDS.contains(sectionId) | ||
|| (skipSectionIds != null && skipSectionIds.contains(sectionId)); | ||
} | ||
|
||
private PrivacyModule forSection(Activity activity, Integer sectionId, GppModel gppModel) { | ||
return new USNatModule(activity, gppReaderFactory.forSection(sectionId, gppModel)); | ||
} | ||
} |
Oops, something went wrong.