Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align IVM parsing to other plugin parsing #218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -35,8 +37,32 @@ public static class IndexValueMakerConf{

private Map<String, Object> parameters;


@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, Object> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,19 @@ public class ConfigBasedIndexValueMakerFactory implements IndexValueMakerFactory
private CachedSupplier<List<IndexValueMaker>> indexers = CachedSupplier.runOnce(()->{
ObjectMapper mapper = new ObjectMapper();
List<IndexValueMaker> 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;
Expand Down