|
1 |
package eu.dnetlib.functionality.index;
|
|
2 |
|
|
3 |
import java.util.Map;
|
|
4 |
|
|
5 |
import org.springframework.beans.BeansException;
|
|
6 |
import org.springframework.beans.factory.BeanFactory;
|
|
7 |
import org.springframework.beans.factory.BeanFactoryAware;
|
|
8 |
import org.springframework.beans.factory.ListableBeanFactory;
|
|
9 |
|
|
10 |
import com.google.common.collect.Maps;
|
|
11 |
|
|
12 |
/**
|
|
13 |
* The Class IndexBackendEnumerator.
|
|
14 |
*/
|
|
15 |
public class IndexBackendEnumerator implements BeanFactoryAware {
|
|
16 |
|
|
17 |
/** The bean factory. */
|
|
18 |
private ListableBeanFactory beanFactory;
|
|
19 |
|
|
20 |
/**
|
|
21 |
* Gets the all.
|
|
22 |
*
|
|
23 |
* @return the all
|
|
24 |
*/
|
|
25 |
public Map<String, IndexBackendDescriptor> getAll() {
|
|
26 |
return beanFactory.getBeansOfType(IndexBackendDescriptor.class);
|
|
27 |
}
|
|
28 |
|
|
29 |
/**
|
|
30 |
* {@inheritDoc}
|
|
31 |
*
|
|
32 |
* @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
|
|
33 |
*/
|
|
34 |
@Override
|
|
35 |
public void setBeanFactory(final BeanFactory beanFactory) throws BeansException {
|
|
36 |
this.beanFactory = (ListableBeanFactory) beanFactory;
|
|
37 |
|
|
38 |
}
|
|
39 |
|
|
40 |
/**
|
|
41 |
* Gets the bean factory.
|
|
42 |
*
|
|
43 |
* @return the beanFactory
|
|
44 |
*/
|
|
45 |
public ListableBeanFactory getBeanFactory() {
|
|
46 |
return beanFactory;
|
|
47 |
}
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Gets the all protocols.
|
|
51 |
*
|
|
52 |
* @return the all protocols
|
|
53 |
*/
|
|
54 |
public Map<String, String> getAllProtocols() {
|
|
55 |
final Map<String, String> res = Maps.newHashMap();
|
|
56 |
for (IndexBackendDescriptor desc : getAll().values()) {
|
|
57 |
res.putAll(desc.getEndpoint());
|
|
58 |
}
|
|
59 |
return res;
|
|
60 |
}
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Gets the all service properties.
|
|
64 |
*
|
|
65 |
* @return the all service properties
|
|
66 |
*/
|
|
67 |
public Map<String, String> getAllServiceProperties() {
|
|
68 |
final Map<String, String> res = Maps.newHashMap();
|
|
69 |
for (IndexBackendDescriptor desc : getAll().values()) {
|
|
70 |
String name = desc.getEndpoint().get("name");
|
|
71 |
if (name == null) throw new IllegalStateException("Missing field name");
|
|
72 |
Map<String, String> currentProp = desc.getServiceProperties();
|
|
73 |
for (String key : currentProp.keySet()) {
|
|
74 |
// Append Prefix Name to each property key
|
|
75 |
res.put(name + ":" + key, currentProp.get(key));
|
|
76 |
}
|
|
77 |
}
|
|
78 |
return res;
|
|
79 |
}
|
|
80 |
|
|
81 |
}
|
Added descriptor for automatic discovery of the index service instance