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 com.google.common.collect.Maps;
7
import eu.dnetlib.data.provision.index.rmi.IndexServiceException;
8
import org.antlr.stringtemplate.StringTemplate;
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11
import org.springframework.beans.factory.annotation.Required;
12

    
13
public class IndexConfigFactory {
14

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

    
23
	public enum CONFIG_PARAMS {
24
		// TODO replace with actual values
25
		luceneMatchVersion;
26

    
27
		static boolean isValid(final String v) {
28
			try {
29
				CONFIG_PARAMS.valueOf(v);
30
				return true;
31
			} catch (Throwable e) {
32
				return false;
33
			}
34
		}
35
	};
36

    
37
	/**
38
	 * Index configuration template.
39
	 */
40
	private StringTemplate solrConfig;
41

    
42
	/**
43
	 * @param params
44
	 *            input document
45
	 * @return the application of the schemaXslt transformation to the docIn
46
	 *         document
47
	 * @throws IndexServiceException
48
	 */
49
	public String getConfig(final Map<String, String> params)
50
			throws IndexServiceException {
51
		final StringTemplate conf = new StringTemplate(getSolrConfig()
52
				.getTemplate());
53
		for (Entry<String, String> e : filter(params).entrySet()) {
54
			log.debug("setting conf property [" + e.getKey() + ":"
55
					+ e.getValue() + "]");
56
			conf.setAttribute(e.getKey(), e.getValue());
57
		}
58
		return conf.toString();
59
	}
60

    
61
	private Map<String, String> filter(final Map<String, String> params) {
62
		return Maps.filterKeys(params, input -> CONFIG_PARAMS.isValid(input));
63
	}
64

    
65
	public StringTemplate getSolrConfig() {
66
		return solrConfig;
67
	}
68

    
69
	@Required
70
	public void setSolrConfig(final StringTemplate solrConfig) {
71
		this.solrConfig = solrConfig;
72
	}
73

    
74
}
(1-1/4)