1
|
package eu.dnetlib.msro.workflows.nodes.collect;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.stream.Collectors;
|
5
|
|
6
|
import org.springframework.beans.BeansException;
|
7
|
import org.springframework.context.ApplicationContext;
|
8
|
import org.springframework.context.ApplicationContextAware;
|
9
|
import org.springframework.stereotype.Component;
|
10
|
|
11
|
import eu.dnetlib.msro.workers.aggregation.collect.plugins.CollectorPlugin;
|
12
|
import eu.dnetlib.msro.workers.aggregation.collect.plugins.DnetCollectorPlugin;
|
13
|
|
14
|
@Component
|
15
|
public class CollectorPluginEnumerator implements ApplicationContextAware {
|
16
|
|
17
|
private ApplicationContext applicationContext;
|
18
|
|
19
|
public List<CollectorPlugin> getAll() {
|
20
|
return applicationContext.getBeansOfType(CollectorPlugin.class)
|
21
|
.values()
|
22
|
.stream()
|
23
|
.filter(o -> o.getClass().isAnnotationPresent(DnetCollectorPlugin.class))
|
24
|
.collect(Collectors.toList());
|
25
|
}
|
26
|
|
27
|
public CollectorPlugin get(final String protocol) throws CollectException {
|
28
|
for (final CollectorPlugin cp : getAll()) {
|
29
|
if (protocol.equalsIgnoreCase(cp.getProtocol())) { return cp; }
|
30
|
}
|
31
|
throw new CollectException("plugin not found for protocol: " + protocol);
|
32
|
}
|
33
|
|
34
|
@Override
|
35
|
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
|
36
|
this.applicationContext = applicationContext;
|
37
|
}
|
38
|
|
39
|
}
|