Project

General

Profile

1
package eu.dnetlib.index.utils;
2

    
3
import java.util.Map;
4
import java.util.Map.Entry;
5

    
6
import org.antlr.stringtemplate.StringTemplate;
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9
import org.springframework.beans.factory.annotation.Required;
10

    
11
import com.google.common.collect.Maps;
12

    
13
import eu.dnetlib.rmi.provision.IndexServiceException;
14

    
15

    
16
public class IndexConfigFactory {
17

    
18
	private static final Log log = LogFactory.getLog(IndexConfigFactory.class); // NOPMD
19
																				// by
20
																				// marko
21
																				// on
22
																				// 11/24/08
23
																				// 5:02
24
																				// PM
25

    
26
	public enum CONFIG_PARAMS {
27
		// TODO replace with actual values
28
		luceneMatchVersion,
29
		serverLibPath,
30
		filterCacheSize,
31
		filterCacheInitialSize,
32
		queryCacheSize,
33
		queryCacheInitialSize,
34
		documentCacheSize,
35
		documentCacheInitialSize,
36
		queryResultWindowSize,
37
		queryResultMaxDocCached,
38
		ramBufferSizeMB,
39
		mergeFactor,
40
		termIndexInterval,
41
		autosoftcommit,
42
		autocommit,
43
		maxIndexingThreads;
44

    
45
		static boolean isValid(final String v) {
46
			try {
47
				CONFIG_PARAMS.valueOf(v);
48
				return true;
49
			} catch (Throwable e) {
50
				return false;
51
			}
52
		}
53
	};
54

    
55
	/**
56
	 * Index configuration template.
57
	 */
58
	private StringTemplate solrConfig;
59

    
60
	/**
61
	 * @param params
62
	 *            input document
63
	 * @return the application of the schemaXslt transformation to the docIn
64
	 *         document
65
	 * @throws IndexServiceException
66
	 */
67
	public String getConfig(final Map<String, String> params) throws IndexServiceException {
68
		final StringTemplate conf = new StringTemplate(getSolrConfig()
69
				.getTemplate());
70
		for (Entry<String, String> e : filter(params).entrySet()) {
71
			log.debug("setting conf property [" + e.getKey() + ":"
72
					+ e.getValue() + "]");
73
			conf.setAttribute(e.getKey(), e.getValue());
74
		}
75
		return conf.toString();
76
	}
77

    
78
	private Map<String, String> filter(final Map<String, String> params) {
79
		return Maps.filterKeys(params, input -> CONFIG_PARAMS.isValid(input));
80
	}
81

    
82
	public StringTemplate getSolrConfig() {
83
		return solrConfig;
84
	}
85

    
86
	@Required
87
	public void setSolrConfig(final StringTemplate solrConfig) {
88
		this.solrConfig = solrConfig;
89
	}
90

    
91
}
(3-3/9)