Skip to content

Commit

Permalink
Core: Add support for multiple cases for account (#3224)
Browse files Browse the repository at this point in the history
  • Loading branch information
CTMBNara authored Jun 27, 2024
1 parent a2e376c commit 1424524
Show file tree
Hide file tree
Showing 97 changed files with 891 additions and 887 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import org.prebid.server.settings.model.Account;
import org.prebid.server.settings.model.AccountPrivacyConfig;
import org.prebid.server.settings.model.activity.AccountActivityConfiguration;
import org.prebid.server.settings.model.activity.rule.AccountActivityComponentRuleConfig;
import org.prebid.server.settings.model.activity.rule.AccountActivityGeoRuleConfig;
import org.prebid.server.settings.model.activity.rule.AccountActivityConditionsRuleConfig;
import org.prebid.server.settings.model.activity.rule.AccountActivityRuleConfig;

import java.util.Collection;
Expand Down Expand Up @@ -63,24 +62,15 @@ private static boolean containsInvalidRule(AccountActivityConfiguration accountA
}

private static boolean isInvalidConditionRule(AccountActivityRuleConfig rule) {
if (rule instanceof AccountActivityComponentRuleConfig conditionRule) {
final AccountActivityComponentRuleConfig.Condition condition = conditionRule.getCondition();
return condition != null && isInvalidCondition(condition);
}

if (rule instanceof AccountActivityGeoRuleConfig geoRule) {
final AccountActivityGeoRuleConfig.Condition condition = geoRule.getCondition();
if (rule instanceof AccountActivityConditionsRuleConfig conditionsRule) {
final AccountActivityConditionsRuleConfig.Condition condition = conditionsRule.getCondition();
return condition != null && isInvalidCondition(condition);
}

return false;
}

private static boolean isInvalidCondition(AccountActivityComponentRuleConfig.Condition condition) {
return isEmptyNotNull(condition.getComponentTypes()) || isEmptyNotNull(condition.getComponentNames());
}

private static boolean isInvalidCondition(AccountActivityGeoRuleConfig.Condition condition) {
private static boolean isInvalidCondition(AccountActivityConditionsRuleConfig.Condition condition) {
return isEmptyNotNull(condition.getComponentTypes()) || isEmptyNotNull(condition.getComponentNames());
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/prebid/server/activity/Activity.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
package org.prebid.server.activity;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonProperty;

public enum Activity {

@JsonProperty("syncUser")
@JsonAlias({"sync_user", "sync-user"})
SYNC_USER,

@JsonProperty("fetchBids")
@JsonAlias({"fetch_bids", "fetch-bids"})
CALL_BIDDER,

@JsonProperty("enrichUfpd")
@JsonAlias({"enrich_ufpd", "enrich-ufpd"})
MODIFY_UFDP,

@JsonProperty("transmitUfpd")
@JsonAlias({"transmit_ufpd", "transmit-ufpd"})
TRANSMIT_UFPD,

@JsonProperty("transmitEids")
@JsonAlias({"transmit_eids", "transmit-eids"})
TRANSMIT_EIDS,

@JsonProperty("transmitPreciseGeo")
@JsonAlias({"transmit_precise_geo", "transmit-precise-geo"})
TRANSMIT_GEO,

@JsonProperty("transmitTid")
@JsonAlias({"transmit_tid", "transmit-tid"})
TRANSMIT_TID,

@JsonProperty("reportAnalytics")
@JsonAlias({"report_analytics", "report-analytics"})
REPORT_ANALYTICS
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import org.prebid.server.activity.ComponentType;
import org.prebid.server.activity.infrastructure.ActivityInfrastructure;
import org.prebid.server.activity.infrastructure.creator.ActivityControllerCreationContext;
import org.prebid.server.activity.infrastructure.rule.GeoRule;
import org.prebid.server.activity.infrastructure.rule.ConditionsRule;
import org.prebid.server.activity.infrastructure.rule.Rule;
import org.prebid.server.settings.model.activity.rule.AccountActivityGeoRuleConfig;
import org.prebid.server.settings.model.activity.rule.AccountActivityConditionsRuleConfig;

import java.util.Collection;
import java.util.HashSet;
Expand All @@ -16,20 +16,20 @@
import java.util.Set;
import java.util.TreeSet;

public class GeoRuleCreator extends AbstractRuleCreator<AccountActivityGeoRuleConfig> {
public class ConditionsRuleCreator extends AbstractRuleCreator<AccountActivityConditionsRuleConfig> {

public GeoRuleCreator() {
super(AccountActivityGeoRuleConfig.class);
public ConditionsRuleCreator() {
super(AccountActivityConditionsRuleConfig.class);
}

@Override
protected Rule fromConfiguration(AccountActivityGeoRuleConfig ruleConfiguration,
protected Rule fromConfiguration(AccountActivityConditionsRuleConfig ruleConfiguration,
ActivityControllerCreationContext creationContext) {

final boolean allow = allowFromConfig(ruleConfiguration.getAllow());
final AccountActivityGeoRuleConfig.Condition condition = ruleConfiguration.getCondition();
final AccountActivityConditionsRuleConfig.Condition condition = ruleConfiguration.getCondition();

return new GeoRule(
return new ConditionsRule(
condition != null ? setOf(condition.getComponentTypes()) : null,
condition != null ? caseInsensitiveSetOf(condition.getComponentNames()) : null,
sidsMatched(condition, creationContext.getGppContext().scope().getSectionsIds()),
Expand All @@ -56,7 +56,7 @@ private static Set<String> caseInsensitiveSetOf(Collection<String> collection) {
return caseInsensitiveSet;
}

private static boolean sidsMatched(AccountActivityGeoRuleConfig.Condition condition, Set<Integer> gppSids) {
private static boolean sidsMatched(AccountActivityConditionsRuleConfig.Condition condition, Set<Integer> gppSids) {
final List<Integer> sids = condition != null ? condition.getSids() : null;
return sids == null || intersects(sids, gppSids);
}
Expand All @@ -66,28 +66,28 @@ private static boolean intersects(Collection<Integer> configurationSids, Collect
&& !CollectionUtils.intersection(configurationSids, gppSids).isEmpty();
}

private static List<GeoRule.GeoCode> geoCodes(List<String> stringGeoCodes) {
private static List<ConditionsRule.GeoCode> geoCodes(List<String> stringGeoCodes) {
return stringGeoCodes != null
? stringGeoCodes.stream()
.map(GeoRuleCreator::from)
.map(ConditionsRuleCreator::from)
.filter(Objects::nonNull)
.toList()
: null;
}

private static GeoRule.GeoCode from(String stringGeoCode) {
private static ConditionsRule.GeoCode from(String stringGeoCode) {
if (StringUtils.isBlank(stringGeoCode)) {
return null;
}

final int firstDot = stringGeoCode.indexOf(".");
if (firstDot == -1) {
return GeoRule.GeoCode.of(stringGeoCode, null);
return ConditionsRule.GeoCode.of(stringGeoCode, null);
} else if (firstDot == stringGeoCode.length() - 1) {
return GeoRule.GeoCode.of(stringGeoCode.substring(0, firstDot), null);
return ConditionsRule.GeoCode.of(stringGeoCode.substring(0, firstDot), null);
}

return GeoRule.GeoCode.of(
return ConditionsRule.GeoCode.of(
stringGeoCode.substring(0, firstDot),
stringGeoCode.substring(firstDot + 1));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.List;
import java.util.Set;

public final class GeoRule extends AbstractMatchRule implements Loggable {
public final class ConditionsRule extends AbstractMatchRule implements Loggable {

private final Set<ComponentType> componentTypes;
private final Set<String> componentNames;
Expand All @@ -22,12 +22,12 @@ public final class GeoRule extends AbstractMatchRule implements Loggable {
private final String gpc;
private final boolean allowed;

public GeoRule(Set<ComponentType> componentTypes,
Set<String> componentNames,
boolean sidsMatched,
List<GeoCode> geoCodes,
String gpc,
boolean allowed) {
public ConditionsRule(Set<ComponentType> componentTypes,
Set<String> componentNames,
boolean sidsMatched,
List<GeoCode> geoCodes,
String gpc,
boolean allowed) {

this.componentTypes = componentTypes;
this.componentNames = componentNames;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/prebid/server/floors/PriceFloorFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ private static AccountPriceFloorsFetchConfig getFetchConfig(Account account) {
}

private void fetchPriceFloorDataAsynchronous(AccountPriceFloorsFetchConfig fetchConfig, String accountId) {
final Long accountTimeout = ObjectUtil.getIfNotNull(fetchConfig, AccountPriceFloorsFetchConfig::getTimeout);
final Long accountTimeout = ObjectUtil.getIfNotNull(fetchConfig, AccountPriceFloorsFetchConfig::getTimeoutMs);
final Long timeout = ObjectUtils.firstNonNull(
ObjectUtil.getIfNotNull(debugProperties, PriceFloorDebugProperties::getMinTimeoutMs),
ObjectUtil.getIfNotNull(debugProperties, PriceFloorDebugProperties::getMaxTimeoutMs),
accountTimeout);
final Long maxFetchFileSizeKb =
ObjectUtil.getIfNotNull(fetchConfig, AccountPriceFloorsFetchConfig::getMaxFileSize);
ObjectUtil.getIfNotNull(fetchConfig, AccountPriceFloorsFetchConfig::getMaxFileSizeKb);
final String fetchUrl = fetchConfig.getUrl();

fetchInProgress.add(accountId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static void validatePriceFloorsFetchConfig(AccountPriceFloorsFetchConfig
throw new PreBidException(invalidPriceFloorsPropertyMessage("period-sec", periodicSec));
}

final Long timeout = fetchConfig.getTimeout();
final Long timeout = fetchConfig.getTimeoutMs();
if (timeout != null && isNotInRange(timeout, MIN_TIMEOUT_MS_VALUE, MAX_TIMEOUT_MS_VALUE)) {
throw new PreBidException(invalidPriceFloorsPropertyMessage("timeout-ms", timeout));
}
Expand All @@ -108,7 +108,7 @@ private static void validatePriceFloorsFetchConfig(AccountPriceFloorsFetchConfig
throw new PreBidException(invalidPriceFloorsPropertyMessage("max-rules", maxRules));
}

final Long maxFileSize = fetchConfig.getMaxFileSize();
final Long maxFileSize = fetchConfig.getMaxFileSizeKb();
if (maxFileSize != null && isNotInRange(maxFileSize, MIN_FILE_SIZE_VALUE, MAX_FILE_SIZE_VALUE)) {
throw new PreBidException(invalidPriceFloorsPropertyMessage("max-file-size-kb", maxFileSize));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.prebid.server.hooks.execution.model;

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

Expand All @@ -11,5 +12,6 @@ public class ExecutionGroup {
Long timeout;

@JsonProperty("hook-sequence")
@JsonAlias("hook_sequence")
List<HookId> hookSequence;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package org.prebid.server.hooks.execution.model;

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

@Value(staticConstructor = "of")
public class HookId {

@JsonProperty("module-code")
@JsonAlias("module_code")
String moduleCode;

@JsonProperty("hook-impl-code")
@JsonAlias("hook_impl_code")
String hookImplCode;
}
Loading

0 comments on commit 1424524

Please sign in to comment.