Skip to content

Commit

Permalink
making preProcessors an array in services of configFile
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachin Karve committed Jul 1, 2024
1 parent 0bfacf3 commit e75bd8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/meta/cp4m/ServiceConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ 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(
@JsonProperty("webhook_path") String webhookPath,
@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 (/)");
this.webhookPath = webhookPath;
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() {
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/com/meta/cp4m/configuration/RootConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,7 +41,7 @@ public class RootConfiguration {
@JsonProperty("plugins") Collection<PluginConfig> plugins,
@JsonProperty("stores") @Nullable Collection<StoreConfig> stores,
@JsonProperty("handlers") Collection<HandlerConfig> handlers,
@JsonProperty("preProcessors") @Nullable Collection<PreProcessorConfig> preProcessors,
@JsonProperty("pre_processors") @Nullable Collection<PreProcessorConfig> preProcessors,
@JsonProperty("services") Collection<ServiceConfiguration> services,
@JsonProperty("port") @Nullable Integer port,
@JsonProperty("heartbeat_path") @Nullable String heartbeatPath) {
Expand Down Expand Up @@ -148,9 +146,16 @@ private <T extends Message> Service<T> createService(
}

PreProcessor<T> preProcessor;
if(serviceConfig.preProcessor() != null){
preProcessor = preProcessors.get(serviceConfig.preProcessor()).toPreProcessor();
return new Service<>(store, handler, plugin, List.of(preProcessor), serviceConfig.webhookPath());
List<PreProcessor<T>> 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());
Expand Down

0 comments on commit e75bd8a

Please sign in to comment.