1
|
package eu.dnetlib.msro.workers.aggregation.collect;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.stream.Collectors;
|
5
|
|
6
|
import org.springframework.beans.BeansException;
|
7
|
import org.springframework.beans.factory.BeanFactory;
|
8
|
import org.springframework.beans.factory.BeanFactoryAware;
|
9
|
import org.springframework.beans.factory.ListableBeanFactory;
|
10
|
import org.springframework.web.bind.annotation.RequestMapping;
|
11
|
import org.springframework.web.bind.annotation.RestController;
|
12
|
|
13
|
import eu.dnetlib.msro.workers.aggregation.collect.plugins.CollectorPlugin;
|
14
|
import eu.dnetlib.msro.workers.aggregation.collect.plugins.DnetCollectorPlugin;
|
15
|
|
16
|
@RestController
|
17
|
@RequestMapping("/collector")
|
18
|
public class CollectorPluginEnumerator implements BeanFactoryAware {
|
19
|
|
20
|
// private static final Log log = LogFactory.getLog(CollectorPluginEnumerator.class); // NOPMD by marko on 11/24/08 5:02 PM
|
21
|
|
22
|
/**
|
23
|
* bean factory.
|
24
|
*/
|
25
|
private ListableBeanFactory beanFactory;
|
26
|
|
27
|
/**
|
28
|
* Get all beans implementing the CollectorPlugin interface.
|
29
|
*
|
30
|
* @return
|
31
|
*/
|
32
|
@RequestMapping("/plugins")
|
33
|
public List<CollectorPlugin> getAll() {
|
34
|
return beanFactory.getBeansOfType(CollectorPlugin.class)
|
35
|
.values()
|
36
|
.stream()
|
37
|
.filter(o -> o.getClass().isAnnotationPresent(DnetCollectorPlugin.class))
|
38
|
.collect(Collectors.toList());
|
39
|
}
|
40
|
|
41
|
public ListableBeanFactory getBeanFactory() {
|
42
|
return beanFactory;
|
43
|
}
|
44
|
|
45
|
@Override
|
46
|
public void setBeanFactory(final BeanFactory beanFactory) throws BeansException {
|
47
|
this.beanFactory = (ListableBeanFactory) beanFactory;
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Get given CollectorPlugin or throws exception.
|
52
|
*
|
53
|
* @param protocol
|
54
|
* @return
|
55
|
* @throws CollectException
|
56
|
*/
|
57
|
public CollectorPlugin get(final String protocol) throws CollectException {
|
58
|
for (final CollectorPlugin cp : getAll()) {
|
59
|
if (protocol.equalsIgnoreCase(cp.getProtocol())) { return cp; }
|
60
|
}
|
61
|
throw new CollectException("plugin not found for protocol: " + protocol);
|
62
|
}
|
63
|
|
64
|
}
|