Skip to content

Commit

Permalink
Change adapter -> name in analytics reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Nahornyi committed Apr 26, 2021
1 parent 0a966d5 commit fa556d0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface AnalyticsReporter {
int vendorId();

/**
* Method for defining adapter which is related to analytics reporter.
* Method for defining name of the related to this analytic adapter.
*/
String adapter();
String name();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebid;
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidAnalytic;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -27,14 +29,14 @@
public class AnalyticsReporterDelegator {

private static final Logger logger = LoggerFactory.getLogger(AnalyticsReporterDelegator.class);
private static final String RELATED_TO_ALL_ADAPTERS = "*";
private static final Set<String> ADAPTERS_PERMITTED_FOR_FULL_DATA = new HashSet<>(Arrays.asList("logAnalytics"));

private final List<AnalyticsReporter> delegates;
private final Vertx vertx;
private final PrivacyEnforcementService privacyEnforcementService;

private final Set<Integer> reporterVendorIds;
private final Set<String> reporterAdapters;
private final Set<String> reporterNames;

public AnalyticsReporterDelegator(List<AnalyticsReporter> delegates,
Vertx vertx,
Expand All @@ -44,7 +46,7 @@ public AnalyticsReporterDelegator(List<AnalyticsReporter> delegates,
this.privacyEnforcementService = Objects.requireNonNull(privacyEnforcementService);

reporterVendorIds = delegates.stream().map(AnalyticsReporter::vendorId).collect(Collectors.toSet());
reporterAdapters = delegates.stream().map(AnalyticsReporter::adapter).collect(Collectors.toSet());
reporterNames = delegates.stream().map(AnalyticsReporter::name).collect(Collectors.toSet());
}

public <T> void processEvent(T event) {
Expand All @@ -66,7 +68,7 @@ private <T> void delegateEvent(T event,
privacyEnforcementMapResult.result();
validateEvent(event);
for (AnalyticsReporter analyticsReporter : delegates) {
final T preparedEvent = prepareEvent(event, analyticsReporter.adapter());
final T preparedEvent = prepareEvent(event, analyticsReporter.name());
final int reporterVendorId = analyticsReporter.vendorId();
// resultForVendorIds is guaranteed returning for each provided value except null,
// but to be sure lets use getOrDefault
Expand Down Expand Up @@ -97,7 +99,7 @@ private void validateExtPrebidAnalytics(AuctionEvent auctionEvent) {
final List<ExtRequestPrebidAnalytic> analytics = extPrebid != null ? extPrebid.getAnalytics() : null;
final List<String> unknownAnalyticsAdapters = CollectionUtils.emptyIfNull(analytics).stream()
.map(ExtRequestPrebidAnalytic::getAdapter)
.filter(s -> !reporterAdapters.contains(s))
.filter(s -> !reporterNames.contains(s))
.collect(Collectors.toList());

if (CollectionUtils.isNotEmpty(unknownAnalyticsAdapters)) {
Expand All @@ -107,7 +109,7 @@ private void validateExtPrebidAnalytics(AuctionEvent auctionEvent) {
}

private <T> T prepareEvent(T event, String delegatorAdapter) {
if (!RELATED_TO_ALL_ADAPTERS.equals(delegatorAdapter) && event instanceof AuctionEvent) {
if (!ADAPTERS_PERMITTED_FOR_FULL_DATA.contains(delegatorAdapter) && event instanceof AuctionEvent) {
final AuctionEvent auctionEvent = (AuctionEvent) event;
final AuctionContext updatedAuctionContext =
updateAuctionContextForDelegator(auctionEvent.getAuctionContext(), delegatorAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public int vendorId() {
}

@Override
public String adapter() {
return "*";
public String name() {
return "logAnalytics";
}

@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public class AnalyticsReporterDelegatorTest {
public void setUp() {
firstReporter = mock(AnalyticsReporter.class);
given(firstReporter.vendorId()).willReturn(FIRST_REPORTER_ID);
given(firstReporter.adapter()).willReturn("*");
given(firstReporter.name()).willReturn("logAnalytics");

secondReporter = mock(AnalyticsReporter.class);
given(secondReporter.vendorId()).willReturn(SECOND_REPORTER_ID);
given(secondReporter.adapter()).willReturn("adapter");
given(secondReporter.name()).willReturn("adapter");

target = new AnalyticsReporterDelegator(asList(firstReporter, secondReporter), vertx,
privacyEnforcementService);
Expand Down

0 comments on commit fa556d0

Please sign in to comment.