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) throws IndexServiceException {
|
50
|
final StringTemplate conf = new StringTemplate(getSolrConfig()
|
51
|
.getTemplate());
|
52
|
for (Entry<String, String> e : filter(params).entrySet()) {
|
53
|
log.debug("setting conf property [" + e.getKey() + ":"
|
54
|
+ e.getValue() + "]");
|
55
|
conf.setAttribute(e.getKey(), e.getValue());
|
56
|
}
|
57
|
return conf.toString();
|
58
|
}
|
59
|
|
60
|
private Map<String, String> filter(final Map<String, String> params) {
|
61
|
return Maps.filterKeys(params, input -> CONFIG_PARAMS.isValid(input));
|
62
|
}
|
63
|
|
64
|
public StringTemplate getSolrConfig() {
|
65
|
return solrConfig;
|
66
|
}
|
67
|
|
68
|
@Required
|
69
|
public void setSolrConfig(final StringTemplate solrConfig) {
|
70
|
this.solrConfig = solrConfig;
|
71
|
}
|
72
|
|
73
|
}
|