From e75bd8ae1af783d855a1ae6d1ccf5c5080a0d771 Mon Sep 17 00:00:00 2001 From: Sachin Karve Date: Mon, 1 Jul 2024 13:23:42 -0700 Subject: [PATCH] making preProcessors an array in services of configFile --- .../com/meta/cp4m/ServiceConfiguration.java | 10 ++++----- .../cp4m/configuration/RootConfiguration.java | 21 ++++++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/meta/cp4m/ServiceConfiguration.java b/src/main/java/com/meta/cp4m/ServiceConfiguration.java index 7ae14bc..44602fb 100644 --- a/src/main/java/com/meta/cp4m/ServiceConfiguration.java +++ b/src/main/java/com/meta/cp4m/ServiceConfiguration.java @@ -19,7 +19,7 @@ public class ServiceConfiguration { private final String handler; private final @Nullable String store; private final String plugin; - private final @Nullable String preProcessor; + private final @Nullable String[] preProcessors; @JsonCreator ServiceConfiguration( @@ -27,7 +27,7 @@ public class ServiceConfiguration { @JsonProperty("handler") String handler, @JsonProperty("store") @Nullable String store, @JsonProperty("plugin") String plugin, - @JsonProperty("pre_processor") @Nullable String preProcessor) { + @JsonProperty("pre_processors") @Nullable String[] preProcessors) { Preconditions.checkArgument( webhookPath != null && webhookPath.startsWith("/"), "webhook_path must be present and it must start with a forward slash (/)"); @@ -35,15 +35,15 @@ public class ServiceConfiguration { this.handler = Objects.requireNonNull(handler, "handler must be present"); this.store = store; this.plugin = Objects.requireNonNull(plugin, "plugin must be present"); - this.preProcessor = preProcessor; + this.preProcessors = preProcessors; } public String webhookPath() { return webhookPath; } - public String preProcessor() { - return preProcessor; + public String[] preProcessors() { + return preProcessors; } public String handler() { diff --git a/src/main/java/com/meta/cp4m/configuration/RootConfiguration.java b/src/main/java/com/meta/cp4m/configuration/RootConfiguration.java index 805809b..0767bf4 100644 --- a/src/main/java/com/meta/cp4m/configuration/RootConfiguration.java +++ b/src/main/java/com/meta/cp4m/configuration/RootConfiguration.java @@ -20,10 +20,8 @@ import com.meta.cp4m.store.ChatStore; import com.meta.cp4m.store.NullStore; import com.meta.cp4m.store.StoreConfig; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; + +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import org.checkerframework.checker.nullness.qual.Nullable; @@ -43,7 +41,7 @@ public class RootConfiguration { @JsonProperty("plugins") Collection plugins, @JsonProperty("stores") @Nullable Collection stores, @JsonProperty("handlers") Collection handlers, - @JsonProperty("preProcessors") @Nullable Collection preProcessors, + @JsonProperty("pre_processors") @Nullable Collection preProcessors, @JsonProperty("services") Collection services, @JsonProperty("port") @Nullable Integer port, @JsonProperty("heartbeat_path") @Nullable String heartbeatPath) { @@ -148,9 +146,16 @@ private Service createService( } PreProcessor preProcessor; - if(serviceConfig.preProcessor() != null){ - preProcessor = preProcessors.get(serviceConfig.preProcessor()).toPreProcessor(); - return new Service<>(store, handler, plugin, List.of(preProcessor), serviceConfig.webhookPath()); + List> preProcessorsList = new ArrayList<>(); + + if(serviceConfig.preProcessors() != null){ + String[] preProcessorNames = serviceConfig.preProcessors(); + for (String i : preProcessorNames) { + preProcessor = preProcessors.get(i).toPreProcessor(); + preProcessorsList.add(preProcessor); + } + + return new Service<>(store, handler, plugin, preProcessorsList, serviceConfig.webhookPath()); } else { // TODO: flow never goes into else. Need to debug why method inherits container annotation return new Service<>(store, handler, plugin, serviceConfig.webhookPath());