diff --git a/backend/src/main/java/com/bakdata/conquery/models/config/FormBackendConfig.java b/backend/src/main/java/com/bakdata/conquery/models/config/FormBackendConfig.java index d8845e24ee..591c398e12 100644 --- a/backend/src/main/java/com/bakdata/conquery/models/config/FormBackendConfig.java +++ b/backend/src/main/java/com/bakdata/conquery/models/config/FormBackendConfig.java @@ -23,6 +23,7 @@ import com.bakdata.conquery.models.config.auth.AuthenticationClientFilterProvider; import com.bakdata.conquery.models.config.auth.MultiInstancePlugin; import com.bakdata.conquery.models.datasets.Dataset; +import com.bakdata.conquery.models.forms.frontendconfiguration.FormConfigProvider; import com.bakdata.conquery.models.forms.frontendconfiguration.FormFrontendConfigInformation; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.ObjectMapper; @@ -97,7 +98,8 @@ public void initialize(ManagerNode managerNode) { managerNode.getEnvironment().healthChecks().register(getId(), externalApi.createHealthCheck()); // Register form configuration provider - managerNode.getFormScanner().registerFrontendFormConfigProvider(this::registerFormConfigs); + log.info("Registering frontend form config provider for '{}'", getId()); + managerNode.getFormScanner().registerFrontendFormConfigProvider(new FormConfigProvider(getId(), this::registerFormConfigs)); } diff --git a/backend/src/main/java/com/bakdata/conquery/models/forms/frontendconfiguration/FormConfigProvider.java b/backend/src/main/java/com/bakdata/conquery/models/forms/frontendconfiguration/FormConfigProvider.java new file mode 100644 index 0000000000..50eabfa6a9 --- /dev/null +++ b/backend/src/main/java/com/bakdata/conquery/models/forms/frontendconfiguration/FormConfigProvider.java @@ -0,0 +1,21 @@ +package com.bakdata.conquery.models.forms.frontendconfiguration; + +import java.util.function.Consumer; + +import com.google.common.collect.ImmutableCollection; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +/** + * Helper class to hold the identifier and the provider method for a form config provider + */ +@RequiredArgsConstructor +public class FormConfigProvider { + @Getter + private final String providerName; + private final Consumer> provider; + + public void addFormConfigs(ImmutableCollection.Builder collect) { + provider.accept(collect); + } +} diff --git a/backend/src/main/java/com/bakdata/conquery/models/forms/frontendconfiguration/FormScanner.java b/backend/src/main/java/com/bakdata/conquery/models/forms/frontendconfiguration/FormScanner.java index c6f2ffc4e0..7e544fbff9 100644 --- a/backend/src/main/java/com/bakdata/conquery/models/forms/frontendconfiguration/FormScanner.java +++ b/backend/src/main/java/com/bakdata/conquery/models/forms/frontendconfiguration/FormScanner.java @@ -6,11 +6,11 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Consumer; import javax.annotation.Nullable; @@ -21,11 +21,9 @@ import com.bakdata.conquery.models.config.FrontendConfig; import com.bakdata.conquery.models.config.ManualConfig; import com.bakdata.conquery.resources.admin.rest.AdminProcessor; -import com.bakdata.conquery.util.QueryUtils; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.TextNode; -import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; @@ -45,16 +43,16 @@ public class FormScanner extends Task { * task accounts the change. */ private final ConqueryConfig config; - private Consumer> providerChain = QueryUtils.getNoOpEntryPoint(); + private List formConfigProviders = new ArrayList<>(); public FormScanner(ConqueryConfig config) { super("form-scanner"); this.config = config; - registerFrontendFormConfigProvider(ResourceFormConfigProvider::accept); + registerFrontendFormConfigProvider(new FormConfigProvider("internal", ResourceFormConfigProvider::accept)); } - public synchronized void registerFrontendFormConfigProvider(Consumer> provider) { - providerChain = providerChain.andThen(provider); + public synchronized void registerFrontendFormConfigProvider(FormConfigProvider provider) { + formConfigProviders.add(provider); } @@ -70,6 +68,18 @@ public static Set getAllFormTypes() { @Override public void execute(Map> parameters, PrintWriter output) throws Exception { FRONTEND_FORM_CONFIGS = generateFEFormConfigMap(); + + if (output == null) { + // Not called from a request + return; + } + + // If called from a request, respond with findings + output.write("Registered forms:\n"); + for (String formId : FRONTEND_FORM_CONFIGS.keySet()) { + output.write(String.format("\t%s\n", formId)); + } + output.flush(); } private Map generateFEFormConfigMap() { @@ -170,19 +180,26 @@ private static Map> findBackendMappingClasses() { /** * Frontend form configurations can be provided from different sources. - * Each source must register a provider with {@link FormScanner#registerFrontendFormConfigProvider(Consumer)} beforehand. + * Each source must register a provider with {@link FormScanner#registerFrontendFormConfigProvider(FormConfigProvider)} beforehand. */ @SneakyThrows private List findFrontendFormConfigs() { final ImmutableList.Builder frontendConfigs = ImmutableList.builder(); - try { - providerChain.accept(frontendConfigs); - } - catch (Exception e) { - log.error("Unable to collect all frontend form configurations.", e); + log.trace("Begin collecting form frontend configurations"); + + for (FormConfigProvider formConfigProvider : formConfigProviders) { + + try { + formConfigProvider.addFormConfigs(frontendConfigs); + } + catch (Exception e) { + log.error("Unable to collect frontend form configurations from {}.", formConfigProvider.getProviderName(), e); + } } + + log.trace("Finished collecting form frontend configurations"); return frontendConfigs.build(); } diff --git a/backend/src/main/java/com/bakdata/conquery/models/forms/frontendconfiguration/ResourceFormConfigProvider.java b/backend/src/main/java/com/bakdata/conquery/models/forms/frontendconfiguration/ResourceFormConfigProvider.java index 6af48c0d0a..77c24a6d69 100644 --- a/backend/src/main/java/com/bakdata/conquery/models/forms/frontendconfiguration/ResourceFormConfigProvider.java +++ b/backend/src/main/java/com/bakdata/conquery/models/forms/frontendconfiguration/ResourceFormConfigProvider.java @@ -18,15 +18,15 @@ * In order to be found, the configuration file name must end with {@code *.frontend_conf.json}. */ @Slf4j -public class ResourceFormConfigProvider{ +public class ResourceFormConfigProvider { public static void accept(ImmutableCollection.Builder formConfigInfos) { ResourceList frontendConfigs = CPSTypeIdResolver.SCAN_RESULT - .getResourcesMatchingPattern(Pattern.compile(".*\\.frontend_conf\\.json")); - + .getResourcesMatchingPattern(Pattern.compile(".*\\.frontend_conf\\.json")); + for (Resource config : frontendConfigs) { - try (config){ - try(InputStream in = config.open()) { + try (config) { + try (InputStream in = config.open()) { JsonNode configTree = Jackson.MAPPER.reader().readTree(in); if (!configTree.isObject()) { log.warn("Expected '{}' to be an JSON object but was '{}'. Skipping registration.", config.getPath(), configTree.getNodeType());