diff --git a/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/config/GreenbidsRealTimeDataConfiguration.java b/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/config/GreenbidsRealTimeDataConfiguration.java index daa04bed859..a19c81a76c7 100644 --- a/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/config/GreenbidsRealTimeDataConfiguration.java +++ b/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/config/GreenbidsRealTimeDataConfiguration.java @@ -35,7 +35,7 @@ public class GreenbidsRealTimeDataConfiguration { @Bean - public DatabaseReader dbReader(GreenbidsRealTimeDataProperties properties) { + DatabaseReader dbReader(GreenbidsRealTimeDataProperties properties) { final File database = new File(properties.getGeoLiteCountryPath()); try { return new DatabaseReader.Builder(database).build(); @@ -45,7 +45,7 @@ public DatabaseReader dbReader(GreenbidsRealTimeDataProperties properties) { } @Bean - public GreenbidsInferenceDataService greenbidsInferenceDataService(DatabaseReader dbReader) { + GreenbidsInferenceDataService greenbidsInferenceDataService(DatabaseReader dbReader) { return new GreenbidsInferenceDataService(dbReader, ObjectMapperProvider.mapper()); } @@ -66,18 +66,18 @@ GreenbidsRealTimeDataModule greenbidsRealTimeDataModule( } @Bean - public FilterService filterService() { + FilterService filterService() { return new FilterService(); } @Bean - public Storage storage(GreenbidsRealTimeDataProperties properties) { + Storage storage(GreenbidsRealTimeDataProperties properties) { return StorageOptions.newBuilder() .setProjectId(properties.getGoogleCloudGreenbidsProject()).build().getService(); } @Bean - public ModelCache modelCache(GreenbidsRealTimeDataProperties properties, Vertx vertx, Storage storage) { + ModelCache modelCache(GreenbidsRealTimeDataProperties properties, Vertx vertx, Storage storage) { final Cache modelCacheWithExpiration = Caffeine.newBuilder() .expireAfterWrite(properties.getCacheExpirationMinutes(), TimeUnit.MINUTES) .build(); @@ -91,7 +91,7 @@ public ModelCache modelCache(GreenbidsRealTimeDataProperties properties, Vertx v } @Bean - public ThresholdCache thresholdCache( + ThresholdCache thresholdCache( GreenbidsRealTimeDataProperties properties, Vertx vertx, Storage storage) { @@ -110,7 +110,7 @@ public ThresholdCache thresholdCache( } @Bean - public OnnxModelRunnerWithThresholds onnxModelRunnerWithThresholds( + OnnxModelRunnerWithThresholds onnxModelRunnerWithThresholds( ModelCache modelCache, ThresholdCache thresholdCache) { @@ -118,7 +118,7 @@ public OnnxModelRunnerWithThresholds onnxModelRunnerWithThresholds( } @Bean - public GreenbidsInvocationService greenbidsInvocationService() { + GreenbidsInvocationService greenbidsInvocationService() { return new GreenbidsInvocationService(); } } diff --git a/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/model/predictor/FilterService.java b/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/model/predictor/FilterService.java index 36502b273b7..67a62cd05e6 100644 --- a/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/model/predictor/FilterService.java +++ b/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/model/predictor/FilterService.java @@ -8,6 +8,7 @@ import org.prebid.server.hooks.modules.greenbids.real.time.data.model.data.ThrottlingMessage; import org.springframework.util.CollectionUtils; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -54,33 +55,31 @@ private Map> processModelResults( validateThrottlingMessages(throttlingMessages); return StreamSupport.stream(results.spliterator(), false) - .filter(onnxItem -> { - validateOnnxTensor(onnxItem); - return Objects.equals(onnxItem.getKey(), "probabilities"); - }) - .map(onnxItem -> (OnnxTensor) onnxItem.getValue()) - .map(tensor -> { - validateTensorSize(tensor, throttlingMessages.size()); - return extractAndProcessProbabilities(tensor, throttlingMessages, threshold); - }) - .flatMap(map -> map.entrySet().stream()) + .peek(FilterService::validateOnnxTensor) + .filter(onnxItem -> Objects.equals(onnxItem.getKey(), "probabilities")) + .map(Map.Entry::getValue) + .map(OnnxTensor.class::cast) + .peek(tensor -> validateTensorSize(tensor, throttlingMessages.size())) + .map(tensor -> extractAndProcessProbabilities(tensor, throttlingMessages, threshold)) + .map(Map::entrySet) + .flatMap(Collection::stream) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } - private void validateThrottlingMessages(List throttlingMessages) { + private static void validateThrottlingMessages(List throttlingMessages) { if (throttlingMessages == null || CollectionUtils.isEmpty(throttlingMessages)) { throw new PreBidException("throttlingMessages cannot be null or empty"); } } - private void validateOnnxTensor(Map.Entry onnxItem) { + private static void validateOnnxTensor(Map.Entry onnxItem) { if (!(onnxItem.getValue() instanceof OnnxTensor)) { throw new PreBidException("Expected OnnxTensor for 'probabilities', but found: " + onnxItem.getValue().getClass().getName()); } } - private void validateTensorSize(OnnxTensor tensor, int expectedSize) { + private static void validateTensorSize(OnnxTensor tensor, int expectedSize) { final long[] tensorShape = tensor.getInfo().getShape(); if (tensorShape.length == 0 || tensorShape[0] != expectedSize) { throw new PreBidException("Mismatch between tensor size and throttlingMessages size"); diff --git a/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/v1/GreenbidsRealTimeDataProcessedAuctionRequestHook.java b/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/v1/GreenbidsRealTimeDataProcessedAuctionRequestHook.java index 7156762b0c3..c6beaddc70c 100644 --- a/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/v1/GreenbidsRealTimeDataProcessedAuctionRequestHook.java +++ b/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/v1/GreenbidsRealTimeDataProcessedAuctionRequestHook.java @@ -44,7 +44,7 @@ public class GreenbidsRealTimeDataProcessedAuctionRequestHook implements ProcessedAuctionRequestHook { - private static final String CODE = "greenbids-real-time-data-processed-auction-request-hook"; + private static final String CODE = "greenbids-real-time-data-processed-auction-request"; private static final String ACTIVITY = "greenbids-filter"; private static final String SUCCESS_STATUS = "success"; private static final String BID_REQUEST_ANALYTICS_EXTENSION_NAME = "greenbids-rtd"; @@ -151,7 +151,7 @@ private InvocationResult toInvocationResult( AnalyticsResult analyticsResult, InvocationAction action) { - final List analyticsResults = (analyticsResult != null) + final List analyticsResults = analyticsResult != null ? Collections.singletonList(analyticsResult) : Collections.emptyList();