Project

General

Profile

1
package eu.dnetlib.functionality.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.base.Predicate;
12
import com.google.common.collect.Maps;
13

    
14
import eu.dnetlib.data.provision.index.rmi.IndexServiceException;
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 docIn
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)
68
			throws IndexServiceException {
69
		final StringTemplate conf = new StringTemplate(getSolrConfig()
70
				.getTemplate());
71
		for (Entry<String, String> e : filter(params).entrySet()) {
72
			log.debug("setting conf property [" + e.getKey() + ":"
73
					+ e.getValue() + "]");
74
			conf.setAttribute(e.getKey(), e.getValue());
75
		}
76
		return conf.toString();
77
	}
78

    
79
	private Map<String, String> filter(final Map<String, String> params) {
80
		return Maps.filterKeys(params, new Predicate<String>() {
81

    
82
			@Override
83
			public boolean apply(final String input) {
84
				return CONFIG_PARAMS.isValid(input);
85
			}
86
		});
87
	}
88

    
89
	public StringTemplate getSolrConfig() {
90
		return solrConfig;
91
	}
92

    
93
	@Required
94
	public void setSolrConfig(final StringTemplate solrConfig) {
95
		this.solrConfig = solrConfig;
96
	}
97

    
98
}
(1-1/4)