1
|
package eu.dnetlib.msro.workflows.nodes.collect;
|
2
|
|
3
|
import java.util.Set;
|
4
|
import java.util.stream.Stream;
|
5
|
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
7
|
import org.springframework.stereotype.Component;
|
8
|
|
9
|
import com.google.common.collect.Sets;
|
10
|
|
11
|
import eu.dnetlib.msro.workers.aggregation.collect.plugins.CollectorPlugin;
|
12
|
import eu.dnetlib.msro.workers.aggregation.objects.InterfaceDescriptor;
|
13
|
|
14
|
@Component
|
15
|
public class MetadataCollector {
|
16
|
|
17
|
@Autowired
|
18
|
private CollectorPluginEnumerator collectorPluginEnumerator;
|
19
|
|
20
|
public Stream<String> collect(final InterfaceDescriptor ifDescriptor) throws CollectException {
|
21
|
return dateRangeCollect(ifDescriptor, null, null);
|
22
|
}
|
23
|
|
24
|
public Stream<String> dateRangeCollect(
|
25
|
final InterfaceDescriptor ifDescriptor, final String from, final String until)
|
26
|
throws CollectException {
|
27
|
final CollectorPlugin plugin = collectorPluginEnumerator.get(ifDescriptor.getProtocol());
|
28
|
|
29
|
if (!verifyParams(ifDescriptor.getParams().keySet(), Sets.newHashSet(plugin.listNameParameters()))) { throw new CollectException(
|
30
|
"Invalid parameters, valid: " + plugin.listNameParameters() + ", current: " + ifDescriptor.getParams().keySet()); }
|
31
|
|
32
|
return plugin.collect(ifDescriptor, from, until);
|
33
|
}
|
34
|
|
35
|
private boolean verifyParams(final Set<String> curr, final Set<String> valid) {
|
36
|
return valid.containsAll(curr);
|
37
|
}
|
38
|
}
|