1 |
47707
|
michele.ar
|
package eu.dnetlib.msro.workflows.nodes.collect;
|
2 |
45395
|
michele.ar
|
|
3 |
45405
|
michele.ar
|
import java.util.List;
|
4 |
|
|
import java.util.stream.Collectors;
|
5 |
45395
|
michele.ar
|
|
6 |
|
|
import org.springframework.beans.BeansException;
|
7 |
46235
|
michele.ar
|
import org.springframework.context.ApplicationContext;
|
8 |
|
|
import org.springframework.context.ApplicationContextAware;
|
9 |
45853
|
michele.ar
|
import org.springframework.stereotype.Component;
|
10 |
45395
|
michele.ar
|
|
11 |
|
|
import eu.dnetlib.msro.workers.aggregation.collect.plugins.CollectorPlugin;
|
12 |
45405
|
michele.ar
|
import eu.dnetlib.msro.workers.aggregation.collect.plugins.DnetCollectorPlugin;
|
13 |
45395
|
michele.ar
|
|
14 |
45853
|
michele.ar
|
@Component
|
15 |
46235
|
michele.ar
|
public class CollectorPluginEnumerator implements ApplicationContextAware {
|
16 |
45395
|
michele.ar
|
|
17 |
46235
|
michele.ar
|
private ApplicationContext applicationContext;
|
18 |
45395
|
michele.ar
|
|
19 |
45405
|
michele.ar
|
public List<CollectorPlugin> getAll() {
|
20 |
46235
|
michele.ar
|
return applicationContext.getBeansOfType(CollectorPlugin.class)
|
21 |
45405
|
michele.ar
|
.values()
|
22 |
|
|
.stream()
|
23 |
|
|
.filter(o -> o.getClass().isAnnotationPresent(DnetCollectorPlugin.class))
|
24 |
|
|
.collect(Collectors.toList());
|
25 |
45395
|
michele.ar
|
}
|
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 |
45406
|
michele.ar
|
|
34 |
46235
|
michele.ar
|
@Override
|
35 |
|
|
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
|
36 |
|
|
this.applicationContext = applicationContext;
|
37 |
|
|
}
|
38 |
|
|
|
39 |
45395
|
michele.ar
|
}
|