-
Notifications
You must be signed in to change notification settings - Fork 181
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
Default account configuration and account status support #959
Changes from 4 commits
f9f9433
3dd6923
00cff33
00dd809
32e842c
afa15bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.prebid.server.settings; | ||
|
||
import io.vertx.core.Future; | ||
import org.prebid.server.execution.Timeout; | ||
import org.prebid.server.settings.model.Account; | ||
import org.prebid.server.settings.model.StoredDataResult; | ||
import org.prebid.server.settings.model.StoredResponseDataResult; | ||
|
||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
public class EnrichingApplicationSettings implements ApplicationSettings { | ||
|
||
private final ApplicationSettings delegate; | ||
private final Account defaultAccount; | ||
|
||
public EnrichingApplicationSettings(ApplicationSettings delegate, Account defaultAccount) { | ||
this.delegate = Objects.requireNonNull(delegate); | ||
this.defaultAccount = Objects.equals(Account.builder().build(), defaultAccount) ? null : defaultAccount; | ||
} | ||
|
||
@Override | ||
public Future<Account> getAccountById(String accountId, Timeout timeout) { | ||
final Future<Account> accountFuture = delegate.getAccountById(accountId, timeout); | ||
|
||
if (defaultAccount == null) { | ||
return accountFuture; | ||
} | ||
|
||
return accountFuture | ||
.map(account -> account.merge(defaultAccount)) | ||
.otherwise(Account.empty(accountId).merge(defaultAccount)); | ||
} | ||
|
||
@Override | ||
public Future<String> getAdUnitConfigById(String adUnitConfigId, Timeout timeout) { | ||
return delegate.getAdUnitConfigById(adUnitConfigId, timeout); | ||
} | ||
|
||
@Override | ||
public Future<StoredDataResult> getStoredData(String accountId, | ||
Set<String> requestIds, | ||
Set<String> impIds, | ||
Timeout timeout) { | ||
|
||
return delegate.getStoredData(accountId, requestIds, impIds, timeout); | ||
} | ||
|
||
@Override | ||
public Future<StoredResponseDataResult> getStoredResponses(Set<String> responseIds, Timeout timeout) { | ||
return delegate.getStoredResponses(responseIds, timeout); | ||
} | ||
|
||
@Override | ||
public Future<StoredDataResult> getAmpStoredData(String accountId, | ||
Set<String> requestIds, | ||
Set<String> impIds, | ||
Timeout timeout) { | ||
|
||
return delegate.getAmpStoredData(accountId, requestIds, impIds, timeout); | ||
} | ||
|
||
@Override | ||
public Future<StoredDataResult> getVideoStoredData(String accountId, | ||
Set<String> requestIds, | ||
Set<String> impIds, | ||
Timeout timeout) { | ||
|
||
return delegate.getVideoStoredData(accountId, requestIds, impIds, timeout); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.prebid.server.settings.model; | ||
|
||
public enum AccountStatus { | ||
|
||
active, inactive | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.prebid.server.spring.config.model; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.prebid.server.json.JacksonMapper; | ||
import org.prebid.server.settings.model.Account; | ||
import org.prebid.server.settings.model.AccountAnalyticsConfig; | ||
import org.prebid.server.settings.model.AccountGdprConfig; | ||
import org.prebid.server.settings.model.AccountStatus; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
@Validated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this annotation required ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. It's been copied along with other annotations that we put on Spring configuration properties POJOs but apparently there are no constraints imposed on any fields in this class so it's redundant. We may put sensible constraints in future and easily overlook adding |
||
@Data | ||
@NoArgsConstructor | ||
public class AccountConfigurationProperties { | ||
|
||
private String priceGranularity; | ||
|
||
private Integer bannerCacheTtl; | ||
|
||
private Integer videoCacheTtl; | ||
|
||
private Boolean eventsEnabled; | ||
|
||
private Boolean enforceCcpa; | ||
|
||
private String gdpr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why cant we use AccountGdprConfig class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we don't want to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably you mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably my mistake. I copy from GdprConfig which we get from yaml. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's a convention for value objects throughout PBS codebase to aspire for immutability unless it is impractical. Another reason to take into consideration - using |
||
|
||
private Integer analyticsSamplingFactor; | ||
|
||
private Integer truncateTargetAttr; | ||
|
||
private String defaultIntegration; | ||
|
||
private String analyticsConfig; | ||
|
||
private AccountStatus status; | ||
|
||
public Account toAccount(JacksonMapper mapper) { | ||
return Account.builder() | ||
.priceGranularity(getPriceGranularity()) | ||
.bannerCacheTtl(getBannerCacheTtl()) | ||
.videoCacheTtl(getVideoCacheTtl()) | ||
.eventsEnabled(getEventsEnabled()) | ||
.enforceCcpa(getEnforceCcpa()) | ||
.gdpr(toModel(mapper, getGdpr(), AccountGdprConfig.class)) | ||
.analyticsSamplingFactor(getAnalyticsSamplingFactor()) | ||
.truncateTargetAttr(getTruncateTargetAttr()) | ||
.defaultIntegration(getDefaultIntegration()) | ||
.analyticsConfig(toModel(mapper, getAnalyticsConfig(), AccountAnalyticsConfig.class)) | ||
.status(getStatus()) | ||
.build(); | ||
} | ||
|
||
private static <T> T toModel(JacksonMapper mapper, String source, Class<T> targetClass) { | ||
return source != null ? mapper.decodeValue(source, targetClass) : null; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor. i'd rather suggest to use
ObjectUtils.defaultIfNull(..)
instead since we have only 2 possible values.