gsrs.indexer.ConfigBasedIndexValueMakerFactory Maven / Gradle / Ivy
The newest version!
package gsrs.indexer;
import com.fasterxml.jackson.databind.ObjectMapper;
import gov.nih.ncats.common.util.CachedSupplier;
import gsrs.springUtils.AutowireHelper;
import ix.core.search.text.CombinedIndexValueMaker;
import ix.core.search.text.IndexValueMaker;
import ix.core.search.text.ReflectingIndexValueMaker;
import ix.core.util.EntityUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
public class ConfigBasedIndexValueMakerFactory implements IndexValueMakerFactory{
private ReflectingIndexValueMaker reflectingIndexValueMaker = new ReflectingIndexValueMaker();
private List confList;
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;
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
return ivms;
});
private CachedSupplier