From e62c65dca12608eeb6fab1bcc4ece314ea6b35b7 Mon Sep 17 00:00:00 2001 From: Tyler Peryea Date: Thu, 5 Oct 2023 16:17:03 -0400 Subject: [PATCH] align IVM parsing to other plugin parsing --- ...nfigBasedIndexValueMakerConfiguration.java | 46 +++++++++++++++---- .../ConfigBasedIndexValueMakerFactory.java | 29 ++++++------ 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/gsrs-spring-legacy-indexer/src/main/java/gsrs/indexer/ConfigBasedIndexValueMakerConfiguration.java b/gsrs-spring-legacy-indexer/src/main/java/gsrs/indexer/ConfigBasedIndexValueMakerConfiguration.java index 0589b40d..6cc5b33e 100644 --- a/gsrs-spring-legacy-indexer/src/main/java/gsrs/indexer/ConfigBasedIndexValueMakerConfiguration.java +++ b/gsrs-spring-legacy-indexer/src/main/java/gsrs/indexer/ConfigBasedIndexValueMakerConfiguration.java @@ -1,21 +1,23 @@ package gsrs.indexer; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; -import gsrs.springUtils.AutowireHelper; -import ix.core.search.text.IndexValueMaker; -import lombok.Data; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; + +import ix.core.search.text.IndexValueMaker; +import lombok.Data; @Configuration @ConfigurationProperties("gsrs.indexers") @@ -35,8 +37,32 @@ public static class IndexValueMakerConf{ private Map parameters; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private Map unknownParameters = new ConcurrentHashMap<>(); + + @JsonAnySetter + public void unknownSetter(String key, Object value){ + unknownParameters.put(key, value); + } + + public IndexValueMaker newIndexValueMaker(ObjectMapper mapper, ClassLoader classLoader) throws ClassNotFoundException { + + if(parameters !=null && !parameters.isEmpty()){ + return (IndexValueMaker) mapper.convertValue(parameters, indexer); + } + if(unknownParameters !=null && !unknownParameters.isEmpty()){ + return (IndexValueMaker) mapper.convertValue(unknownParameters, indexer); + + } + return (IndexValueMaker) mapper.convertValue(Collections.emptyMap(), indexer); + } + + + } + @Bean @ConditionalOnMissingBean @Order diff --git a/gsrs-spring-legacy-indexer/src/main/java/gsrs/indexer/ConfigBasedIndexValueMakerFactory.java b/gsrs-spring-legacy-indexer/src/main/java/gsrs/indexer/ConfigBasedIndexValueMakerFactory.java index 15c236c6..b024cc41 100644 --- a/gsrs-spring-legacy-indexer/src/main/java/gsrs/indexer/ConfigBasedIndexValueMakerFactory.java +++ b/gsrs-spring-legacy-indexer/src/main/java/gsrs/indexer/ConfigBasedIndexValueMakerFactory.java @@ -23,22 +23,19 @@ public class ConfigBasedIndexValueMakerFactory implements IndexValueMakerFactory private CachedSupplier> indexers = CachedSupplier.runOnce(()->{ ObjectMapper mapper = new ObjectMapper(); List ivms = confList.stream() - .map(c ->{ - IndexValueMaker indexer =null; - if(c.getParameters() !=null){ - indexer= (IndexValueMaker) mapper.convertValue(c.getParameters(), c.getIndexer()); - }else{ - try { - indexer= (IndexValueMaker) c.getIndexer().newInstance(); - } catch (Exception e) { - throw new IllegalStateException("error creating indexer for " + c, e); - } - } - if(indexer !=null) { - indexer = AutowireHelper.getInstance().autowireAndProxy(indexer); - } - return indexer; - }) + .map(c ->{ + try { + IndexValueMaker indexer = (IndexValueMaker)c.newIndexValueMaker(mapper, AutowireHelper.getInstance().getClassLoader()); + if(indexer !=null) { + indexer = AutowireHelper.getInstance().autowireAndProxy(indexer); + } + + return (IndexValueMaker)indexer; + } catch (Exception e) { + throw new IllegalStateException("error creating indexer for " + c, e); + } + + }) .filter(Objects::nonNull) .collect(Collectors.toList()); return ivms;