1
|
package eu.dnetlib.index.solr.client;
|
2
|
|
3
|
import java.lang.reflect.Type;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
7
|
import org.springframework.beans.factory.annotation.Required;
|
8
|
|
9
|
import com.google.common.reflect.TypeToken;
|
10
|
import com.google.gson.Gson;
|
11
|
|
12
|
import eu.dnetlib.clients.index.client.AbstractIndexClientFactory;
|
13
|
import eu.dnetlib.clients.index.client.IndexClient;
|
14
|
import eu.dnetlib.clients.index.client.IndexClientException;
|
15
|
import eu.dnetlib.clients.index.client.IndexClientFactory;
|
16
|
import eu.dnetlib.index.query.SolrIndexQueryFactory;
|
17
|
import eu.dnetlib.index.query.SolrIndexQueryResponseFactory;
|
18
|
import eu.dnetlib.index.solr.cql.SolrTypeBasedCqlValueTransformerMapFactory;
|
19
|
import eu.dnetlib.utils.MetadataReference;
|
20
|
import eu.dnetlib.utils.MetadataReferenceFactory;
|
21
|
|
22
|
/**
|
23
|
* The Class SolrIndexClientFactory.
|
24
|
*/
|
25
|
public class SolrIndexClientFactory extends AbstractIndexClientFactory implements IndexClientFactory {
|
26
|
|
27
|
/** The id. */
|
28
|
private static String ID = "id";
|
29
|
|
30
|
/** The configuration. */
|
31
|
private String configuration;
|
32
|
|
33
|
/** The type token. */
|
34
|
protected Type typeToken = new TypeToken<Map<String, String>>() {}.getType();
|
35
|
|
36
|
/** The service properties. */
|
37
|
private Map<String, String> serviceProperties;
|
38
|
|
39
|
@Autowired
|
40
|
private SolrIndexQueryFactory solrIndexQueryFactory;
|
41
|
|
42
|
@Autowired
|
43
|
private SolrIndexQueryResponseFactory solrIndexQueryResponseFactory;
|
44
|
|
45
|
@Autowired
|
46
|
private SolrTypeBasedCqlValueTransformerMapFactory tMapFactory;
|
47
|
|
48
|
/**
|
49
|
* Inits the class.
|
50
|
*
|
51
|
* @throws IndexClientException
|
52
|
* the index client exception
|
53
|
*/
|
54
|
@Override
|
55
|
public void init() throws IndexClientException {
|
56
|
try {
|
57
|
serviceProperties = new Gson().fromJson(getConfiguration(), typeToken);
|
58
|
} catch (Throwable e) {
|
59
|
throw new IndexClientException("unable to parse configuration: " + getConfiguration(), e);
|
60
|
}
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* {@inheritDoc}
|
65
|
*
|
66
|
* @see IndexClientFactory#getBackendId()
|
67
|
*/
|
68
|
@Override
|
69
|
public String getBackendId() {
|
70
|
return serviceProperties.get(SolrIndexClientFactory.ID);
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* {@inheritDoc}
|
75
|
*
|
76
|
* @throws IndexClientException
|
77
|
*
|
78
|
* @see IndexClientFactory#getClient(String, String, String)
|
79
|
*/
|
80
|
@Override
|
81
|
public IndexClient getClient(final String format, final String layout, final String interpretation) throws IndexClientException {
|
82
|
return new SolrIndexClient(format, layout, interpretation, isQueryTools.getIndexProperties(getBackendId()), solrIndexQueryFactory,
|
83
|
solrIndexQueryResponseFactory, tMapFactory);
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* {@inheritDoc}
|
88
|
*
|
89
|
* @throws IndexClientException
|
90
|
*
|
91
|
* @see IndexClientFactory#getClient(MetadataReference)
|
92
|
*/
|
93
|
@Override
|
94
|
public IndexClient getClient(final MetadataReference mdRef) throws IndexClientException {
|
95
|
return getClient(mdRef.getFormat(), mdRef.getLayout(), mdRef.getInterpretation());
|
96
|
}
|
97
|
|
98
|
@Override
|
99
|
public IndexClient getClient(final String collection) throws IndexClientException {
|
100
|
return getClient(MetadataReferenceFactory.decodeMetadata(collection));
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* Gets the configuration.
|
105
|
*
|
106
|
* @return the configuration
|
107
|
*/
|
108
|
public String getConfiguration() {
|
109
|
return configuration;
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* Sets the configuration.
|
114
|
*
|
115
|
* @param configuration
|
116
|
* the configuration
|
117
|
*/
|
118
|
@Required
|
119
|
public void setConfiguration(final String configuration) {
|
120
|
this.configuration = configuration;
|
121
|
}
|
122
|
|
123
|
}
|